#ifndef __CPPLUGINS__INTERFACE__MESH__HXX__ #define __CPPLUGINS__INTERFACE__MESH__HXX__ #include #include #include #include #include #include #include // ------------------------------------------------------------------------- template< class M > void cpPlugins::Interface::Mesh:: _ITK_2_VTK( itk::LightObject* o ) { M* mesh = dynamic_cast< M* >( o ); if( mesh == NULL ) return; long numPoints = mesh->GetNumberOfPoints( ); if( numPoints == 0 ) return; vtkSmartPointer< vtkPoints > vpoints = vtkSmartPointer< vtkPoints >::New( ); vpoints->SetNumberOfPoints( numPoints ); auto points = mesh->GetPoints( ); // Copy points vtkIdType VTKId = 0; std::map< vtkIdType, long > IndexMap; for( auto i = points->Begin( ); i != points->End( ); ++i, VTKId++ ) { IndexMap[ VTKId ] = i->Index( ); if( M::PointDimension == 2 ) vpoints->SetPoint( VTKId, i->Value( )[ 0 ], i->Value( )[ 1 ], 0 ); else if( M::PointDimension == 3 ) vpoints->SetPoint( VTKId, i->Value( )[ 0 ], i->Value( )[ 1 ], i->Value( )[ 2 ] ); } // rof // Copy cells vtkSmartPointer< vtkCellArray > vcells = vtkSmartPointer< vtkCellArray >::New( ); auto cells = mesh->GetCells( ); for( auto j = cells->Begin( ); j != cells->End( ); ++j ) { auto cell = j->Value( ); vcells->InsertNextCell( cell->GetNumberOfPoints( ) ); for( auto k = cell->PointIdsBegin( ); k != cell->PointIdsEnd( ); ++k ) vcells->InsertCellPoint( IndexMap[ *k ] ); } // rof // Final assignations vtkSmartPointer< vtkPolyData > vmesh = vtkSmartPointer< vtkPolyData >::New( ); vmesh->SetPoints( vpoints ); vmesh->SetPolys( vcells ); this->m_VTKObject = vmesh; this->Modified( ); } // ------------------------------------------------------------------------- #define cpPlugins_Mesh_Import( N, T, D ) \ cpPlugins_TEMPLATE_IMPORT( \ 2(class cpPlugins_Interface_EXPORT itk::N< T, D >) \ ) // ------------------------------------------------------------------------- #ifndef cpPlugins_Interface_EXPORTS cpPlugins_Mesh_Import( Mesh, float, 2 ); cpPlugins_Mesh_Import( Mesh, double, 2 ); cpPlugins_Mesh_Import( Mesh, float, 3 ); cpPlugins_Mesh_Import( Mesh, double, 3 ); cpPlugins_Mesh_Import( QuadEdgeMesh, float, 2 ); cpPlugins_Mesh_Import( QuadEdgeMesh, double, 2 ); cpPlugins_Mesh_Import( QuadEdgeMesh, float, 3 ); cpPlugins_Mesh_Import( QuadEdgeMesh, double, 3 ); #endif // cpPlugins_Interface_EXPORTS #endif // __CPPLUGINS__INTERFACE__MESH__HXX__ // eof - $RCSfile$