X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpPlugins%2FInterface%2FMesh.cxx;h=d56d1929aebeb81719640b70f20d80460975c775;hb=b20f90fb12b2d66ca0aadfe093ddf6520067db6f;hp=94adb2bb163ae5f47da17ff9e62abb41d22d74c4;hpb=882f5dec6fd8c3e9d1e8753658d40ef9ffe208dc;p=cpPlugins.git diff --git a/lib/cpPlugins/Interface/Mesh.cxx b/lib/cpPlugins/Interface/Mesh.cxx index 94adb2b..d56d192 100644 --- a/lib/cpPlugins/Interface/Mesh.cxx +++ b/lib/cpPlugins/Interface/Mesh.cxx @@ -1,16 +1,85 @@ #include +#include +#include +#include +#include + #include // ------------------------------------------------------------------------- void cpPlugins::Interface::Mesh:: -SetVTK( vtkObject* mesh ) +SetVTK( vtkObject* object ) { - if( dynamic_cast< vtkPolyData* >( mesh ) != NULL ) + typedef itk::Mesh< double, 3 > _TMesh; + typedef _TMesh::CellType _TCell; + typedef _TCell::CellAutoPointer _TCellAutoPointer; + typedef itk::LineCell< _TCell > _TLine; + typedef itk::TriangleCell< _TCell > _TTriangle; + typedef itk::PolygonCell< _TCell > _TPolygon; + + vtkPolyData* mesh = dynamic_cast< vtkPolyData* >( object ); + if( mesh == NULL ) + { + this->m_ITKObject = NULL; + this->Modified( ); + return; + + } // fi + + if( this->m_VTKObject.GetPointer( ) != mesh ) + { this->m_VTKObject = mesh; - else - this->m_VTKObject = NULL; - this->Modified( ); + + // Copy points + _TMesh::Pointer imesh = _TMesh::New( ); + double point[ 3 ]; + for( long i = 0; i < mesh->GetNumberOfPoints( ); ++i ) + { + mesh->GetPoint( i, point ); + _TMesh::PointType ipoint; + ipoint[ 0 ] = point[ 0 ]; + ipoint[ 1 ] = point[ 1 ]; + ipoint[ 2 ] = point[ 2 ]; + imesh->SetPoint( i, ipoint ); + + } // rof + + // Copy cells + for( long i = 0; i < mesh->GetNumberOfCells( ); ++i ) + { + auto cell = mesh->GetCell( i ); + long nPoints = cell->GetNumberOfPoints( ); + _TCellAutoPointer icell; + if( nPoints == 2 ) + { + icell.TakeOwnership( new _TLine ); + icell->SetPointId( 0, cell->GetPointId( 0 ) ); + icell->SetPointId( 1, cell->GetPointId( 1 ) ); + } + else if( nPoints == 3 ) + { + icell.TakeOwnership( new _TTriangle ); + icell->SetPointId( 0, cell->GetPointId( 0 ) ); + icell->SetPointId( 1, cell->GetPointId( 1 ) ); + icell->SetPointId( 2, cell->GetPointId( 2 ) ); + } + else if( nPoints > 3 ) + { + _TPolygon* polygon = new _TPolygon( ); + for( long j = 0; j < nPoints; ++j ) + polygon->AddPointId( cell->GetPointId( j ) ); + icell.TakeOwnership( polygon ); + + } // fi + imesh->SetCell( imesh->GetNumberOfCells( ), icell ); + + } // rof + + this->m_ITKObject = imesh; + this->Modified( ); + + } // fi } // ------------------------------------------------------------------------- cpPlugins::Interface::Mesh::