3 #include <vtkPolyDataReader.h>
4 #include <vtkPolyDataWriter.h>
5 #include <vtkPolyData.h>
6 #include <vtkPointData.h>
8 #include <vtkCellArray.h>
9 #include <vtkTriangle.h>
11 int main(
int argc,
char* argv[])
17 vtkPolyDataReader *vtkMeshReader = vtkPolyDataReader::New();
18 vtkMeshReader->SetFileName(argv[1]);
19 vtkMeshReader->Update();
20 vtkPolyData *vtkMesh = vtkMeshReader->GetOutput();
21 vtkPoints *vtkPoints = vtkMesh->GetPoints();
22 vtkCellArray *vtkStrips = vtkMesh->GetStrips();
25 ASSERTL0(vtkPoints,
"ERROR: cannot get points from mesh.");
26 ASSERTL0(vtkStrips,
"ERROR: cannot get triangle strips from mesh.");
29 vtkCellArray *vtkPolys = vtkCellArray::New();
32 vtkStrips->InitTraversal();
33 for (
int i = 0; vtkStrips->GetNextCell(npts, pts); ++i)
35 for (
int j = 0; j < npts - 2; ++j)
37 vtkPolys->InsertNextCell(3, &pts[j]);
42 vtkPolyData *vtkNewMesh = vtkPolyData::New();
43 vtkNewMesh->SetPoints(vtkPoints);
44 vtkNewMesh->SetPolys(vtkPolys);
47 for (
int i = 0; i < vtkMesh->GetPointData()->GetNumberOfArrays(); ++i)
49 vtkNewMesh->GetPointData()->SetScalars(
50 vtkMesh->GetPointData()->GetArray(i));
54 vtkPolyDataWriter *vtkMeshWriter = vtkPolyDataWriter::New();
55 vtkMeshWriter->SetFileName(argv[2]);
56 #if VTK_MAJOR_VERSION <= 5
57 vtkMeshWriter->SetInput(vtkNewMesh);
59 vtkMeshWriter->SetInputData(vtkNewMesh);
61 vtkMeshWriter->Write();
#define ASSERTL0(condition, msg)
int main(int argc, char *argv[])