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>
47 template <
class V0,
class V,
class IV>
inline void Delaunay2D(
const V0 & points_in, V & points, IV & cells);
50 template <
class V0,
class V,
class IV>
inline void Delaunay3D(
const V0 & points_in, V & points, IV & cells);
57 vtkSmartPointer<vtkLookupTable> BuildLookupTable(
RGBTable & xrgb,
size_t size);
60 vtkSmartPointer<vtkScalarBarActor> BuildColorBar(vtkSmartPointer<vtkPolyDataMapper> mapper,
int irank=0);
63 void PrintPoints(vtkSmartPointer<vtkPoints> pts, std::ostream & os);
66 void PrintArray(vtkSmartPointer<vtkDataArray> data, std::ostream & os);
70 template <
class V0,
class V,
class IV>
inline void Delaunay2D(
const V0 & points_in, V & points, IV & cells)
72 assert(points.size()==0);
73 assert(cells.size()==0);
75 auto inpoints =vtkSmartPointer<vtkPoints>::New();
77 for (
size_t i=0; i<points_in.size(); i+=2)
78 inpoints->InsertNextPoint(points_in[i], points_in[i+1],0);
81 auto aPolyData= vtkSmartPointer<vtkPolyData>::New();
82 aPolyData->SetPoints(inpoints);
85 auto delaunay = vtkSmartPointer<vtkDelaunay2D>::New();
86 delaunay->SetInputData(aPolyData);
88 auto dgrid=delaunay->GetOutput();
91 auto npoints=dgrid->GetNumberOfPoints();
92 auto ncells=dgrid->GetNumberOfPolys();
94 auto vtkpoints=dgrid->GetPoints();
95 for (
int i=0;i<npoints;i++)
98 vtkpoints->GetPoint(i,x);
99 points.push_back(x[0]);
100 points.push_back(x[1]);
103 auto pts =vtkSmartPointer<vtkIdList>::New();
105 for (vtkIdType i=0;i<ncells;i++)
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));
115 template <
class V0,
class V,
class IV>
inline void Delaunay3D(
const V0 & points_in, V & points, IV & cells)
117 assert(points.size()==0);
118 assert(cells.size()==0);
120 auto inpoints = vtkSmartPointer<vtkPoints>::New();
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]);
127 auto aPolyData = vtkSmartPointer<vtkPolyData>::New();
128 aPolyData->SetPoints(inpoints);
131 auto delaunay = vtkSmartPointer<vtkDelaunay3D>::New();
132 delaunay->SetInputData(aPolyData);
134 auto dgrid=delaunay->GetOutput();
137 auto npoints=dgrid->GetNumberOfPoints();
138 auto ncells=dgrid->GetNumberOfCells();
140 auto vtkpoints=dgrid->GetPoints();
141 for (
int i=0;i<npoints;i++)
144 vtkpoints->GetPoint(i,x);
145 points.push_back(x[0]);
146 points.push_back(x[1]);
147 points.push_back(x[2]);
150 auto pts = vtkSmartPointer<vtkIdList>::New();
152 for (vtkIdType i=0;i<ncells;i++)
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));
166 #define ___show(x) std::cout << #x << " = " << x << std::endl;