Nektar++
Functions
VtkStripsToPolys.cpp File Reference
#include <LibUtilities/BasicUtils/SessionReader.h>
#include <vtkPolyDataReader.h>
#include <vtkPolyDataWriter.h>
#include <vtkPolyData.h>
#include <vtkPointData.h>
#include <vtkPoints.h>
#include <vtkCellArray.h>
#include <vtkTriangle.h>
Include dependency graph for VtkStripsToPolys.cpp:

Go to the source code of this file.

Functions

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

Function Documentation

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

Definition at line 11 of file VtkStripsToPolys.cpp.

References ASSERTL0, and npts.

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