]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Extensions/Visualization/MeshMapper.hxx
5b44f2c8d2dedf3d695b2ffa876b9b28fd67446d
[cpPlugins.git] / lib / cpPlugins / Extensions / Visualization / MeshMapper.hxx
1 #ifndef __CPPLUGINS__EXTENSIONS__VISUALIZATION__MESHMAPPER__HXX__
2 #define __CPPLUGINS__EXTENSIONS__VISUALIZATION__MESHMAPPER__HXX__
3
4 #include <vtkInformation.h>
5 #include <vtkMath.h>
6
7 // TODO: #include <cpPlugins/Extensions/Visualization/OpenGLMeshMapper.h>
8
9 // -------------------------------------------------------------------------
10 /* TODO
11    template< class M >
12    typename cpPlugins::Extensions::Visualization::MeshMapper< M >::
13    Self* cpPlugins::Extensions::Visualization::MeshMapper< M >::
14    New( )
15    {
16    return(
17    cpPlugins::Extensions::Visualization::OpenGLMeshMapper< M >::New( )
18    );
19    }
20 */
21
22 // -------------------------------------------------------------------------
23 template< class M >
24 void cpPlugins::Extensions::Visualization::MeshMapper< M >::
25 ShallowCopy( vtkAbstractMapper* m )
26 {
27   Self* mapper = Self::SafeDownCast( m );
28   if( m != NULL )
29     this->SetInputData( mapper->GetInput( ) );
30   this->vtkMapper::ShallowCopy( m );
31 }
32
33 // -------------------------------------------------------------------------
34 template< class M >
35 void cpPlugins::Extensions::Visualization::MeshMapper< M >::
36 SetInputData( M* in )
37 {
38   if( this->Mesh != in )
39   {
40     this->Mesh = in;
41     this->Modified( );
42
43   } // fi
44 }
45
46 // -------------------------------------------------------------------------
47 template< class M >
48 M* cpPlugins::Extensions::Visualization::MeshMapper< M >::
49 GetInput( )
50 {
51   return( this->Mesh );
52 }
53
54 // -------------------------------------------------------------------------
55 template< class M >
56 const M* cpPlugins::Extensions::Visualization::MeshMapper< M >::
57 GetInput( ) const
58 {
59   return( this->Mesh );
60 }
61
62 // -------------------------------------------------------------------------
63 template< class M >
64 double* cpPlugins::Extensions::Visualization::MeshMapper< M >::
65 GetBounds( )
66 {
67   // do we have an input
68   if( this->Mesh.IsNull( ) )
69   {
70     vtkMath::UninitializeBounds( this->Bounds );
71     return( this->Bounds );
72   }
73   else
74   {
75     this->Mesh->Update( );
76     this->ComputeBounds( );
77
78     if( !vtkMath::AreBoundsInitialized( this->Bounds ) )
79       return( NULL );
80     return( this->Bounds );
81
82   } // fi
83 }
84
85 // -------------------------------------------------------------------------
86 template< class M >
87 void cpPlugins::Extensions::Visualization::MeshMapper< M >::
88 GetBounds( double bounds[ 6 ] )
89 {
90   this->Superclass::GetBounds( bounds );
91 }
92
93 // -------------------------------------------------------------------------
94 template< class M >
95 void cpPlugins::Extensions::Visualization::MeshMapper< M >::
96 Render( vtkRenderer* aren, vtkActor* act )
97 {
98   if( this->Mesh.IsNull( ) )
99   {
100     vtkErrorMacro( "Mapper has no input." );
101     return;
102
103   } // fi
104   this->RenderPiece( aren, act );
105 }
106
107 // -------------------------------------------------------------------------
108 template< class M >
109 void cpPlugins::Extensions::Visualization::MeshMapper< M >::
110 Update( )
111 {
112   // TODO:
113   std::cout << "Update( )" << std::endl;
114 }
115
116 // -------------------------------------------------------------------------
117 template< class M >
118 void cpPlugins::Extensions::Visualization::MeshMapper< M >::
119 Update( int port )
120 {
121   // TODO:
122   std::cout << "Update( port = " << port << " ) "<< std::endl;
123 }
124
125 // -------------------------------------------------------------------------
126 template< class M >
127 void cpPlugins::Extensions::Visualization::MeshMapper< M >::
128 MapDataArrayToVertexAttribute(
129   const char* vertexAttributeName,
130   const char* dataArrayName,
131   int fieldAssociation,
132   int componentno
133   )
134 {
135   vtkErrorMacro( "Not implemented at this level..." );
136 }
137
138 // -------------------------------------------------------------------------
139 template< class M >
140 void cpPlugins::Extensions::Visualization::MeshMapper< M >::
141 MapDataArrayToMultiTextureAttribute(
142   int unit,
143   const char* dataArrayName,
144   int fieldAssociation,
145   int componentno
146   )
147 {
148   vtkErrorMacro( "Not implemented at this level..." );
149 }
150
151 // -------------------------------------------------------------------------
152 template< class M >
153 void cpPlugins::Extensions::Visualization::MeshMapper< M >::
154 RemoveVertexAttributeMapping( const char* vertexAttributeName )
155 {
156   vtkErrorMacro( "Not implemented at this level..." );
157 }
158
159 // -------------------------------------------------------------------------
160 template< class M >
161 void cpPlugins::Extensions::Visualization::MeshMapper< M >::
162 RemoveAllVertexAttributeMappings( )
163 {
164   vtkErrorMacro( "Not implemented at this level..." );
165 }
166
167 // -------------------------------------------------------------------------
168 template< class M >
169 cpPlugins::Extensions::Visualization::MeshMapper< M >::
170 MeshMapper( )
171   : Superclass( )
172 {
173 }
174
175 // -------------------------------------------------------------------------
176 template< class M >
177 cpPlugins::Extensions::Visualization::MeshMapper< M >::
178 ~MeshMapper( )
179 {
180 }
181
182 // -------------------------------------------------------------------------
183 template< class M >
184 void cpPlugins::Extensions::Visualization::MeshMapper< M >::
185 ComputeBounds( )
186 {
187   static const TScalar _0 = TScalar( 0 );
188   if( this->Mesh.IsNotNull( ) )
189   {
190     const typename M::BoundingBoxType* bb = this->Mesh->GetBoundingBox( );
191     TPoint minP = bb->GetMinimum( );
192     TPoint maxP = bb->GetMaximum( );
193     this->Bounds[ 0 ] = double( ( Self::Dimension >= 1 )? minP[ 0 ]: _0 );
194     this->Bounds[ 1 ] = double( ( Self::Dimension >= 1 )? maxP[ 0 ]: _0 );
195     this->Bounds[ 2 ] = double( ( Self::Dimension >= 2 )? minP[ 1 ]: _0 );
196     this->Bounds[ 3 ] = double( ( Self::Dimension >= 2 )? maxP[ 1 ]: _0 );
197     this->Bounds[ 4 ] = double( ( Self::Dimension >= 3 )? minP[ 2 ]: _0 );
198     this->Bounds[ 5 ] = double( ( Self::Dimension >= 3 )? maxP[ 2 ]: _0 );
199   }
200   else
201   {
202     this->Bounds[ 0 ] =
203       this->Bounds[ 1 ] =
204       this->Bounds[ 2 ] =
205       this->Bounds[ 3 ] =
206       this->Bounds[ 4 ] =
207       this->Bounds[ 5 ] =
208       double( 0 );
209
210   } // fi
211 }
212
213 // -------------------------------------------------------------------------
214 template< class M >
215 int cpPlugins::Extensions::Visualization::MeshMapper< M >::
216 FillInputPortInformation( int port, vtkInformation* info )
217 {
218   info->Set( vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE( ), "itk::Mesh" );
219   return( 1 );
220 }
221
222 #endif // __CPPLUGINS__EXTENSIONS__VISUALIZATION__MESHMAPPER__HXX__
223
224 // eof - $RCSfile$