1 #include <cpExtensions/Visualization/MPRActors.h>
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>
12 // -------------------------------------------------------------------------
13 cpExtensions::Visualization::MPRActors*
14 cpExtensions::Visualization::MPRActors::
17 return( new Self( ) );
20 // -------------------------------------------------------------------------
21 cpExtensions::Visualization::
22 ImageSliceActors* cpExtensions::Visualization::MPRActors::
23 GetSliceActors( const int& i ) const
26 return( this->Slices[ 0 ][ i ] );
31 // -------------------------------------------------------------------------
32 void cpExtensions::Visualization::MPRActors::
33 SetInputConnection( vtkAlgorithmOutput* aout )
35 for( int i = 0; i < 2; ++i )
37 for( int j = 0; j < 3; ++j )
39 this->Slices[ i ][ j ]->SetInputConnection( aout );
40 this->Slices[ i ][ j ]->SetAxis( j );
45 this->_CreateBoundingBox( );
48 // -------------------------------------------------------------------------
49 void cpExtensions::Visualization::MPRActors::
50 SetInputImage( vtkImageData* data )
52 for( int i = 0; i < 2; ++i )
54 for( int j = 0; j < 3; ++j )
56 this->Slices[ i ][ j ]->SetInputImage( data );
57 this->Slices[ i ][ j ]->SetAxis( j );
62 this->_CreateBoundingBox( );
65 // -------------------------------------------------------------------------
66 int cpExtensions::Visualization::MPRActors::
68 vtkAlgorithmOutput* aout,
69 const double& r, const double& g, const double& b
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 ) );
80 // -------------------------------------------------------------------------
81 int cpExtensions::Visualization::MPRActors::
84 const double& r, const double& g, const double& b
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 ) );
95 // -------------------------------------------------------------------------
96 void cpExtensions::Visualization::MPRActors::
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( );
107 // -------------------------------------------------------------------------
108 vtkImageData* cpExtensions::Visualization::MPRActors::
111 return( this->Slices[ 0 ][ 0 ]->GetInputImage( ) );
114 // -------------------------------------------------------------------------
115 const vtkImageData* cpExtensions::Visualization::MPRActors::
116 GetInputImage( ) const
118 return( this->Slices[ 0 ][ 0 ]->GetInputImage( ) );
121 // -------------------------------------------------------------------------
122 unsigned int cpExtensions::Visualization::MPRActors::
123 GetNumberOfImages( ) const
125 return( this->Slices[ 0 ][ 0 ]->GetNumberOfImages( ) );
128 // -------------------------------------------------------------------------
129 void cpExtensions::Visualization::MPRActors::
130 SetInterpolate( bool v )
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 );
140 // -------------------------------------------------------------------------
141 void cpExtensions::Visualization::MPRActors::
144 this->SetInterpolate( true );
147 // -------------------------------------------------------------------------
148 void cpExtensions::Visualization::MPRActors::
151 this->SetInterpolate( false );
154 // -------------------------------------------------------------------------
155 void cpExtensions::Visualization::MPRActors::
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 );
171 ( w != NULL )? w->GetRenderers( )->GetFirstRenderer( ): NULL;
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( ) );
182 // -------------------------------------------------------------------------
183 void cpExtensions::Visualization::MPRActors::
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 );
199 ( w != NULL )? w->GetRenderers( )->GetFirstRenderer( ): NULL;
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( ) );
210 // -------------------------------------------------------------------------
211 double cpExtensions::Visualization::MPRActors::
212 GetMinWindow( ) const
214 return( this->Slices[ 0 ][ 0 ]->GetMinWindow( ) );
217 // -------------------------------------------------------------------------
218 double cpExtensions::Visualization::MPRActors::
219 GetMaxWindow( ) const
221 return( this->Slices[ 0 ][ 0 ]->GetMaxWindow( ) );
224 // -------------------------------------------------------------------------
225 double cpExtensions::Visualization::MPRActors::
228 return( this->Slices[ 0 ][ 0 ]->GetMinLevel( ) );
231 // -------------------------------------------------------------------------
232 double cpExtensions::Visualization::MPRActors::
235 return( this->Slices[ 0 ][ 0 ]->GetMaxLevel( ) );
238 // -------------------------------------------------------------------------
239 double cpExtensions::Visualization::MPRActors::
242 return( this->Slices[ 0 ][ 0 ]->GetWindow( ) );
245 // -------------------------------------------------------------------------
246 double cpExtensions::Visualization::MPRActors::
249 return( this->Slices[ 0 ][ 0 ]->GetLevel( ) );
252 // -------------------------------------------------------------------------
253 void cpExtensions::Visualization::MPRActors::
254 SetWindow( double w )
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 );
264 // -------------------------------------------------------------------------
265 void cpExtensions::Visualization::MPRActors::
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 );
276 // -------------------------------------------------------------------------
277 void cpExtensions::Visualization::MPRActors::
278 SetWindowLevel( double w, double l )
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 );
288 // -------------------------------------------------------------------------
289 void cpExtensions::Visualization::MPRActors::
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( );
300 // -------------------------------------------------------------------------
301 int cpExtensions::Visualization::MPRActors::
302 GetSliceNumber( const int& axis ) const
305 return( this->Slices[ 0 ][ axis ]->GetSliceNumber( ) );
310 // -------------------------------------------------------------------------
311 int cpExtensions::Visualization::MPRActors::
312 GetSliceNumberMinValue( const int& axis ) const
315 return( this->Slices[ 0 ][ axis ]->GetSliceNumberMinValue( ) );
320 // -------------------------------------------------------------------------
321 int cpExtensions::Visualization::MPRActors::
322 GetSliceNumberMaxValue( const int& axis ) const
325 return( this->Slices[ 0 ][ axis ]->GetSliceNumberMaxValue( ) );
330 // -------------------------------------------------------------------------
331 void cpExtensions::Visualization::MPRActors::
332 SetSliceNumber( const int& axis, const int& slice )
336 this->Slices[ 0 ][ axis ]->SetSliceNumber( slice );
337 this->Slices[ 1 ][ axis ]->SetSliceNumber( slice );
342 // -------------------------------------------------------------------------
343 void cpExtensions::Visualization::MPRActors::
344 SetSlice( const int& axis, double* pos )
348 this->Slices[ 0 ][ axis ]->SetSlice( pos );
349 this->Slices[ 1 ][ axis ]->SetSlice( pos );
354 // -------------------------------------------------------------------------
355 void cpExtensions::Visualization::MPRActors::
356 SetAxesCursor( const int& axis, double* pos )
359 this->Slices[ 0 ][ axis ]->SetAxesCursor( pos );
362 // -------------------------------------------------------------------------
363 void cpExtensions::Visualization::MPRActors::
364 Render( const int& axis )
368 this->Slices[ 0 ][ axis ]->Render( );
369 this->Slices[ 1 ][ axis ]->Render( );
374 // -------------------------------------------------------------------------
375 void cpExtensions::Visualization::MPRActors::
383 // -------------------------------------------------------------------------
384 void cpExtensions::Visualization::MPRActors::
385 ResetCamera( const int& axis )
388 this->Slices[ 0 ][ axis ]->ResetCamera( );
391 // -------------------------------------------------------------------------
392 void cpExtensions::Visualization::MPRActors::
395 this->ResetCamera( 0 );
396 this->ResetCamera( 1 );
397 this->ResetCamera( 2 );
400 // -------------------------------------------------------------------------
401 cpExtensions::Visualization::MPRActors::
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( );
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 ] );
414 for( unsigned int i = 0; i < 3; ++ i )
416 this->Slices[ 0 ][ i ]->AddRenderCommand(
417 Self::_RenderCommand, this
419 this->Slices[ 0 ][ i ]->AddWindowLevelCommand(
420 Self::_WindowLevelCommand, this
422 this->Slices[ 0 ][ i ]->AddSlicesCommand( Self::_SlicesCommand, this );
427 // -------------------------------------------------------------------------
428 cpExtensions::Visualization::MPRActors::
433 // -------------------------------------------------------------------------
434 void cpExtensions::Visualization::MPRActors::
435 _CreateBoundingBox( )
437 vtkImageData* image =
438 dynamic_cast< vtkImageData* >( this->Slices[ 0 ][ 0 ]->GetInputImage( ) );
444 image->GetBounds( bb );
446 vtkSmartPointer< vtkOutlineSource > img_ol =
447 vtkSmartPointer< vtkOutlineSource >::New( );
448 img_ol->SetBounds( bb );
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 );
457 this->AddItem( this->ImageOutlineActor );
460 // -------------------------------------------------------------------------
461 void cpExtensions::Visualization::MPRActors::
462 _SlicesCommand( double* pos, int axis, void* data )
464 MPRActors* actors = reinterpret_cast< MPRActors* >( data );
467 for( unsigned int j = 0; j < 3; ++j )
469 if( actors->Slices[ 0 ][ j ]->GetAxis( ) != axis )
471 actors->SetSlice( j, pos );
472 actors->SetAxesCursor( j, pos );
480 // -------------------------------------------------------------------------
481 void cpExtensions::Visualization::MPRActors::
482 _WindowLevelCommand( double window, double level, void* data )
484 MPRActors* actors = reinterpret_cast< MPRActors* >( data );
487 actors->SetWindowLevel( window, level );
491 // -------------------------------------------------------------------------
492 void cpExtensions::Visualization::MPRActors::
493 _RenderCommand( void* data )
495 MPRActors* actors = reinterpret_cast< MPRActors* >( data );