00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef VTKWRAP_TRIANGULATE_H
00022 #define VTKWRAP_TRIANGULATE_H
00023
00024 #include <cassert>
00025 #include <vector>
00026
00027 #include "numerical/meshgrid.h"
00028
00029 #include "vtkPoints.h"
00030 #include "vtkPolyData.h"
00031 #include "vtkDelaunay3D.h"
00032 #include "vtkUnstructuredGridWriter.h"
00033
00034 class Triangulate
00035 {
00036 public:
00037 Triangulate(double const * X,
00038 double const * Y,
00039 double const * Z, int Size, char const * Filename)
00040 : _use_vector(false), _npoints(Size), _filename(Filename), _X(X), _Y(Y), _Z(Z)
00041 {
00042 assert(Size>0);
00043 }
00044 Triangulate(std::vector<double> & X,
00045 std::vector<double> & Y,
00046 std::vector<double> & Z, char const * Filename)
00047 : _use_vector(true), _npoints(X.size()), _filename(Filename), _X(NULL), _Y(NULL), _Z(NULL), _vX(X), _vY(Y), _vZ(Z)
00048 {
00049 assert(X.size()>0);
00050 assert(X.size()==Y.size());
00051 assert(Y.size()==Z.size());
00052 }
00053 void Start();
00054 private:
00055 bool _use_vector;
00056 int _npoints;
00057 char const * _filename;
00058 double const * _X;
00059 double const * _Y;
00060 double const * _Z;
00061 std::vector<double> _vX;
00062 std::vector<double> _vY;
00063 std::vector<double> _vZ;
00064 };
00065
00066
00068
00069
00070 inline void Triangulate::Start()
00071 {
00072
00073 vtkPoints * points = vtkPoints::New();
00074 points->Allocate(_npoints);
00075 if (_use_vector)
00076 {
00077 for (int i=0; i<_npoints; ++i)
00078 {
00079 double P[3] = {_vX[i], _vY[i], _vZ[i]};
00080 points->InsertPoint(i,P);
00081 }
00082 }
00083 else
00084 {
00085 for (int i=0; i<_npoints; ++i)
00086 {
00087 double P[3] = {_X[i], _Y[i], _Z[i]};
00088 points->InsertPoint(i,P);
00089 }
00090 }
00091
00092
00093
00094
00095
00096
00097 vtkPolyData * vertices = vtkPolyData::New();
00098 vtkDelaunay3D * delaunay = vtkDelaunay3D::New();
00099 vertices -> SetPoints(points);
00100 delaunay -> SetInput(vertices);
00101 delaunay -> SetTolerance(0.01);
00102
00103 delaunay -> BoundingTriangulationOff();
00104
00105
00106 vtkUnstructuredGridWriter * writer = vtkUnstructuredGridWriter::New();
00107 writer -> SetInputConnection(delaunay->GetOutputPort());
00108 writer -> SetFileName(_filename);
00109 writer -> Write();
00110
00111
00112 points -> Delete();
00113 vertices -> Delete();
00114 delaunay -> Delete();
00115 writer -> Delete();
00116 }
00117
00118 #endif // VTKWRAP_TRIANGULATE_H
00119
00120