1 #ifndef __CPPLUGINS__MESH__HXX__
2 #define __CPPLUGINS__MESH__HXX__
5 #include <vtkSmartPointer.h>
6 #include <vtkCellArray.h>
8 #include <vtkPolyData.h>
10 // -------------------------------------------------------------------------
12 bool cpPlugins::Mesh::
13 _ITK_2_VTK( itk::LightObject* o )
15 M* mesh = dynamic_cast< M* >( o );
19 long numPoints = mesh->GetNumberOfPoints( );
23 vtkSmartPointer< vtkPoints > vpoints =
24 vtkSmartPointer< vtkPoints >::New( );
25 vpoints->SetNumberOfPoints( numPoints );
26 auto points = mesh->GetPoints( );
30 std::map< vtkIdType, long > IndexMap;
31 for( auto i = points->Begin( ); i != points->End( ); ++i, VTKId++ )
33 IndexMap[ VTKId ] = i->Index( );
34 if( M::PointDimension == 2 )
37 i->Value( )[ 0 ], i->Value( )[ 1 ], 0
39 else if( M::PointDimension == 3 )
42 i->Value( )[ 0 ], i->Value( )[ 1 ], i->Value( )[ 2 ]
48 vtkSmartPointer< vtkCellArray > vcells =
49 vtkSmartPointer< vtkCellArray >::New( );
50 auto cells = mesh->GetCells( );
51 for( auto j = cells->Begin( ); j != cells->End( ); ++j )
53 auto cell = j->Value( );
54 vcells->InsertNextCell( cell->GetNumberOfPoints( ) );
55 for( auto k = cell->PointIdsBegin( ); k != cell->PointIdsEnd( ); ++k )
56 vcells->InsertCellPoint( IndexMap[ *k ] );
61 vtkSmartPointer< vtkPolyData > vmesh =
62 vtkSmartPointer< vtkPolyData >::New( );
63 vmesh->SetPoints( vpoints );
64 vmesh->SetPolys( vcells );
65 this->m_VTKObject = vmesh;
70 #endif // __CPPLUGINS__MESH__HXX__