]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Interface/Mesh.cxx
07bd28d434f87f9ae791e0e9c1877dbcb3b740b1
[cpPlugins.git] / lib / cpPlugins / Interface / Mesh.cxx
1 #include <cpPlugins/Interface/Mesh.h>
2
3 #include <vtkMapper.h>
4
5 #include <cpPlugins/Extensions/QuadEdgeMesh.h>
6 #include <cpPlugins/Extensions/OpenGLMeshMapper.h>
7
8 // -------------------------------------------------------------------------
9 cpPlugins::Interface::Mesh::
10 Mesh( )
11   : Superclass( ),
12     m_Mapper( NULL )
13 {
14 }
15
16 // -------------------------------------------------------------------------
17 cpPlugins::Interface::Mesh::
18 ~Mesh( )
19 {
20   if( this->m_Mapper != NULL ) this->m_Mapper->Delete( );
21 }
22
23 // -------------------------------------------------------------------------
24 std::string cpPlugins::Interface::Mesh::
25 GetClassName( ) const
26 {
27   return( "cpPlugins::Interface::Mesh" );
28 }
29
30 // -------------------------------------------------------------------------
31 void cpPlugins::Interface::Mesh::
32 SetDataObject( itk::DataObject* dobj )
33 {
34   this->Superclass::SetDataObject( dobj );
35   
36   // WARNING: Only 2 and 3 dimensions at this moment
37   typedef cpPlugins::Extensions::QuadEdgeMesh< float, 2 >  _TF2;
38   typedef cpPlugins::Extensions::QuadEdgeMesh< double, 2 > _TD2;
39   typedef cpPlugins::Extensions::QuadEdgeMesh< float, 3 >  _TF3;
40   typedef cpPlugins::Extensions::QuadEdgeMesh< double, 3 > _TD3;
41
42   if     ( dynamic_cast< _TF2* >( dobj ) ) this->_Map< _TF2 >( );
43   else if( dynamic_cast< _TD2* >( dobj ) ) this->_Map< _TD2 >( );
44   else if( dynamic_cast< _TF3* >( dobj ) ) this->_Map< _TF3 >( );
45   else if( dynamic_cast< _TD3* >( dobj ) ) this->_Map< _TD3 >( );
46 }
47
48 // -------------------------------------------------------------------------
49 vtkMapper* cpPlugins::Interface::Mesh::
50 GetVTKMapper( ) const
51 {
52   return( this->m_Mapper );
53 }
54
55 // -------------------------------------------------------------------------
56 template< class M >
57 void cpPlugins::Interface::Mesh::
58 _Map( )
59 {
60   typedef cpPlugins::Extensions::OpenGLMeshMapper< M > _TMapper;
61
62   if( this->m_Mapper != NULL ) this->m_Mapper->Delete( );
63   M* mesh = dynamic_cast< M* >( this->Superclass::GetDataObject( ) );
64   _TMapper* mapper = _TMapper::New( );
65   mapper->SetInputData( mesh );
66   mapper->Update( );
67   this->m_Mapper = mapper;
68 }
69
70 // -------------------------------------------------------------------------
71 /* TODO
72 template< unsigned int D >
73 void cpPlugins::Interface::Mesh::
74 _ConnectToVTK_0( )
75 {
76   itk::DataObject* dobj = this->Superclass::GetDataObject( );
77
78   cpPlugins_Interface_Mesh_Pixel( char, D, dobj, _ConnectToVTK_1 );
79   else cpPlugins_Interface_Mesh_Pixel( short, D, dobj, _ConnectToVTK_1 );
80   else cpPlugins_Interface_Mesh_Pixel( int, D, dobj, _ConnectToVTK_1 );
81   else cpPlugins_Interface_Mesh_Pixel( long, D, dobj, _ConnectToVTK_1 );
82   else cpPlugins_Interface_Mesh_Pixel( unsigned char, D, dobj, _ConnectToVTK_1 );
83   else cpPlugins_Interface_Mesh_Pixel( unsigned short, D, dobj, _ConnectToVTK_1 );
84   else cpPlugins_Interface_Mesh_Pixel( unsigned int, D, dobj, _ConnectToVTK_1 );
85   else cpPlugins_Interface_Mesh_Pixel( unsigned long, D, dobj, _ConnectToVTK_1 );
86   else cpPlugins_Interface_Mesh_Pixel( float, D, dobj, _ConnectToVTK_1 );
87   else cpPlugins_Interface_Mesh_Pixel( double, D, dobj, _ConnectToVTK_1 );
88   else cpPlugins_Interface_Mesh_RGB( char, D, dobj, _ConnectToVTK_1 );
89   else cpPlugins_Interface_Mesh_RGB( short, D, dobj, _ConnectToVTK_1 );
90   else cpPlugins_Interface_Mesh_RGB( int, D, dobj, _ConnectToVTK_1 );
91   else cpPlugins_Interface_Mesh_RGB( long, D, dobj, _ConnectToVTK_1 );
92   else cpPlugins_Interface_Mesh_RGB( unsigned char, D, dobj, _ConnectToVTK_1 );
93   else cpPlugins_Interface_Mesh_RGB( unsigned short, D, dobj, _ConnectToVTK_1 );
94   else cpPlugins_Interface_Mesh_RGB( unsigned int, D, dobj, _ConnectToVTK_1 );
95   else cpPlugins_Interface_Mesh_RGB( unsigned long, D, dobj, _ConnectToVTK_1 );
96   else cpPlugins_Interface_Mesh_RGB( float, D, dobj, _ConnectToVTK_1 );
97   else cpPlugins_Interface_Mesh_RGB( double, D, dobj, _ConnectToVTK_1 );
98 }
99
100 // -------------------------------------------------------------------------
101 template< class P, unsigned int D >
102 void cpPlugins::Interface::Mesh::
103 _ConnectToVTK_1( )
104 {
105   typedef itk::Mesh< P, D > _TMesh;
106   typedef itk::MeshToVTKMeshFilter< _TMesh > _TFilter;
107
108   _TMesh* img =
109     dynamic_cast< _TMesh* >( this->Superclass::GetDataObject( ) );
110   typename _TFilter::Pointer filter = _TFilter::New( );
111   filter->SetInput( img );
112   filter->Update( );
113   this->m_VTKMeshData = filter->GetOutput( );
114   this->m_Mesh2VTKMeshData = filter;
115 }
116 */
117
118 // eof - $RCSfile$