]> Creatis software - cpPlugins.git/blob - lib/cpExtensions/Visualization/MPRObjects.cxx
Merge branch 'master' of ssh://git.creatis.insa-lyon.fr/cpPlugins
[cpPlugins.git] / lib / cpExtensions / Visualization / MPRObjects.cxx
1 #include <cpExtensions/Visualization/MPRObjects.h>
2
3 #include <cmath>
4 #include <vtkImageData.h>
5 #include <vtkLookupTable.h>
6
7 // -------------------------------------------------------------------------
8 cpExtensions::Visualization::MPRObjects*
9 cpExtensions::Visualization::MPRObjects::
10 New( )
11 {
12   return( new Self( ) );
13 }
14
15 // -------------------------------------------------------------------------
16 void cpExtensions::Visualization::MPRObjects::
17 SetRenderWindows(
18   vtkRenderWindow* x, vtkRenderWindow* y,
19   vtkRenderWindow* z, vtkRenderWindow* w
20   )
21 {
22   this->m_Windows[ 0 ] = x;
23   this->m_Windows[ 1 ] = y;
24   this->m_Windows[ 2 ] = z;
25   this->m_Windows[ 3 ] = w;
26
27   // Prepare 2D renderers
28   for( int i = 0; i < 4; ++i )
29   {
30     // Create renderer, if render window exists
31     if( this->m_Windows[ i ] != NULL )
32     {
33       this->m_Renderers[ i ] = vtkSmartPointer< vtkRenderer >::New( );
34       this->m_Renderers[ i ]->SetBackground( 0.3, 0.3, 0.3 );
35       this->m_Windows[ i ]->AddRenderer( this->m_Renderers[ i ] );
36     }
37     else
38       this->m_Renderers[ i ] = NULL;
39
40   } // rof
41 }
42
43 // -------------------------------------------------------------------------
44 void cpExtensions::Visualization::MPRObjects::
45 SetInputConnection( vtkAlgorithmOutput* aout )
46 {
47   this->m_MPRActors->SetInputConnection( aout );
48 }
49
50 // -------------------------------------------------------------------------
51 void cpExtensions::Visualization::MPRObjects::
52 SetInputImage( vtkImageData* data )
53 {
54   this->m_MPRActors->SetInputImage( data );
55 }
56
57 // -------------------------------------------------------------------------
58 int cpExtensions::Visualization::MPRObjects::
59 AddBinaryConnection(
60   vtkAlgorithmOutput* aout,
61   const double& r, const double& g, const double& b
62   )
63 {
64   return( this->m_MPRActors->AddBinaryConnection( aout, r, g, b ) );
65 }
66
67 // -------------------------------------------------------------------------
68 int cpExtensions::Visualization::MPRObjects::
69 AddBinaryImage(
70   vtkImageData* data,
71   const double& r, const double& g, const double& b
72   )
73 {
74   return( this->m_MPRActors->AddBinaryImage( data, r, g, b ) );
75 }
76
77 // -------------------------------------------------------------------------
78 void cpExtensions::Visualization::MPRObjects::
79 Clear( )
80 {
81   this->m_MPRActors->Clear( );
82 }
83
84 // -------------------------------------------------------------------------
85 vtkImageData* cpExtensions::Visualization::MPRObjects::
86 GetInputImage( )
87 {
88   return( this->m_MPRActors->GetInputImage( ) );
89 }
90
91 // -------------------------------------------------------------------------
92 const vtkImageData* cpExtensions::Visualization::MPRObjects::
93 GetInputImage( ) const
94 {
95   return( this->m_MPRActors->GetInputImage( ) );
96 }
97
98 // -------------------------------------------------------------------------
99 unsigned int cpExtensions::Visualization::MPRObjects::
100 GetNumberOfImages( ) const
101 {
102   return( this->m_MPRActors->GetNumberOfImages( ) );
103 }
104
105 // -------------------------------------------------------------------------
106 void cpExtensions::Visualization::MPRObjects::
107 SetInterpolate( bool v )
108 {
109   this->m_MPRActors->SetInterpolate( v );
110 }
111
112 // -------------------------------------------------------------------------
113 void cpExtensions::Visualization::MPRObjects::
114 InterpolateOn( )
115 {
116   this->m_MPRActors->InterpolateOn( );
117 }
118
119 // -------------------------------------------------------------------------
120 void cpExtensions::Visualization::MPRObjects::
121 InterpolateOff( )
122 {
123   this->m_MPRActors->InterpolateOff( );
124 }
125
126 // -------------------------------------------------------------------------
127 double cpExtensions::Visualization::MPRObjects::
128 GetMinWindow( ) const
129 {
130   return( this->m_MPRActors->GetMinWindow( ) );
131 }
132
133 // -------------------------------------------------------------------------
134 double cpExtensions::Visualization::MPRObjects::
135 GetMaxWindow( ) const
136 {
137   return( this->m_MPRActors->GetMaxWindow( ) );
138 }
139
140 // -------------------------------------------------------------------------
141 double cpExtensions::Visualization::MPRObjects::
142 GetMinLevel( ) const
143 {
144   return( this->m_MPRActors->GetMinLevel( ) );
145 }
146
147 // -------------------------------------------------------------------------
148 double cpExtensions::Visualization::MPRObjects::
149 GetMaxLevel( ) const
150 {
151   return( this->m_MPRActors->GetMaxLevel( ) );
152 }
153
154 // -------------------------------------------------------------------------
155 double cpExtensions::Visualization::MPRObjects::
156 GetWindow( ) const
157 {
158   return( this->m_MPRActors->GetWindow( ) );
159 }
160
161 // -------------------------------------------------------------------------
162 double cpExtensions::Visualization::MPRObjects::
163 GetLevel( ) const
164 {
165   return( this->m_MPRActors->GetLevel( ) );
166 }
167
168 // -------------------------------------------------------------------------
169 void cpExtensions::Visualization::MPRObjects::
170 SetWindow( double w )
171 {
172   this->m_MPRActors->SetWindow( w );
173 }
174
175 // -------------------------------------------------------------------------
176 void cpExtensions::Visualization::MPRObjects::
177 SetLevel( double l )
178 {
179   this->m_MPRActors->SetLevel( l );
180 }
181
182 // -------------------------------------------------------------------------
183 void cpExtensions::Visualization::MPRObjects::
184 SetWindowLevel( double w, double l )
185 {
186   this->m_MPRActors->SetWindowLevel( w, l );
187 }
188
189 // -------------------------------------------------------------------------
190 void cpExtensions::Visualization::MPRObjects::
191 ResetWindowLevel( )
192 {
193   this->m_MPRActors->ResetWindowLevel( );
194 }
195
196 // -------------------------------------------------------------------------
197 int cpExtensions::Visualization::MPRObjects::
198 GetSliceNumber( const int& axis ) const
199 {
200   return( this->m_MPRActors->GetSliceNumber( axis ) );
201 }
202
203 // -------------------------------------------------------------------------
204 int cpExtensions::Visualization::MPRObjects::
205 GetSliceNumberMinValue( const int& axis ) const
206 {
207   return( this->m_MPRActors->GetSliceNumberMinValue( axis ) );
208 }
209
210 // -------------------------------------------------------------------------
211 int cpExtensions::Visualization::MPRObjects::
212 GetSliceNumberMaxValue( const int& axis ) const
213 {
214   return( this->m_MPRActors->GetSliceNumberMaxValue( axis ) );
215 }
216
217 // -------------------------------------------------------------------------
218 void cpExtensions::Visualization::MPRObjects::
219 SetSliceNumber( const int& axis, const int& slice )
220 {
221   this->m_MPRActors->SetSliceNumber( axis, slice );
222 }
223
224 // -------------------------------------------------------------------------
225 void cpExtensions::Visualization::MPRObjects::
226 SetSlice( const int& axis, double* pos )
227 {
228   this->m_MPRActors->SetSlice( axis, pos );
229 }
230
231 // -------------------------------------------------------------------------
232 void cpExtensions::Visualization::MPRObjects::
233 Render( const double& t )
234 {
235   this->Render( 0, t );
236   this->Render( 1, t );
237   this->Render( 2, t );
238   this->Render( 3, t );
239 }
240
241 // -------------------------------------------------------------------------
242 void cpExtensions::Visualization::MPRObjects::
243 Render( const int& axis, const double& t )
244 {
245   if( axis < 4 )
246   {
247     if( this->m_Windows[ axis ].GetPointer( ) != NULL )
248     {
249       if( this->m_Renderers[ axis ].GetPointer( ) != NULL )
250         this->m_Renderers[ axis ]->SetAllocatedRenderTime( t );
251       this->m_Windows[ axis ]->Render( );
252
253     } // fi
254
255   } // fi
256 }
257
258 // -------------------------------------------------------------------------
259 void cpExtensions::Visualization::MPRObjects::
260 ResetCamera( const int& axis )
261 {
262   if( axis < 4 )
263     if( this->m_Renderers[ axis ].GetPointer( ) != NULL )
264       this->m_Renderers[ axis ]->ResetCamera( );
265 }
266
267 // -------------------------------------------------------------------------
268 void cpExtensions::Visualization::MPRObjects::
269 ResetCameras( )
270 {
271   this->ResetCamera( 0 );
272   this->ResetCamera( 1 );
273   this->ResetCamera( 2 );
274   this->ResetCamera( 3 );
275 }
276
277 // -------------------------------------------------------------------------
278 cpExtensions::Visualization::MPRObjects::
279 MPRObjects( )
280   : vtkObject( )
281 {
282   this->m_MPRActors = vtkSmartPointer< MPRActors >::New( );
283 }
284
285 // -------------------------------------------------------------------------
286 cpExtensions::Visualization::MPRObjects::
287 ~MPRObjects( )
288 {
289 }
290
291
292
293
294 /*
295 // -------------------------------------------------------------------------
296 void cpExtensions::Visualization::MPRObjects::
297 SetRenderWindows(
298   vtkRenderWindow* wx, vtkRenderWindow* wy,
299   vtkRenderWindow* wz, vtkRenderWindow* w3D
300   )
301 {
302 }
303
304 // -------------------------------------------------------------------------
305 void cpExtensions::Visualization::MPRObjects::
306 AddImage( vtkImageData* image )
307 {
308   this->m_MPRActors->AddInputData( image );
309   this->m_MPRActors->PushActorsInto(
310     this->m_Windows[ 0 ],
311     this->m_Windows[ 1 ],
312     this->m_Windows[ 2 ],
313     this->m_Windows[ 3 ]
314     );
315
316   // First rendering
317   if( this->m_MPRActors->GetNumberOfImages( ) == 1 )
318   {
319     this->m_MPRActors->ResetSlices( );
320     this->ResetCameras( );
321
322   } // fi
323   this->RenderAll( 1e-3 );
324 }
325
326 // -------------------------------------------------------------------------
327 unsigned int cpExtensions::Visualization::MPRObjects::
328 GetNumberOfImages( ) const
329 {
330   return( this->m_MPRActors->GetNumberOfImages( ) );
331 }
332
333 // -------------------------------------------------------------------------
334 void cpExtensions::Visualization::MPRObjects::
335 ClearAll( )
336 {
337   this->m_MPRActors->PopActorsFrom(
338     this->m_Windows[ 0 ],
339     this->m_Windows[ 1 ],
340     this->m_Windows[ 2 ],
341     this->m_Windows[ 3 ]
342     );
343   this->ResetCameras( );
344   this->RenderAll( 1e-3 );
345 }
346
347 // -------------------------------------------------------------------------
348 void cpExtensions::Visualization::MPRObjects::
349 ResetCamera( const int& id )
350 {
351   if( id < 4 )
352     if( this->m_Windows[ id ] != NULL )
353       this->m_Renderers[ id ]->ResetCamera( );
354 }
355
356 // -------------------------------------------------------------------------
357 void cpExtensions::Visualization::MPRObjects::
358 ResetCameras( )
359 {
360   for( int i = 0; i < 4; ++i )
361     if( this->m_Windows[ i ] != NULL )
362       this->m_Renderers[ i ]->ResetCamera( );
363 }
364
365 // -------------------------------------------------------------------------
366 void cpExtensions::Visualization::MPRObjects::
367 Render( const int& id, const double& t )
368 {
369   if( id < 4 )
370   {
371     if( this->m_Windows[ id ] != NULL )
372     {
373       if( this->m_Renderers[ id ] != NULL )
374         this->m_Renderers[ id ]->SetAllocatedRenderTime( t );
375       this->m_Windows[ id ]->Render( );
376       
377     } // fi
378
379   } // fi
380 }
381
382 // -------------------------------------------------------------------------
383 void cpExtensions::Visualization::MPRObjects::
384 RenderAll( const double& t )
385 {
386   for( int i = 0; i < 4; ++i )
387   {
388     if( this->m_Windows[ i ] != NULL )
389     {
390       if( this->m_Renderers[ i ] != NULL )
391         this->m_Renderers[ i ]->SetAllocatedRenderTime( t );
392       this->m_Windows[ i ]->Render( );
393
394     } // fi
395
396   } // rof
397 }
398
399 // -------------------------------------------------------------------------
400 vtkRenderer* cpExtensions::Visualization::MPRObjects::
401 GetXRenderer( )
402 {
403   return( this->m_Renderers[ 0 ] );
404 }
405
406 // -------------------------------------------------------------------------
407 vtkRenderer* cpExtensions::Visualization::MPRObjects::
408 GetYRenderer( )
409 {
410   return( this->m_Renderers[ 1 ] );
411 }
412
413 // -------------------------------------------------------------------------
414 vtkRenderer* cpExtensions::Visualization::MPRObjects::
415 GetZRenderer( )
416 {
417   return( this->m_Renderers[ 2 ] );
418 }
419
420 // -------------------------------------------------------------------------
421 vtkRenderer* cpExtensions::Visualization::MPRObjects::
422 Get3DRenderer( )
423 {
424   return( this->m_Renderers[ 3 ] );
425 }
426
427 // -------------------------------------------------------------------------
428 const vtkRenderer* cpExtensions::Visualization::MPRObjects::
429 GetXRenderer( ) const
430 {
431   return( this->m_Renderers[ 0 ] );
432 }
433
434 // -------------------------------------------------------------------------
435 const vtkRenderer* cpExtensions::Visualization::MPRObjects::
436 GetYRenderer( ) const
437 {
438   return( this->m_Renderers[ 1 ] );
439 }
440
441 // -------------------------------------------------------------------------
442 const vtkRenderer* cpExtensions::Visualization::MPRObjects::
443 GetZRenderer( ) const
444 {
445   return( this->m_Renderers[ 2 ] );
446 }
447
448 // -------------------------------------------------------------------------
449 const vtkRenderer* cpExtensions::Visualization::MPRObjects::
450 Get3DRenderer( ) const
451 {
452   return( this->m_Renderers[ 3 ] );
453 }
454
455 // -------------------------------------------------------------------------
456 cpExtensions::Visualization::
457 MPRActors* cpExtensions::Visualization::MPRObjects::
458 GetMPRActors( )
459 {
460   return( this->m_MPRActors );
461 }
462
463 // -------------------------------------------------------------------------
464 const cpExtensions::Visualization::
465 MPRActors* cpExtensions::Visualization::MPRObjects::
466 GetMPRActors( ) const
467 {
468   return( this->m_MPRActors );
469 }
470
471 // -------------------------------------------------------------------------
472 double cpExtensions::Visualization::MPRObjects::
473 GetWindow( ) const
474 {
475   return( this->m_MPRActors->GetWindow( ) );
476 }
477
478 // -------------------------------------------------------------------------
479 double cpExtensions::Visualization::MPRObjects::
480 GetLevel( ) const
481 {
482   return( this->m_MPRActors->GetLevel( ) );
483 }
484
485 // -------------------------------------------------------------------------
486 cpExtensions::Visualization::MPRObjects::
487 MPRObjects( )
488   : vtkObject( )
489 {
490   // Prepare actors
491   this->m_MPRActors = vtkSmartPointer< MPRActors >::New( );
492 }
493
494 // -------------------------------------------------------------------------
495 cpExtensions::Visualization::MPRObjects::
496 ~MPRObjects( )
497 {
498 }
499 */
500
501 // eof - $RCSfile$