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 int cpExtensions::Visualization::MPRActors::
32 AddInputConnection( vtkAlgorithmOutput* aout )
34 for( unsigned int i = 0; i < 2; ++i )
36 for( unsigned int j = 0; j < 3; ++j )
38 this->Slices[ i ][ j ]->SetInputConnection( aout );
39 this->Slices[ i ][ j ]->SetAxis( j );
44 this->_CreateBoundingBox( );
48 // -------------------------------------------------------------------------
49 int cpExtensions::Visualization::MPRActors::
50 AddInputData( vtkImageData* new_image )
52 for( unsigned int i = 0; i < 2; ++i )
54 for( unsigned int j = 0; j < 3; ++j )
56 this->Slices[ i ][ j ]->SetInputImage( new_image );
57 this->Slices[ i ][ j ]->SetAxis( j );
62 this->_CreateBoundingBox( );
66 // -------------------------------------------------------------------------
67 unsigned int cpExtensions::Visualization::MPRActors::
68 GetNumberOfImages( ) const
70 return( this->Slices[ 0 ][ 0 ]->GetNumberOfImages( ) );
73 // -------------------------------------------------------------------------
74 void cpExtensions::Visualization::MPRActors::
76 vtkRenderWindow* x, vtkRenderWindow* y, vtkRenderWindow* z,
80 this->Slices[ 0 ][ 0 ]->PushActorsInto( x, true );
81 this->Slices[ 0 ][ 1 ]->PushActorsInto( y, true );
82 this->Slices[ 0 ][ 2 ]->PushActorsInto( z, true );
83 this->Slices[ 1 ][ 0 ]->PushActorsInto( w, false );
84 this->Slices[ 1 ][ 1 ]->PushActorsInto( w, false );
85 this->Slices[ 1 ][ 2 ]->PushActorsInto( w, false );
88 ( w != NULL )? w->GetRenderers( )->GetFirstRenderer( ): NULL;
90 wren->AddActor( this->ImageOutlineActor );
93 // -------------------------------------------------------------------------
94 void cpExtensions::Visualization::MPRActors::
96 vtkRenderWindow* x, vtkRenderWindow* y, vtkRenderWindow* z,
100 this->Slices[ 0 ][ 0 ]->PopActorsFrom( x );
101 this->Slices[ 0 ][ 1 ]->PopActorsFrom( y );
102 this->Slices[ 0 ][ 2 ]->PopActorsFrom( z );
103 this->Slices[ 1 ][ 0 ]->PopActorsFrom( w );
104 this->Slices[ 1 ][ 1 ]->PopActorsFrom( w );
105 this->Slices[ 1 ][ 2 ]->PopActorsFrom( w );
108 ( w != NULL )? w->GetRenderers( )->GetFirstRenderer( ): NULL;
110 wren->RemoveActor( this->ImageOutlineActor );
112 this->Slices[ 0 ][ 0 ]->Clear( );
113 this->Slices[ 0 ][ 1 ]->Clear( );
114 this->Slices[ 0 ][ 2 ]->Clear( );
115 this->Slices[ 1 ][ 0 ]->Clear( );
116 this->Slices[ 1 ][ 1 ]->Clear( );
117 this->Slices[ 1 ][ 2 ]->Clear( );
120 // -------------------------------------------------------------------------
121 double cpExtensions::Visualization::MPRActors::
124 return( this->Slices[ 0 ][ 0 ]->GetWindow( ) );
127 // -------------------------------------------------------------------------
128 double cpExtensions::Visualization::MPRActors::
131 return( this->Slices[ 0 ][ 0 ]->GetLevel( ) );
134 // -------------------------------------------------------------------------
135 int cpExtensions::Visualization::MPRActors::
136 GetSliceNumberMinValue( const int& axis ) const
138 return( this->Slices[ 0 ][ axis ]->GetSliceNumberMinValue( ) );
141 // -------------------------------------------------------------------------
142 int cpExtensions::Visualization::MPRActors::
143 GetSliceNumberMaxValue( const int& axis ) const
145 return( this->Slices[ 0 ][ axis ]->GetSliceNumberMaxValue( ) );
148 // -------------------------------------------------------------------------
149 int cpExtensions::Visualization::MPRActors::
150 GetSlice( const int& axis ) const
152 return( this->Slices[ 0 ][ axis ]->GetSliceNumber( ) );
155 // -------------------------------------------------------------------------
156 void cpExtensions::Visualization::MPRActors::
157 SetSlice( const int& axis, const int& slice )
159 vtkImageData* image =
160 dynamic_cast< vtkImageData* >( this->Slices[ 0 ][ 0 ]->GetInputImage( ) );
164 // Get image data extent
166 image->GetExtent( ext );
168 // Check if the slice is valid
170 if( slice < ext[ axis << 1 ] )
171 real = ext[ axis << 1 ];
172 if( ext[ ( axis << 1 ) + 1 ] < slice )
173 real = ext[ ( axis << 1 ) + 1 ];
176 this->Slices[ 0 ][ axis ]->SetSliceNumber( real );
177 this->Slices[ 1 ][ axis ]->SetSliceNumber( real );
181 // -------------------------------------------------------------------------
182 void cpExtensions::Visualization::MPRActors::
183 SetSlice( const int& axis, const double& slice )
185 vtkImageData* image =
186 dynamic_cast< vtkImageData* >( this->Slices[ 0 ][ 0 ]->GetInputImage( ) );
190 double x[ 3 ] = { double( 0 ) };
195 image->ComputeStructuredCoordinates( x, ijk, pcoords );
196 this->SetSlice( axis, ijk[ axis ] );
199 // -------------------------------------------------------------------------
200 void cpExtensions::Visualization::MPRActors::
203 for( unsigned int i = 0; i < 2; ++i )
204 for( unsigned int j = 0; j < 3; ++j )
205 this->Slices[ i ][ j ]->SetSliceNumber(
206 this->Slices[ i ][ j ]->GetSliceNumberMinValue( )
210 // -------------------------------------------------------------------------
211 cpExtensions::Visualization::MPRActors::
215 this->ImageOutlineActor = vtkSmartPointer< vtkActor >::New( );
216 for( unsigned int i = 0; i < 2; ++i )
217 for( unsigned int j = 0; j < 3; ++j )
218 this->Slices[ i ][ j ] = vtkSmartPointer< ImageSliceActors >::New( );
220 this->Slices[ 0 ][ 0 ]->AssociateSlice( this->Slices[ 1 ][ 0 ] );
221 this->Slices[ 0 ][ 1 ]->AssociateSlice( this->Slices[ 1 ][ 1 ] );
222 this->Slices[ 0 ][ 2 ]->AssociateSlice( this->Slices[ 1 ][ 2 ] );
224 for( unsigned int i = 0; i < 3; ++ i )
226 this->Slices[ 0 ][ i ]->AddRenderCommand(
227 Self::_RenderCommand, this
229 this->Slices[ 0 ][ i ]->AddWindowLevelCommand(
230 Self::_WindowLevelCommand, this
232 this->Slices[ 0 ][ i ]->AddSlicesCommand( Self::_SlicesCommand, this );
237 // -------------------------------------------------------------------------
238 cpExtensions::Visualization::MPRActors::
243 // -------------------------------------------------------------------------
244 void cpExtensions::Visualization::MPRActors::
245 _CreateBoundingBox( )
247 vtkImageData* image =
248 dynamic_cast< vtkImageData* >( this->Slices[ 0 ][ 0 ]->GetInputImage( ) );
254 image->GetBounds( bb );
256 vtkSmartPointer< vtkOutlineSource > img_ol =
257 vtkSmartPointer< vtkOutlineSource >::New( );
258 img_ol->SetBounds( bb );
260 vtkSmartPointer< vtkPolyDataMapper > img_ol_mapper =
261 vtkSmartPointer< vtkPolyDataMapper >::New( );
262 img_ol_mapper->SetInputConnection( img_ol->GetOutputPort( ) );
263 this->ImageOutlineActor->SetMapper( img_ol_mapper );
264 this->ImageOutlineActor->GetProperty( )->SetColor( 1, 1, 1 );
265 this->ImageOutlineActor->GetProperty( )->SetLineWidth( 1 );
267 this->AddItem( this->ImageOutlineActor );
270 // -------------------------------------------------------------------------
271 void cpExtensions::Visualization::MPRActors::
272 _SlicesCommand( double* pos, int axis, void* data )
274 MPRActors* actors = reinterpret_cast< MPRActors* >( data );
277 for( unsigned int j = 0; j < 3; ++j )
279 if( actors->Slices[ 0 ][ j ]->GetAxis( ) != axis )
281 actors->Slices[ 0 ][ j ]->SetSlice( pos );
282 actors->Slices[ 1 ][ j ]->SetSlice( pos );
283 actors->Slices[ 0 ][ j ]->Render( 1e-3 );
284 actors->Slices[ 1 ][ j ]->Render( 1e-3 );
291 // -------------------------------------------------------------------------
292 void cpExtensions::Visualization::MPRActors::
293 _WindowLevelCommand( double window, double level, void* data )
295 MPRActors* actors = reinterpret_cast< MPRActors* >( data );
299 actors->Slices[ 0 ][ 0 ]->SetWindowLevel( window, level );
300 actors->Slices[ 0 ][ 1 ]->SetWindowLevel( window, level );
301 actors->Slices[ 0 ][ 2 ]->SetWindowLevel( window, level );
302 actors->Slices[ 1 ][ 0 ]->SetWindowLevel( window, level );
303 actors->Slices[ 1 ][ 1 ]->SetWindowLevel( window, level );
304 actors->Slices[ 1 ][ 2 ]->SetWindowLevel( window, level );
306 actors->Slices[ 0 ][ 0 ]->Render( 1e-3 );
307 actors->Slices[ 0 ][ 1 ]->Render( 1e-3 );
308 actors->Slices[ 0 ][ 2 ]->Render( 1e-3 );
309 actors->Slices[ 1 ][ 0 ]->Render( 1e-3 );
310 actors->Slices[ 1 ][ 1 ]->Render( 1e-3 );
311 actors->Slices[ 1 ][ 2 ]->Render( 1e-3 );
314 // -------------------------------------------------------------------------
315 void cpExtensions::Visualization::MPRActors::
316 _RenderCommand( void* data )
318 MPRActors* actors = reinterpret_cast< MPRActors* >( data );
321 actors->Slices[ 0 ][ 0 ]->Render( 1e-3 );
322 actors->Slices[ 0 ][ 1 ]->Render( 1e-3 );
323 actors->Slices[ 0 ][ 2 ]->Render( 1e-3 );
324 actors->Slices[ 1 ][ 0 ]->Render( 1e-3 );
325 actors->Slices[ 1 ][ 1 ]->Render( 1e-3 );
326 actors->Slices[ 1 ][ 2 ]->Render( 1e-3 );