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[ 0 ][ 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::
51 vtkRenderer* x, vtkRenderer* y, vtkRenderer* z, vtkRenderer* w
54 vtkRenderer* rends[] = { x, y, z };
55 for( int i = 0; i < 3; ++i )
57 if( rends[ i ] != NULL )
59 rends[ i ]->AddActor( this->Slices[ 0 ][ i ]->GetImageActor( ) );
60 rends[ i ]->AddActor( this->Slices[ 0 ][ i ]->GetTextActor( ) );
61 for( int j = 0; j < 3; ++j )
62 rends[ i ]->AddActor( this->Slices[ 0 ][ j ]->GetPlaneActor( ) );
67 w->AddActor( this->Slices[ 1 ][ i ]->GetImageActor( ) );
68 w->AddActor( this->Slices[ 1 ][ i ]->GetPlaneActor( ) );
74 w->AddActor( this->ImageOutlineActor );
77 // -------------------------------------------------------------------------
78 void cpExtensions::Visualization::MPRActors::
79 PopDataFrom( vtkRenderer* x, vtkRenderer* y, vtkRenderer* z, vtkRenderer* w )
81 vtkRenderer* rends[] = { x, y, z };
82 for( int i = 0; i < 3; ++i )
84 if( rends[ i ] != NULL )
86 rends[ i ]->RemoveActor( this->Slices[ 0 ][ i ]->GetImageActor( ) );
87 rends[ i ]->RemoveActor( this->Slices[ 0 ][ i ]->GetTextActor( ) );
88 for( int j = 0; j < 3; ++j )
89 rends[ i ]->RemoveActor( this->Slices[ 0 ][ j ]->GetPlaneActor( ) );
92 w->RemoveActor( this->Slices[ 1 ][ i ]->GetImageActor( ) );
93 w->RemoveActor( this->Slices[ 1 ][ i ]->GetPlaneActor( ) );
102 w->RemoveActor( this->ImageOutlineActor );
105 // -------------------------------------------------------------------------
106 vtkScalarsToColors* cpExtensions::Visualization::MPRActors::
107 GetLookupTable( ) const
109 return( this->ImageMapToColors->GetLookupTable( ) );
112 // -------------------------------------------------------------------------
113 void cpExtensions::Visualization::MPRActors::
114 SetLookupTable( vtkScalarsToColors* lut )
116 this->ImageMapToColors->SetLookupTable( lut );
117 this->ImageMapToColors->Update( );
121 // -------------------------------------------------------------------------
122 vtkWindowLevelLookupTable* cpExtensions::Visualization::MPRActors::
123 GetLookupTableAsWindowLevel( ) const
126 dynamic_cast< vtkWindowLevelLookupTable* >( this->GetLookupTable( ) )
130 // -------------------------------------------------------------------------
131 void cpExtensions::Visualization::MPRActors::
132 SetLookupTableToWindowLevel( )
134 // Check if the input has been configured
135 vtkImageData* image = this->_InputImage( );
140 image->GetScalarRange( r );
142 vtkSmartPointer< vtkWindowLevelLookupTable > lut =
143 vtkSmartPointer< vtkWindowLevelLookupTable >::New( );
144 lut->SetScaleToLinear( );
145 lut->SetTableRange( r );
148 this->SetLookupTable( lut );
151 // -------------------------------------------------------------------------
152 double cpExtensions::Visualization::MPRActors::
153 GetMinWindow( ) const
155 return( double( 0 ) );
158 // -------------------------------------------------------------------------
159 double cpExtensions::Visualization::MPRActors::
160 GetMaxWindow( ) const
162 // Check if the input has been configured
163 vtkImageData* image = this->_InputImage( );
165 return( double( 0 ) );
168 image->GetScalarRange( r );
169 return( r[ 1 ] - r[ 0 ] );
172 // -------------------------------------------------------------------------
173 double cpExtensions::Visualization::MPRActors::
176 // Check if the input has been configured
177 vtkImageData* image = this->_InputImage( );
179 return( double( 0 ) );
182 image->GetScalarRange( r );
186 // -------------------------------------------------------------------------
187 double cpExtensions::Visualization::MPRActors::
190 // Check if the input has been configured
191 vtkImageData* image = this->_InputImage( );
193 return( double( 0 ) );
196 image->GetScalarRange( r );
200 // -------------------------------------------------------------------------
201 double cpExtensions::Visualization::MPRActors::
204 vtkWindowLevelLookupTable* lut = this->GetLookupTableAsWindowLevel( );
206 return( lut->GetWindow( ) );
208 return( double( 0 ) );
211 // -------------------------------------------------------------------------
212 double cpExtensions::Visualization::MPRActors::
215 vtkWindowLevelLookupTable* lut = this->GetLookupTableAsWindowLevel( );
217 return( lut->GetLevel( ) );
219 return( double( 0 ) );
222 // -------------------------------------------------------------------------
223 void cpExtensions::Visualization::MPRActors::
224 SetWindow( const double& w )
226 vtkWindowLevelLookupTable* lut = this->GetLookupTableAsWindowLevel( );
231 this->ImageMapToColors->Modified( );
237 // -------------------------------------------------------------------------
238 void cpExtensions::Visualization::MPRActors::
239 SetLevel( const double& l )
241 vtkWindowLevelLookupTable* lut = this->GetLookupTableAsWindowLevel( );
246 this->ImageMapToColors->Modified( );
252 // -------------------------------------------------------------------------
253 void cpExtensions::Visualization::MPRActors::
254 SetWindowLevel( const double& w, const double& l )
256 vtkWindowLevelLookupTable* lut = this->GetLookupTableAsWindowLevel( );
262 this->ImageMapToColors->Modified( );
268 // -------------------------------------------------------------------------
269 void cpExtensions::Visualization::MPRActors::
272 vtkImageData* image = this->_InputImage( );
273 vtkWindowLevelLookupTable* lut = this->GetLookupTableAsWindowLevel( );
274 if( image != NULL && lut != NULL )
277 image->GetScalarRange( r );
278 lut->SetTableRange( r );
280 this->ImageMapToColors->Modified( );
286 // -------------------------------------------------------------------------
287 int cpExtensions::Visualization::MPRActors::
288 GetSliceNumberMinValue( const int& axis ) const
290 return( this->Slices[ 0 ][ axis ]->GetSliceNumberMinValue( ) );
293 // -------------------------------------------------------------------------
294 int cpExtensions::Visualization::MPRActors::
295 GetSliceNumberMaxValue( const int& axis ) const
297 return( this->Slices[ 0 ][ axis ]->GetSliceNumberMaxValue( ) );
300 // -------------------------------------------------------------------------
301 int cpExtensions::Visualization::MPRActors::
302 GetSlice( const int& axis ) const
304 return( this->Slices[ 0 ][ axis ]->GetSliceNumber( ) );
307 // -------------------------------------------------------------------------
308 void cpExtensions::Visualization::MPRActors::
309 SetSlice( const int& axis, const int& slice )
311 vtkImageData* image = this->_InputImage( );
315 // Get image data extent
317 image->GetExtent( ext );
319 // Check if the slice is valid
321 if( slice < ext[ axis << 1 ] )
322 real = ext[ axis << 1 ];
323 if( ext[ ( axis << 1 ) + 1 ] < slice )
324 real = ext[ ( axis << 1 ) + 1 ];
327 this->Slices[ 0 ][ axis ]->SetSliceNumber( real );
328 this->Slices[ 1 ][ axis ]->SetSliceNumber( real );
332 // -------------------------------------------------------------------------
333 void cpExtensions::Visualization::MPRActors::
334 SetSlice( const int& axis, const double& slice )
336 vtkImageData* image = this->_InputImage( );
340 double x[ 3 ] = { double( 0 ) };
345 image->ComputeStructuredCoordinates( x, ijk, pcoords );
346 this->SetSlice( axis, ijk[ axis ] );
349 // -------------------------------------------------------------------------
350 void cpExtensions::Visualization::MPRActors::
356 // -------------------------------------------------------------------------
357 void cpExtensions::Visualization::MPRActors::
358 GetImageBounds( double bounds[ 6 ] ) const
360 vtkImageData* image = this->_InputImage( );
362 image->GetBounds( bounds );
365 // -------------------------------------------------------------------------
366 cpExtensions::Visualization::MPRActors::
370 this->ImageMapToColors = vtkSmartPointer< vtkImageMapToColors >::New( );
371 this->ImageOutlineActor = vtkSmartPointer< vtkActor >::New( );
372 this->Slices[ 0 ][ 0 ] = vtkSmartPointer< _TSlice >::New( );
373 this->Slices[ 0 ][ 1 ] = vtkSmartPointer< _TSlice >::New( );
374 this->Slices[ 0 ][ 2 ] = vtkSmartPointer< _TSlice >::New( );
375 this->Slices[ 1 ][ 0 ] = vtkSmartPointer< _TSlice >::New( );
376 this->Slices[ 1 ][ 1 ] = vtkSmartPointer< _TSlice >::New( );
377 this->Slices[ 1 ][ 2 ] = vtkSmartPointer< _TSlice >::New( );
380 // -------------------------------------------------------------------------
381 cpExtensions::Visualization::MPRActors::
386 // -------------------------------------------------------------------------
387 vtkImageData* cpExtensions::Visualization::MPRActors::
390 vtkAlgorithm* algo = this->ImageMapToColors->GetInputAlgorithm( );
391 vtkInformation* info = algo->GetOutputInformation( 0 );
393 vtkImageData::SafeDownCast( info->Get( vtkDataObject::DATA_OBJECT( ) ) )
397 // -------------------------------------------------------------------------
398 void cpExtensions::Visualization::MPRActors::
401 // Check if the input has been configured
402 vtkImageData* image = this->_InputImage( );
405 this->ImageMapToColors->Update( );
407 for( int j = 0; j < 2; ++j )
409 for( int i = 0; i < 3; ++i )
411 this->Slices[ j ][ i ]->SetInputConnection(
412 this->ImageMapToColors->GetOutputPort( ), i
414 this->Slices[ j ][ i ]->UpdateText( );
422 image->GetBounds( bb );
424 vtkSmartPointer< vtkOutlineSource > img_ol =
425 vtkSmartPointer< vtkOutlineSource >::New( );
426 img_ol->SetBounds( bb );
428 vtkSmartPointer< vtkPolyDataMapper > img_ol_mapper =
429 vtkSmartPointer< vtkPolyDataMapper >::New( );
430 img_ol_mapper->SetInputConnection( img_ol->GetOutputPort( ) );
431 this->ImageOutlineActor->SetMapper( img_ol_mapper );
432 this->ImageOutlineActor->GetProperty( )->SetColor( 1, 1, 1 );
433 this->ImageOutlineActor->GetProperty( )->SetLineWidth( 1 );
435 this->ImageOutlineActorIndex = this->GetNumberOfItems( );
436 this->AddItem( this->ImageOutlineActor );
441 image->GetSpacing( spac );
442 double radius = spac[ 0 ];
443 radius = ( spac[ 1 ] < radius )? spac[ 1 ]: radius;
444 radius = ( spac[ 2 ] < radius )? spac[ 2 ]: radius;
445 radius *= double( 6 );
446 this->Cursor->SetRadius( radius );
447 this->CursorMapper->Modified( );
448 this->CursorActor->Modified( );
451 for( int a = 0; a < 3; ++a )
454 this->Planes[ a ].Configure( this->ImageToWindowLevel->GetOutputPort( ), a );
455 this->Planes[ a ].ConfigureRegion( this->Region->GetOutputPort( ) );
456 this->Planes[ a ].UpdateText( this->GetWindow( ), this->GetLevel( ) );
458 // Add them to renderer
459 vtkRenderer* ren = this->Interactors[ a ]->GetRenderWindow( )->
460 GetRenderers( )->GetFirstRenderer( );
462 vtkErrorMacro( "At least one interactor doesn't have a valid renderer" );
463 ren->AddActor( this->Planes[ a ].ImageActor );
464 ren->AddActor( this->Planes[ a ].TextActor );
466 for( int i = 0; i < 3; ++i )
467 this->Interactors[ a ]->GetRenderWindow( )->
468 GetRenderers( )->GetFirstRenderer( )->
469 AddActor( this->Planes[ i ].PlaneActor );
473 // Keep track into collection
475 this->XPlaneIndex = this->GetNumberOfItems( );
476 this->AddItem( this->Planes[ 0 ].ImageActor.GetPointer( ) );
477 this->XTextIndex = this->GetNumberOfItems( );
478 this->AddItem( this->Planes[ 0 ].TextActor.GetPointer( ) );
479 this->XBoundsIndex = this->GetNumberOfItems( );
480 this->AddItem( this->Planes[ 0 ].PlaneActor.GetPointer( ) );
482 this->YPlaneIndex = this->GetNumberOfItems( );
483 this->AddItem( this->Planes[ 1 ].ImageActor.GetPointer( ) );
484 this->YTextIndex = this->GetNumberOfItems( );
485 this->AddItem( this->Planes[ 1 ].TextActor.GetPointer( ) );
486 this->YBoundsIndex = this->GetNumberOfItems( );
487 this->AddItem( this->Planes[ 1 ].PlaneActor.GetPointer( ) );
489 this->ZPlaneIndex = this->GetNumberOfItems( );
490 this->AddItem( this->Planes[ 2 ].ImageActor.GetPointer( ) );
491 this->ZTextIndex = this->GetNumberOfItems( );
492 this->AddItem( this->Planes[ 2 ].TextActor.GetPointer( ) );
493 this->ZBoundsIndex = this->GetNumberOfItems( );
494 this->AddItem( this->Planes[ 2 ].PlaneActor.GetPointer( ) );
496 // Initialize slice visualization
497 // this->ResetSlices( );
500 #error CONTOUR_WIDGET <- ACA VOY
501 static vtkSmartPointer<vtkOrientedGlyphContourRepresentation> contourRep =
502 vtkSmartPointer<vtkOrientedGlyphContourRepresentation>::New();
503 static vtkSmartPointer<vtkContourWidget> contourWidget =
504 vtkSmartPointer<vtkContourWidget>::New();
505 contourWidget->SetInteractor( zi );
506 contourWidget->SetRepresentation( contourRep );
507 contourWidget->On( );