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