1 #include <cpExtensions/Visualization/MPRActors.h>
3 #include <vtkImageData.h>
4 #include <vtkInformation.h>
5 #include <vtkOutlineSource.h>
6 #include <vtkPolyDataMapper.h>
7 #include <vtkProperty.h>
8 #include <vtkRenderer.h>
9 #include <vtkWindowLevelLookupTable.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[ i ] );
30 // -------------------------------------------------------------------------
31 void cpExtensions::Visualization::MPRActors::
32 SetInputConnection( vtkAlgorithmOutput* aout )
34 this->ImageMapToColors->SetInputConnection( aout );
35 this->SetLookupTableToWindowLevel( );
36 this->_UpdateSlices( );
39 // -------------------------------------------------------------------------
40 void cpExtensions::Visualization::MPRActors::
41 SetInputData( vtkImageData* image )
43 this->ImageMapToColors->SetInputData( image );
44 this->SetLookupTableToWindowLevel( );
45 this->_UpdateSlices( );
48 // -------------------------------------------------------------------------
49 void cpExtensions::Visualization::MPRActors::
50 PushDataInto( vtkRenderer* x, vtkRenderer* y, vtkRenderer* z, vtkRenderer* w )
52 vtkRenderer* rends[] = { x, y, z };
53 for( int i = 0; i < 3; ++i )
55 if( rends[ i ] != NULL )
57 rends[ i ]->AddActor( this->Slices[ i ]->GetImageActor( ) );
58 rends[ i ]->AddActor( this->Slices[ i ]->GetTextActor( ) );
59 for( int j = 0; j < 3; ++j )
60 rends[ i ]->AddActor( this->Slices[ j ]->GetPlaneActor( ) );
63 w->AddActor( this->Slices[ i ]->GetImageActor( ) );
64 w->AddActor( this->Slices[ i ]->GetPlaneActor( ) );
73 w->AddActor( this->ImageOutlineActor );
76 // -------------------------------------------------------------------------
77 void cpExtensions::Visualization::MPRActors::
78 PopDataFrom( vtkRenderer* x, vtkRenderer* y, vtkRenderer* z, vtkRenderer* w )
80 vtkRenderer* rends[] = { x, y, z };
81 for( int i = 0; i < 3; ++i )
83 if( rends[ i ] != NULL )
85 rends[ i ]->RemoveActor( this->Slices[ i ]->GetImageActor( ) );
86 rends[ i ]->RemoveActor( this->Slices[ i ]->GetTextActor( ) );
87 for( int j = 0; j < 3; ++j )
88 rends[ i ]->RemoveActor( this->Slices[ j ]->GetPlaneActor( ) );
91 w->RemoveActor( this->Slices[ i ]->GetImageActor( ) );
92 w->RemoveActor( this->Slices[ i ]->GetPlaneActor( ) );
102 w->RemoveActor( this->ImageOutlineActor );
107 // -------------------------------------------------------------------------
108 vtkScalarsToColors* cpExtensions::Visualization::MPRActors::
109 GetLookupTable( ) const
111 return( this->ImageMapToColors->GetLookupTable( ) );
114 // -------------------------------------------------------------------------
115 void cpExtensions::Visualization::MPRActors::
116 SetLookupTable( vtkScalarsToColors* lut )
118 this->ImageMapToColors->SetLookupTable( lut );
119 this->ImageMapToColors->Update( );
123 // -------------------------------------------------------------------------
124 vtkWindowLevelLookupTable* cpExtensions::Visualization::MPRActors::
125 GetLookupTableAsWindowLevel( ) const
128 dynamic_cast< vtkWindowLevelLookupTable* >( this->GetLookupTable( ) )
132 // -------------------------------------------------------------------------
133 void cpExtensions::Visualization::MPRActors::
134 SetLookupTableToWindowLevel( )
136 // Check if the input has been configured
137 vtkImageData* image = this->_InputImage( );
142 image->GetScalarRange( r );
144 vtkSmartPointer< vtkWindowLevelLookupTable > lut =
145 vtkSmartPointer< vtkWindowLevelLookupTable >::New( );
146 lut->SetScaleToLinear( );
147 lut->SetTableRange( r );
150 this->SetLookupTable( lut );
153 // -------------------------------------------------------------------------
154 double cpExtensions::Visualization::MPRActors::
155 GetMinWindow( ) const
157 return( double( 0 ) );
160 // -------------------------------------------------------------------------
161 double cpExtensions::Visualization::MPRActors::
162 GetMaxWindow( ) const
164 // Check if the input has been configured
165 vtkImageData* image = this->_InputImage( );
167 return( double( 0 ) );
170 image->GetScalarRange( r );
171 return( r[ 1 ] - r[ 0 ] );
174 // -------------------------------------------------------------------------
175 double cpExtensions::Visualization::MPRActors::
178 // Check if the input has been configured
179 vtkImageData* image = this->_InputImage( );
181 return( double( 0 ) );
184 image->GetScalarRange( r );
188 // -------------------------------------------------------------------------
189 double cpExtensions::Visualization::MPRActors::
192 // Check if the input has been configured
193 vtkImageData* image = this->_InputImage( );
195 return( double( 0 ) );
198 image->GetScalarRange( r );
202 // -------------------------------------------------------------------------
203 double cpExtensions::Visualization::MPRActors::
206 vtkWindowLevelLookupTable* lut = this->GetLookupTableAsWindowLevel( );
208 return( lut->GetWindow( ) );
210 return( double( 0 ) );
213 // -------------------------------------------------------------------------
214 double cpExtensions::Visualization::MPRActors::
217 vtkWindowLevelLookupTable* lut = this->GetLookupTableAsWindowLevel( );
219 return( lut->GetLevel( ) );
221 return( double( 0 ) );
224 // -------------------------------------------------------------------------
225 void cpExtensions::Visualization::MPRActors::
226 SetWindow( const double& w )
228 vtkWindowLevelLookupTable* lut = this->GetLookupTableAsWindowLevel( );
233 this->ImageMapToColors->Modified( );
239 // -------------------------------------------------------------------------
240 void cpExtensions::Visualization::MPRActors::
241 SetLevel( const double& l )
243 vtkWindowLevelLookupTable* lut = this->GetLookupTableAsWindowLevel( );
248 this->ImageMapToColors->Modified( );
254 // -------------------------------------------------------------------------
255 void cpExtensions::Visualization::MPRActors::
256 SetWindowLevel( const double& w, const double& l )
258 vtkWindowLevelLookupTable* lut = this->GetLookupTableAsWindowLevel( );
264 this->ImageMapToColors->Modified( );
270 // -------------------------------------------------------------------------
271 void cpExtensions::Visualization::MPRActors::
274 vtkImageData* image = this->_InputImage( );
275 vtkWindowLevelLookupTable* lut = this->GetLookupTableAsWindowLevel( );
276 if( image != NULL && lut != NULL )
279 image->GetScalarRange( r );
280 lut->SetTableRange( r );
282 this->ImageMapToColors->Modified( );
288 // -------------------------------------------------------------------------
289 int cpExtensions::Visualization::MPRActors::
290 GetSliceNumberMinValue( const int& axis ) const
292 return( this->Slices[ axis ]->GetSliceNumberMinValue( ) );
295 // -------------------------------------------------------------------------
296 int cpExtensions::Visualization::MPRActors::
297 GetSliceNumberMaxValue( const int& axis ) const
299 return( this->Slices[ axis ]->GetSliceNumberMaxValue( ) );
302 // -------------------------------------------------------------------------
303 int cpExtensions::Visualization::MPRActors::
304 GetSlice( const int& axis ) const
306 return( this->Slices[ axis ]->GetSliceNumber( ) );
309 // -------------------------------------------------------------------------
310 void cpExtensions::Visualization::MPRActors::
311 SetSlice( const int& axis, const int& slice )
313 vtkImageData* image = this->_InputImage( );
317 // Get image data extent
319 image->GetExtent( ext );
321 // Check if the slice is valid
323 if( slice < ext[ axis << 1 ] )
324 real = ext[ axis << 1 ];
325 if( ext[ ( axis << 1 ) + 1 ] < slice )
326 real = ext[ ( axis << 1 ) + 1 ];
329 this->Slices[ axis ]->SetSliceNumber( real );
333 // -------------------------------------------------------------------------
334 void cpExtensions::Visualization::MPRActors::
335 SetSlice( const int& axis, const double& slice )
337 vtkImageData* image = this->_InputImage( );
341 double x[ 3 ] = { double( 0 ) };
346 image->ComputeStructuredCoordinates( x, ijk, pcoords );
347 this->SetSlice( axis, ijk[ axis ] );
350 // -------------------------------------------------------------------------
351 void cpExtensions::Visualization::MPRActors::
357 // -------------------------------------------------------------------------
358 void cpExtensions::Visualization::MPRActors::
359 GetImageBounds( double bounds[ 6 ] ) const
361 vtkImageData* image = this->_InputImage( );
363 image->GetBounds( bounds );
366 // -------------------------------------------------------------------------
367 cpExtensions::Visualization::MPRActors::
371 this->ImageMapToColors = vtkSmartPointer< vtkImageMapToColors >::New( );
372 this->ImageOutlineActor = vtkSmartPointer< vtkActor >::New( );
373 this->Slices[ 0 ] = vtkSmartPointer< _TSlice >::New( );
374 this->Slices[ 1 ] = vtkSmartPointer< _TSlice >::New( );
375 this->Slices[ 2 ] = vtkSmartPointer< _TSlice >::New( );
378 // -------------------------------------------------------------------------
379 cpExtensions::Visualization::MPRActors::
384 // -------------------------------------------------------------------------
385 vtkImageData* cpExtensions::Visualization::MPRActors::
388 vtkAlgorithm* algo = this->ImageMapToColors->GetInputAlgorithm( );
389 vtkInformation* info = algo->GetOutputInformation( 0 );
391 vtkImageData::SafeDownCast( info->Get( vtkDataObject::DATA_OBJECT( ) ) )
395 // -------------------------------------------------------------------------
396 void cpExtensions::Visualization::MPRActors::
399 // Check if the input has been configured
400 vtkImageData* image = this->_InputImage( );
403 this->ImageMapToColors->Update( );
405 for( int i = 0; i < 3; ++i )
407 this->Slices[ i ]->SetInputConnection(
408 this->ImageMapToColors->GetOutputPort( ), i
410 this->Slices[ i ]->UpdateText( );
416 image->GetBounds( bb );
418 vtkSmartPointer< vtkOutlineSource > img_ol =
419 vtkSmartPointer< vtkOutlineSource >::New( );
420 img_ol->SetBounds( bb );
422 vtkSmartPointer< vtkPolyDataMapper > img_ol_mapper =
423 vtkSmartPointer< vtkPolyDataMapper >::New( );
424 img_ol_mapper->SetInputConnection( img_ol->GetOutputPort( ) );
425 this->ImageOutlineActor->SetMapper( img_ol_mapper );
426 this->ImageOutlineActor->GetProperty( )->SetColor( 1, 1, 1 );
427 this->ImageOutlineActor->GetProperty( )->SetLineWidth( 1 );
429 this->ImageOutlineActorIndex = this->GetNumberOfItems( );
430 this->AddItem( this->ImageOutlineActor );
435 image->GetSpacing( spac );
436 double radius = spac[ 0 ];
437 radius = ( spac[ 1 ] < radius )? spac[ 1 ]: radius;
438 radius = ( spac[ 2 ] < radius )? spac[ 2 ]: radius;
439 radius *= double( 6 );
440 this->Cursor->SetRadius( radius );
441 this->CursorMapper->Modified( );
442 this->CursorActor->Modified( );
445 for( int a = 0; a < 3; ++a )
448 this->Planes[ a ].Configure( this->ImageToWindowLevel->GetOutputPort( ), a );
449 this->Planes[ a ].ConfigureRegion( this->Region->GetOutputPort( ) );
450 this->Planes[ a ].UpdateText( this->GetWindow( ), this->GetLevel( ) );
452 // Add them to renderer
453 vtkRenderer* ren = this->Interactors[ a ]->GetRenderWindow( )->
454 GetRenderers( )->GetFirstRenderer( );
456 vtkErrorMacro( "At least one interactor doesn't have a valid renderer" );
457 ren->AddActor( this->Planes[ a ].ImageActor );
458 ren->AddActor( this->Planes[ a ].TextActor );
460 for( int i = 0; i < 3; ++i )
461 this->Interactors[ a ]->GetRenderWindow( )->
462 GetRenderers( )->GetFirstRenderer( )->
463 AddActor( this->Planes[ i ].PlaneActor );
467 // Keep track into collection
469 this->XPlaneIndex = this->GetNumberOfItems( );
470 this->AddItem( this->Planes[ 0 ].ImageActor.GetPointer( ) );
471 this->XTextIndex = this->GetNumberOfItems( );
472 this->AddItem( this->Planes[ 0 ].TextActor.GetPointer( ) );
473 this->XBoundsIndex = this->GetNumberOfItems( );
474 this->AddItem( this->Planes[ 0 ].PlaneActor.GetPointer( ) );
476 this->YPlaneIndex = this->GetNumberOfItems( );
477 this->AddItem( this->Planes[ 1 ].ImageActor.GetPointer( ) );
478 this->YTextIndex = this->GetNumberOfItems( );
479 this->AddItem( this->Planes[ 1 ].TextActor.GetPointer( ) );
480 this->YBoundsIndex = this->GetNumberOfItems( );
481 this->AddItem( this->Planes[ 1 ].PlaneActor.GetPointer( ) );
483 this->ZPlaneIndex = this->GetNumberOfItems( );
484 this->AddItem( this->Planes[ 2 ].ImageActor.GetPointer( ) );
485 this->ZTextIndex = this->GetNumberOfItems( );
486 this->AddItem( this->Planes[ 2 ].TextActor.GetPointer( ) );
487 this->ZBoundsIndex = this->GetNumberOfItems( );
488 this->AddItem( this->Planes[ 2 ].PlaneActor.GetPointer( ) );
490 // Initialize slice visualization
491 // this->ResetSlices( );
494 #error CONTOUR_WIDGET <- ACA VOY
495 static vtkSmartPointer<vtkOrientedGlyphContourRepresentation> contourRep =
496 vtkSmartPointer<vtkOrientedGlyphContourRepresentation>::New();
497 static vtkSmartPointer<vtkContourWidget> contourWidget =
498 vtkSmartPointer<vtkContourWidget>::New();
499 contourWidget->SetInteractor( zi );
500 contourWidget->SetRepresentation( contourRep );
501 contourWidget->On( );