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