1 #include <cpExtensions/Visualization/MPRActors.h>
3 #include <vtkAlgorithmOutput.h>
4 #include <vtkImageData.h>
5 #include <vtkOutlineSource.h>
6 #include <vtkProperty.h>
7 #include <vtkRenderer.h>
8 #include <vtkRendererCollection.h>
9 #include <vtkRenderWindow.h>
11 // -------------------------------------------------------------------------
12 cpExtensions::Visualization::MPRActors*
13 cpExtensions::Visualization::MPRActors::
16 return( new Self( ) );
19 // -------------------------------------------------------------------------
20 cpExtensions::Visualization::
21 ImageSliceActors* cpExtensions::Visualization::MPRActors::
22 GetSliceActors( const int& i ) const
25 return( this->Slices[ 0 ][ i ] );
30 // -------------------------------------------------------------------------
31 void cpExtensions::Visualization::MPRActors::
32 SetInputConnection( vtkAlgorithmOutput* aout )
34 for( int i = 0; i < 2; ++i )
36 for( int j = 0; j < 3; ++j )
38 this->Slices[ i ][ j ]->SetInputConnection( aout );
39 this->Slices[ i ][ j ]->SetAxis( j );
44 this->_CreateBoundingBox( );
47 // -------------------------------------------------------------------------
48 void cpExtensions::Visualization::MPRActors::
49 SetInputImage( vtkImageData* data )
51 for( int i = 0; i < 2; ++i )
53 for( int j = 0; j < 3; ++j )
55 this->Slices[ i ][ j ]->SetInputImage( data );
56 this->Slices[ i ][ j ]->SetAxis( j );
61 this->_CreateBoundingBox( );
64 // -------------------------------------------------------------------------
65 int cpExtensions::Visualization::MPRActors::
67 vtkAlgorithmOutput* aout,
68 const double& r, const double& g, const double& b
71 this->Slices[ 0 ][ 0 ]->AddBinaryConnection( aout, r, g, b );
72 this->Slices[ 0 ][ 1 ]->AddBinaryConnection( aout, r, g, b );
73 this->Slices[ 0 ][ 2 ]->AddBinaryConnection( aout, r, g, b );
74 this->Slices[ 1 ][ 0 ]->AddBinaryConnection( aout, r, g, b );
75 this->Slices[ 1 ][ 1 ]->AddBinaryConnection( aout, r, g, b );
76 return( this->Slices[ 1 ][ 2 ]->AddBinaryConnection( aout, r, g, b ) );
79 // -------------------------------------------------------------------------
80 int cpExtensions::Visualization::MPRActors::
83 const double& r, const double& g, const double& b
86 this->Slices[ 0 ][ 0 ]->AddBinaryImage( data, r, g, b );
87 this->Slices[ 0 ][ 1 ]->AddBinaryImage( data, r, g, b );
88 this->Slices[ 0 ][ 2 ]->AddBinaryImage( data, r, g, b );
89 this->Slices[ 1 ][ 0 ]->AddBinaryImage( data, r, g, b );
90 this->Slices[ 1 ][ 1 ]->AddBinaryImage( data, r, g, b );
91 return( this->Slices[ 1 ][ 2 ]->AddBinaryImage( data, r, g, b ) );
94 // -------------------------------------------------------------------------
95 void cpExtensions::Visualization::MPRActors::
98 this->Slices[ 0 ][ 0 ]->Clear( );
99 this->Slices[ 0 ][ 1 ]->Clear( );
100 this->Slices[ 0 ][ 2 ]->Clear( );
101 this->Slices[ 1 ][ 0 ]->Clear( );
102 this->Slices[ 1 ][ 1 ]->Clear( );
103 this->Slices[ 1 ][ 2 ]->Clear( );
106 // -------------------------------------------------------------------------
107 vtkImageData* cpExtensions::Visualization::MPRActors::
110 return( this->Slices[ 0 ][ 0 ]->GetInputImage( ) );
113 // -------------------------------------------------------------------------
114 const vtkImageData* cpExtensions::Visualization::MPRActors::
115 GetInputImage( ) const
117 return( this->Slices[ 0 ][ 0 ]->GetInputImage( ) );
120 // -------------------------------------------------------------------------
121 unsigned int cpExtensions::Visualization::MPRActors::
122 GetNumberOfImages( ) const
124 return( this->Slices[ 0 ][ 0 ]->GetNumberOfImages( ) );
127 // -------------------------------------------------------------------------
128 void cpExtensions::Visualization::MPRActors::
129 SetInterpolate( bool v )
131 this->Slices[ 0 ][ 0 ]->SetInterpolate( v );
132 this->Slices[ 0 ][ 1 ]->SetInterpolate( v );
133 this->Slices[ 0 ][ 2 ]->SetInterpolate( v );
134 this->Slices[ 1 ][ 0 ]->SetInterpolate( v );
135 this->Slices[ 1 ][ 1 ]->SetInterpolate( v );
136 this->Slices[ 1 ][ 2 ]->SetInterpolate( v );
139 // -------------------------------------------------------------------------
140 void cpExtensions::Visualization::MPRActors::
143 this->SetInterpolate( true );
146 // -------------------------------------------------------------------------
147 void cpExtensions::Visualization::MPRActors::
150 this->SetInterpolate( false );
153 // -------------------------------------------------------------------------
154 void cpExtensions::Visualization::MPRActors::
162 this->Slices[ 0 ][ 0 ]->PushActorsInto( x, true );
163 this->Slices[ 0 ][ 1 ]->PushActorsInto( y, true );
164 this->Slices[ 0 ][ 2 ]->PushActorsInto( z, true );
165 this->Slices[ 1 ][ 0 ]->PushActorsInto( w, false );
166 this->Slices[ 1 ][ 1 ]->PushActorsInto( w, false );
167 this->Slices[ 1 ][ 2 ]->PushActorsInto( w, false );
170 ( w != NULL )? w->GetRenderers( )->GetFirstRenderer( ): NULL;
173 wren->AddViewProp( this->ImageOutlineActor );
174 wren->AddViewProp( this->Slices[ 1 ][ 0 ]->GetPlaneActor( ) );
175 wren->AddViewProp( this->Slices[ 1 ][ 1 ]->GetPlaneActor( ) );
176 wren->AddViewProp( this->Slices[ 1 ][ 2 ]->GetPlaneActor( ) );
181 // -------------------------------------------------------------------------
182 void cpExtensions::Visualization::MPRActors::
190 this->Slices[ 0 ][ 0 ]->PopActorsFrom( x );
191 this->Slices[ 0 ][ 1 ]->PopActorsFrom( y );
192 this->Slices[ 0 ][ 2 ]->PopActorsFrom( z );
193 this->Slices[ 1 ][ 0 ]->PopActorsFrom( w );
194 this->Slices[ 1 ][ 1 ]->PopActorsFrom( w );
195 this->Slices[ 1 ][ 2 ]->PopActorsFrom( w );
198 ( w != NULL )? w->GetRenderers( )->GetFirstRenderer( ): NULL;
201 wren->RemoveViewProp( this->ImageOutlineActor );
202 wren->RemoveViewProp( this->Slices[ 1 ][ 0 ]->GetPlaneActor( ) );
203 wren->RemoveViewProp( this->Slices[ 1 ][ 1 ]->GetPlaneActor( ) );
204 wren->RemoveViewProp( this->Slices[ 1 ][ 2 ]->GetPlaneActor( ) );
209 // -------------------------------------------------------------------------
210 double cpExtensions::Visualization::MPRActors::
211 GetMinWindow( ) const
213 return( this->Slices[ 0 ][ 0 ]->GetMinWindow( ) );
216 // -------------------------------------------------------------------------
217 double cpExtensions::Visualization::MPRActors::
218 GetMaxWindow( ) const
220 return( this->Slices[ 0 ][ 0 ]->GetMaxWindow( ) );
223 // -------------------------------------------------------------------------
224 double cpExtensions::Visualization::MPRActors::
227 return( this->Slices[ 0 ][ 0 ]->GetMinLevel( ) );
230 // -------------------------------------------------------------------------
231 double cpExtensions::Visualization::MPRActors::
234 return( this->Slices[ 0 ][ 0 ]->GetMaxLevel( ) );
237 // -------------------------------------------------------------------------
238 double cpExtensions::Visualization::MPRActors::
241 return( this->Slices[ 0 ][ 0 ]->GetWindow( ) );
244 // -------------------------------------------------------------------------
245 double cpExtensions::Visualization::MPRActors::
248 return( this->Slices[ 0 ][ 0 ]->GetLevel( ) );
251 // -------------------------------------------------------------------------
252 void cpExtensions::Visualization::MPRActors::
253 SetWindow( double w )
255 this->Slices[ 0 ][ 0 ]->SetWindow( w );
256 this->Slices[ 0 ][ 1 ]->SetWindow( w );
257 this->Slices[ 0 ][ 2 ]->SetWindow( w );
258 this->Slices[ 1 ][ 0 ]->SetWindow( w );
259 this->Slices[ 1 ][ 1 ]->SetWindow( w );
260 this->Slices[ 1 ][ 2 ]->SetWindow( w );
263 // -------------------------------------------------------------------------
264 void cpExtensions::Visualization::MPRActors::
267 this->Slices[ 0 ][ 0 ]->SetLevel( l );
268 this->Slices[ 0 ][ 1 ]->SetLevel( l );
269 this->Slices[ 0 ][ 2 ]->SetLevel( l );
270 this->Slices[ 1 ][ 0 ]->SetLevel( l );
271 this->Slices[ 1 ][ 1 ]->SetLevel( l );
272 this->Slices[ 1 ][ 2 ]->SetLevel( l );
275 // -------------------------------------------------------------------------
276 void cpExtensions::Visualization::MPRActors::
277 SetWindowLevel( double w, double l )
279 this->Slices[ 0 ][ 0 ]->SetWindowLevel( w, l );
280 this->Slices[ 0 ][ 1 ]->SetWindowLevel( w, l );
281 this->Slices[ 0 ][ 2 ]->SetWindowLevel( w, l );
282 this->Slices[ 1 ][ 0 ]->SetWindowLevel( w, l );
283 this->Slices[ 1 ][ 1 ]->SetWindowLevel( w, l );
284 this->Slices[ 1 ][ 2 ]->SetWindowLevel( w, l );
287 // -------------------------------------------------------------------------
288 void cpExtensions::Visualization::MPRActors::
291 this->Slices[ 0 ][ 0 ]->ResetWindowLevel( );
292 this->Slices[ 0 ][ 1 ]->ResetWindowLevel( );
293 this->Slices[ 0 ][ 2 ]->ResetWindowLevel( );
294 this->Slices[ 1 ][ 0 ]->ResetWindowLevel( );
295 this->Slices[ 1 ][ 1 ]->ResetWindowLevel( );
296 this->Slices[ 1 ][ 2 ]->ResetWindowLevel( );
299 // -------------------------------------------------------------------------
300 int cpExtensions::Visualization::MPRActors::
301 GetSliceNumber( const int& axis ) const
304 return( this->Slices[ 0 ][ axis ]->GetSliceNumber( ) );
309 // -------------------------------------------------------------------------
310 int cpExtensions::Visualization::MPRActors::
311 GetSliceNumberMinValue( const int& axis ) const
314 return( this->Slices[ 0 ][ axis ]->GetSliceNumberMinValue( ) );
319 // -------------------------------------------------------------------------
320 int cpExtensions::Visualization::MPRActors::
321 GetSliceNumberMaxValue( const int& axis ) const
324 return( this->Slices[ 0 ][ axis ]->GetSliceNumberMaxValue( ) );
329 // -------------------------------------------------------------------------
330 void cpExtensions::Visualization::MPRActors::
331 SetSliceNumber( const int& axis, const int& slice )
335 this->Slices[ 0 ][ axis ]->SetSliceNumber( slice );
336 this->Slices[ 1 ][ axis ]->SetSliceNumber( slice );
341 // -------------------------------------------------------------------------
342 void cpExtensions::Visualization::MPRActors::
343 SetSlice( const int& axis, double* pos )
347 this->Slices[ 0 ][ axis ]->SetSlice( pos );
348 this->Slices[ 1 ][ axis ]->SetSlice( pos );
353 // -------------------------------------------------------------------------
354 void cpExtensions::Visualization::MPRActors::
355 Render( const int& axis )
359 this->Slices[ 0 ][ axis ]->Render( );
360 this->Slices[ 1 ][ axis ]->Render( );
365 // -------------------------------------------------------------------------
366 void cpExtensions::Visualization::MPRActors::
374 // -------------------------------------------------------------------------
375 void cpExtensions::Visualization::MPRActors::
376 ResetCamera( const int& axis )
379 this->Slices[ 0 ][ axis ]->ResetCamera( );
382 // -------------------------------------------------------------------------
383 void cpExtensions::Visualization::MPRActors::
386 this->ResetCamera( 0 );
387 this->ResetCamera( 1 );
388 this->ResetCamera( 2 );
391 // -------------------------------------------------------------------------
392 cpExtensions::Visualization::MPRActors::
396 this->ImageOutlineActor = vtkSmartPointer< vtkActor >::New( );
397 for( unsigned int i = 0; i < 2; ++i )
398 for( unsigned int j = 0; j < 3; ++j )
399 this->Slices[ i ][ j ] = vtkSmartPointer< ImageSliceActors >::New( );
401 this->Slices[ 0 ][ 0 ]->AssociateSlice( this->Slices[ 1 ][ 0 ] );
402 this->Slices[ 0 ][ 1 ]->AssociateSlice( this->Slices[ 1 ][ 1 ] );
403 this->Slices[ 0 ][ 2 ]->AssociateSlice( this->Slices[ 1 ][ 2 ] );
405 for( unsigned int i = 0; i < 3; ++ i )
407 this->Slices[ 0 ][ i ]->AddRenderCommand(
408 Self::_RenderCommand, this
410 this->Slices[ 0 ][ i ]->AddWindowLevelCommand(
411 Self::_WindowLevelCommand, this
413 this->Slices[ 0 ][ i ]->AddSlicesCommand( Self::_SlicesCommand, this );
418 // -------------------------------------------------------------------------
419 cpExtensions::Visualization::MPRActors::
424 // -------------------------------------------------------------------------
425 void cpExtensions::Visualization::MPRActors::
426 _CreateBoundingBox( )
428 vtkImageData* image =
429 dynamic_cast< vtkImageData* >( this->Slices[ 0 ][ 0 ]->GetInputImage( ) );
435 image->GetBounds( bb );
437 vtkSmartPointer< vtkOutlineSource > img_ol =
438 vtkSmartPointer< vtkOutlineSource >::New( );
439 img_ol->SetBounds( bb );
441 vtkSmartPointer< vtkPolyDataMapper > img_ol_mapper =
442 vtkSmartPointer< vtkPolyDataMapper >::New( );
443 img_ol_mapper->SetInputConnection( img_ol->GetOutputPort( ) );
444 this->ImageOutlineActor->SetMapper( img_ol_mapper );
445 this->ImageOutlineActor->GetProperty( )->SetColor( 1, 1, 1 );
446 this->ImageOutlineActor->GetProperty( )->SetLineWidth( 1 );
448 this->AddItem( this->ImageOutlineActor );
451 // -------------------------------------------------------------------------
452 void cpExtensions::Visualization::MPRActors::
453 _SlicesCommand( double* pos, int axis, void* data )
455 MPRActors* actors = reinterpret_cast< MPRActors* >( data );
458 for( unsigned int j = 0; j < 3; ++j )
460 if( actors->Slices[ 0 ][ j ]->GetAxis( ) != axis )
462 actors->SetSlice( j, pos );
470 // -------------------------------------------------------------------------
471 void cpExtensions::Visualization::MPRActors::
472 _WindowLevelCommand( double window, double level, void* data )
474 MPRActors* actors = reinterpret_cast< MPRActors* >( data );
477 actors->SetWindowLevel( window, level );
481 // -------------------------------------------------------------------------
482 void cpExtensions::Visualization::MPRActors::
483 _RenderCommand( void* data )
485 MPRActors* actors = reinterpret_cast< MPRActors* >( data );