Nektar++
Functions
VtkStripsToPolys.cpp File Reference
#include <LibUtilities/BasicUtils/SessionReader.h>
#include <LibUtilities/BasicUtils/VtkUtil.hpp>
#include <vtkCellArray.h>
#include <vtkPointData.h>
#include <vtkPoints.h>
#include <vtkPolyData.h>
#include <vtkPolyDataReader.h>
#include <vtkPolyDataWriter.h>
#include <vtkTriangle.h>

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 12 of file VtkStripsToPolys.cpp.

13 {
14  if (argc < 2)
15  {
16  cout << "Usage: VtkStripsToPolys vtk-file" << endl;
17  exit(-1);
18  }
19 
20  vtkIdType npts;
21 #if VTK_MAJOR_VERSION >= 9 || \
22  (VTK_MAJOR_VERSION >= 8 && VTK_MINOR_VERSION >= 90)
23  const vtkIdType *pts = 0;
24 #else
25  vtkIdType *pts = 0;
26 #endif
27 
28  // Read mesh
29  vtkPolyDataReader *vtkMeshReader = vtkPolyDataReader::New();
30  vtkMeshReader->SetFileName(argv[1]);
31  vtkMeshReader->Update();
32  vtkPolyData *vtkMesh = vtkMeshReader->GetOutput();
33  vtkPoints *vtkPoints = vtkMesh->GetPoints();
34  vtkCellArray *vtkStrips = vtkMesh->GetStrips();
35 
36  // Check we found points and strips in the file.
37  ASSERTL0(vtkPoints, "ERROR: cannot get points from mesh.");
38  ASSERTL0(vtkStrips, "ERROR: cannot get triangle strips from mesh.");
39 
40  // Create new cell array for polygons
41  vtkCellArray *vtkPolys = vtkCellArray::New();
42 
43  // Generate the polygons from the triangle strips
44  vtkStrips->InitTraversal();
45  for (int i = 0; vtkStrips->GetNextCell(npts, pts); ++i)
46  {
47  for (int j = 0; j < npts - 2; ++j)
48  {
49  vtkPolys->InsertNextCell(3, &pts[j]);
50  }
51  }
52 
53  // Create the new poly data
54  vtkPolyData *vtkNewMesh = vtkPolyData::New();
55  vtkNewMesh->SetPoints(vtkPoints);
56  vtkNewMesh->SetPolys(vtkPolys);
57 
58  // Copy data across
59  for (int i = 0; i < vtkMesh->GetPointData()->GetNumberOfArrays(); ++i)
60  {
61  vtkNewMesh->GetPointData()->SetScalars(
62  vtkMesh->GetPointData()->GetArray(i));
63  }
64 
65  // Write out the new mesh
66  vtkPolyDataWriter *vtkMeshWriter = vtkPolyDataWriter::New();
67  vtkMeshWriter->SetFileName(argv[2]);
68 #if VTK_MAJOR_VERSION <= 5
69  vtkMeshWriter->SetInput(vtkNewMesh);
70 #else
71  vtkMeshWriter->SetInputData(vtkNewMesh);
72 #endif
73  vtkMeshWriter->Write();
74 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:215

References ASSERTL0.