VTKFIG  0.25.0
Easy VTK based in situ visualization
vtkfigTools.h
Go to the documentation of this file.
1 
7 #ifndef VTKFIG_TOOLS_H
8 #define VTKFIG_TOOLS_H
9 
10 #include <vtkSmartPointer.h>
11 #include <vtkDelaunay2D.h>
12 #include <vtkDelaunay3D.h>
13 #include <vtkProperty.h>
14 #include <vtkIdList.h>
15 #include <vtkPolyDataMapper.h>
16 #include <vtkPoints.h>
17 #include <vtkPointData.h>
18 #include <vtkPolyData.h>
19 #include <vtkUnstructuredGrid.h>
20 #include <vtkPolyDataMapper.h>
21 #include <vtkPolyDataMapper.h>
22 #include <vtkLookupTable.h>
23 #include <vtkScalarBarActor.h>
24 
25 
26 namespace vtkfig
27 {
28 
32  void PrintOpenGLInfo(void);
33 
37  size_t NSpin();
38 
40  struct RGBPoint { double x,r,g,b;};
41 
43  typedef std::vector<RGBPoint> RGBTable;
44 
45 
47  template <class V0, class V, class IV> inline void Delaunay2D(const V0 & points_in, V & points, IV & cells);
48 
50  template <class V0, class V, class IV> inline void Delaunay3D(const V0 & points_in, V & points, IV & cells);
51 
52 
53  namespace internal
54  {
55 
57  vtkSmartPointer<vtkLookupTable> BuildLookupTable(RGBTable & xrgb, size_t size);
58 
60  vtkSmartPointer<vtkScalarBarActor> BuildColorBar(vtkSmartPointer<vtkPolyDataMapper> mapper, int irank=0);
61 
63  void PrintPoints(vtkSmartPointer<vtkPoints> pts, std::ostream & os);
64 
66  void PrintArray(vtkSmartPointer<vtkDataArray> data, std::ostream & os);
67 
68  }
69 
70  template <class V0, class V, class IV> inline void Delaunay2D(const V0 & points_in, V & points, IV & cells)
71  {
72  assert(points.size()==0);
73  assert(cells.size()==0);
74 
75  auto inpoints =vtkSmartPointer<vtkPoints>::New();
76 
77  for (size_t i=0; i<points_in.size(); i+=2)
78  inpoints->InsertNextPoint(points_in[i], points_in[i+1],0);
79 
80 
81  auto aPolyData= vtkSmartPointer<vtkPolyData>::New();
82  aPolyData->SetPoints(inpoints);
83 
84 
85  auto delaunay = vtkSmartPointer<vtkDelaunay2D>::New();
86  delaunay->SetInputData(aPolyData);
87 
88  auto dgrid=delaunay->GetOutput();
89  delaunay->Update();
90 
91  auto npoints=dgrid->GetNumberOfPoints();
92  auto ncells=dgrid->GetNumberOfPolys();
93 
94  auto vtkpoints=dgrid->GetPoints();
95  for (int i=0;i<npoints;i++)
96  {
97  double x[3];
98  vtkpoints->GetPoint(i,x);
99  points.push_back(x[0]);
100  points.push_back(x[1]);
101  }
102 
103  auto pts =vtkSmartPointer<vtkIdList>::New();
104 
105  for (vtkIdType i=0;i<ncells;i++)
106  {
107  dgrid->GetCellPoints(i,pts);
108  cells.push_back(pts->GetId(0));
109  cells.push_back(pts->GetId(1));
110  cells.push_back(pts->GetId(2));
111  }
112 
113  }
114 
115  template <class V0, class V, class IV> inline void Delaunay3D(const V0 & points_in, V & points, IV & cells)
116  {
117  assert(points.size()==0);
118  assert(cells.size()==0);
119 
120  auto inpoints = vtkSmartPointer<vtkPoints>::New();
121 
122  for (size_t i=0; i<points_in.size(); i+=3)
123  inpoints->InsertNextPoint(points_in[i], points_in[i+1], points_in[i+2]);
124 
125 
126 
127  auto aPolyData = vtkSmartPointer<vtkPolyData>::New();
128  aPolyData->SetPoints(inpoints);
129 
130 
131  auto delaunay = vtkSmartPointer<vtkDelaunay3D>::New();
132  delaunay->SetInputData(aPolyData);
133 
134  auto dgrid=delaunay->GetOutput();
135  delaunay->Update();
136 
137  auto npoints=dgrid->GetNumberOfPoints();
138  auto ncells=dgrid->GetNumberOfCells();
139 
140  auto vtkpoints=dgrid->GetPoints();
141  for (int i=0;i<npoints;i++)
142  {
143  double x[3];
144  vtkpoints->GetPoint(i,x);
145  points.push_back(x[0]);
146  points.push_back(x[1]);
147  points.push_back(x[2]);
148  }
149 
150  auto pts = vtkSmartPointer<vtkIdList>::New();
151 
152  for (vtkIdType i=0;i<ncells;i++)
153  {
154  dgrid->GetCellPoints(i,pts);
155  cells.push_back(pts->GetId(0));
156  cells.push_back(pts->GetId(1));
157  cells.push_back(pts->GetId(2));
158  cells.push_back(pts->GetId(3));
159  }
160 
161 
162  }
163 
164 
165 }
166 #define ___show(x) std::cout << #x << " = " << x << std::endl;
167 #endif
vtkfig::Delaunay2D
void Delaunay2D(const V0 &points_in, V &points, IV &cells)
Create a 2D Delaunay triangulation from point set.
Definition: vtkfigTools.h:70
vtkfig::Delaunay3D
void Delaunay3D(const V0 &points_in, V &points, IV &cells)
Create a 3D Delaunay triangulation from point set.
Definition: vtkfigTools.h:115
vtkfig::PrintOpenGLInfo
void PrintOpenGLInfo(void)
Print Open GL info to screen.
vtkfig::RGBPoint
RGB point struct for color tables.
Definition: vtkfigTools.h:40
vtkfig::NSpin
size_t NSpin()
Return content of environment variable VTKFIG_NSPIN or large value.
vtkfig::RGBTable
std::vector< RGBPoint > RGBTable
Color table.
Definition: vtkfigTools.h:43