1 #include <cpExtensions/Visualization/MPRActors.h>
3 #include <vtkAlgorithmOutput.h>
4 #include <vtkImageData.h>
5 #include <vtkInformation.h>
6 #include <vtkRenderer.h>
7 #include <vtkWindowLevelLookupTable.h>
9 // -------------------------------------------------------------------------
10 cpExtensions::Visualization::MPRActors*
11 cpExtensions::Visualization::MPRActors::
14 return( new Self( ) );
17 // -------------------------------------------------------------------------
18 int cpExtensions::Visualization::MPRActors::
19 AddInputConnection( vtkAlgorithmOutput* aout )
21 int N = this->ImageMaps.size( );
24 this->ImageMaps.push_back(
25 vtkSmartPointer< vtkImageMapToColors >::New( )
27 this->ImageMaps[ 0 ]->SetInputConnection( aout );
28 this->SetLookupTableToWindowLevel( 0 );
34 // Check if the image share the same space
35 vtkImageData* ref_image = this->_Image( 0 );
36 vtkImageData* new_image =
37 vtkImageData::SafeDownCast(
38 aout->GetProducer( )->GetOutputInformation( 0 )->
39 Get( vtkDataObject::DATA_OBJECT( ) )
41 int ref_ext[ 6 ], new_ext[ 6 ];
42 ref_image->GetExtent( ref_ext );
43 new_image->GetExtent( new_ext );
45 ref_ext[ 0 ] == new_ext[ 0 ] && ref_ext[ 1 ] == new_ext[ 1 ] &&
46 ref_ext[ 2 ] == new_ext[ 2 ] && ref_ext[ 3 ] == new_ext[ 3 ] &&
47 ref_ext[ 4 ] == new_ext[ 4 ] && ref_ext[ 5 ] == new_ext[ 5 ]
50 this->ImageMaps.push_back(
51 vtkSmartPointer< vtkImageMapToColors >::New( )
53 this->ImageMaps[ N ]->SetInputConnection( aout );
54 this->SetLookupTableToWindowLevel( N );
64 // -------------------------------------------------------------------------
65 int cpExtensions::Visualization::MPRActors::
66 AddInputData( vtkImageData* image )
68 int N = this->ImageMaps.size( );
71 this->ImageMaps.push_back(
72 vtkSmartPointer< vtkImageMapToColors >::New( )
74 this->ImageMaps[ 0 ]->SetInputData( image );
75 this->SetLookupTableToWindowLevel( 0 );
81 // Check if the image share the same space
82 vtkImageData* ref_image = this->_Image( 0 );
83 vtkImageData* new_image = image;
84 int ref_ext[ 6 ], new_ext[ 6 ];
85 ref_image->GetExtent( ref_ext );
86 new_image->GetExtent( new_ext );
88 ref_ext[ 0 ] == new_ext[ 0 ] && ref_ext[ 1 ] == new_ext[ 1 ] &&
89 ref_ext[ 2 ] == new_ext[ 2 ] && ref_ext[ 3 ] == new_ext[ 3 ] &&
90 ref_ext[ 4 ] == new_ext[ 4 ] && ref_ext[ 5 ] == new_ext[ 5 ]
93 this->ImageMaps.push_back(
94 vtkSmartPointer< vtkImageMapToColors >::New( )
96 this->ImageMaps[ N ]->SetInputData( image );
97 this->SetLookupTableToWindowLevel( N );
107 // -------------------------------------------------------------------------
108 void cpExtensions::Visualization::MPRActors::
109 PushDataInto( vtkRenderer* x, vtkRenderer* y, vtkRenderer* z, vtkRenderer* w )
111 vtkRenderer* rends[] = { x, y, z };
112 for( int i = 0; i < 3; ++i )
114 if( rends[ i ] != NULL )
118 k < this->Slices[ 0 ][ i ]->GetNumberOfImageActors( );
121 rends[ i ]->AddActor( this->Slices[ 0 ][ i ]->GetImageActor( k ) );
122 rends[ i ]->AddActor( this->Slices[ 0 ][ i ]->GetTextActor( ) );
123 for( int j = 0; j < 3; ++j )
124 rends[ i ]->AddActor( this->Slices[ 0 ][ j ]->GetPlaneActor( ) );
131 k < this->Slices[ 1 ][ i ]->GetNumberOfImageActors( );
134 w->AddActor( this->Slices[ 1 ][ i ]->GetImageActor( k ) );
135 w->AddActor( this->Slices[ 1 ][ i ]->GetPlaneActor( ) );
141 w->AddActor( this->ImageOutlineActor );
144 // -------------------------------------------------------------------------
145 void cpExtensions::Visualization::MPRActors::
153 vtkRenderer* rends[] = { x, y, z };
154 for( int i = 0; i < 3; ++i )
156 if( rends[ i ] != NULL )
160 k < this->Slices[ 0 ][ i ]->GetNumberOfImageActors( );
163 rends[ i ]->RemoveActor( this->Slices[ 0 ][ i ]->GetImageActor( k ) );
164 rends[ i ]->RemoveActor( this->Slices[ 0 ][ i ]->GetTextActor( ) );
165 for( int j = 0; j < 3; ++j )
166 rends[ i ]->RemoveActor( this->Slices[ 0 ][ j ]->GetPlaneActor( ) );
173 k < this->Slices[ 1 ][ i ]->GetNumberOfImageActors( );
176 w->RemoveActor( this->Slices[ 1 ][ i ]->GetImageActor( k ) );
177 w->RemoveActor( this->Slices[ 1 ][ i ]->GetPlaneActor( ) );
183 w->RemoveActor( this->ImageOutlineActor );
186 // -------------------------------------------------------------------------
187 void cpExtensions::Visualization::MPRActors::
188 SetLookupTable( unsigned int i, vtkScalarsToColors* lut )
190 if( i < this->ImageMaps.size( ) )
192 this->ImageMaps[ i ]->SetLookupTable( lut );
193 this->ImageMaps[ i ]->Update( );
199 // -------------------------------------------------------------------------
200 vtkScalarsToColors* cpExtensions::Visualization::MPRActors::
201 GetLookupTable( unsigned int i ) const
203 if( i < this->ImageMaps.size( ) )
204 return( this->ImageMaps[ i ]->GetLookupTable( ) );
209 // -------------------------------------------------------------------------
210 void cpExtensions::Visualization::MPRActors::
211 SetLookupTableToWindowLevel( unsigned int i )
213 // Check if the input has been configured
214 vtkImageData* image = this->_Image( i );
219 image->GetScalarRange( r );
221 vtkSmartPointer< vtkWindowLevelLookupTable > lut =
222 vtkSmartPointer< vtkWindowLevelLookupTable >::New( );
223 lut->SetScaleToLinear( );
224 lut->SetTableRange( r );
227 this->SetLookupTable( i, lut );
230 // -------------------------------------------------------------------------
231 double cpExtensions::Visualization::MPRActors::
232 GetMinWindow( unsigned int i ) const
237 // -------------------------------------------------------------------------
238 double cpExtensions::Visualization::MPRActors::
239 GetMaxWindow( unsigned int i ) const
241 // Check if the input has been configured
242 vtkImageData* image = this->_Image( i );
244 return( double( 0 ) );
247 image->GetScalarRange( r );
248 return( r[ 1 ] - r[ 0 ] );
251 // -------------------------------------------------------------------------
252 double cpExtensions::Visualization::MPRActors::
253 GetMinLevel( unsigned int i ) const
255 // Check if the input has been configured
256 vtkImageData* image = this->_Image( i );
258 return( double( 0 ) );
261 image->GetScalarRange( r );
265 // -------------------------------------------------------------------------
266 double cpExtensions::Visualization::MPRActors::
267 GetMaxLevel( unsigned int i ) const
269 // Check if the input has been configured
270 vtkImageData* image = this->_Image( i );
272 return( double( 0 ) );
275 image->GetScalarRange( r );
279 // -------------------------------------------------------------------------
280 double cpExtensions::Visualization::MPRActors::
281 GetWindow( unsigned int i ) const
283 vtkWindowLevelLookupTable* lut =
284 dynamic_cast< vtkWindowLevelLookupTable* >( this->GetLookupTable( i ) );
286 return( lut->GetWindow( ) );
288 return( double( 0 ) );
291 // -------------------------------------------------------------------------
292 double cpExtensions::Visualization::MPRActors::
293 GetLevel( unsigned int i ) const
295 vtkWindowLevelLookupTable* lut =
296 dynamic_cast< vtkWindowLevelLookupTable* >( this->GetLookupTable( i ) );
298 return( lut->GetLevel( ) );
300 return( double( 0 ) );
303 // -------------------------------------------------------------------------
304 void cpExtensions::Visualization::MPRActors::
305 SetWindow( unsigned int i, const double& w )
307 vtkWindowLevelLookupTable* lut =
308 dynamic_cast< vtkWindowLevelLookupTable* >( this->GetLookupTable( i ) );
313 this->ImageMaps[ i ]->Modified( );
319 // -------------------------------------------------------------------------
320 void cpExtensions::Visualization::MPRActors::
321 SetLevel( unsigned int i, const double& l )
323 vtkWindowLevelLookupTable* lut =
324 dynamic_cast< vtkWindowLevelLookupTable* >( this->GetLookupTable( i ) );
329 this->ImageMaps[ i ]->Modified( );
335 // -------------------------------------------------------------------------
336 void cpExtensions::Visualization::MPRActors::
337 ResetWindowLevel( unsigned int i )
339 vtkImageData* image = this->_Image( i );
340 vtkWindowLevelLookupTable* lut =
341 dynamic_cast< vtkWindowLevelLookupTable* >( this->GetLookupTable( i ) );
342 if( image != NULL && lut != NULL )
345 image->GetScalarRange( r );
346 lut->SetTableRange( r );
348 this->ImageMaps[ i ]->Modified( );
354 // -------------------------------------------------------------------------
355 int cpExtensions::Visualization::MPRActors::
356 GetSliceNumberMinValue( const int& axis ) const
358 return( this->Slices[ 0 ][ axis ]->GetSliceNumberMinValue( ) );
361 // -------------------------------------------------------------------------
362 int cpExtensions::Visualization::MPRActors::
363 GetSliceNumberMaxValue( const int& axis ) const
365 return( this->Slices[ 0 ][ axis ]->GetSliceNumberMaxValue( ) );
368 // -------------------------------------------------------------------------
369 int cpExtensions::Visualization::MPRActors::
370 GetSlice( const int& axis ) const
372 return( this->Slices[ 0 ][ axis ]->GetSliceNumber( ) );
375 // -------------------------------------------------------------------------
376 void cpExtensions::Visualization::MPRActors::
377 SetSlice( const int& axis, const int& slice )
379 vtkImageData* image = this->_Image( 0 );
383 // Get image data extent
385 image->GetExtent( ext );
387 // Check if the slice is valid
389 if( slice < ext[ axis << 1 ] )
390 real = ext[ axis << 1 ];
391 if( ext[ ( axis << 1 ) + 1 ] < slice )
392 real = ext[ ( axis << 1 ) + 1 ];
395 this->Slices[ 0 ][ axis ]->SetSliceNumber( real );
396 this->Slices[ 1 ][ axis ]->SetSliceNumber( real );
400 // -------------------------------------------------------------------------
401 void cpExtensions::Visualization::MPRActors::
402 SetSlice( const int& axis, const double& slice )
404 vtkImageData* image = this->_Image( 0 );
408 double x[ 3 ] = { double( 0 ) };
413 image->ComputeStructuredCoordinates( x, ijk, pcoords );
414 this->SetSlice( axis, ijk[ axis ] );
417 // -------------------------------------------------------------------------
418 void cpExtensions::Visualization::MPRActors::
424 // -------------------------------------------------------------------------
425 cpExtensions::Visualization::MPRActors::
429 this->ImageOutlineActor = vtkSmartPointer< vtkActor >::New( );
430 for( unsigned int i = 0; i < 2; ++i )
431 for( unsigned int j = 0; j < 3; ++j )
432 this->Slices[ i ][ j ] = vtkSmartPointer< ImageSliceActors >::New( );
435 // -------------------------------------------------------------------------
436 cpExtensions::Visualization::MPRActors::
441 // -------------------------------------------------------------------------
442 vtkImageData* cpExtensions::Visualization::MPRActors::
443 _Image( unsigned int i ) const
445 if( i < this->ImageMaps.size( ) )
447 vtkAlgorithm* algo = this->ImageMaps[ i ]->GetInputAlgorithm( );
448 vtkInformation* info = algo->GetOutputInformation( 0 );
450 vtkImageData::SafeDownCast( info->Get( vtkDataObject::DATA_OBJECT( ) ) )
457 // -------------------------------------------------------------------------
458 void cpExtensions::Visualization::MPRActors::
459 _Update( unsigned int i )
462 // Check if the input has been configured
463 vtkImageData* image = this->_InputImage( );
466 this->ImageMapToColors->Update( );
468 for( int j = 0; j < 2; ++j )
470 for( int i = 0; i < 3; ++i )
472 this->Slices[ j ][ i ]->AddInputConnection(
473 this->ImageMapToColors->GetOutputPort( ), i
475 this->Slices[ j ][ i ]->UpdateText( );
483 image->GetBounds( bb );
485 vtkSmartPointer< vtkOutlineSource > img_ol =
486 vtkSmartPointer< vtkOutlineSource >::New( );
487 img_ol->SetBounds( bb );
489 vtkSmartPointer< vtkPolyDataMapper > img_ol_mapper =
490 vtkSmartPointer< vtkPolyDataMapper >::New( );
491 img_ol_mapper->SetInputConnection( img_ol->GetOutputPort( ) );
492 this->ImageOutlineActor->SetMapper( img_ol_mapper );
493 this->ImageOutlineActor->GetProperty( )->SetColor( 1, 1, 1 );
494 this->ImageOutlineActor->GetProperty( )->SetLineWidth( 1 );
496 this->AddItem( this->ImageOutlineActor );