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 SetITK( itk::LightObject* o )
14 this->Superclass::SetITK( o );
15 this->_ITK_2_VTK< itk::Mesh< float, 2 > >( o );
16 this->_ITK_2_VTK< itk::Mesh< double, 2 > >( o );
17 this->_ITK_2_VTK< itk::Mesh< float, 3 > >( o );
18 this->_ITK_2_VTK< itk::Mesh< double, 3 > >( o );
19 this->_ITK_2_VTK< itk::QuadEdgeMesh< float, 2 > >( o );
20 this->_ITK_2_VTK< itk::QuadEdgeMesh< double, 2 > >( o );
21 this->_ITK_2_VTK< itk::QuadEdgeMesh< float, 3 > >( o );
22 this->_ITK_2_VTK< itk::QuadEdgeMesh< double, 3 > >( o );
25 // -------------------------------------------------------------------------
26 void cpPlugins::Interface::Mesh::
27 SetVTK( vtkObjectBase* o )
29 typedef itk::Mesh< double, 3 > _TMesh;
30 typedef _TMesh::CellType _TCell;
31 typedef _TCell::CellAutoPointer _TCellAutoPointer;
32 typedef itk::LineCell< _TCell > _TLine;
33 typedef itk::TriangleCell< _TCell > _TTriangle;
34 typedef itk::PolygonCell< _TCell > _TPolygon;
36 vtkPolyData* mesh = dynamic_cast< vtkPolyData* >( o );
39 this->m_ITKObject = NULL;
45 if( this->m_VTKObject.GetPointer( ) != mesh )
47 this->m_VTKObject = mesh;
50 _TMesh::Pointer imesh = _TMesh::New( );
52 for( long i = 0; i < mesh->GetNumberOfPoints( ); ++i )
54 mesh->GetPoint( i, point );
55 _TMesh::PointType ipoint;
56 ipoint[ 0 ] = point[ 0 ];
57 ipoint[ 1 ] = point[ 1 ];
58 ipoint[ 2 ] = point[ 2 ];
59 imesh->SetPoint( i, ipoint );
64 for( long i = 0; i < mesh->GetNumberOfCells( ); ++i )
66 auto cell = mesh->GetCell( i );
67 long nPoints = cell->GetNumberOfPoints( );
68 _TCellAutoPointer icell;
71 icell.TakeOwnership( new _TLine );
72 icell->SetPointId( 0, cell->GetPointId( 0 ) );
73 icell->SetPointId( 1, cell->GetPointId( 1 ) );
75 else if( nPoints == 3 )
77 icell.TakeOwnership( new _TTriangle );
78 icell->SetPointId( 0, cell->GetPointId( 0 ) );
79 icell->SetPointId( 1, cell->GetPointId( 1 ) );
80 icell->SetPointId( 2, cell->GetPointId( 2 ) );
82 else if( nPoints > 3 )
84 _TPolygon* polygon = new _TPolygon( );
85 for( long j = 0; j < nPoints; ++j )
86 polygon->AddPointId( cell->GetPointId( j ) );
87 icell.TakeOwnership( polygon );
90 imesh->SetCell( imesh->GetNumberOfCells( ), icell );
94 this->m_ITKObject = imesh;
99 // -------------------------------------------------------------------------
100 cpPlugins::Interface::Mesh::
106 // -------------------------------------------------------------------------
107 cpPlugins::Interface::Mesh::