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 this->Slices[ 0 ][ 0 ]->SetInputConnection( aout );
35 this->Slices[ 0 ][ 1 ]->SetInputConnection( aout );
36 this->Slices[ 0 ][ 2 ]->SetInputConnection( aout );
37 this->Slices[ 1 ][ 0 ]->SetInputConnection( aout );
38 this->Slices[ 1 ][ 1 ]->SetInputConnection( aout );
39 this->Slices[ 1 ][ 2 ]->SetInputConnection( aout );
42 // -------------------------------------------------------------------------
43 void cpExtensions::Visualization::MPRActors::
44 SetInputImage( vtkImageData* data )
46 this->Slices[ 0 ][ 0 ]->SetInputImage( data );
47 this->Slices[ 0 ][ 1 ]->SetInputImage( data );
48 this->Slices[ 0 ][ 2 ]->SetInputImage( data );
49 this->Slices[ 1 ][ 0 ]->SetInputImage( data );
50 this->Slices[ 1 ][ 1 ]->SetInputImage( data );
51 this->Slices[ 1 ][ 2 ]->SetInputImage( data );
54 // -------------------------------------------------------------------------
55 int cpExtensions::Visualization::MPRActors::
57 vtkAlgorithmOutput* aout,
58 const double& r, const double& g, const double& b
61 this->Slices[ 0 ][ 0 ]->AddBinaryConnection( aout, r, g, b );
62 this->Slices[ 0 ][ 1 ]->AddBinaryConnection( aout, r, g, b );
63 this->Slices[ 0 ][ 2 ]->AddBinaryConnection( aout, r, g, b );
64 this->Slices[ 1 ][ 0 ]->AddBinaryConnection( aout, r, g, b );
65 this->Slices[ 1 ][ 1 ]->AddBinaryConnection( aout, r, g, b );
66 return( this->Slices[ 1 ][ 2 ]->AddBinaryConnection( aout, r, g, b ) );
69 // -------------------------------------------------------------------------
70 int cpExtensions::Visualization::MPRActors::
73 const double& r, const double& g, const double& b
76 this->Slices[ 0 ][ 0 ]->AddBinaryImage( data, r, g, b );
77 this->Slices[ 0 ][ 1 ]->AddBinaryImage( data, r, g, b );
78 this->Slices[ 0 ][ 2 ]->AddBinaryImage( data, r, g, b );
79 this->Slices[ 1 ][ 0 ]->AddBinaryImage( data, r, g, b );
80 this->Slices[ 1 ][ 1 ]->AddBinaryImage( data, r, g, b );
81 return( this->Slices[ 1 ][ 2 ]->AddBinaryImage( data, r, g, b ) );
84 // -------------------------------------------------------------------------
85 void cpExtensions::Visualization::MPRActors::
88 this->Slices[ 0 ][ 0 ]->Clear( );
89 this->Slices[ 0 ][ 1 ]->Clear( );
90 this->Slices[ 0 ][ 2 ]->Clear( );
91 this->Slices[ 1 ][ 0 ]->Clear( );
92 this->Slices[ 1 ][ 1 ]->Clear( );
93 this->Slices[ 1 ][ 2 ]->Clear( );
96 // -------------------------------------------------------------------------
97 vtkImageData* cpExtensions::Visualization::MPRActors::
100 return( this->Slices[ 0 ][ 0 ]->GetInputImage( ) );
103 // -------------------------------------------------------------------------
104 const vtkImageData* cpExtensions::Visualization::MPRActors::
105 GetInputImage( ) const
107 return( this->Slices[ 0 ][ 0 ]->GetInputImage( ) );
110 // -------------------------------------------------------------------------
111 unsigned int cpExtensions::Visualization::MPRActors::
112 GetNumberOfImages( ) const
114 return( this->Slices[ 0 ][ 0 ]->GetNumberOfImages( ) );
117 // -------------------------------------------------------------------------
118 void cpExtensions::Visualization::MPRActors::
119 SetInterpolate( bool v )
121 this->Slices[ 0 ][ 0 ]->SetInterpolate( v );
122 this->Slices[ 0 ][ 1 ]->SetInterpolate( v );
123 this->Slices[ 0 ][ 2 ]->SetInterpolate( v );
124 this->Slices[ 1 ][ 0 ]->SetInterpolate( v );
125 this->Slices[ 1 ][ 1 ]->SetInterpolate( v );
126 this->Slices[ 1 ][ 2 ]->SetInterpolate( v );
129 // -------------------------------------------------------------------------
130 void cpExtensions::Visualization::MPRActors::
133 this->SetInterpolate( true );
136 // -------------------------------------------------------------------------
137 void cpExtensions::Visualization::MPRActors::
140 this->SetInterpolate( false );
143 // -------------------------------------------------------------------------
144 void cpExtensions::Visualization::MPRActors::
152 this->Slices[ 0 ][ 0 ]->PushActorsInto( x, true );
153 this->Slices[ 0 ][ 1 ]->PushActorsInto( y, true );
154 this->Slices[ 0 ][ 2 ]->PushActorsInto( z, true );
155 this->Slices[ 1 ][ 0 ]->PushActorsInto( w, false );
156 this->Slices[ 1 ][ 1 ]->PushActorsInto( w, false );
157 this->Slices[ 1 ][ 2 ]->PushActorsInto( w, false );
160 ( w != NULL )? w->GetRenderers( )->GetFirstRenderer( ): NULL;
162 wren->AddViewProp( this->ImageOutlineActor );
165 // -------------------------------------------------------------------------
166 void cpExtensions::Visualization::MPRActors::
174 this->Slices[ 0 ][ 0 ]->PopActorsFrom( x );
175 this->Slices[ 0 ][ 1 ]->PopActorsFrom( y );
176 this->Slices[ 0 ][ 2 ]->PopActorsFrom( z );
177 this->Slices[ 1 ][ 0 ]->PopActorsFrom( w );
178 this->Slices[ 1 ][ 1 ]->PopActorsFrom( w );
179 this->Slices[ 1 ][ 2 ]->PopActorsFrom( w );
182 ( w != NULL )? w->GetRenderers( )->GetFirstRenderer( ): NULL;
184 wren->RemoveViewProp( this->ImageOutlineActor );
187 // -------------------------------------------------------------------------
188 double cpExtensions::Visualization::MPRActors::
189 GetMinWindow( ) const
191 return( this->Slices[ 0 ][ 0 ]->GetMinWindow( ) );
194 // -------------------------------------------------------------------------
195 double cpExtensions::Visualization::MPRActors::
196 GetMaxWindow( ) const
198 return( this->Slices[ 0 ][ 0 ]->GetMaxWindow( ) );
201 // -------------------------------------------------------------------------
202 double cpExtensions::Visualization::MPRActors::
205 return( this->Slices[ 0 ][ 0 ]->GetMinLevel( ) );
208 // -------------------------------------------------------------------------
209 double cpExtensions::Visualization::MPRActors::
212 return( this->Slices[ 0 ][ 0 ]->GetMaxLevel( ) );
215 // -------------------------------------------------------------------------
216 double cpExtensions::Visualization::MPRActors::
219 return( this->Slices[ 0 ][ 0 ]->GetWindow( ) );
222 // -------------------------------------------------------------------------
223 double cpExtensions::Visualization::MPRActors::
226 return( this->Slices[ 0 ][ 0 ]->GetLevel( ) );
229 // -------------------------------------------------------------------------
230 void cpExtensions::Visualization::MPRActors::
231 SetWindow( double w )
233 this->Slices[ 0 ][ 0 ]->SetWindow( w );
234 this->Slices[ 0 ][ 1 ]->SetWindow( w );
235 this->Slices[ 0 ][ 2 ]->SetWindow( w );
236 this->Slices[ 1 ][ 0 ]->SetWindow( w );
237 this->Slices[ 1 ][ 1 ]->SetWindow( w );
238 this->Slices[ 1 ][ 2 ]->SetWindow( w );
241 // -------------------------------------------------------------------------
242 void cpExtensions::Visualization::MPRActors::
245 this->Slices[ 0 ][ 0 ]->SetLevel( l );
246 this->Slices[ 0 ][ 1 ]->SetLevel( l );
247 this->Slices[ 0 ][ 2 ]->SetLevel( l );
248 this->Slices[ 1 ][ 0 ]->SetLevel( l );
249 this->Slices[ 1 ][ 1 ]->SetLevel( l );
250 this->Slices[ 1 ][ 2 ]->SetLevel( l );
253 // -------------------------------------------------------------------------
254 void cpExtensions::Visualization::MPRActors::
255 SetWindowLevel( double w, double l )
257 this->Slices[ 0 ][ 0 ]->SetWindowLevel( w, l );
258 this->Slices[ 0 ][ 1 ]->SetWindowLevel( w, l );
259 this->Slices[ 0 ][ 2 ]->SetWindowLevel( w, l );
260 this->Slices[ 1 ][ 0 ]->SetWindowLevel( w, l );
261 this->Slices[ 1 ][ 1 ]->SetWindowLevel( w, l );
262 this->Slices[ 1 ][ 2 ]->SetWindowLevel( w, l );
265 // -------------------------------------------------------------------------
266 void cpExtensions::Visualization::MPRActors::
269 this->Slices[ 0 ][ 0 ]->ResetWindowLevel( );
270 this->Slices[ 0 ][ 1 ]->ResetWindowLevel( );
271 this->Slices[ 0 ][ 2 ]->ResetWindowLevel( );
272 this->Slices[ 1 ][ 0 ]->ResetWindowLevel( );
273 this->Slices[ 1 ][ 1 ]->ResetWindowLevel( );
274 this->Slices[ 1 ][ 2 ]->ResetWindowLevel( );
277 // -------------------------------------------------------------------------
278 int cpExtensions::Visualization::MPRActors::
279 GetSliceNumber( const int& axis ) const
282 return( this->Slices[ 0 ][ axis ]->GetSliceNumber( ) );
287 // -------------------------------------------------------------------------
288 int cpExtensions::Visualization::MPRActors::
289 GetSliceNumberMinValue( const int& axis ) const
292 return( this->Slices[ 0 ][ axis ]->GetSliceNumberMinValue( ) );
297 // -------------------------------------------------------------------------
298 int cpExtensions::Visualization::MPRActors::
299 GetSliceNumberMaxValue( const int& axis ) const
302 return( this->Slices[ 0 ][ axis ]->GetSliceNumberMaxValue( ) );
307 // -------------------------------------------------------------------------
308 void cpExtensions::Visualization::MPRActors::
309 SetSliceNumber( const int& axis, const int& slice )
313 this->Slices[ 0 ][ axis ]->SetSliceNumber( slice );
314 this->Slices[ 1 ][ axis ]->SetSliceNumber( slice );
319 // -------------------------------------------------------------------------
320 void cpExtensions::Visualization::MPRActors::
321 SetSlice( const int& axis, double* pos )
325 this->Slices[ 0 ][ axis ]->SetSlice( pos );
326 this->Slices[ 1 ][ axis ]->SetSlice( pos );
331 // -------------------------------------------------------------------------
332 cpExtensions::Visualization::MPRActors::
336 this->ImageOutlineActor = vtkSmartPointer< vtkActor >::New( );
337 for( unsigned int i = 0; i < 2; ++i )
338 for( unsigned int j = 0; j < 3; ++j )
339 this->Slices[ i ][ j ] = vtkSmartPointer< ImageSliceActors >::New( );
341 this->Slices[ 0 ][ 0 ]->AssociateSlice( this->Slices[ 1 ][ 0 ] );
342 this->Slices[ 0 ][ 1 ]->AssociateSlice( this->Slices[ 1 ][ 1 ] );
343 this->Slices[ 0 ][ 2 ]->AssociateSlice( this->Slices[ 1 ][ 2 ] );
345 for( unsigned int i = 0; i < 3; ++ i )
347 this->Slices[ 0 ][ i ]->AddRenderCommand(
348 Self::_RenderCommand, this
350 this->Slices[ 0 ][ i ]->AddWindowLevelCommand(
351 Self::_WindowLevelCommand, this
353 this->Slices[ 0 ][ i ]->AddSlicesCommand( Self::_SlicesCommand, this );
358 // -------------------------------------------------------------------------
359 cpExtensions::Visualization::MPRActors::
364 // -------------------------------------------------------------------------
365 void cpExtensions::Visualization::MPRActors::
366 _CreateBoundingBox( )
368 vtkImageData* image =
369 dynamic_cast< vtkImageData* >( this->Slices[ 0 ][ 0 ]->GetInputImage( ) );
375 image->GetBounds( bb );
377 vtkSmartPointer< vtkOutlineSource > img_ol =
378 vtkSmartPointer< vtkOutlineSource >::New( );
379 img_ol->SetBounds( bb );
381 vtkSmartPointer< vtkPolyDataMapper > img_ol_mapper =
382 vtkSmartPointer< vtkPolyDataMapper >::New( );
383 img_ol_mapper->SetInputConnection( img_ol->GetOutputPort( ) );
384 this->ImageOutlineActor->SetMapper( img_ol_mapper );
385 this->ImageOutlineActor->GetProperty( )->SetColor( 1, 1, 1 );
386 this->ImageOutlineActor->GetProperty( )->SetLineWidth( 1 );
388 this->AddItem( this->ImageOutlineActor );
391 // -------------------------------------------------------------------------
392 void cpExtensions::Visualization::MPRActors::
393 _SlicesCommand( double* pos, int axis, void* data )
395 MPRActors* actors = reinterpret_cast< MPRActors* >( data );
398 for( unsigned int j = 0; j < 3; ++j )
399 if( actors->Slices[ 0 ][ j ]->GetAxis( ) != axis )
400 actors->SetSlice( j, pos );
403 // -------------------------------------------------------------------------
404 void cpExtensions::Visualization::MPRActors::
405 _WindowLevelCommand( double window, double level, void* data )
407 MPRActors* actors = reinterpret_cast< MPRActors* >( data );
410 actors->SetWindowLevel( window, level );
413 // -------------------------------------------------------------------------
414 void cpExtensions::Visualization::MPRActors::
415 _RenderCommand( void* data )
417 MPRActors* actors = reinterpret_cast< MPRActors* >( data );