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 // -------------------------------------------------------------------------
16 void cpPlugins::Interface::Mesh::
17 _ITK_2_VTK( itk::LightObject* o )
19 M* mesh = dynamic_cast< M* >( o );
23 long numPoints = mesh->GetNumberOfPoints( );
27 vtkSmartPointer< vtkPoints > vpoints =
28 vtkSmartPointer< vtkPoints >::New( );
29 vpoints->SetNumberOfPoints( numPoints );
30 auto points = mesh->GetPoints( );
34 std::map< vtkIdType, long > IndexMap;
35 for( auto i = points->Begin( ); i != points->End( ); ++i, VTKId++ )
37 IndexMap[ VTKId ] = i->Index( );
38 if( M::PointDimension == 2 )
41 i->Value( )[ 0 ], i->Value( )[ 1 ], 0
43 else if( M::PointDimension == 3 )
46 i->Value( )[ 0 ], i->Value( )[ 1 ], i->Value( )[ 2 ]
52 vtkSmartPointer< vtkCellArray > vcells =
53 vtkSmartPointer< vtkCellArray >::New( );
54 auto cells = mesh->GetCells( );
55 for( auto j = cells->Begin( ); j != cells->End( ); ++j )
57 auto cell = j->Value( );
58 vcells->InsertNextCell( cell->GetNumberOfPoints( ) );
59 for( auto k = cell->PointIdsBegin( ); k != cell->PointIdsEnd( ); ++k )
60 vcells->InsertCellPoint( IndexMap[ *k ] );
65 vtkSmartPointer< vtkPolyData > vmesh =
66 vtkSmartPointer< vtkPolyData >::New( );
67 vmesh->SetPoints( vpoints );
68 vmesh->SetPolys( vcells );
69 this->m_VTKObject = vmesh;
73 // -------------------------------------------------------------------------
74 #define cpPlugins_Mesh_Import( N, T, D ) \
75 cpPlugins_TEMPLATE_IMPORT( \
76 2(class cpPlugins_Interface_EXPORT itk::N< T, D >) \
79 // -------------------------------------------------------------------------
81 #ifndef cpPlugins_Interface_EXPORTS
83 cpPlugins_Mesh_Import( Mesh, float, 2 );
84 cpPlugins_Mesh_Import( Mesh, double, 2 );
85 cpPlugins_Mesh_Import( Mesh, float, 3 );
86 cpPlugins_Mesh_Import( Mesh, double, 3 );
87 cpPlugins_Mesh_Import( QuadEdgeMesh, float, 2 );
88 cpPlugins_Mesh_Import( QuadEdgeMesh, double, 2 );
89 cpPlugins_Mesh_Import( QuadEdgeMesh, float, 3 );
90 cpPlugins_Mesh_Import( QuadEdgeMesh, double, 3 );
92 #endif // cpPlugins_Interface_EXPORTS
94 #endif // __CPPLUGINS__INTERFACE__MESH__HXX__