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