#include <cpExtensions/Visualization/MPRActors.h>
+#include <vtkAlgorithmOutput.h>
#include <vtkImageData.h>
#include <vtkRenderer.h>
#include <vtkRendererCollection.h>
// -------------------------------------------------------------------------
int cpExtensions::Visualization::MPRActors::
-AddInputConnection(
- vtkAlgorithmOutput* aout, ImageSliceActors::LUTType lut
- )
+AddInputConnection( vtkAlgorithmOutput* aout )
{
int N = this->Slices[ 0 ][ 0 ]->GetNumberOfImageActors( );
if( N == 0 )
{
- this->Slices[ 0 ][ 0 ]->AddInputConnection( aout, 0, lut );
+ this->Slices[ 0 ][ 0 ]->AddInputConnection( aout, 0 );
vtkImageMapToColors* imap = this->Slices[ 0 ][ 0 ]->GetImageMap( 0 );
for( unsigned int i = 0; i < 2; ++i )
for( unsigned int j = 0; j < 3; ++j )
if( i != 0 || j != 0 )
this->Slices[ i ][ j ]->AddInputConnection(
- ( ( imap != NULL )? imap->GetOutputPort( ): aout ), j,
- ImageSliceActors::LUTType_None
+ ( ( imap != NULL )? imap->GetOutputPort( ): aout ), j
);
}
else
{
- /*
// 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 ]
- )
+ vtkImageData* new_image = dynamic_cast< vtkImageData* >(
+ aout->GetProducer( )->GetOutputDataObject( aout->GetIndex( ) )
+ );
+ if( new_image != NULL )
{
- this->ImageMaps.push_back(
- vtkSmartPointer< vtkImageMapToColors >::New( )
+ vtkAlgorithmOutput* ref_aout =
+ this->Slices[ 0 ][ 0 ]->GetImageMap( 0 )->GetOutputPort( );
+ vtkImageData* ref_image = dynamic_cast< vtkImageData* >(
+ ref_aout->GetProducer( )->GetOutputDataObject( ref_aout->GetIndex( ) )
);
- this->ImageMaps[ N ]->SetInputConnection( aout );
- this->SetLookupTableToColor(
- N, double( 1 ), double( 0 ), double( 0 )
- );
- this->_Update( N );
- return( N );
+ if( ref_image != NULL )
+ {
+ 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->Slices[ 0 ][ 0 ]->AddInputConnection( aout, 0 );
+ vtkImageMapToColors* imap = this->Slices[ 0 ][ 0 ]->GetImageMap( N );
+ for( unsigned int i = 0; i < 2; ++i )
+ for( unsigned int j = 0; j < 3; ++j )
+ if( i != 0 || j != 0 )
+ this->Slices[ i ][ j ]->AddInputConnection(
+ ( ( imap != NULL )? imap->GetOutputPort( ): aout ), j
+ );
+ }
+ else
+ N = -1;
+ }
+ else
+ N = -1;
}
else
- N = -1;
- */
+ N = -1;
} // fi
return( N );
// -------------------------------------------------------------------------
int cpExtensions::Visualization::MPRActors::
-AddInputData( vtkImageData* image, ImageSliceActors::LUTType lut )
+AddInputData( vtkImageData* new_image )
{
int N = this->Slices[ 0 ][ 0 ]->GetNumberOfImageActors( );
if( N == 0 )
{
- this->Slices[ 0 ][ 0 ]->AddInputData( image, 0, lut );
+ this->Slices[ 0 ][ 0 ]->AddInputData( new_image, 0 );
vtkImageMapToColors* imap = this->Slices[ 0 ][ 0 ]->GetImageMap( 0 );
for( unsigned int i = 0; i < 2; ++i )
for( unsigned int j = 0; j < 3; ++j )
{
if( imap != NULL )
this->Slices[ i ][ j ]->AddInputConnection(
- imap->GetOutputPort( ), j,
- ImageSliceActors::LUTType_None
+ imap->GetOutputPort( ), j
);
else
- this->Slices[ i ][ j ]->AddInputData(
- image, j,
- ImageSliceActors::LUTType_None
- );
+ this->Slices[ i ][ j ]->AddInputData( new_image, j );
+
} // fi
}
else
- {
- } // fi
- return( N );
- /*
- 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 );
- this->ResetWindowLevel( 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 ]
- )
+ vtkAlgorithmOutput* ref_aout =
+ this->Slices[ 0 ][ 0 ]->GetImageMap( 0 )->GetOutputPort( );
+ vtkImageData* ref_image = dynamic_cast< vtkImageData* >(
+ ref_aout->GetProducer( )->GetOutputDataObject( ref_aout->GetIndex( ) )
+ );
+ if( ref_image != NULL )
{
- this->ImageMaps.push_back(
- vtkSmartPointer< vtkImageMapToColors >::New( )
- );
- this->ImageMaps[ N ]->SetInputData( image );
- this->SetLookupTableToColor(
- N, double( 1 ), double( 0 ), double( 0 )
- );
- this->_Update( N );
- return( N );
+ 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->Slices[ 0 ][ 0 ]->AddInputData( new_image, 0 );
+ vtkImageMapToColors* imap = this->Slices[ 0 ][ 0 ]->GetImageMap( N );
+ for( unsigned int i = 0; i < 2; ++i )
+ for( unsigned int j = 0; j < 3; ++j )
+ if( i != 0 || j != 0 )
+ {
+ if( imap != NULL )
+ this->Slices[ i ][ j ]->AddInputConnection(
+ imap->GetOutputPort( ), j
+ );
+ else
+ this->Slices[ i ][ j ]->AddInputData( new_image, j );
+
+ } // fi
+ }
+ else
+ N = -1;
}
else
- return( -1 );
+ N = -1;
} // fi
- */
+ return( N );
+}
+
+// -------------------------------------------------------------------------
+unsigned int cpExtensions::Visualization::MPRActors::
+GetNumberOfImages( ) const
+{
+ return( this->Slices[ 0 ][ 0 ]->GetNumberOfImageActors( ) );
}
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
void cpExtensions::Visualization::MPRActors::
-PopDataFrom(
- vtkRenderer* x,
- vtkRenderer* y,
- vtkRenderer* z,
- vtkRenderer* w
+PopActorsFrom(
+ vtkRenderWindow* x, vtkRenderWindow* y, vtkRenderWindow* z,
+ vtkRenderWindow* w
)
{
- /*
- vtkRenderer* rends[] = { x, y, z };
+ this->Slices[ 0 ][ 0 ]->PopActorsFrom( x );
+ this->Slices[ 0 ][ 1 ]->PopActorsFrom( y );
+ this->Slices[ 0 ][ 2 ]->PopActorsFrom( z );
+
+ vtkRenderer* wren =
+ ( w != NULL )? w->GetRenderers( )->GetFirstRenderer( ): NULL;
+ vtkRenderer* rends[ ] =
+ {
+ ( x != NULL )? x->GetRenderers( )->GetFirstRenderer( ): NULL,
+ ( y != NULL )? y->GetRenderers( )->GetFirstRenderer( ): NULL,
+ ( z != NULL )? z->GetRenderers( )->GetFirstRenderer( ): NULL
+ };
for( int i = 0; i < 3; ++i )
{
if( rends[ i ] != NULL )
- {
- 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( ) );
-
- } // fi
- if( w != NULL )
+ if( i != j )
+ rends[ i ]->RemoveActor( this->Slices[ 0 ][ j ]->GetPlaneActor( ) );
+ if( wren != 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( ) );
+ wren->RemoveActor( this->Slices[ 1 ][ i ]->GetImageActor( k ) );
+ wren->RemoveActor( this->Slices[ 1 ][ i ]->GetPlaneActor( ) );
} // fi
} // rof
- if( w != NULL )
- w->RemoveActor( this->ImageOutlineActor );
- */
-}
-
-// -------------------------------------------------------------------------
- /*
-void cpExtensions::Visualization::MPRActors::
-LinkInteractors( )
-{
- this->_Update( 0 );
- this->_Update( 1 );
- this->_Update( 2 );
-}
- */
-
-// -------------------------------------------------------------------------
-void cpExtensions::Visualization::MPRActors::
-SetLookupTable( unsigned int i, vtkScalarsToColors* lut )
-{
- /*
- if( i < this->ImageMaps.size( ) )
- {
- this->ImageMaps[ i ]->SetLookupTable( lut );
- this->ImageMaps[ i ]->Update( );
- this->Modified( );
-
- } // fi
- */
-}
-
-// -------------------------------------------------------------------------
-vtkScalarsToColors* cpExtensions::Visualization::MPRActors::
-GetLookupTable( unsigned int i ) const
-{
- /*
- if( i < this->ImageMaps.size( ) )
- return( this->ImageMaps[ i ]->GetLookupTable( ) );
- else
- return( NULL );
- */
-}
-
-// -------------------------------------------------------------------------
-void cpExtensions::Visualization::MPRActors::
-SetLookupTableToWindowLevel( unsigned int i )
-{
- /*
- // Check if the input has been configured
- vtkImageData* image = this->_Image( i );
- 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( i, lut );
- */
-}
-
-// -------------------------------------------------------------------------
-double cpExtensions::Visualization::MPRActors::
-GetMinWindow( unsigned int i ) const
-{
- return( 0 );
-}
-
-// -------------------------------------------------------------------------
-double cpExtensions::Visualization::MPRActors::
-GetMaxWindow( unsigned int i ) const
-{
- /*
- // Check if the input has been configured
- vtkImageData* image = this->_Image( i );
- if( image == NULL )
- return( double( 0 ) );
-
- double r[ 2 ];
- image->GetScalarRange( r );
- return( r[ 1 ] - r[ 0 ] );
- */
-}
-
-// -------------------------------------------------------------------------
-double cpExtensions::Visualization::MPRActors::
-GetMinLevel( unsigned int i ) const
-{
- /*
- // Check if the input has been configured
- vtkImageData* image = this->_Image( i );
- if( image == NULL )
- return( double( 0 ) );
-
- double r[ 2 ];
- image->GetScalarRange( r );
- return( r[ 0 ] );
- */
-}
-
-// -------------------------------------------------------------------------
-double cpExtensions::Visualization::MPRActors::
-GetMaxLevel( unsigned int i ) const
-{
- /*
- // Check if the input has been configured
- vtkImageData* image = this->_Image( i );
- if( image == NULL )
- return( double( 0 ) );
-
- double r[ 2 ];
- image->GetScalarRange( r );
- return( r[ 1 ] );
- */
-}
-
-// -------------------------------------------------------------------------
-double cpExtensions::Visualization::MPRActors::
-GetWindow( unsigned int i ) const
-{
- /*
- vtkWindowLevelLookupTable* lut =
- dynamic_cast< vtkWindowLevelLookupTable* >( this->GetLookupTable( i ) );
- if( lut != NULL )
- return( lut->GetWindow( ) );
- else
- return( double( 0 ) );
- */
-}
-
-// -------------------------------------------------------------------------
-double cpExtensions::Visualization::MPRActors::
-GetLevel( unsigned int i ) const
-{
- /*
- vtkWindowLevelLookupTable* lut =
- dynamic_cast< vtkWindowLevelLookupTable* >( this->GetLookupTable( i ) );
- if( lut != NULL )
- return( lut->GetLevel( ) );
- else
- return( double( 0 ) );
- */
-}
-
-// -------------------------------------------------------------------------
-void cpExtensions::Visualization::MPRActors::
-SetWindow( unsigned int i, const double& w )
-{
- /*
- vtkWindowLevelLookupTable* lut =
- dynamic_cast< vtkWindowLevelLookupTable* >( this->GetLookupTable( i ) );
- if( lut != NULL )
- {
- lut->SetWindow( w );
- lut->Build( );
- this->ImageMaps[ i ]->Modified( );
- this->Modified( );
-
- } // fi
- */
-}
-
-// -------------------------------------------------------------------------
-void cpExtensions::Visualization::MPRActors::
-SetLevel( unsigned int i, const double& l )
-{
- /*
- vtkWindowLevelLookupTable* lut =
- dynamic_cast< vtkWindowLevelLookupTable* >( this->GetLookupTable( i ) );
- if( lut != NULL )
- {
- lut->SetLevel( l );
- lut->Build( );
- this->ImageMaps[ i ]->Modified( );
- this->Modified( );
-
- } // fi
- */
-}
-
-// -------------------------------------------------------------------------
-void cpExtensions::Visualization::MPRActors::
-SetWindowLevel( unsigned int i, const double& w, const double& l )
-{
- /*
- vtkWindowLevelLookupTable* lut =
- dynamic_cast< vtkWindowLevelLookupTable* >( this->GetLookupTable( i ) );
- if( lut != NULL )
- {
- lut->SetWindow( w );
- lut->SetLevel( l );
- lut->Build( );
- this->ImageMaps[ i ]->Modified( );
-
- for( unsigned int j = 0; j < 3; ++j )
- this->Slices[ 0 ][ j ]->UpdateText( w, l );
-
- this->Modified( );
-
- } // fi
- */
-}
-
-// -------------------------------------------------------------------------
-void cpExtensions::Visualization::MPRActors::
-ResetWindowLevel( unsigned int i )
-{
- /*
- 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->SetWindow( r[ 1 ] - r[ 0 ] );
- lut->SetLevel( ( r[ 1 ] + r[ 0 ] ) / double( 2 ) );
- lut->Build( );
- this->ImageMaps[ i ]->Modified( );
- this->Modified( );
+ if( wren != NULL )
+ wren->RemoveActor( this->ImageOutlineActor );
- } // fi
- */
+ this->Slices[ 0 ][ 0 ]->Clear( );
+ this->Slices[ 0 ][ 1 ]->Clear( );
+ this->Slices[ 0 ][ 2 ]->Clear( );
+ this->Slices[ 1 ][ 0 ]->Clear( );
+ this->Slices[ 1 ][ 1 ]->Clear( );
+ this->Slices[ 1 ][ 2 ]->Clear( );
}
// -------------------------------------------------------------------------
void cpExtensions::Visualization::MPRActors::
-SetLookupTableToColor(
- unsigned int i, const double& r, const double& g, const double& b
- )
-{
- /*
- static const double _0 = double( 0 );
- static const double _1 = double( 1 );
- static const double _2 = double( 2 );
- static const double _4 = double( 4 );
- static const double _6 = double( 6 );
- static const double _OPACITY = double( 0.6 );
-
- // Check if the input has been configured
- vtkImageData* image = this->_Image( i );
- if( image == NULL )
- return;
-
- double range[ 2 ];
- image->GetScalarRange( range );
-
- // Get HSV from display color
- double cmax = ( r > g )? r: g; cmax = ( b > cmax )? b: cmax;
- double cmin = ( r < g )? r: g; cmin = ( b < cmin )? b: cmin;
- double d = cmax - cmin;
-
- double saturation = ( std::fabs( cmax ) > _0 )? d / cmax: _0;
- double value = cmax;
- double hue = _0;
- if( d > _0 )
- {
- if( r == cmax )
- hue = std::fmod( ( g - b ) / d, _6 );
- else if( g == cmax )
- hue = ( ( b - r ) / d ) + _2;
- else if( b == cmax )
- hue = ( ( r - g ) / d ) + _4;
- hue *= _1 / _6;
-
- } // fi
-
- // Define new lookup table
- vtkSmartPointer< vtkLookupTable > lut =
- vtkSmartPointer< vtkLookupTable >::New( );
- lut->SetScaleToLinear( );
- lut->SetNanColor( _0, _0, _0, _0 );
- lut->SetTableRange( range[ 0 ], range[ 1 ] );
- lut->SetAlphaRange( _0, _OPACITY );
- lut->SetHueRange( _0, hue );
- lut->SetSaturationRange( _0, saturation );
- lut->SetValueRange( _0, value );
- lut->Build( );
-
- this->SetLookupTable( i, lut );
- */
+SetLookupTableAsColor( unsigned int i, double r, double g, double b )
+{
+ this->Slices[ 0 ][ 0 ]->SetLookupTableAsColor( 0, r, g, b );
+ this->Slices[ 0 ][ 1 ]->Modified( );
+ this->Slices[ 0 ][ 2 ]->Modified( );
+ this->Slices[ 1 ][ 0 ]->Modified( );
+ this->Slices[ 1 ][ 1 ]->Modified( );
+ this->Slices[ 1 ][ 2 ]->Modified( );
+ this->Modified( );
}
// -------------------------------------------------------------------------