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