Nektar++
Functions
VtkStripsToPolys.cpp File Reference
#include <LibUtilities/BasicUtils/SessionReader.h>
#include <LibUtilities/BasicUtils/VtkUtil.hpp>
#include <vtkPolyDataReader.h>
#include <vtkPolyDataWriter.h>
#include <vtkPolyData.h>
#include <vtkPointData.h>
#include <vtkPoints.h>
#include <vtkCellArray.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.

References ASSERTL0.

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