1 #ifndef __cpPlugins__DataObjects__Mesh__hxx__
2 #define __cpPlugins__DataObjects__Mesh__hxx__
4 #include <cpPlugins_Meshes.h>
5 #include <vtkCellArray.h>
7 #include <vtkPolyData.h>
8 #include <vtkSmartPointer.h>
10 // -------------------------------------------------------------------------
11 template< class _TMesh >
12 void cpPlugins::DataObjects::Mesh::
13 _ITK_2_VTK( _TMesh* mesh )
15 long numPoints = mesh->GetNumberOfPoints( );
19 vtkSmartPointer< vtkPoints > vpoints =
20 vtkSmartPointer< vtkPoints >::New( );
21 vpoints->SetNumberOfPoints( numPoints );
22 auto points = mesh->GetPoints( );
26 std::map< vtkIdType, long > IndexMap;
27 for( auto i = points->Begin( ); i != points->End( ); ++i, VTKId++ )
29 IndexMap[ VTKId ] = i->Index( );
30 if( _TMesh::PointDimension == 2 )
33 i->Value( )[ 0 ], i->Value( )[ 1 ], 0
35 else if( _TMesh::PointDimension == 3 )
38 i->Value( )[ 0 ], i->Value( )[ 1 ], i->Value( )[ 2 ]
44 vtkSmartPointer< vtkCellArray > vcells =
45 vtkSmartPointer< vtkCellArray >::New( );
46 auto cells = mesh->GetCells( );
47 for( auto j = cells->Begin( ); j != cells->End( ); ++j )
49 auto cell = j->Value( );
50 vcells->InsertNextCell( cell->GetNumberOfPoints( ) );
51 for( auto k = cell->PointIdsBegin( ); k != cell->PointIdsEnd( ); ++k )
52 vcells->InsertCellPoint( IndexMap[ *k ] );
57 vtkSmartPointer< vtkPolyData > vmesh =
58 vtkSmartPointer< vtkPolyData >::New( );
59 vmesh->SetPoints( vpoints );
60 vmesh->SetPolys( vcells );
65 #endif // __cpPlugins__DataObjects__Mesh__hxx__