]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Mesh.cxx
76bde83298cd9161ff3a8e9925e954db02a0b03e
[cpPlugins.git] / lib / cpPlugins / Mesh.cxx
1 #include <cpPlugins/Mesh.h>
2
3 #include <itkMesh.h>
4 #include <itkQuadEdgeMesh.h>
5 #include <itkLineCell.h>
6 #include <itkTriangleCell.h>
7 #include <itkPolygonCell.h>
8
9 #include <vtkPolyData.h>
10
11 // -------------------------------------------------------------------------
12 void cpPlugins::Mesh::
13 SetITK( itk::LightObject* o )
14 {
15   this->Superclass::SetITK( o );
16   bool     r = this->_ITK_2_VTK< itk::Mesh< float, 2 > >( o );
17   if( !r ) r = this->_ITK_2_VTK< itk::Mesh< double, 2 > >( o );
18   if( !r ) r = this->_ITK_2_VTK< itk::Mesh< float, 3 > >( o );
19   if( !r ) r = this->_ITK_2_VTK< itk::Mesh< double, 3 > >( o );
20   if( !r ) r = this->_ITK_2_VTK< itk::QuadEdgeMesh< float, 2 > >( o );
21   if( !r ) r = this->_ITK_2_VTK< itk::QuadEdgeMesh< double, 2 > >( o );
22   if( !r ) r = this->_ITK_2_VTK< itk::QuadEdgeMesh< float, 3 > >( o );
23   if( !r ) r = this->_ITK_2_VTK< itk::QuadEdgeMesh< double, 3 > >( o );
24 }
25
26 // -------------------------------------------------------------------------
27 void cpPlugins::Mesh::
28 SetVTK( vtkObjectBase* o )
29 {
30   typedef itk::Mesh< double, 3 >      _TMesh;
31   typedef _TMesh::CellType            _TCell;
32   typedef _TCell::CellAutoPointer     _TCellAutoPointer;
33   typedef itk::LineCell< _TCell >     _TLine;
34   typedef itk::TriangleCell< _TCell > _TTriangle;
35   typedef itk::PolygonCell< _TCell >  _TPolygon;
36
37   vtkPolyData* mesh = dynamic_cast< vtkPolyData* >( o );
38   if( mesh == NULL )
39   {
40     this->m_ITKObject = NULL;
41     this->Modified( );
42     return;
43
44   } // fi
45
46   if( this->m_VTKObject.GetPointer( ) != mesh )
47   {
48     this->m_VTKObject = mesh;
49
50     // Copy points
51     /* TODO
52        _TMesh::Pointer imesh = _TMesh::New( );
53        double point[ 3 ];
54        for( long i = 0; i < mesh->GetNumberOfPoints( ); ++i )
55        {
56        mesh->GetPoint( i, point );
57        _TMesh::PointType ipoint;
58        ipoint[ 0 ] = point[ 0 ];
59        ipoint[ 1 ] = point[ 1 ];
60        ipoint[ 2 ] = point[ 2 ];
61        imesh->SetPoint( i, ipoint );
62
63        } // rof
64
65        // Copy cells
66        for( long i = 0; i < mesh->GetNumberOfCells( ); ++i )
67        {
68        auto cell = mesh->GetCell( i );
69        long nPoints = cell->GetNumberOfPoints( );
70        _TCellAutoPointer icell;
71        if( nPoints == 2 )
72        {
73        icell.TakeOwnership( new _TLine );
74        icell->SetPointId( 0, cell->GetPointId( 0 ) );
75        icell->SetPointId( 1, cell->GetPointId( 1 ) );
76        }
77        else if( nPoints == 3 )
78        {
79        icell.TakeOwnership( new _TTriangle );
80        icell->SetPointId( 0, cell->GetPointId( 0 ) );
81        icell->SetPointId( 1, cell->GetPointId( 1 ) );
82        icell->SetPointId( 2, cell->GetPointId( 2 ) );
83        }
84        else if( nPoints > 3 )
85        {
86        _TPolygon* polygon = new _TPolygon( );
87        for( long j = 0; j < nPoints; ++j )
88        polygon->AddPointId( cell->GetPointId( j ) );
89        icell.TakeOwnership( polygon );
90
91        } // fi
92        imesh->SetCell( imesh->GetNumberOfCells( ), icell );
93
94        } // rof
95
96        this->m_ITKObject = imesh;
97     */
98     this->m_ITKObject = NULL; // TODO: replace this
99     this->Modified( );
100
101   } // fi
102 }
103 // -------------------------------------------------------------------------
104 cpPlugins::Mesh::
105 Mesh( )
106   : Superclass( )
107 {
108 }
109
110 // -------------------------------------------------------------------------
111 cpPlugins::Mesh::
112 ~Mesh( )
113 {
114 }
115
116 // eof - $RCSfile$