1 #include <cpPlugins/DataObjects/Mesh.h>
2 #include <vtkPolyData.h>
4 // -------------------------------------------------------------------------
5 void cpPlugins::DataObjects::Mesh::
6 SetITK( itk::LightObject* o )
9 this->Superclass::SetITK( o );
11 cpPlugins_Demangle_Meshes_Dims( o, _ITK_2_VTK );
15 // -------------------------------------------------------------------------
16 void cpPlugins::DataObjects::Mesh::
17 SetVTK( vtkObjectBase* o )
20 typedef itk::Mesh< double, 3 > _TMesh;
21 typedef _TMesh::CellType _TCell;
22 typedef _TCell::CellAutoPointer _TCellAutoPointer;
23 typedef itk::LineCell< _TCell > _TLine;
24 typedef itk::TriangleCell< _TCell > _TTriangle;
25 typedef itk::PolygonCell< _TCell > _TPolygon;
27 vtkPolyData* mesh = dynamic_cast< vtkPolyData* >( o );
36 if( this->m_VTK.GetPointer( ) != mesh )
41 _TMesh::Pointer imesh = _TMesh::New( );
43 for( long i = 0; i < mesh->GetNumberOfPoints( ); ++i )
45 mesh->GetPoint( i, point );
46 _TMesh::PointType ipoint;
47 ipoint[ 0 ] = point[ 0 ];
48 ipoint[ 1 ] = point[ 1 ];
49 ipoint[ 2 ] = point[ 2 ];
50 imesh->SetPoint( i, ipoint );
55 vtkCellArray* arrays[ 4 ];
56 arrays[ 0 ] = mesh->GetLines( );
57 arrays[ 1 ] = mesh->GetPolys( );
58 arrays[ 2 ] = NULL; // TODO: mesh->GetStrips( );
59 arrays[ 3 ] = mesh->GetVerts( );
61 for( unsigned int c = 0; c < 4; c++ )
63 if( arrays[ c ] != NULL )
65 vtkSmartPointer< vtkIdList > ids =
66 vtkSmartPointer< vtkIdList >::New( );
67 arrays[ c ]->InitTraversal( );
68 while( arrays[ c ]->GetNextCell( ids ) == 1 )
70 long nPoints = ids->GetNumberOfIds( );
71 _TCellAutoPointer icell;
74 icell.TakeOwnership( new _TLine );
75 icell->SetPointId( 0, ids->GetId( 0 ) );
76 icell->SetPointId( 1, ids->GetId( 1 ) );
78 else if( nPoints == 3 )
80 icell.TakeOwnership( new _TTriangle );
81 icell->SetPointId( 0, ids->GetId( 0 ) );
82 icell->SetPointId( 1, ids->GetId( 1 ) );
83 icell->SetPointId( 2, ids->GetId( 2 ) );
85 else if( nPoints > 3 )
87 _TPolygon* polygon = new _TPolygon( );
88 for( long j = 0; j < nPoints; ++j )
89 polygon->AddPointId( ids->GetId( j ) );
90 icell.TakeOwnership( polygon );
93 imesh->SetCell( imesh->GetNumberOfCells( ), icell );
107 // -------------------------------------------------------------------------
108 cpPlugins::DataObjects::Mesh::
114 // -------------------------------------------------------------------------
115 cpPlugins::DataObjects::Mesh::