1 #include <cpPlugins/Interface/Mesh.h>
4 #include <itkLineCell.h>
5 #include <itkTriangleCell.h>
6 #include <itkPolygonCell.h>
8 #include <vtkPolyData.h>
10 // -------------------------------------------------------------------------
11 void cpPlugins::Interface::Mesh::
12 SetVTK( vtkObject* object )
14 typedef itk::Mesh< double, 3 > _TMesh;
15 typedef _TMesh::CellType _TCell;
16 typedef _TCell::CellAutoPointer _TCellAutoPointer;
17 typedef itk::LineCell< _TCell > _TLine;
18 typedef itk::TriangleCell< _TCell > _TTriangle;
19 typedef itk::PolygonCell< _TCell > _TPolygon;
21 vtkPolyData* mesh = dynamic_cast< vtkPolyData* >( object );
24 this->m_ITKObject = NULL;
30 if( this->m_VTKObject.GetPointer( ) != mesh )
32 this->m_VTKObject = mesh;
35 _TMesh::Pointer imesh = _TMesh::New( );
37 for( long i = 0; i < mesh->GetNumberOfPoints( ); ++i )
39 mesh->GetPoint( i, point );
40 _TMesh::PointType ipoint;
41 ipoint[ 0 ] = point[ 0 ];
42 ipoint[ 1 ] = point[ 1 ];
43 ipoint[ 2 ] = point[ 2 ];
44 imesh->SetPoint( i, ipoint );
49 for( long i = 0; i < mesh->GetNumberOfCells( ); ++i )
51 auto cell = mesh->GetCell( i );
52 long nPoints = cell->GetNumberOfPoints( );
53 _TCellAutoPointer icell;
56 icell.TakeOwnership( new _TLine );
57 icell->SetPointId( 0, cell->GetPointId( 0 ) );
58 icell->SetPointId( 1, cell->GetPointId( 1 ) );
60 else if( nPoints == 3 )
62 icell.TakeOwnership( new _TTriangle );
63 icell->SetPointId( 0, cell->GetPointId( 0 ) );
64 icell->SetPointId( 1, cell->GetPointId( 1 ) );
65 icell->SetPointId( 2, cell->GetPointId( 2 ) );
67 else if( nPoints > 3 )
69 _TPolygon* polygon = new _TPolygon( );
70 for( long j = 0; j < nPoints; ++j )
71 polygon->AddPointId( cell->GetPointId( j ) );
72 icell.TakeOwnership( polygon );
75 imesh->SetCell( imesh->GetNumberOfCells( ), icell );
79 this->m_ITKObject = imesh;
84 // -------------------------------------------------------------------------
85 cpPlugins::Interface::Mesh::
91 // -------------------------------------------------------------------------
92 cpPlugins::Interface::Mesh::