#include <cpExtensions/Visualization/MPRActors.h>
+#include <vtkAlgorithmOutput.h>
#include <vtkImageData.h>
#include <vtkInformation.h>
-#include <vtkOutlineSource.h>
-#include <vtkPolyDataMapper.h>
-#include <vtkProperty.h>
#include <vtkRenderer.h>
#include <vtkWindowLevelLookupTable.h>
}
// -------------------------------------------------------------------------
-cpExtensions::Visualization::
-ImageSliceActors* cpExtensions::Visualization::MPRActors::
-GetSliceActors( const int& i ) const
+int cpExtensions::Visualization::MPRActors::
+AddInputConnection( vtkAlgorithmOutput* aout )
{
- if( i < 3 )
- return( this->Slices[ 0 ][ i ] );
+ int N = this->ImageMaps.size( );
+ if( N == 0 )
+ {
+ this->ImageMaps.push_back(
+ vtkSmartPointer< vtkImageMapToColors >::New( )
+ );
+ this->ImageMaps[ 0 ]->SetInputConnection( aout );
+ this->SetLookupTableToWindowLevel( 0 );
+ this->_Update( 0 );
+ return( 0 );
+ }
else
- return( NULL );
-}
+ {
+ // Check if the image share the same space
+ vtkImageData* ref_image = this->_Image( 0 );
+ vtkImageData* new_image =
+ vtkImageData::SafeDownCast(
+ aout->GetProducer( )->GetOutputInformation( 0 )->
+ Get( vtkDataObject::DATA_OBJECT( ) )
+ );
+ int ref_ext[ 6 ], new_ext[ 6 ];
+ ref_image->GetExtent( ref_ext );
+ new_image->GetExtent( new_ext );
+ if(
+ ref_ext[ 0 ] == new_ext[ 0 ] && ref_ext[ 1 ] == new_ext[ 1 ] &&
+ ref_ext[ 2 ] == new_ext[ 2 ] && ref_ext[ 3 ] == new_ext[ 3 ] &&
+ ref_ext[ 4 ] == new_ext[ 4 ] && ref_ext[ 5 ] == new_ext[ 5 ]
+ )
+ {
+ this->ImageMaps.push_back(
+ vtkSmartPointer< vtkImageMapToColors >::New( )
+ );
+ this->ImageMaps[ N ]->SetInputConnection( aout );
+ this->SetLookupTableToWindowLevel( N );
+ this->_Update( N );
+ return( N );
+ }
+ else
+ return( -1 );
-// -------------------------------------------------------------------------
-void cpExtensions::Visualization::MPRActors::
-SetInputConnection( vtkAlgorithmOutput* aout )
-{
- this->ImageMapToColors->SetInputConnection( aout );
- this->SetLookupTableToWindowLevel( );
- this->_UpdateSlices( );
+ } // fi
}
// -------------------------------------------------------------------------
-void cpExtensions::Visualization::MPRActors::
-SetInputData( vtkImageData* image )
+int cpExtensions::Visualization::MPRActors::
+AddInputData( vtkImageData* image )
{
- this->ImageMapToColors->SetInputData( image );
- this->SetLookupTableToWindowLevel( );
- this->_UpdateSlices( );
+ int N = this->ImageMaps.size( );
+ if( N == 0 )
+ {
+ this->ImageMaps.push_back(
+ vtkSmartPointer< vtkImageMapToColors >::New( )
+ );
+ this->ImageMaps[ 0 ]->SetInputData( image );
+ this->SetLookupTableToWindowLevel( 0 );
+ this->_Update( 0 );
+ return( 0 );
+ }
+ else
+ {
+ // Check if the image share the same space
+ vtkImageData* ref_image = this->_Image( 0 );
+ vtkImageData* new_image = image;
+ int ref_ext[ 6 ], new_ext[ 6 ];
+ ref_image->GetExtent( ref_ext );
+ new_image->GetExtent( new_ext );
+ if(
+ ref_ext[ 0 ] == new_ext[ 0 ] && ref_ext[ 1 ] == new_ext[ 1 ] &&
+ ref_ext[ 2 ] == new_ext[ 2 ] && ref_ext[ 3 ] == new_ext[ 3 ] &&
+ ref_ext[ 4 ] == new_ext[ 4 ] && ref_ext[ 5 ] == new_ext[ 5 ]
+ )
+ {
+ this->ImageMaps.push_back(
+ vtkSmartPointer< vtkImageMapToColors >::New( )
+ );
+ this->ImageMaps[ N ]->SetInputData( image );
+ this->SetLookupTableToWindowLevel( N );
+ this->_Update( N );
+ return( N );
+ }
+ else
+ return( -1 );
+
+ } // fi
}
// -------------------------------------------------------------------------
void cpExtensions::Visualization::MPRActors::
-PushDataInto(
- vtkRenderer* x, vtkRenderer* y, vtkRenderer* z, vtkRenderer* w
- )
+PushDataInto( 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 ]->AddActor( this->Slices[ 0 ][ i ]->GetImageActor( ) );
+ for(
+ unsigned int k = 0;
+ k < this->Slices[ 0 ][ i ]->GetNumberOfImageActors( );
+ ++k
+ )
+ rends[ i ]->AddActor( this->Slices[ 0 ][ i ]->GetImageActor( k ) );
rends[ i ]->AddActor( this->Slices[ 0 ][ i ]->GetTextActor( ) );
for( int j = 0; j < 3; ++j )
rends[ i ]->AddActor( this->Slices[ 0 ][ j ]->GetPlaneActor( ) );
} // fi
if( w != NULL )
{
- w->AddActor( this->Slices[ 1 ][ i ]->GetImageActor( ) );
+ for(
+ unsigned int k = 0;
+ k < this->Slices[ 1 ][ i ]->GetNumberOfImageActors( );
+ ++k
+ )
+ w->AddActor( this->Slices[ 1 ][ i ]->GetImageActor( k ) );
w->AddActor( this->Slices[ 1 ][ i ]->GetPlaneActor( ) );
} // fi
// -------------------------------------------------------------------------
void cpExtensions::Visualization::MPRActors::
-PopDataFrom( vtkRenderer* x, vtkRenderer* y, vtkRenderer* z, vtkRenderer* w )
+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[ 0 ][ i ]->GetImageActor( ) );
+ for(
+ unsigned int k = 0;
+ k < this->Slices[ 0 ][ i ]->GetNumberOfImageActors( );
+ ++k
+ )
+ rends[ i ]->RemoveActor( this->Slices[ 0 ][ i ]->GetImageActor( k ) );
rends[ i ]->RemoveActor( this->Slices[ 0 ][ i ]->GetTextActor( ) );
for( int j = 0; j < 3; ++j )
rends[ i ]->RemoveActor( this->Slices[ 0 ][ j ]->GetPlaneActor( ) );
- if( w != NULL )
- {
- w->RemoveActor( this->Slices[ 1 ][ i ]->GetImageActor( ) );
- w->RemoveActor( this->Slices[ 1 ][ i ]->GetPlaneActor( ) );
- } // fi
+ } // fi
+ if( w != NULL )
+ {
+ for(
+ unsigned int k = 0;
+ k < this->Slices[ 1 ][ i ]->GetNumberOfImageActors( );
+ ++k
+ )
+ w->RemoveActor( this->Slices[ 1 ][ i ]->GetImageActor( k ) );
+ w->RemoveActor( this->Slices[ 1 ][ i ]->GetPlaneActor( ) );
} // fi
} // rof
-
if( w != NULL )
w->RemoveActor( this->ImageOutlineActor );
}
-// -------------------------------------------------------------------------
-vtkScalarsToColors* cpExtensions::Visualization::MPRActors::
-GetLookupTable( ) const
-{
- return( this->ImageMapToColors->GetLookupTable( ) );
-}
-
// -------------------------------------------------------------------------
void cpExtensions::Visualization::MPRActors::
-SetLookupTable( vtkScalarsToColors* lut )
+SetLookupTable( unsigned int i, vtkScalarsToColors* lut )
{
- this->ImageMapToColors->SetLookupTable( lut );
- this->ImageMapToColors->Update( );
- this->Modified( );
+ if( i < this->ImageMaps.size( ) )
+ {
+ this->ImageMaps[ i ]->SetLookupTable( lut );
+ this->ImageMaps[ i ]->Update( );
+ this->Modified( );
+
+ } // fi
}
// -------------------------------------------------------------------------
-vtkWindowLevelLookupTable* cpExtensions::Visualization::MPRActors::
-GetLookupTableAsWindowLevel( ) const
+vtkScalarsToColors* cpExtensions::Visualization::MPRActors::
+GetLookupTable( unsigned int i ) const
{
- return(
- dynamic_cast< vtkWindowLevelLookupTable* >( this->GetLookupTable( ) )
- );
+ if( i < this->ImageMaps.size( ) )
+ return( this->ImageMaps[ i ]->GetLookupTable( ) );
+ else
+ return( NULL );
}
// -------------------------------------------------------------------------
void cpExtensions::Visualization::MPRActors::
-SetLookupTableToWindowLevel( )
+SetLookupTableToWindowLevel( unsigned int i )
{
// Check if the input has been configured
- vtkImageData* image = this->_InputImage( );
+ vtkImageData* image = this->_Image( i );
if( image == NULL )
return;
lut->SetTableRange( r );
lut->Build( );
- this->SetLookupTable( lut );
+ this->SetLookupTable( i, lut );
}
// -------------------------------------------------------------------------
double cpExtensions::Visualization::MPRActors::
-GetMinWindow( ) const
+GetMinWindow( unsigned int i ) const
{
- return( double( 0 ) );
+ return( 0 );
}
// -------------------------------------------------------------------------
double cpExtensions::Visualization::MPRActors::
-GetMaxWindow( ) const
+GetMaxWindow( unsigned int i ) const
{
// Check if the input has been configured
- vtkImageData* image = this->_InputImage( );
+ vtkImageData* image = this->_Image( i );
if( image == NULL )
return( double( 0 ) );
// -------------------------------------------------------------------------
double cpExtensions::Visualization::MPRActors::
-GetMinLevel( ) const
+GetMinLevel( unsigned int i ) const
{
// Check if the input has been configured
- vtkImageData* image = this->_InputImage( );
+ vtkImageData* image = this->_Image( i );
if( image == NULL )
return( double( 0 ) );
// -------------------------------------------------------------------------
double cpExtensions::Visualization::MPRActors::
-GetMaxLevel( ) const
+GetMaxLevel( unsigned int i ) const
{
// Check if the input has been configured
- vtkImageData* image = this->_InputImage( );
+ vtkImageData* image = this->_Image( i );
if( image == NULL )
return( double( 0 ) );
// -------------------------------------------------------------------------
double cpExtensions::Visualization::MPRActors::
-GetWindow( ) const
+GetWindow( unsigned int i ) const
{
- vtkWindowLevelLookupTable* lut = this->GetLookupTableAsWindowLevel( );
+ vtkWindowLevelLookupTable* lut =
+ dynamic_cast< vtkWindowLevelLookupTable* >( this->GetLookupTable( i ) );
if( lut != NULL )
return( lut->GetWindow( ) );
else
// -------------------------------------------------------------------------
double cpExtensions::Visualization::MPRActors::
-GetLevel( ) const
+GetLevel( unsigned int i ) const
{
- vtkWindowLevelLookupTable* lut = this->GetLookupTableAsWindowLevel( );
+ vtkWindowLevelLookupTable* lut =
+ dynamic_cast< vtkWindowLevelLookupTable* >( this->GetLookupTable( i ) );
if( lut != NULL )
return( lut->GetLevel( ) );
else
// -------------------------------------------------------------------------
void cpExtensions::Visualization::MPRActors::
-SetWindow( const double& w )
+SetWindow( unsigned int i, const double& w )
{
- vtkWindowLevelLookupTable* lut = this->GetLookupTableAsWindowLevel( );
+ vtkWindowLevelLookupTable* lut =
+ dynamic_cast< vtkWindowLevelLookupTable* >( this->GetLookupTable( i ) );
if( lut != NULL )
{
lut->SetWindow( w );
lut->Build( );
- this->ImageMapToColors->Modified( );
+ this->ImageMaps[ i ]->Modified( );
this->Modified( );
} // fi
// -------------------------------------------------------------------------
void cpExtensions::Visualization::MPRActors::
-SetLevel( const double& l )
+SetLevel( unsigned int i, const double& l )
{
- vtkWindowLevelLookupTable* lut = this->GetLookupTableAsWindowLevel( );
+ vtkWindowLevelLookupTable* lut =
+ dynamic_cast< vtkWindowLevelLookupTable* >( this->GetLookupTable( i ) );
if( lut != NULL )
{
lut->SetLevel( l );
lut->Build( );
- this->ImageMapToColors->Modified( );
+ this->ImageMaps[ i ]->Modified( );
this->Modified( );
} // fi
// -------------------------------------------------------------------------
void cpExtensions::Visualization::MPRActors::
-SetWindowLevel( const double& w, const double& l )
+ResetWindowLevel( unsigned int i )
{
- vtkWindowLevelLookupTable* lut = this->GetLookupTableAsWindowLevel( );
- if( lut != NULL )
- {
- lut->SetWindow( l );
- lut->SetLevel( l );
- lut->Build( );
- this->ImageMapToColors->Modified( );
- this->Modified( );
-
- } // fi
-}
-
-// -------------------------------------------------------------------------
-void cpExtensions::Visualization::MPRActors::
-ResetWindowLevel( )
-{
- vtkImageData* image = this->_InputImage( );
- vtkWindowLevelLookupTable* lut = this->GetLookupTableAsWindowLevel( );
+ vtkImageData* image = this->_Image( i );
+ vtkWindowLevelLookupTable* lut =
+ dynamic_cast< vtkWindowLevelLookupTable* >( this->GetLookupTable( i ) );
if( image != NULL && lut != NULL )
{
double r[ 2 ];
image->GetScalarRange( r );
lut->SetTableRange( r );
lut->Build( );
- this->ImageMapToColors->Modified( );
+ this->ImageMaps[ i ]->Modified( );
this->Modified( );
} // fi
void cpExtensions::Visualization::MPRActors::
SetSlice( const int& axis, const int& slice )
{
- vtkImageData* image = this->_InputImage( );
+ vtkImageData* image = this->_Image( 0 );
if( image == NULL )
return;
void cpExtensions::Visualization::MPRActors::
SetSlice( const int& axis, const double& slice )
{
- vtkImageData* image = this->_InputImage( );
+ vtkImageData* image = this->_Image( 0 );
if( image == NULL )
return;
// TODO
}
-// -------------------------------------------------------------------------
-void cpExtensions::Visualization::MPRActors::
-GetImageBounds( double bounds[ 6 ] ) const
-{
- vtkImageData* image = this->_InputImage( );
- if( image != NULL )
- image->GetBounds( bounds );
-}
-
// -------------------------------------------------------------------------
cpExtensions::Visualization::MPRActors::
MPRActors( )
: Superclass( )
{
- this->ImageMapToColors = vtkSmartPointer< vtkImageMapToColors >::New( );
this->ImageOutlineActor = vtkSmartPointer< vtkActor >::New( );
- this->Slices[ 0 ][ 0 ] = vtkSmartPointer< _TSlice >::New( );
- this->Slices[ 0 ][ 1 ] = vtkSmartPointer< _TSlice >::New( );
- this->Slices[ 0 ][ 2 ] = vtkSmartPointer< _TSlice >::New( );
- this->Slices[ 1 ][ 0 ] = vtkSmartPointer< _TSlice >::New( );
- this->Slices[ 1 ][ 1 ] = vtkSmartPointer< _TSlice >::New( );
- this->Slices[ 1 ][ 2 ] = vtkSmartPointer< _TSlice >::New( );
+ for( unsigned int i = 0; i < 2; ++i )
+ for( unsigned int j = 0; j < 3; ++j )
+ this->Slices[ i ][ j ] = vtkSmartPointer< ImageSliceActors >::New( );
}
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
vtkImageData* cpExtensions::Visualization::MPRActors::
-_InputImage( ) const
+_Image( unsigned int i ) const
{
- vtkAlgorithm* algo = this->ImageMapToColors->GetInputAlgorithm( );
- vtkInformation* info = algo->GetOutputInformation( 0 );
- return(
- vtkImageData::SafeDownCast( info->Get( vtkDataObject::DATA_OBJECT( ) ) )
- );
+ if( i < this->ImageMaps.size( ) )
+ {
+ vtkAlgorithm* algo = this->ImageMaps[ i ]->GetInputAlgorithm( );
+ vtkInformation* info = algo->GetOutputInformation( 0 );
+ return(
+ vtkImageData::SafeDownCast( info->Get( vtkDataObject::DATA_OBJECT( ) ) )
+ );
+ }
+ else
+ return( NULL );
}
// -------------------------------------------------------------------------
void cpExtensions::Visualization::MPRActors::
-_UpdateSlices( )
+_Update( unsigned int i )
{
+ /*
// Check if the input has been configured
vtkImageData* image = this->_InputImage( );
if( image == NULL )
{
for( int i = 0; i < 3; ++i )
{
- this->Slices[ j ][ i ]->SetInputConnection(
+ this->Slices[ j ][ i ]->AddInputConnection(
this->ImageMapToColors->GetOutputPort( ), i
);
this->Slices[ j ][ i ]->UpdateText( );
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( );
*/
}