]> Creatis software - cpPlugins.git/blob - lib/cpExtensions/Visualization/MPRObjects.cxx
First dump for version 0.1.0
[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 Show( )
80 {
81   this->m_MPRActors->PushActorsInto(
82     this->m_Windows[ 0 ],
83     this->m_Windows[ 1 ],
84     this->m_Windows[ 2 ],
85     this->m_Windows[ 3 ]
86     );
87 }
88
89 // -------------------------------------------------------------------------
90 void cpExtensions::Visualization::MPRObjects::
91 Hide( )
92 {
93 }
94
95 // -------------------------------------------------------------------------
96 void cpExtensions::Visualization::MPRObjects::
97 Clear( )
98 {
99   this->m_MPRActors->Clear( );
100 }
101
102 // -------------------------------------------------------------------------
103 vtkImageData* cpExtensions::Visualization::MPRObjects::
104 GetInputImage( )
105 {
106   return( this->m_MPRActors->GetInputImage( ) );
107 }
108
109 // -------------------------------------------------------------------------
110 const vtkImageData* cpExtensions::Visualization::MPRObjects::
111 GetInputImage( ) const
112 {
113   return( this->m_MPRActors->GetInputImage( ) );
114 }
115
116 // -------------------------------------------------------------------------
117 unsigned int cpExtensions::Visualization::MPRObjects::
118 GetNumberOfImages( ) const
119 {
120   return( this->m_MPRActors->GetNumberOfImages( ) );
121 }
122
123 // -------------------------------------------------------------------------
124 void cpExtensions::Visualization::MPRObjects::
125 SetInterpolate( bool v )
126 {
127   this->m_MPRActors->SetInterpolate( v );
128 }
129
130 // -------------------------------------------------------------------------
131 void cpExtensions::Visualization::MPRObjects::
132 InterpolateOn( )
133 {
134   this->m_MPRActors->InterpolateOn( );
135 }
136
137 // -------------------------------------------------------------------------
138 void cpExtensions::Visualization::MPRObjects::
139 InterpolateOff( )
140 {
141   this->m_MPRActors->InterpolateOff( );
142 }
143
144 // -------------------------------------------------------------------------
145 double cpExtensions::Visualization::MPRObjects::
146 GetMinWindow( ) const
147 {
148   return( this->m_MPRActors->GetMinWindow( ) );
149 }
150
151 // -------------------------------------------------------------------------
152 double cpExtensions::Visualization::MPRObjects::
153 GetMaxWindow( ) const
154 {
155   return( this->m_MPRActors->GetMaxWindow( ) );
156 }
157
158 // -------------------------------------------------------------------------
159 double cpExtensions::Visualization::MPRObjects::
160 GetMinLevel( ) const
161 {
162   return( this->m_MPRActors->GetMinLevel( ) );
163 }
164
165 // -------------------------------------------------------------------------
166 double cpExtensions::Visualization::MPRObjects::
167 GetMaxLevel( ) const
168 {
169   return( this->m_MPRActors->GetMaxLevel( ) );
170 }
171
172 // -------------------------------------------------------------------------
173 double cpExtensions::Visualization::MPRObjects::
174 GetWindow( ) const
175 {
176   return( this->m_MPRActors->GetWindow( ) );
177 }
178
179 // -------------------------------------------------------------------------
180 double cpExtensions::Visualization::MPRObjects::
181 GetLevel( ) const
182 {
183   return( this->m_MPRActors->GetLevel( ) );
184 }
185
186 // -------------------------------------------------------------------------
187 void cpExtensions::Visualization::MPRObjects::
188 SetWindow( double w )
189 {
190   this->m_MPRActors->SetWindow( w );
191 }
192
193 // -------------------------------------------------------------------------
194 void cpExtensions::Visualization::MPRObjects::
195 SetLevel( double l )
196 {
197   this->m_MPRActors->SetLevel( l );
198 }
199
200 // -------------------------------------------------------------------------
201 void cpExtensions::Visualization::MPRObjects::
202 SetWindowLevel( double w, double l )
203 {
204   this->m_MPRActors->SetWindowLevel( w, l );
205 }
206
207 // -------------------------------------------------------------------------
208 void cpExtensions::Visualization::MPRObjects::
209 ResetWindowLevel( )
210 {
211   this->m_MPRActors->ResetWindowLevel( );
212 }
213
214 // -------------------------------------------------------------------------
215 int cpExtensions::Visualization::MPRObjects::
216 GetSliceNumber( const int& axis ) const
217 {
218   return( this->m_MPRActors->GetSliceNumber( axis ) );
219 }
220
221 // -------------------------------------------------------------------------
222 int cpExtensions::Visualization::MPRObjects::
223 GetSliceNumberMinValue( const int& axis ) const
224 {
225   return( this->m_MPRActors->GetSliceNumberMinValue( axis ) );
226 }
227
228 // -------------------------------------------------------------------------
229 int cpExtensions::Visualization::MPRObjects::
230 GetSliceNumberMaxValue( const int& axis ) const
231 {
232   return( this->m_MPRActors->GetSliceNumberMaxValue( axis ) );
233 }
234
235 // -------------------------------------------------------------------------
236 void cpExtensions::Visualization::MPRObjects::
237 SetSliceNumber( const int& axis, const int& slice )
238 {
239   this->m_MPRActors->SetSliceNumber( axis, slice );
240 }
241
242 // -------------------------------------------------------------------------
243 void cpExtensions::Visualization::MPRObjects::
244 SetSlice( const int& axis, double* pos )
245 {
246   this->m_MPRActors->SetSlice( axis, pos );
247 }
248
249 // -------------------------------------------------------------------------
250 void cpExtensions::Visualization::MPRObjects::
251 Render( const double& t )
252 {
253   this->Render( 0, t );
254   this->Render( 1, t );
255   this->Render( 2, t );
256   this->Render( 3, t );
257 }
258
259 // -------------------------------------------------------------------------
260 void cpExtensions::Visualization::MPRObjects::
261 Render( const int& axis, const double& t )
262 {
263   if( axis < 4 )
264   {
265     if( this->m_Windows[ axis ].GetPointer( ) != NULL )
266     {
267       if( this->m_Renderers[ axis ].GetPointer( ) != NULL )
268         this->m_Renderers[ axis ]->SetAllocatedRenderTime( t );
269       this->m_Windows[ axis ]->Render( );
270
271     } // fi
272
273   } // fi
274 }
275
276 // -------------------------------------------------------------------------
277 void cpExtensions::Visualization::MPRObjects::
278 ResetCamera( const int& axis )
279 {
280   if( axis < 4 )
281     if( this->m_Renderers[ axis ].GetPointer( ) != NULL )
282       this->m_Renderers[ axis ]->ResetCamera( );
283 }
284
285 // -------------------------------------------------------------------------
286 void cpExtensions::Visualization::MPRObjects::
287 ResetCameras( )
288 {
289   this->ResetCamera( 0 );
290   this->ResetCamera( 1 );
291   this->ResetCamera( 2 );
292   this->ResetCamera( 3 );
293 }
294
295 // -------------------------------------------------------------------------
296 cpExtensions::Visualization::MPRObjects::
297 MPRObjects( )
298   : vtkObject( )
299 {
300   this->m_MPRActors = vtkSmartPointer< MPRActors >::New( );
301 }
302
303 // -------------------------------------------------------------------------
304 cpExtensions::Visualization::MPRObjects::
305 ~MPRObjects( )
306 {
307 }
308
309
310
311
312 /*
313 // -------------------------------------------------------------------------
314 void cpExtensions::Visualization::MPRObjects::
315 SetRenderWindows(
316   vtkRenderWindow* wx, vtkRenderWindow* wy,
317   vtkRenderWindow* wz, vtkRenderWindow* w3D
318   )
319 {
320 }
321
322 // -------------------------------------------------------------------------
323 void cpExtensions::Visualization::MPRObjects::
324 AddImage( vtkImageData* image )
325 {
326   this->m_MPRActors->AddInputData( image );
327   this->m_MPRActors->PushActorsInto(
328     this->m_Windows[ 0 ],
329     this->m_Windows[ 1 ],
330     this->m_Windows[ 2 ],
331     this->m_Windows[ 3 ]
332     );
333
334   // First rendering
335   if( this->m_MPRActors->GetNumberOfImages( ) == 1 )
336   {
337     this->m_MPRActors->ResetSlices( );
338     this->ResetCameras( );
339
340   } // fi
341   this->RenderAll( 1e-3 );
342 }
343
344 // -------------------------------------------------------------------------
345 unsigned int cpExtensions::Visualization::MPRObjects::
346 GetNumberOfImages( ) const
347 {
348   return( this->m_MPRActors->GetNumberOfImages( ) );
349 }
350
351 // -------------------------------------------------------------------------
352 void cpExtensions::Visualization::MPRObjects::
353 ClearAll( )
354 {
355   this->m_MPRActors->PopActorsFrom(
356     this->m_Windows[ 0 ],
357     this->m_Windows[ 1 ],
358     this->m_Windows[ 2 ],
359     this->m_Windows[ 3 ]
360     );
361   this->ResetCameras( );
362   this->RenderAll( 1e-3 );
363 }
364
365 // -------------------------------------------------------------------------
366 void cpExtensions::Visualization::MPRObjects::
367 ResetCamera( const int& id )
368 {
369   if( id < 4 )
370     if( this->m_Windows[ id ] != NULL )
371       this->m_Renderers[ id ]->ResetCamera( );
372 }
373
374 // -------------------------------------------------------------------------
375 void cpExtensions::Visualization::MPRObjects::
376 ResetCameras( )
377 {
378   for( int i = 0; i < 4; ++i )
379     if( this->m_Windows[ i ] != NULL )
380       this->m_Renderers[ i ]->ResetCamera( );
381 }
382
383 // -------------------------------------------------------------------------
384 void cpExtensions::Visualization::MPRObjects::
385 Render( const int& id, const double& t )
386 {
387   if( id < 4 )
388   {
389     if( this->m_Windows[ id ] != NULL )
390     {
391       if( this->m_Renderers[ id ] != NULL )
392         this->m_Renderers[ id ]->SetAllocatedRenderTime( t );
393       this->m_Windows[ id ]->Render( );
394       
395     } // fi
396
397   } // fi
398 }
399
400 // -------------------------------------------------------------------------
401 void cpExtensions::Visualization::MPRObjects::
402 RenderAll( const double& t )
403 {
404   for( int i = 0; i < 4; ++i )
405   {
406     if( this->m_Windows[ i ] != NULL )
407     {
408       if( this->m_Renderers[ i ] != NULL )
409         this->m_Renderers[ i ]->SetAllocatedRenderTime( t );
410       this->m_Windows[ i ]->Render( );
411
412     } // fi
413
414   } // rof
415 }
416
417 // -------------------------------------------------------------------------
418 vtkRenderer* cpExtensions::Visualization::MPRObjects::
419 GetXRenderer( )
420 {
421   return( this->m_Renderers[ 0 ] );
422 }
423
424 // -------------------------------------------------------------------------
425 vtkRenderer* cpExtensions::Visualization::MPRObjects::
426 GetYRenderer( )
427 {
428   return( this->m_Renderers[ 1 ] );
429 }
430
431 // -------------------------------------------------------------------------
432 vtkRenderer* cpExtensions::Visualization::MPRObjects::
433 GetZRenderer( )
434 {
435   return( this->m_Renderers[ 2 ] );
436 }
437
438 // -------------------------------------------------------------------------
439 vtkRenderer* cpExtensions::Visualization::MPRObjects::
440 Get3DRenderer( )
441 {
442   return( this->m_Renderers[ 3 ] );
443 }
444
445 // -------------------------------------------------------------------------
446 const vtkRenderer* cpExtensions::Visualization::MPRObjects::
447 GetXRenderer( ) const
448 {
449   return( this->m_Renderers[ 0 ] );
450 }
451
452 // -------------------------------------------------------------------------
453 const vtkRenderer* cpExtensions::Visualization::MPRObjects::
454 GetYRenderer( ) const
455 {
456   return( this->m_Renderers[ 1 ] );
457 }
458
459 // -------------------------------------------------------------------------
460 const vtkRenderer* cpExtensions::Visualization::MPRObjects::
461 GetZRenderer( ) const
462 {
463   return( this->m_Renderers[ 2 ] );
464 }
465
466 // -------------------------------------------------------------------------
467 const vtkRenderer* cpExtensions::Visualization::MPRObjects::
468 Get3DRenderer( ) const
469 {
470   return( this->m_Renderers[ 3 ] );
471 }
472
473 // -------------------------------------------------------------------------
474 cpExtensions::Visualization::
475 MPRActors* cpExtensions::Visualization::MPRObjects::
476 GetMPRActors( )
477 {
478   return( this->m_MPRActors );
479 }
480
481 // -------------------------------------------------------------------------
482 const cpExtensions::Visualization::
483 MPRActors* cpExtensions::Visualization::MPRObjects::
484 GetMPRActors( ) const
485 {
486   return( this->m_MPRActors );
487 }
488
489 // -------------------------------------------------------------------------
490 double cpExtensions::Visualization::MPRObjects::
491 GetWindow( ) const
492 {
493   return( this->m_MPRActors->GetWindow( ) );
494 }
495
496 // -------------------------------------------------------------------------
497 double cpExtensions::Visualization::MPRObjects::
498 GetLevel( ) const
499 {
500   return( this->m_MPRActors->GetLevel( ) );
501 }
502
503 // -------------------------------------------------------------------------
504 cpExtensions::Visualization::MPRObjects::
505 MPRObjects( )
506   : vtkObject( )
507 {
508   // Prepare actors
509   this->m_MPRActors = vtkSmartPointer< MPRActors >::New( );
510 }
511
512 // -------------------------------------------------------------------------
513 cpExtensions::Visualization::MPRObjects::
514 ~MPRObjects( )
515 {
516 }
517 */
518
519 // eof - $RCSfile$