Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
VtkStripsToPolys.cpp
Go to the documentation of this file.
2 
3 #include <vtkPolyDataReader.h>
4 #include <vtkPolyDataWriter.h>
5 #include <vtkPolyData.h>
6 #include <vtkPointData.h>
7 #include <vtkPoints.h>
8 #include <vtkCellArray.h>
9 #include <vtkTriangle.h>
10 
11 int main(int argc, char* argv[])
12 {
13  vtkIdType npts;
14  vtkIdType* pts;
15 
16  // Read mesh
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();
23 
24  // Check we found points and strips in the file.
25  ASSERTL0(vtkPoints, "ERROR: cannot get points from mesh.");
26  ASSERTL0(vtkStrips, "ERROR: cannot get triangle strips from mesh.");
27 
28  // Create new cell array for polygons
29  vtkCellArray *vtkPolys = vtkCellArray::New();
30 
31  // Generate the polygons from the triangle strips
32  vtkStrips->InitTraversal();
33  for (int i = 0; vtkStrips->GetNextCell(npts, pts); ++i)
34  {
35  for (int j = 0; j < npts - 2; ++j)
36  {
37  vtkPolys->InsertNextCell(3, &pts[j]);
38  }
39  }
40 
41  // Create the new poly data
42  vtkPolyData *vtkNewMesh = vtkPolyData::New();
43  vtkNewMesh->SetPoints(vtkPoints);
44  vtkNewMesh->SetPolys(vtkPolys);
45 
46  // Copy data across
47  for (int i = 0; i < vtkMesh->GetPointData()->GetNumberOfArrays(); ++i)
48  {
49  vtkNewMesh->GetPointData()->SetScalars(
50  vtkMesh->GetPointData()->GetArray(i));
51  }
52 
53  // Write out the new mesh
54  vtkPolyDataWriter *vtkMeshWriter = vtkPolyDataWriter::New();
55  vtkMeshWriter->SetFileName(argv[2]);
56 #if VTK_MAJOR_VERSION <= 5
57  vtkMeshWriter->SetInput(vtkNewMesh);
58 #else
59  vtkMeshWriter->SetInputData(vtkNewMesh);
60 #endif
61  vtkMeshWriter->Write();
62 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:161
static std::string npts
Definition: InputFld.cpp:43
int main(int argc, char *argv[])