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