1 #ifndef __CPPLUGINS__INTERFACE__MESH__HXX__
2 #define __CPPLUGINS__INTERFACE__MESH__HXX__
7 #include <itkQuadEdgeMesh.h>
9 #include <vtkSmartPointer.h>
10 #include <vtkCellArray.h>
11 #include <vtkPoints.h>
12 #include <vtkPolyData.h>
14 // -------------------------------------------------------------------------
15 #define cpPlugins_Mesh_Import( N, T, D ) \
16 cpPlugins_TEMPLATE_IMPORT( \
17 2(class cpPlugins_Interface_EXPORT itk::N< T, D >) \
20 // -------------------------------------------------------------------------
22 #ifndef cpPlugins_Interface_EXPORTS
24 cpPlugins_Mesh_Import( Mesh, float, 2 );
25 cpPlugins_Mesh_Import( Mesh, double, 2 );
26 cpPlugins_Mesh_Import( Mesh, float, 3 );
27 cpPlugins_Mesh_Import( Mesh, double, 3 );
28 cpPlugins_Mesh_Import( QuadEdgeMesh, float, 2 );
29 cpPlugins_Mesh_Import( QuadEdgeMesh, double, 2 );
30 cpPlugins_Mesh_Import( QuadEdgeMesh, float, 3 );
31 cpPlugins_Mesh_Import( QuadEdgeMesh, double, 3 );
33 #endif // cpPlugins_Interface_EXPORTS
35 // -------------------------------------------------------------------------
37 void cpPlugins::Interface::Mesh::
40 if( this->m_ITKObject.GetPointer( ) == mesh )
43 this->m_ITKObject = mesh;
45 long numPoints = mesh->GetNumberOfPoints( );
49 vtkSmartPointer< vtkPoints > vpoints =
50 vtkSmartPointer< vtkPoints >::New( );
51 vpoints->SetNumberOfPoints( numPoints );
52 auto points = mesh->GetPoints( );
56 std::map< vtkIdType, long > IndexMap;
57 for( auto i = points->Begin( ); i != points->End( ); ++i, VTKId++ )
59 IndexMap[ VTKId ] = i->Index( );
60 if( M::PointDimension == 2 )
63 i->Value( )[ 0 ], i->Value( )[ 1 ], 0
65 else if( M::PointDimension == 3 )
68 i->Value( )[ 0 ], i->Value( )[ 1 ], i->Value( )[ 2 ]
74 vtkSmartPointer< vtkCellArray > vcells =
75 vtkSmartPointer< vtkCellArray >::New( );
76 auto cells = mesh->GetCells( );
77 for( auto j = cells->Begin( ); j != cells->End( ); ++j )
79 auto cell = j->Value( );
80 vcells->InsertNextCell( cell->GetNumberOfPoints( ) );
81 for( auto k = cell->PointIdsBegin( ); k != cell->PointIdsEnd( ); ++k )
82 vcells->InsertCellPoint( IndexMap[ *k ] );
87 vtkSmartPointer< vtkPolyData > vmesh =
88 vtkSmartPointer< vtkPolyData >::New( );
89 vmesh->SetPoints( vpoints );
90 vmesh->SetPolys( vcells );
91 this->m_VTKObject = vmesh;
95 #endif // __CPPLUGINS__INTERFACE__MESH__HXX__