X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpPlugins%2FInterface%2FMesh.hxx;h=16504f095a31d9ea9ee3be828fbbf9c907a73fec;hb=6ffc11d77924d6ab7e94db95d41105982ac73e00;hp=9163971ad774f73f8810b3bd8bdbdcc505b4549a;hpb=75740198fa0c55f8fdcd8b33ddff00071c893a94;p=cpPlugins.git diff --git a/lib/cpPlugins/Interface/Mesh.hxx b/lib/cpPlugins/Interface/Mesh.hxx index 9163971..16504f0 100644 --- a/lib/cpPlugins/Interface/Mesh.hxx +++ b/lib/cpPlugins/Interface/Mesh.hxx @@ -1,11 +1,75 @@ #ifndef __CPPLUGINS__INTERFACE__MESH__HXX__ #define __CPPLUGINS__INTERFACE__MESH__HXX__ -#include +#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( \ @@ -13,6 +77,9 @@ ) // ------------------------------------------------------------------------- + +#ifndef cpPlugins_Interface_EXPORTS + cpPlugins_Mesh_Import( Mesh, float, 2 ); cpPlugins_Mesh_Import( Mesh, double, 2 ); cpPlugins_Mesh_Import( Mesh, float, 3 ); @@ -22,34 +89,7 @@ cpPlugins_Mesh_Import( QuadEdgeMesh, double, 2 ); cpPlugins_Mesh_Import( QuadEdgeMesh, float, 3 ); cpPlugins_Mesh_Import( QuadEdgeMesh, double, 3 ); -// ------------------------------------------------------------------------- -template< class M > -void cpPlugins::Interface::Mesh:: -SetITKMesh( itk::DataObject* object ) -{ - std::cerr << "SetITKMesh: TODO" << std::endl; - std::exit( 1 ); -} - -// ------------------------------------------------------------------------- -template< class M > -M* cpPlugins::Interface::Mesh:: -GetITKMesh( ) -{ - std::cerr << "GetITKMesh: TODO" << std::endl; - std::exit( 1 ); - return( NULL ); -} - -// ------------------------------------------------------------------------- -template< class M > -const M* cpPlugins::Interface::Mesh:: -GetITKMesh( ) const -{ - std::cerr << "GetITKMesh (const): TODO" << std::endl; - std::exit( 1 ); - return( NULL ); -} +#endif // cpPlugins_Interface_EXPORTS #endif // __CPPLUGINS__INTERFACE__MESH__HXX__