1 #include <cpPlugins/Extensions/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 cpPlugins::Extensions::Visualization::MPRActors*
13 cpPlugins::Extensions::Visualization::MPRActors::
16 return( new Self( ) );
19 // -------------------------------------------------------------------------
20 cpPlugins::Extensions::Visualization::
21 ImageSliceActors* cpPlugins::Extensions::Visualization::MPRActors::
22 GetSliceActors( const int& i ) const
25 return( this->Slices[ i ] );
30 // -------------------------------------------------------------------------
31 void cpPlugins::Extensions::Visualization::MPRActors::
32 SetInputConnection( vtkAlgorithmOutput* aout )
34 this->ImageMapToColors->SetInputConnection( aout );
35 this->SetLookupTableToWindowLevel( );
36 this->_UpdateSlices( );
39 // -------------------------------------------------------------------------
40 void cpPlugins::Extensions::Visualization::MPRActors::
41 SetInputData( vtkImageData* image )
43 this->ImageMapToColors->SetInputData( image );
44 this->SetLookupTableToWindowLevel( );
45 this->_UpdateSlices( );
48 // -------------------------------------------------------------------------
49 void cpPlugins::Extensions::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( ) );
74 w->AddActor( this->ImageOutlineActor );
79 // -------------------------------------------------------------------------
80 void cpPlugins::Extensions::Visualization::MPRActors::
81 PopDataFrom( vtkRenderer* x, vtkRenderer* y, vtkRenderer* z, vtkRenderer* w )
83 vtkRenderer* rends[] = { x, y, z };
84 for( int i = 0; i < 3; ++i )
86 if( rends[ i ] != NULL )
88 rends[ i ]->RemoveActor( this->Slices[ i ]->GetImageActor( ) );
89 rends[ i ]->RemoveActor( this->Slices[ i ]->GetTextActor( ) );
90 for( int j = 0; j < 3; ++j )
91 rends[ i ]->RemoveActor( this->Slices[ j ]->GetPlaneActor( ) );
94 w->RemoveActor( this->Slices[ i ]->GetImageActor( ) );
95 w->RemoveActor( this->Slices[ i ]->GetPlaneActor( ) );
105 w->RemoveActor( this->ImageOutlineActor );
110 // -------------------------------------------------------------------------
111 vtkScalarsToColors* cpPlugins::Extensions::Visualization::MPRActors::
112 GetLookupTable( ) const
114 return( this->ImageMapToColors->GetLookupTable( ) );
117 // -------------------------------------------------------------------------
118 void cpPlugins::Extensions::Visualization::MPRActors::
119 SetLookupTable( vtkScalarsToColors* lut )
121 this->ImageMapToColors->SetLookupTable( lut );
122 this->ImageMapToColors->Update( );
126 // -------------------------------------------------------------------------
127 vtkWindowLevelLookupTable* cpPlugins::Extensions::Visualization::MPRActors::
128 GetLookupTableAsWindowLevel( ) const
131 dynamic_cast< vtkWindowLevelLookupTable* >( this->GetLookupTable( ) )
135 // -------------------------------------------------------------------------
136 void cpPlugins::Extensions::Visualization::MPRActors::
137 SetLookupTableToWindowLevel( )
139 // Check if the input has been configured
140 vtkImageData* image = this->_InputImage( );
145 image->GetScalarRange( r );
147 vtkSmartPointer< vtkWindowLevelLookupTable > lut =
148 vtkSmartPointer< vtkWindowLevelLookupTable >::New( );
149 lut->SetScaleToLinear( );
150 lut->SetTableRange( r );
153 this->SetLookupTable( lut );
156 // -------------------------------------------------------------------------
157 double cpPlugins::Extensions::Visualization::MPRActors::
158 GetMinWindow( ) const
160 return( double( 0 ) );
163 // -------------------------------------------------------------------------
164 double cpPlugins::Extensions::Visualization::MPRActors::
165 GetMaxWindow( ) const
167 // Check if the input has been configured
168 vtkImageData* image = this->_InputImage( );
170 return( double( 0 ) );
173 image->GetScalarRange( r );
174 return( r[ 1 ] - r[ 0 ] );
177 // -------------------------------------------------------------------------
178 double cpPlugins::Extensions::Visualization::MPRActors::
181 // Check if the input has been configured
182 vtkImageData* image = this->_InputImage( );
184 return( double( 0 ) );
187 image->GetScalarRange( r );
191 // -------------------------------------------------------------------------
192 double cpPlugins::Extensions::Visualization::MPRActors::
195 // Check if the input has been configured
196 vtkImageData* image = this->_InputImage( );
198 return( double( 0 ) );
201 image->GetScalarRange( r );
205 // -------------------------------------------------------------------------
206 double cpPlugins::Extensions::Visualization::MPRActors::
209 vtkWindowLevelLookupTable* lut = this->GetLookupTableAsWindowLevel( );
211 return( lut->GetWindow( ) );
213 return( double( 0 ) );
216 // -------------------------------------------------------------------------
217 double cpPlugins::Extensions::Visualization::MPRActors::
220 vtkWindowLevelLookupTable* lut = this->GetLookupTableAsWindowLevel( );
222 return( lut->GetLevel( ) );
224 return( double( 0 ) );
227 // -------------------------------------------------------------------------
228 void cpPlugins::Extensions::Visualization::MPRActors::
229 SetWindow( const double& w )
231 vtkWindowLevelLookupTable* lut = this->GetLookupTableAsWindowLevel( );
236 this->ImageMapToColors->Modified( );
242 // -------------------------------------------------------------------------
243 void cpPlugins::Extensions::Visualization::MPRActors::
244 SetLevel( const double& l )
246 vtkWindowLevelLookupTable* lut = this->GetLookupTableAsWindowLevel( );
251 this->ImageMapToColors->Modified( );
257 // -------------------------------------------------------------------------
258 void cpPlugins::Extensions::Visualization::MPRActors::
259 SetWindowLevel( const double& w, const double& l )
261 vtkWindowLevelLookupTable* lut = this->GetLookupTableAsWindowLevel( );
267 this->ImageMapToColors->Modified( );
273 // -------------------------------------------------------------------------
274 void cpPlugins::Extensions::Visualization::MPRActors::
277 vtkImageData* image = this->_InputImage( );
278 vtkWindowLevelLookupTable* lut = this->GetLookupTableAsWindowLevel( );
279 if( image != NULL && lut != NULL )
282 image->GetScalarRange( r );
283 lut->SetTableRange( r );
285 this->ImageMapToColors->Modified( );
291 // -------------------------------------------------------------------------
292 int cpPlugins::Extensions::Visualization::MPRActors::
293 GetSliceNumberMinValue( const int& axis ) const
295 return( this->Slices[ axis ]->GetSliceNumberMinValue( ) );
298 // -------------------------------------------------------------------------
299 int cpPlugins::Extensions::Visualization::MPRActors::
300 GetSliceNumberMaxValue( const int& axis ) const
302 return( this->Slices[ axis ]->GetSliceNumberMaxValue( ) );
305 // -------------------------------------------------------------------------
306 int cpPlugins::Extensions::Visualization::MPRActors::
307 GetSlice( const int& axis ) const
309 return( this->Slices[ axis ]->GetSliceNumber( ) );
312 // -------------------------------------------------------------------------
313 void cpPlugins::Extensions::Visualization::MPRActors::
314 SetSlice( const int& axis, const int& slice )
316 vtkImageData* image = this->_InputImage( );
320 // Get image data extent
322 image->GetExtent( ext );
324 // Check if the slice is valid
326 if( slice < ext[ axis << 1 ] )
327 real = ext[ axis << 1 ];
328 if( ext[ ( axis << 1 ) + 1 ] < slice )
329 real = ext[ ( axis << 1 ) + 1 ];
332 this->Slices[ axis ]->SetSliceNumber( real );
336 // -------------------------------------------------------------------------
337 void cpPlugins::Extensions::Visualization::MPRActors::
338 SetSlice( const int& axis, const double& slice )
340 vtkImageData* image = this->_InputImage( );
344 double x[ 3 ] = { double( 0 ) };
349 image->ComputeStructuredCoordinates( x, ijk, pcoords );
350 this->SetSlice( axis, ijk[ axis ] );
353 // -------------------------------------------------------------------------
354 void cpPlugins::Extensions::Visualization::MPRActors::
360 // -------------------------------------------------------------------------
361 void cpPlugins::Extensions::Visualization::MPRActors::
362 GetImageBounds( double bounds[ 6 ] ) const
364 vtkImageData* image = this->_InputImage( );
366 image->GetBounds( bounds );
369 // -------------------------------------------------------------------------
370 cpPlugins::Extensions::Visualization::MPRActors::
374 this->ImageMapToColors = vtkSmartPointer< vtkImageMapToColors >::New( );
375 this->ImageOutlineActor = vtkSmartPointer< vtkActor >::New( );
376 this->Slices[ 0 ] = vtkSmartPointer< _TSlice >::New( );
377 this->Slices[ 1 ] = vtkSmartPointer< _TSlice >::New( );
378 this->Slices[ 2 ] = vtkSmartPointer< _TSlice >::New( );
381 // -------------------------------------------------------------------------
382 cpPlugins::Extensions::Visualization::MPRActors::
387 // -------------------------------------------------------------------------
388 vtkImageData* cpPlugins::Extensions::Visualization::MPRActors::
391 vtkAlgorithm* algo = this->ImageMapToColors->GetInputAlgorithm( );
392 vtkInformation* info = algo->GetOutputInformation( 0 );
394 vtkImageData::SafeDownCast( info->Get( vtkDataObject::DATA_OBJECT( ) ) )
398 // -------------------------------------------------------------------------
399 void cpPlugins::Extensions::Visualization::MPRActors::
402 // Check if the input has been configured
403 vtkImageData* image = this->_InputImage( );
406 this->ImageMapToColors->Update( );
408 for( int i = 0; i < 3; ++i )
410 this->Slices[ i ]->SetInputConnection(
411 this->ImageMapToColors->GetOutputPort( ), i
413 this->Slices[ i ]->UpdateText( );
419 image->GetBounds( bb );
421 vtkSmartPointer< vtkOutlineSource > img_ol =
422 vtkSmartPointer< vtkOutlineSource >::New( );
423 img_ol->SetBounds( bb );
425 vtkSmartPointer< vtkPolyDataMapper > img_ol_mapper =
426 vtkSmartPointer< vtkPolyDataMapper >::New( );
427 img_ol_mapper->SetInputConnection( img_ol->GetOutputPort( ) );
428 this->ImageOutlineActor->SetMapper( img_ol_mapper );
429 this->ImageOutlineActor->GetProperty( )->SetColor( 1, 1, 1 );
430 this->ImageOutlineActor->GetProperty( )->SetLineWidth( 1 );
432 this->ImageOutlineActorIndex = this->GetNumberOfItems( );
433 this->AddItem( this->ImageOutlineActor );
438 image->GetSpacing( spac );
439 double radius = spac[ 0 ];
440 radius = ( spac[ 1 ] < radius )? spac[ 1 ]: radius;
441 radius = ( spac[ 2 ] < radius )? spac[ 2 ]: radius;
442 radius *= double( 6 );
443 this->Cursor->SetRadius( radius );
444 this->CursorMapper->Modified( );
445 this->CursorActor->Modified( );
448 for( int a = 0; a < 3; ++a )
451 this->Planes[ a ].Configure( this->ImageToWindowLevel->GetOutputPort( ), a );
452 this->Planes[ a ].ConfigureRegion( this->Region->GetOutputPort( ) );
453 this->Planes[ a ].UpdateText( this->GetWindow( ), this->GetLevel( ) );
455 // Add them to renderer
456 vtkRenderer* ren = this->Interactors[ a ]->GetRenderWindow( )->
457 GetRenderers( )->GetFirstRenderer( );
459 vtkErrorMacro( "At least one interactor doesn't have a valid renderer" );
460 ren->AddActor( this->Planes[ a ].ImageActor );
461 ren->AddActor( this->Planes[ a ].TextActor );
463 for( int i = 0; i < 3; ++i )
464 this->Interactors[ a ]->GetRenderWindow( )->
465 GetRenderers( )->GetFirstRenderer( )->
466 AddActor( this->Planes[ i ].PlaneActor );
470 // Keep track into collection
472 this->XPlaneIndex = this->GetNumberOfItems( );
473 this->AddItem( this->Planes[ 0 ].ImageActor.GetPointer( ) );
474 this->XTextIndex = this->GetNumberOfItems( );
475 this->AddItem( this->Planes[ 0 ].TextActor.GetPointer( ) );
476 this->XBoundsIndex = this->GetNumberOfItems( );
477 this->AddItem( this->Planes[ 0 ].PlaneActor.GetPointer( ) );
479 this->YPlaneIndex = this->GetNumberOfItems( );
480 this->AddItem( this->Planes[ 1 ].ImageActor.GetPointer( ) );
481 this->YTextIndex = this->GetNumberOfItems( );
482 this->AddItem( this->Planes[ 1 ].TextActor.GetPointer( ) );
483 this->YBoundsIndex = this->GetNumberOfItems( );
484 this->AddItem( this->Planes[ 1 ].PlaneActor.GetPointer( ) );
486 this->ZPlaneIndex = this->GetNumberOfItems( );
487 this->AddItem( this->Planes[ 2 ].ImageActor.GetPointer( ) );
488 this->ZTextIndex = this->GetNumberOfItems( );
489 this->AddItem( this->Planes[ 2 ].TextActor.GetPointer( ) );
490 this->ZBoundsIndex = this->GetNumberOfItems( );
491 this->AddItem( this->Planes[ 2 ].PlaneActor.GetPointer( ) );
493 // Initialize slice visualization
494 // this->ResetSlices( );
497 #error CONTOUR_WIDGET <- ACA VOY
498 static vtkSmartPointer<vtkOrientedGlyphContourRepresentation> contourRep =
499 vtkSmartPointer<vtkOrientedGlyphContourRepresentation>::New();
500 static vtkSmartPointer<vtkContourWidget> contourWidget =
501 vtkSmartPointer<vtkContourWidget>::New();
502 contourWidget->SetInteractor( zi );
503 contourWidget->SetRepresentation( contourRep );
504 contourWidget->On( );