TECA
The Toolkit for Extreme Climate Analysis
teca_vtk_util.h
Go to the documentation of this file.
1 #ifndef teca_vtk_util_h
2 #define teca_vtk_util_h
3 
4 /// @file
5 
6 #include "teca_config.h"
7 #include "teca_cartesian_mesh.h"
8 
9 #if defined(TECA_HAS_VTK) || defined(TECA_HAS_PARAVIEW)
10 #include "vtkFloatArray.h"
11 #include "vtkDoubleArray.h"
12 #include "vtkCharArray.h"
13 #include "vtkUnsignedCharArray.h"
14 #include "vtkShortArray.h"
15 #include "vtkUnsignedShortArray.h"
16 #include "vtkIntArray.h"
17 #include "vtkUnsignedIntArray.h"
18 #include "vtkLongArray.h"
19 #include "vtkUnsignedLongArray.h"
20 #include "vtkLongLongArray.h"
21 #include "vtkUnsignedLongLongArray.h"
22 #include "vtkPointData.h"
23 class vtkRectilinearGrid;
24 #else
25 using vtkFloatArray = void*;
26 using vtkDoubleArray = void*;
27 using vtkCharArray = void*;
28 using vtkUnsignedCharArray = void*;
29 using vtkShortArray = void*;
30 using vtkUnsignedShortArray = void*;
31 using vtkIntArray = void*;
32 using vtkUnsignedIntArray = void*;
33 using vtkLongArray = void*;
34 using vtkUnsignedLongArray = void*;
35 using vtkLongLongArray = void*;
36 using vtkUnsignedLongLongArray = void*;
37 class vtkRectilinearGrid;
38 #endif
39 
40 
41 /// Codes dealing with VTK
42 namespace teca_vtk_util
43 {
44 
45 /// @cond
46 
47 // traits class for naming and/or selecting
48 // the VTK type given a C++ type
49 template <typename T> struct TECA_EXPORT vtk_tt {};
50 #define VTK_TT_SPEC(_ctype, _ctypestr, _vtype, _fmt) \
51 template <> \
52 struct vtk_tt <_ctype> \
53 { \
54  using type = _vtype; \
55  \
56  static constexpr const char *str() \
57  { return #_ctypestr; } \
58  \
59  static constexpr const char *fmt() \
60  { return _fmt; } \
61 };
62 VTK_TT_SPEC(float, float, vtkFloatArray, "%g")
63 VTK_TT_SPEC(double, double, vtkDoubleArray, "%g")
64 VTK_TT_SPEC(char, char, vtkCharArray, "%hhi")
65 VTK_TT_SPEC(unsigned char, unsigned_char, vtkUnsignedCharArray, "%hhu")
66 VTK_TT_SPEC(short, short, vtkShortArray, "%hi")
67 VTK_TT_SPEC(unsigned short, unsigned_short, vtkUnsignedShortArray, "%hu")
68 VTK_TT_SPEC(int, int, vtkIntArray, "%i")
69 VTK_TT_SPEC(unsigned int, unsigned_int, vtkUnsignedIntArray, "%u")
70 VTK_TT_SPEC(long, long, vtkLongArray, "%li")
71 VTK_TT_SPEC(unsigned long, unsigned_long, vtkUnsignedLongArray, "%lu")
72 VTK_TT_SPEC(long long, long_long, vtkLongLongArray, "%lli")
73 VTK_TT_SPEC(unsigned long long, unsigned_long_long, vtkUnsignedLongLongArray, "%llu")
74 
75 /// @endcond
76 
77 /// deep copy input mesh into the VTK object. @returns 0 if successful
79 int deep_copy(vtkRectilinearGrid *output,
80  const_p_teca_cartesian_mesh input);
81 
82 
83 /** write spatio-temporal partitions as a VTK unstructured grid that can be
84  * visualized in ParaView
85  */
87 {
88 public:
89  /// create the writer
90  partition_writer(const std::string &file_name,
91  double x0, double y0, double t0,
92  double dx, double dy, double dt) :
93  m_file_name(file_name),
94  m_x0(x0), m_y0(y0), m_t0(t0),
95  m_dx(dx), m_dy(dy), m_dt(dt) {}
96 
97  /// add a partition
98  void add_partition(const unsigned long extent[6],
99  const unsigned long temporal_extent[2], int owner);
100 
101  /// write the vtk dataset
102  void write();
103 
104 private:
105  std::string m_file_name;
106  std::vector<double> m_points;
107  std::vector<long> m_cells;
108  std::vector<unsigned char> m_types;
109  std::vector<int> m_owner;
110  double m_x0;
111  double m_y0;
112  double m_t0;
113  double m_dx;
114  double m_dy;
115  double m_dt;
116 };
117 
118 
119 };
120 
121 #endif
Definition: teca_vtk_util.h:87
partition_writer(const std::string &file_name, double x0, double y0, double t0, double dx, double dy, double dt)
create the writer
Definition: teca_vtk_util.h:90
void write()
write the vtk dataset
void add_partition(const unsigned long extent[6], const unsigned long temporal_extent[2], int owner)
add a partition
p_teca_error_handler error_handler TECA_EXPORT
The global error handler instance.
Codes dealing with VTK.
Definition: teca_vtk_util.h:43
TECA_EXPORT int deep_copy(vtkRectilinearGrid *output, const_p_teca_cartesian_mesh input)
deep copy input mesh into the VTK object.