/
TriMesh.cc
executable file
·48 lines (40 loc) · 1.15 KB
/
TriMesh.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "TriMesh.h"
bool PolyDataToTriMesh(vtkSmartPointer<vtkPolyData> polydata, TriMesh *mesh)
{
cout << "inside PolyDataToTriMesh" << endl;
for(vtkIdType i = 0; i < polydata->GetNumberOfPoints(); i++)
{
double p[3];
polydata->GetPoint(i, p);
mesh->vertices.push_back(point(p[0],p[1],p[2]));
}
vtkSmartPointer<vtkCellArray> cells = polydata->GetPolys();
/*
cout << polydata->GetNumberOfCells() << " cells." << endl;
for(vtkIdType i = 0; i < polydata->GetNumberOfCells(); i++)
{
vtkIdType npts;
vtkIdType *pts;
cells->GetNextCell(npts, pts);
if(npts != 3)
{
cout << "face " << i << " is not a triangle, it has " << npts << " points!" << endl;
return false;
}
mesh->faces.push_back(TriMesh::Face(pts[0], pts[1], pts[2]));
}
*/
vtkIdType npts;
vtkIdType *pts;
cells->InitTraversal();
while(cells->GetNextCell(npts, pts))
{
if(npts != 3)
{
cout << "not a triangle, it has " << npts << " points!" << endl;
return false;
}
mesh->faces.push_back(TriMesh::Face(pts[0], pts[1], pts[2]));
}
return true;
}