1 #include <cpPlugins/DataObjects/Mesh.h>
2 #include <vtkPolyData.h>
4 // -------------------------------------------------------------------------
5 void cpPlugins::DataObjects::Mesh::
6 SetITK( itk::LightObject* o )
8 this->Superclass::SetITK( o );
10 cpPlugins_Demangle_Meshes_Dims( o, _ITK_2_VTK );
13 // -------------------------------------------------------------------------
14 void cpPlugins::DataObjects::Mesh::
15 SetVTK( vtkObjectBase* o )
17 typedef itk::Mesh< double, 3 > _TMesh;
18 typedef _TMesh::CellType _TCell;
19 typedef _TCell::CellAutoPointer _TCellAutoPointer;
20 typedef itk::LineCell< _TCell > _TLine;
21 typedef itk::TriangleCell< _TCell > _TTriangle;
22 typedef itk::PolygonCell< _TCell > _TPolygon;
24 vtkPolyData* mesh = dynamic_cast< vtkPolyData* >( o );
33 if( this->m_VTK.GetPointer( ) != mesh )
38 _TMesh::Pointer imesh = _TMesh::New( );
40 for( long i = 0; i < mesh->GetNumberOfPoints( ); ++i )
42 mesh->GetPoint( i, point );
43 _TMesh::PointType ipoint;
44 ipoint[ 0 ] = point[ 0 ];
45 ipoint[ 1 ] = point[ 1 ];
46 ipoint[ 2 ] = point[ 2 ];
47 imesh->SetPoint( i, ipoint );
52 vtkCellArray* arrays[ 4 ];
53 arrays[ 0 ] = mesh->GetLines( );
54 arrays[ 1 ] = mesh->GetPolys( );
55 arrays[ 2 ] = NULL; // TODO: mesh->GetStrips( );
56 arrays[ 3 ] = mesh->GetVerts( );
58 for( unsigned int c = 0; c < 4; c++ )
60 if( arrays[ c ] != NULL )
62 vtkSmartPointer< vtkIdList > ids =
63 vtkSmartPointer< vtkIdList >::New( );
64 arrays[ c ]->InitTraversal( );
65 while( arrays[ c ]->GetNextCell( ids ) == 1 )
67 long nPoints = ids->GetNumberOfIds( );
68 _TCellAutoPointer icell;
71 icell.TakeOwnership( new _TLine );
72 icell->SetPointId( 0, ids->GetId( 0 ) );
73 icell->SetPointId( 1, ids->GetId( 1 ) );
75 else if( nPoints == 3 )
77 icell.TakeOwnership( new _TTriangle );
78 icell->SetPointId( 0, ids->GetId( 0 ) );
79 icell->SetPointId( 1, ids->GetId( 1 ) );
80 icell->SetPointId( 2, ids->GetId( 2 ) );
82 else if( nPoints > 3 )
84 _TPolygon* polygon = new _TPolygon( );
85 for( long j = 0; j < nPoints; ++j )
86 polygon->AddPointId( ids->GetId( j ) );
87 icell.TakeOwnership( polygon );
90 imesh->SetCell( imesh->GetNumberOfCells( ), icell );
103 // -------------------------------------------------------------------------
104 cpPlugins::DataObjects::Mesh::
110 // -------------------------------------------------------------------------
111 cpPlugins::DataObjects::Mesh::