]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/DataObjects/Mesh.cxx
c40bb021baa4c3a592424a9a8b0bda63b215379e
[cpPlugins.git] / lib / cpPlugins / DataObjects / Mesh.cxx
1 #include <cpPlugins/DataObjects/Mesh.h>
2 #include <vtkPolyData.h>
3
4 // -------------------------------------------------------------------------
5 void cpPlugins::DataObjects::Mesh::
6 SetITK( itk::LightObject* o )
7 {
8   /* TODO
9      this->Superclass::SetITK( o );
10      bool s = false;
11      cpPlugins_Demangle_Meshes_Dims( o, _ITK_2_VTK );
12   */
13 }
14
15 // -------------------------------------------------------------------------
16 void cpPlugins::DataObjects::Mesh::
17 SetVTK( vtkObjectBase* o )
18 {
19   /* TODO
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;
26
27      vtkPolyData* mesh = dynamic_cast< vtkPolyData* >( o );
28      if( mesh == NULL )
29      {
30      this->m_ITK = NULL;
31      this->Modified( );
32      return;
33
34      } // fi
35
36      if( this->m_VTK.GetPointer( ) != mesh )
37      {
38      this->m_VTK = mesh;
39
40      // Copy points
41      _TMesh::Pointer imesh = _TMesh::New( );
42      double point[ 3 ];
43      for( long i = 0; i < mesh->GetNumberOfPoints( ); ++i )
44      {
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 );
51
52      } // rof
53
54      // Copy cells
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( );
60
61      for( unsigned int c = 0; c < 4; c++ )
62      {
63      if( arrays[ c ] != NULL )
64      {
65      vtkSmartPointer< vtkIdList > ids =
66      vtkSmartPointer< vtkIdList >::New( );
67      arrays[ c ]->InitTraversal( );
68      while( arrays[ c ]->GetNextCell( ids ) == 1 )
69      {
70      long nPoints = ids->GetNumberOfIds( );
71      _TCellAutoPointer icell;
72      if( nPoints == 2 )
73      {
74      icell.TakeOwnership( new _TLine );
75      icell->SetPointId( 0, ids->GetId( 0 ) );
76      icell->SetPointId( 1, ids->GetId( 1 ) );
77      }
78      else if( nPoints == 3 )
79      {
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 ) );
84      }
85      else if( nPoints > 3 )
86      {
87      _TPolygon* polygon = new _TPolygon( );
88      for( long j = 0; j < nPoints; ++j )
89      polygon->AddPointId( ids->GetId( j ) );
90      icell.TakeOwnership( polygon );
91
92      } // fi
93      imesh->SetCell( imesh->GetNumberOfCells( ), icell );
94
95      } // elihw
96
97      } // fi
98
99      } // rof
100      this->m_ITK = imesh;
101      this->Modified( );
102
103      } // fi
104   */
105 }
106
107 // -------------------------------------------------------------------------
108 cpPlugins::DataObjects::Mesh::
109 Mesh( )
110   : Superclass( )
111 {
112 }
113
114 // -------------------------------------------------------------------------
115 cpPlugins::DataObjects::Mesh::
116 ~Mesh( )
117 {
118 }
119
120 // eof - $RCSfile$