#include <cpPlugins/Extensions/Visualization/MPRActors.h>
#include <vtkImageData.h>
-#include <vtkLookupTable.h>
+#include <vtkInformation.h>
#include <vtkOutlineSource.h>
#include <vtkPolyDataMapper.h>
#include <vtkProperty.h>
#include <vtkRenderer.h>
+#include <vtkWindowLevelLookupTable.h>
// -------------------------------------------------------------------------
cpPlugins::Extensions::Visualization::MPRActors*
// -------------------------------------------------------------------------
void cpPlugins::Extensions::Visualization::MPRActors::
-SetInputData( vtkImageData* image )
+SetInputConnection( vtkAlgorithmOutput* aout )
{
- if( image == NULL )
- return;
-
- this->Image = image;
-
- this->ImageToWindowLevel->SetInputData( this->Image );
- this->ResetWindowLevel( );
- this->ImageToWindowLevel->Update( );
-
- for( int i = 0; i < 3; ++i )
- {
- this->Slices[ i ]->SetInputConnection(
- this->ImageToWindowLevel->GetOutputPort( ), i
- );
- this->Slices[ i ]->UpdateText( this->GetWindow( ), this->GetLevel( ) );
-
- } // rof
-
- // Create 3D outline
- vtkSmartPointer< vtkOutlineSource > img_ol =
- vtkSmartPointer< vtkOutlineSource >::New( );
- img_ol->SetBounds( this->Image->GetBounds( ) );
-
- vtkSmartPointer< vtkPolyDataMapper > img_ol_mapper =
- vtkSmartPointer< vtkPolyDataMapper >::New( );
- img_ol_mapper->SetInputConnection( img_ol->GetOutputPort( ) );
- this->ImageOutlineActor->SetMapper( img_ol_mapper );
- this->ImageOutlineActor->GetProperty( )->SetColor( 1, 1, 1 );
- this->ImageOutlineActor->GetProperty( )->SetLineWidth( 1 );
-
- this->ImageOutlineActorIndex = this->GetNumberOfItems( );
- this->AddItem( this->ImageOutlineActor );
-
- /*
- // Cursor radius
- double spac[ 3 ];
- image->GetSpacing( spac );
- double radius = spac[ 0 ];
- radius = ( spac[ 1 ] < radius )? spac[ 1 ]: radius;
- radius = ( spac[ 2 ] < radius )? spac[ 2 ]: radius;
- radius *= double( 6 );
- this->Cursor->SetRadius( radius );
- this->CursorMapper->Modified( );
- this->CursorActor->Modified( );
-
- // Plane actors
- for( int a = 0; a < 3; ++a )
- {
- // Configure actors
- this->Planes[ a ].Configure( this->ImageToWindowLevel->GetOutputPort( ), a );
- this->Planes[ a ].ConfigureRegion( this->Region->GetOutputPort( ) );
- this->Planes[ a ].UpdateText( this->GetWindow( ), this->GetLevel( ) );
-
- // Add them to renderer
- vtkRenderer* ren = this->Interactors[ a ]->GetRenderWindow( )->
- GetRenderers( )->GetFirstRenderer( );
- if( ren == NULL )
- vtkErrorMacro( "At least one interactor doesn't have a valid renderer" );
- ren->AddActor( this->Planes[ a ].ImageActor );
- ren->AddActor( this->Planes[ a ].TextActor );
-
- for( int i = 0; i < 3; ++i )
- this->Interactors[ a ]->GetRenderWindow( )->
- GetRenderers( )->GetFirstRenderer( )->
- AddActor( this->Planes[ i ].PlaneActor );
-
- } // rof
- */
- // Keep track into collection
-/*
- this->XPlaneIndex = this->GetNumberOfItems( );
- this->AddItem( this->Planes[ 0 ].ImageActor.GetPointer( ) );
- this->XTextIndex = this->GetNumberOfItems( );
- this->AddItem( this->Planes[ 0 ].TextActor.GetPointer( ) );
- this->XBoundsIndex = this->GetNumberOfItems( );
- this->AddItem( this->Planes[ 0 ].PlaneActor.GetPointer( ) );
-
- this->YPlaneIndex = this->GetNumberOfItems( );
- this->AddItem( this->Planes[ 1 ].ImageActor.GetPointer( ) );
- this->YTextIndex = this->GetNumberOfItems( );
- this->AddItem( this->Planes[ 1 ].TextActor.GetPointer( ) );
- this->YBoundsIndex = this->GetNumberOfItems( );
- this->AddItem( this->Planes[ 1 ].PlaneActor.GetPointer( ) );
-
- this->ZPlaneIndex = this->GetNumberOfItems( );
- this->AddItem( this->Planes[ 2 ].ImageActor.GetPointer( ) );
- this->ZTextIndex = this->GetNumberOfItems( );
- this->AddItem( this->Planes[ 2 ].TextActor.GetPointer( ) );
- this->ZBoundsIndex = this->GetNumberOfItems( );
- this->AddItem( this->Planes[ 2 ].PlaneActor.GetPointer( ) );
-*/
- // Initialize slice visualization
- this->ResetSlices( );
-
- /*
- #error CONTOUR_WIDGET <- ACA VOY
- static vtkSmartPointer<vtkOrientedGlyphContourRepresentation> contourRep =
- vtkSmartPointer<vtkOrientedGlyphContourRepresentation>::New();
- static vtkSmartPointer<vtkContourWidget> contourWidget =
- vtkSmartPointer<vtkContourWidget>::New();
- contourWidget->SetInteractor( zi );
- contourWidget->SetRepresentation( contourRep );
- contourWidget->On( );
- */
+ this->ImageMapToColors->SetInputConnection( aout );
+ this->SetLookupTableToWindowLevel( );
+ this->_UpdateSlices( );
}
// -------------------------------------------------------------------------
void cpPlugins::Extensions::Visualization::MPRActors::
-SetSegmentationData( vtkImageData* segmentation )
+SetInputData( vtkImageData* image )
{
- double range[ 2 ];
- this->Segmentation = segmentation;
- this->Segmentation->GetScalarRange( range );
-
- vtkSmartPointer< vtkLookupTable > lut =
- vtkSmartPointer< vtkLookupTable >::New( );
- lut->SetNumberOfTableValues( 2 );
- lut->SetTableRange( range );
- lut->SetTableValue( 0, 0, 0, 0, 0 );
- lut->SetTableValue( 1, 1, 0, 0, 0.4 );
-
- this->SegmentationToColors->SetInputData( this->Segmentation );
- this->SegmentationToColors->SetLookupTable( lut );
- this->SegmentationToColors->Update( );
-
- for( int i = 0; i < 3; ++i )
- this->Slices[ i ]->SetSegmentationConnection(
- this->SegmentationToColors->GetOutputPort( )
- );
+ this->ImageMapToColors->SetInputData( image );
+ this->SetLookupTableToWindowLevel( );
+ this->_UpdateSlices( );
}
// -------------------------------------------------------------------------
rends[ i ]->AddActor( this->Slices[ i ]->GetTextActor( ) );
for( int j = 0; j < 3; ++j )
rends[ i ]->AddActor( this->Slices[ j ]->GetPlaneActor( ) );
- if( this->Segmentation != NULL )
- rends[ i ]->AddActor( this->Slices[ i ]->GetSegmentationActor( ) );
if( w != NULL )
+ {
+ w->AddActor( this->Slices[ i ]->GetImageActor( ) );
w->AddActor( this->Slices[ i ]->GetPlaneActor( ) );
+ } // fi
+
} // fi
} // rof
void cpPlugins::Extensions::Visualization::MPRActors::
PopDataFrom( vtkRenderer* x, vtkRenderer* y, vtkRenderer* z, vtkRenderer* w )
{
+ vtkRenderer* rends[] = { x, y, z };
+ for( int i = 0; i < 3; ++i )
+ {
+ if( rends[ i ] != NULL )
+ {
+ rends[ i ]->RemoveActor( this->Slices[ i ]->GetImageActor( ) );
+ rends[ i ]->RemoveActor( this->Slices[ i ]->GetTextActor( ) );
+ for( int j = 0; j < 3; ++j )
+ rends[ i ]->RemoveActor( this->Slices[ j ]->GetPlaneActor( ) );
+ if( w != NULL )
+ {
+ w->RemoveActor( this->Slices[ i ]->GetImageActor( ) );
+ w->RemoveActor( this->Slices[ i ]->GetPlaneActor( ) );
+
+ } // fi
+
+ } // fi
+
+ } // rof
+
+ if( w != NULL )
+ {
+ w->RemoveActor( this->ImageOutlineActor );
+
+ } // fi
+}
+
+// -------------------------------------------------------------------------
+vtkScalarsToColors* cpPlugins::Extensions::Visualization::MPRActors::
+GetLookupTable( ) const
+{
+ return( this->ImageMapToColors->GetLookupTable( ) );
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::Extensions::Visualization::MPRActors::
+SetLookupTable( vtkScalarsToColors* lut )
+{
+ this->ImageMapToColors->SetLookupTable( lut );
+ this->ImageMapToColors->Update( );
+ this->Modified( );
+}
+
+// -------------------------------------------------------------------------
+vtkWindowLevelLookupTable* cpPlugins::Extensions::Visualization::MPRActors::
+GetLookupTableAsWindowLevel( ) const
+{
+ return(
+ dynamic_cast< vtkWindowLevelLookupTable* >( this->GetLookupTable( ) )
+ );
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::Extensions::Visualization::MPRActors::
+SetLookupTableToWindowLevel( )
+{
+ // Check if the input has been configured
+ vtkImageData* image = this->_InputImage( );
+ if( image == NULL )
+ return;
+
+ double r[ 2 ];
+ image->GetScalarRange( r );
+
+ vtkSmartPointer< vtkWindowLevelLookupTable > lut =
+ vtkSmartPointer< vtkWindowLevelLookupTable >::New( );
+ lut->SetScaleToLinear( );
+ lut->SetTableRange( r );
+ lut->Build( );
+
+ this->SetLookupTable( lut );
}
// -------------------------------------------------------------------------
double cpPlugins::Extensions::Visualization::MPRActors::
GetMaxWindow( ) const
{
- if( this->Image == NULL )
+ // Check if the input has been configured
+ vtkImageData* image = this->_InputImage( );
+ if( image == NULL )
return( double( 0 ) );
- double range[ 2 ];
- this->Image->GetScalarRange( range );
- return( range[ 1 ] - range[ 0 ] );
+ double r[ 2 ];
+ image->GetScalarRange( r );
+ return( r[ 1 ] - r[ 0 ] );
}
// -------------------------------------------------------------------------
double cpPlugins::Extensions::Visualization::MPRActors::
GetMinLevel( ) const
{
- if( this->Image == NULL )
+ // Check if the input has been configured
+ vtkImageData* image = this->_InputImage( );
+ if( image == NULL )
return( double( 0 ) );
- double range[ 2 ];
- this->Image->GetScalarRange( range );
- return( range[ 0 ] );
+ double r[ 2 ];
+ image->GetScalarRange( r );
+ return( r[ 0 ] );
}
// -------------------------------------------------------------------------
double cpPlugins::Extensions::Visualization::MPRActors::
GetMaxLevel( ) const
{
- if( this->Image == NULL )
+ // Check if the input has been configured
+ vtkImageData* image = this->_InputImage( );
+ if( image == NULL )
return( double( 0 ) );
- double range[ 2 ];
- this->Image->GetScalarRange( range );
- return( range[ 1 ] );
+ double r[ 2 ];
+ image->GetScalarRange( r );
+ return( r[ 1 ] );
}
// -------------------------------------------------------------------------
double cpPlugins::Extensions::Visualization::MPRActors::
GetWindow( ) const
{
- if( this->Image != NULL )
- return( this->ImageToWindowLevel->GetWindow( ) );
+ vtkWindowLevelLookupTable* lut = this->GetLookupTableAsWindowLevel( );
+ if( lut != NULL )
+ return( lut->GetWindow( ) );
else
- return( 0 );
+ return( double( 0 ) );
}
// -------------------------------------------------------------------------
double cpPlugins::Extensions::Visualization::MPRActors::
GetLevel( ) const
{
- if( this->Image != NULL )
- return( this->ImageToWindowLevel->GetLevel( ) );
+ vtkWindowLevelLookupTable* lut = this->GetLookupTableAsWindowLevel( );
+ if( lut != NULL )
+ return( lut->GetLevel( ) );
else
- return( 0 );
+ return( double( 0 ) );
}
// -------------------------------------------------------------------------
void cpPlugins::Extensions::Visualization::MPRActors::
SetWindow( const double& w )
{
- if( this->Image != NULL )
- this->ImageToWindowLevel->SetWindow( w );
+ vtkWindowLevelLookupTable* lut = this->GetLookupTableAsWindowLevel( );
+ if( lut != NULL )
+ {
+ lut->SetWindow( w );
+ lut->Build( );
+ this->ImageMapToColors->Modified( );
+ this->Modified( );
+
+ } // fi
}
// -------------------------------------------------------------------------
void cpPlugins::Extensions::Visualization::MPRActors::
SetLevel( const double& l )
{
- if( this->Image != NULL )
- this->ImageToWindowLevel->SetLevel( l );
+ vtkWindowLevelLookupTable* lut = this->GetLookupTableAsWindowLevel( );
+ if( lut != NULL )
+ {
+ lut->SetLevel( l );
+ lut->Build( );
+ this->ImageMapToColors->Modified( );
+ this->Modified( );
+
+ } // fi
}
// -------------------------------------------------------------------------
void cpPlugins::Extensions::Visualization::MPRActors::
SetWindowLevel( const double& w, const double& l )
{
- this->ImageToWindowLevel->SetWindow( w );
- this->ImageToWindowLevel->SetLevel( l );
- for( int i = 0; i < 3; ++i )
- this->Slices[ i ]->UpdateText( w, l );
+ vtkWindowLevelLookupTable* lut = this->GetLookupTableAsWindowLevel( );
+ if( lut != NULL )
+ {
+ lut->SetWindow( l );
+ lut->SetLevel( l );
+ lut->Build( );
+ this->ImageMapToColors->Modified( );
+ this->Modified( );
+
+ } // fi
}
// -------------------------------------------------------------------------
void cpPlugins::Extensions::Visualization::MPRActors::
ResetWindowLevel( )
{
- double range[ 2 ];
- this->Image->GetScalarRange( range );
- this->SetWindowLevel(
- range[ 1 ] - range[ 0 ],
- ( ( range[ 1 ] + range[ 0 ] ) / double( 2 ) ) + range[ 0 ]
- );
-}
+ vtkImageData* image = this->_InputImage( );
+ vtkWindowLevelLookupTable* lut = this->GetLookupTableAsWindowLevel( );
+ if( image != NULL && lut != NULL )
+ {
+ double r[ 2 ];
+ image->GetScalarRange( r );
+ lut->SetTableRange( r );
+ lut->Build( );
+ this->ImageMapToColors->Modified( );
+ this->Modified( );
-// -------------------------------------------------------------------------
-vtkPlane* cpPlugins::Extensions::Visualization::MPRActors::
-GetSlicePlane( const int& axis ) const
-{
+ } // fi
}
// -------------------------------------------------------------------------
void cpPlugins::Extensions::Visualization::MPRActors::
SetSlice( const int& axis, const int& slice )
{
- // Get image data extent
- if( this->Image == NULL )
+ vtkImageData* image = this->_InputImage( );
+ if( image == NULL )
return;
+
+ // Get image data extent
int ext[ 6 ];
- this->Image->GetExtent( ext );
+ image->GetExtent( ext );
// Check if the slice is valid
int real = slice;
void cpPlugins::Extensions::Visualization::MPRActors::
SetSlice( const int& axis, const double& slice )
{
- if( this->Image == NULL )
+ vtkImageData* image = this->_InputImage( );
+ if( image == NULL )
return;
-
+
double x[ 3 ] = { double( 0 ) };
double pcoords[ 3 ];
int ijk[ 3 ];
x[ axis ] = slice;
- this->Image->ComputeStructuredCoordinates( x, ijk, pcoords );
+ image->ComputeStructuredCoordinates( x, ijk, pcoords );
this->SetSlice( axis, ijk[ axis ] );
}
void cpPlugins::Extensions::Visualization::MPRActors::
ResetSlices( )
{
+ // TODO
}
// -------------------------------------------------------------------------
void cpPlugins::Extensions::Visualization::MPRActors::
GetImageBounds( double bounds[ 6 ] ) const
{
+ vtkImageData* image = this->_InputImage( );
+ if( image != NULL )
+ image->GetBounds( bounds );
}
// -------------------------------------------------------------------------
cpPlugins::Extensions::Visualization::MPRActors::
MPRActors( )
- : Superclass( ),
- Image( NULL ),
- Segmentation( NULL )
+ : Superclass( )
{
- this->ImageToWindowLevel =
- vtkSmartPointer< vtkImageMapToWindowLevelColors >::New( );
- this->SegmentationToColors = vtkSmartPointer< vtkImageMapToColors >::New( );
+ this->ImageMapToColors = vtkSmartPointer< vtkImageMapToColors >::New( );
this->ImageOutlineActor = vtkSmartPointer< vtkActor >::New( );
- this->Slices[ 0 ] = vtkSmartPointer< TSlice >::New( );
- this->Slices[ 1 ] = vtkSmartPointer< TSlice >::New( );
- this->Slices[ 2 ] = vtkSmartPointer< TSlice >::New( );
+ this->Slices[ 0 ] = vtkSmartPointer< _TSlice >::New( );
+ this->Slices[ 1 ] = vtkSmartPointer< _TSlice >::New( );
+ this->Slices[ 2 ] = vtkSmartPointer< _TSlice >::New( );
}
// -------------------------------------------------------------------------
{
}
+// -------------------------------------------------------------------------
+vtkImageData* cpPlugins::Extensions::Visualization::MPRActors::
+_InputImage( ) const
+{
+ vtkAlgorithm* algo = this->ImageMapToColors->GetInputAlgorithm( );
+ vtkInformation* info = algo->GetOutputInformation( 0 );
+ return(
+ vtkImageData::SafeDownCast( info->Get( vtkDataObject::DATA_OBJECT( ) ) )
+ );
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::Extensions::Visualization::MPRActors::
+_UpdateSlices( )
+{
+ // Check if the input has been configured
+ vtkImageData* image = this->_InputImage( );
+ if( image == NULL )
+ return;
+ this->ImageMapToColors->Update( );
+
+ for( int i = 0; i < 3; ++i )
+ {
+ this->Slices[ i ]->SetInputConnection(
+ this->ImageMapToColors->GetOutputPort( ), i
+ );
+ this->Slices[ i ]->UpdateText( );
+
+ } // rof
+
+ // Create 3D outline
+ double bb[ 6 ];
+ image->GetBounds( bb );
+
+ vtkSmartPointer< vtkOutlineSource > img_ol =
+ vtkSmartPointer< vtkOutlineSource >::New( );
+ img_ol->SetBounds( bb );
+
+ vtkSmartPointer< vtkPolyDataMapper > img_ol_mapper =
+ vtkSmartPointer< vtkPolyDataMapper >::New( );
+ img_ol_mapper->SetInputConnection( img_ol->GetOutputPort( ) );
+ this->ImageOutlineActor->SetMapper( img_ol_mapper );
+ this->ImageOutlineActor->GetProperty( )->SetColor( 1, 1, 1 );
+ this->ImageOutlineActor->GetProperty( )->SetLineWidth( 1 );
+
+ this->ImageOutlineActorIndex = this->GetNumberOfItems( );
+ this->AddItem( this->ImageOutlineActor );
+
+ // Cursor radius
+ /*
+ double spac[ 3 ];
+ image->GetSpacing( spac );
+ double radius = spac[ 0 ];
+ radius = ( spac[ 1 ] < radius )? spac[ 1 ]: radius;
+ radius = ( spac[ 2 ] < radius )? spac[ 2 ]: radius;
+ radius *= double( 6 );
+ this->Cursor->SetRadius( radius );
+ this->CursorMapper->Modified( );
+ this->CursorActor->Modified( );
+
+ // Plane actors
+ for( int a = 0; a < 3; ++a )
+ {
+ // Configure actors
+ this->Planes[ a ].Configure( this->ImageToWindowLevel->GetOutputPort( ), a );
+ this->Planes[ a ].ConfigureRegion( this->Region->GetOutputPort( ) );
+ this->Planes[ a ].UpdateText( this->GetWindow( ), this->GetLevel( ) );
+
+ // Add them to renderer
+ vtkRenderer* ren = this->Interactors[ a ]->GetRenderWindow( )->
+ GetRenderers( )->GetFirstRenderer( );
+ if( ren == NULL )
+ vtkErrorMacro( "At least one interactor doesn't have a valid renderer" );
+ ren->AddActor( this->Planes[ a ].ImageActor );
+ ren->AddActor( this->Planes[ a ].TextActor );
+
+ for( int i = 0; i < 3; ++i )
+ this->Interactors[ a ]->GetRenderWindow( )->
+ GetRenderers( )->GetFirstRenderer( )->
+ AddActor( this->Planes[ i ].PlaneActor );
+
+ } // rof
+ */
+ // Keep track into collection
+ /*
+ this->XPlaneIndex = this->GetNumberOfItems( );
+ this->AddItem( this->Planes[ 0 ].ImageActor.GetPointer( ) );
+ this->XTextIndex = this->GetNumberOfItems( );
+ this->AddItem( this->Planes[ 0 ].TextActor.GetPointer( ) );
+ this->XBoundsIndex = this->GetNumberOfItems( );
+ this->AddItem( this->Planes[ 0 ].PlaneActor.GetPointer( ) );
+
+ this->YPlaneIndex = this->GetNumberOfItems( );
+ this->AddItem( this->Planes[ 1 ].ImageActor.GetPointer( ) );
+ this->YTextIndex = this->GetNumberOfItems( );
+ this->AddItem( this->Planes[ 1 ].TextActor.GetPointer( ) );
+ this->YBoundsIndex = this->GetNumberOfItems( );
+ this->AddItem( this->Planes[ 1 ].PlaneActor.GetPointer( ) );
+
+ this->ZPlaneIndex = this->GetNumberOfItems( );
+ this->AddItem( this->Planes[ 2 ].ImageActor.GetPointer( ) );
+ this->ZTextIndex = this->GetNumberOfItems( );
+ this->AddItem( this->Planes[ 2 ].TextActor.GetPointer( ) );
+ this->ZBoundsIndex = this->GetNumberOfItems( );
+ this->AddItem( this->Planes[ 2 ].PlaneActor.GetPointer( ) );
+ */
+ // Initialize slice visualization
+ // this->ResetSlices( );
+
+ /*
+ #error CONTOUR_WIDGET <- ACA VOY
+ static vtkSmartPointer<vtkOrientedGlyphContourRepresentation> contourRep =
+ vtkSmartPointer<vtkOrientedGlyphContourRepresentation>::New();
+ static vtkSmartPointer<vtkContourWidget> contourWidget =
+ vtkSmartPointer<vtkContourWidget>::New();
+ contourWidget->SetInteractor( zi );
+ contourWidget->SetRepresentation( contourRep );
+ contourWidget->On( );
+ */
+}
+
// eof - $RCSfile$