#include <cpExtensions/Visualization/ImageSliceActors.h>
-#include <cmath>
#include <sstream>
#include <vtkAlgorithmOutput.h>
#include <vtkCamera.h>
#include <vtkCellArray.h>
#include <vtkImageData.h>
-#include <vtkInformation.h>
-#include <vtkPlane.h>
#include <vtkPoints.h>
#include <vtkProperty.h>
#include <vtkRenderer.h>
#include <vtkRendererCollection.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
-#include <vtkStreamingDemandDrivenPipeline.h>
#include <vtkTextProperty.h>
-#include <vtkWindowLevelLookupTable.h>
// -------------------------------------------------------------------------
cpExtensions::Visualization::ImageSliceActors*
return( new Self( ) );
}
+// -------------------------------------------------------------------------
+cpExtensions::Visualization::
+ImageBlender* cpExtensions::Visualization::ImageSliceActors::
+GetBlender( )
+{
+ return( this->m_ImageBlender );
+}
+
+// -------------------------------------------------------------------------
+const cpExtensions::Visualization::
+ImageBlender* cpExtensions::Visualization::ImageSliceActors::
+GetBlender( ) const
+{
+ return( this->m_ImageBlender );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::ImageSliceActors::
+SetBlender( ImageBlender* blender )
+{
+ this->m_ImageBlender = blender;
+
+ // Create mapper and actors
+ this->m_ImageMapper = vtkSmartPointer< vtkImageSliceMapper >::New( );
+ this->m_ImageMapper->SetInputConnection(
+ this->m_ImageBlender->GetOutputPort( )
+ );
+ this->m_ImageMapper->SetOrientation( 0 );
+ this->m_ImageMapper->Update( );
+
+ // Create actor
+ this->m_ImageActor = vtkSmartPointer< vtkImageActor >::New( );
+ this->m_ImageActor->SetMapper( this->m_ImageMapper );
+ this->m_ImageActor->SetInterpolate( this->m_Interpolate );
+ this->m_ImageActor->Modified( );
+
+ if( this->m_Style.GetPointer( ) != NULL )
+ this->m_Style->AssociateImageActor( this->m_ImageActor );
+ this->AddItem( this->m_ImageActor );
+
+ this->SetSliceNumber( this->GetSliceNumberMinValue( ) );
+ this->ResetCursor( );
+ this->Modified( );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::ImageSliceActors::
+SetAxis( int axis )
+{
+ this->m_ImageMapper->SetOrientation( axis );
+ this->m_ImageMapper->Update( );
+ this->SetSliceNumber( this->GetSliceNumberMinValue( ) );
+ this->m_ImageActor->Modified( );
+ this->Modified( );
+ this->ResetCamera( );
+}
+
// -------------------------------------------------------------------------
void cpExtensions::Visualization::ImageSliceActors::
-AddInputConnection( vtkAlgorithmOutput* aout, int axis )
+AddInputConnection( vtkAlgorithmOutput* aout )
{
// Get input vtkImageData
if( aout == NULL )
return;
- vtkAlgorithm* producer = aout->GetProducer( );
- vtkImageData* data = dynamic_cast< vtkImageData* >(
- producer->GetOutputDataObject( aout->GetIndex( ) )
- );
- if( data == NULL )
- return;
- // Try to infere if input comes from a color mapping filter
- vtkImageMapToColors* new_map =
- dynamic_cast< vtkImageMapToColors* >( producer );
- if( new_map == NULL )
+ if( this->m_ImageBlender.GetPointer( ) == NULL )
{
- // Configure LUT, if possible (NULL is returned if not)
- this->_ConfigureNewLUT( data );
- new_map = *( this->m_ImageMaps.rbegin( ) );
- if( new_map != NULL )
+ // Try to infere if input comes from a color mapping filter
+ vtkAlgorithm* producer = aout->GetProducer( );
+ vtkSmartPointer< ImageBlender > blender =
+ dynamic_cast< ImageBlender* >( producer );
+ if( blender.GetPointer( ) == NULL )
{
- new_map->SetInputConnection( aout );
- new_map->Update( );
+ // Ok, create a new blender with default window level
+ vtkImageData* data = dynamic_cast< vtkImageData* >(
+ producer->GetOutputDataObject( aout->GetIndex( ) )
+ );
+ double r[ 2 ];
+ data->GetScalarRange( r );
+
+ blender = vtkSmartPointer< ImageBlender >::New( );
+ blender->AddInputConnection( aout );
+ blender->SetWindow( r[ 1 ] - r[ 0 ] );
+ blender->SetLevel( ( r[ 1 ] + r[ 0 ] ) / double( 2 ) );
} // fi
+ this->SetBlender( blender );
}
else
- this->m_ImageMaps.push_back( new_map );
-
- // Update window level values
- if( new_map != NULL )
- {
- double range[ 2 ];
- dynamic_cast< vtkImageData* >( new_map->GetInput( ) )->
- GetScalarRange( range );
- this->m_MinWindow = double( 0 );
- this->m_MaxWindow = range[ 1 ] - range[ 0 ];
- this->m_MinLevel = range[ 0 ];
- this->m_MaxLevel = range[ 1 ];
-
- } // fi
-
- // Create mapper and actors
- vtkSmartPointer< vtkImageSliceMapper > mapper =
- vtkSmartPointer< vtkImageSliceMapper >::New( );
- if( new_map != NULL )
- mapper->SetInputConnection( new_map->GetOutputPort( ) );
- else
- mapper->SetInputConnection( aout );
- this->m_SliceMappers.push_back( mapper );
- this->_ConfigureNewInput( axis );
+ this->m_ImageBlender->AddInputConnection( aout );
}
// -------------------------------------------------------------------------
void cpExtensions::Visualization::ImageSliceActors::
-AddInputData( vtkImageData* data, int axis )
+AddInputData( vtkImageData* data )
{
- // Update window level values
- if( this->m_ImageMaps.size( ) == 0 )
- {
- double range[ 2 ];
- data->GetScalarRange( range );
- this->m_MinWindow = double( 0 );
- this->m_MaxWindow = range[ 1 ] - range[ 0 ];
- this->m_MinLevel = range[ 0 ];
- this->m_MaxLevel = range[ 1 ];
-
- } // fi
+ // Get input vtkImageData
+ if( data == NULL )
+ return;
- // Configure LUT, if possible (NULL is returned if not)
- this->_ConfigureNewLUT( data );
- vtkImageMapToColors* new_map = *( this->m_ImageMaps.rbegin( ) );
- if( new_map != NULL )
+ if( this->m_ImageBlender.GetPointer( ) == NULL )
{
- new_map->SetInputData( data );
- new_map->Update( );
-
- } // fi
-
- // Create mapper and actors
- vtkSmartPointer< vtkImageSliceMapper > mapper =
- vtkSmartPointer< vtkImageSliceMapper >::New( );
- if( new_map != NULL )
- mapper->SetInputConnection( new_map->GetOutputPort( ) );
+ // Create a new blender with default window level
+ double r[ 2 ];
+ data->GetScalarRange( r );
+
+ vtkSmartPointer< ImageBlender > blender =
+ vtkSmartPointer< ImageBlender >::New( );
+ blender->AddInputData( data );
+ blender->SetWindow( r[ 1 ] - r[ 0 ] );
+ blender->SetLevel( ( r[ 1 ] + r[ 0 ] ) / double( 2 ) );
+ this->SetBlender( blender );
+ }
else
- mapper->SetInputData( data );
- this->m_SliceMappers.push_back( mapper );
- this->_ConfigureNewInput( axis );
+ this->m_ImageBlender->AddInputData( data );
}
// -------------------------------------------------------------------------
Clear( )
{
// Reset values
- this->m_MinWindow = double( 0 );
- this->m_MaxWindow = double( 0 );
- this->m_MinLevel = double( 0 );
- this->m_MaxLevel = double( 0 );
this->m_VisibleExtent[ 0 ] =
this->m_VisibleExtent[ 2 ] =
this->m_VisibleExtent[ 4 ] = -1;
this->RemoveAllItems( );
// Delete all images
- this->m_ImageMaps.clear( );
- this->m_SliceMappers.clear( );
- this->m_ImageActors.clear( );
+ this->m_ImageActor = NULL;
+ this->m_ImageMapper = NULL;
+ this->m_ImageBlender = NULL;
// Reconfigure unique objects
this->m_Cursor = vtkSmartPointer< vtkPolyData >::New( );
vtkImageData* cpExtensions::Visualization::ImageSliceActors::
GetInputImage( unsigned int id )
{
- vtkAlgorithmOutput* aout = this->m_ImageMaps[ id ]->GetOutputPort( );
- vtkImageData* image = dynamic_cast< vtkImageData* >(
- aout->GetProducer( )->GetOutputDataObject( aout->GetIndex( ) )
- );
- return( image );
+ if( this->m_ImageBlender.GetPointer( ) != NULL )
+ return(
+ dynamic_cast< vtkImageData* >( this->m_ImageBlender->GetInput( id ) )
+ );
+ else
+ return( NULL );
}
// -------------------------------------------------------------------------
const vtkImageData* cpExtensions::Visualization::ImageSliceActors::
GetInputImage( unsigned int id ) const
{
- vtkAlgorithmOutput* aout = this->m_ImageMaps[ id ]->GetOutputPort( );
- const vtkImageData* image = dynamic_cast< const vtkImageData* >(
- aout->GetProducer( )->GetOutputDataObject( aout->GetIndex( ) )
- );
- return( image );
+ if( this->m_ImageBlender.GetPointer( ) != NULL )
+ return(
+ dynamic_cast< const vtkImageData* >(
+ this->m_ImageBlender->GetInput( )
+ )
+ );
+ else
+ return( NULL );
}
// -------------------------------------------------------------------------
}
else // if( axis == 2 )
{
- camera->SetPosition( double( 0 ), double( 0 ), double( -1 ) );
- camera->SetViewUp ( double( 0 ), double( -1 ), double( 0 ) );
+ camera->SetPosition( double( 0 ), double( 0 ), double( 1 ) );
+ camera->SetViewUp ( double( 0 ), double( -1 ), double( 0 ) );
} // fi
rwi->Render( );
}
-// -------------------------------------------------------------------------
-unsigned int cpExtensions::Visualization::ImageSliceActors::
-GetNumberOfImageActors( ) const
-{
- return( this->m_ImageActors.size( ) );
-}
-
// -------------------------------------------------------------------------
vtkImageActor* cpExtensions::Visualization::ImageSliceActors::
-GetImageActor( unsigned int id )
+GetImageActor( )
{
- if( id < this->m_ImageActors.size( ) )
- return( this->m_ImageActors[ id ] );
- else
- return( NULL );
+ return( this->m_ImageActor );
}
// -------------------------------------------------------------------------
const vtkImageActor* cpExtensions::Visualization::ImageSliceActors::
-GetImageActor( unsigned int id ) const
+GetImageActor( ) const
{
- if( id < this->m_ImageActors.size( ) )
- return( this->m_ImageActors[ id ] );
- else
- return( NULL );
+ return( this->m_ImageActor );
}
// -------------------------------------------------------------------------
vtkPlane* cpExtensions::Visualization::ImageSliceActors::
GetPlaneFunction( )
{
- return( this->m_SliceMappers[ 0 ]->GetSlicePlane( ) );
+ if( this->m_ImageMapper.GetPointer( ) != NULL )
+ return( this->m_ImageMapper->GetSlicePlane( ) );
+ else
+ return( NULL );
}
// -------------------------------------------------------------------------
const vtkPlane* cpExtensions::Visualization::ImageSliceActors::
GetPlaneFunction( ) const
{
- return( this->m_SliceMappers[ 0 ]->GetSlicePlane( ) );
+ if( this->m_ImageMapper.GetPointer( ) != NULL )
+ return( this->m_ImageMapper->GetSlicePlane( ) );
+ else
+ return( NULL );
}
// -------------------------------------------------------------------------
{
if( this->m_Interpolate != v )
{
- for( unsigned int i = 0; i < this->m_ImageActors.size( ); ++i )
- this->m_ImageActors[ i ]->SetInterpolate( v );
+ this->m_ImageActor->SetInterpolate( v );
this->m_Interpolate = v;
this->Modified( );
double* cpExtensions::Visualization::ImageSliceActors::
GetDisplayBounds( ) const
{
- if( this->m_ImageActors.size( ) > 0 )
- return( this->m_ImageActors[ 0 ]->GetDisplayBounds( ) );
+ if( this->m_ImageActor.GetPointer( ) != NULL )
+ return( this->m_ImageActor->GetDisplayBounds( ) );
else
return( NULL );
}
void cpExtensions::Visualization::ImageSliceActors::
GetDisplayBounds( double bounds[ 6 ] ) const
{
- if( this->m_ImageActors.size( ) == 0 )
+ if( this->m_ImageActor.GetPointer( ) == NULL )
{
bounds[ 0 ] = bounds[ 2 ] = bounds[ 4 ] = double( -1 );
bounds[ 1 ] = bounds[ 3 ] = bounds[ 5 ] = double( -1 );
}
else
- this->m_ImageActors[ 0 ]->GetDisplayBounds( bounds );
+ this->m_ImageActor->GetDisplayBounds( bounds );
}
// -------------------------------------------------------------------------
void cpExtensions::Visualization::ImageSliceActors::
ResetCursor( )
{
- if( this->m_SliceMappers.size( ) > 0 )
+ if( this->m_ImageMapper.GetPointer( ) != NULL )
{
double bounds[ 6 ];
- this->m_SliceMappers[ 0 ]->GetInput( )->GetBounds( bounds );
+ this->m_ImageMapper->GetInput( )->GetBounds( bounds );
double pos[] =
{
this->m_VisibleBounds[ 0 ],
void cpExtensions::Visualization::ImageSliceActors::
SetCursor( double pos[ 3 ] )
{
- if( this->m_SliceMappers.size( ) == 0 )
+ if( this->m_ImageMapper.GetPointer( ) == NULL )
return;
// Get ordered axes
this->m_CursorActor->Modified( );
}
-// -------------------------------------------------------------------------
-vtkImageMapToColors* cpExtensions::Visualization::ImageSliceActors::
-GetImageMap( unsigned int id )
-{
- if( id < this->m_ImageMaps.size( ) )
- return( this->m_ImageMaps[ id ].GetPointer( ) );
- else
- return( NULL );
-}
-
-// -------------------------------------------------------------------------
-const vtkImageMapToColors* cpExtensions::Visualization::ImageSliceActors::
-GetImageMap( unsigned int id ) const
-{
- if( id < this->m_ImageMaps.size( ) )
- return( this->m_ImageMaps[ id ].GetPointer( ) );
- else
- return( NULL );
-}
-
// -------------------------------------------------------------------------
double cpExtensions::Visualization::ImageSliceActors::
GetMinWindow( ) const
{
- return( this->m_MinWindow );
+ if( this->m_ImageBlender.GetPointer( ) != NULL )
+ return( this->m_ImageBlender->GetMinWindow( ) );
+ else
+ return( double( 0 ) );
}
// -------------------------------------------------------------------------
double cpExtensions::Visualization::ImageSliceActors::
GetMaxWindow( ) const
{
- return( this->m_MaxWindow );
+ if( this->m_ImageBlender.GetPointer( ) != NULL )
+ return( this->m_ImageBlender->GetMaxWindow( ) );
+ else
+ return( double( 0 ) );
}
// -------------------------------------------------------------------------
double cpExtensions::Visualization::ImageSliceActors::
GetMinLevel( ) const
{
- return( this->m_MinLevel );
+ if( this->m_ImageBlender.GetPointer( ) != NULL )
+ return( this->m_ImageBlender->GetMinLevel( ) );
+ else
+ return( double( 0 ) );
}
// -------------------------------------------------------------------------
double cpExtensions::Visualization::ImageSliceActors::
GetMaxLevel( ) const
{
- return( this->m_MaxLevel );
+ if( this->m_ImageBlender.GetPointer( ) != NULL )
+ return( this->m_ImageBlender->GetMaxLevel( ) );
+ else
+ return( double( 0 ) );
}
// -------------------------------------------------------------------------
double cpExtensions::Visualization::ImageSliceActors::
GetWindow( ) const
{
- if( this->m_ImageMaps.size( ) == 0 )
- return( double( 0 ) );
- if( this->m_ImageMaps[ 0 ].GetPointer( ) == NULL )
- return( double( 0 ) );
-
- vtkWindowLevelLookupTable* lut =
- dynamic_cast< vtkWindowLevelLookupTable* >(
- this->m_ImageMaps[ 0 ]->GetLookupTable( )
- );
- if( lut != NULL )
- return( lut->GetWindow( ) );
+ if( this->m_ImageBlender.GetPointer( ) != NULL )
+ return( this->m_ImageBlender->GetWindow( ) );
else
return( double( 0 ) );
}
double cpExtensions::Visualization::ImageSliceActors::
GetLevel( ) const
{
- if( this->m_ImageMaps.size( ) == 0 )
- return( double( 0 ) );
- if( this->m_ImageMaps[ 0 ].GetPointer( ) == NULL )
- return( double( 0 ) );
-
- vtkWindowLevelLookupTable* lut =
- dynamic_cast< vtkWindowLevelLookupTable* >(
- this->m_ImageMaps[ 0 ]->GetLookupTable( )
- );
- if( lut != NULL )
- return( lut->GetLevel( ) );
+ if( this->m_ImageBlender.GetPointer( ) != NULL )
+ return( this->m_ImageBlender->GetLevel( ) );
else
return( double( 0 ) );
}
void cpExtensions::Visualization::ImageSliceActors::
SetWindow( double w )
{
- if( this->m_ImageMaps.size( ) == 0 )
- return;
- if( this->m_ImageMaps[ 0 ].GetPointer( ) == NULL )
- return;
- vtkWindowLevelLookupTable* lut =
- dynamic_cast< vtkWindowLevelLookupTable* >(
- this->m_ImageMaps[ 0 ]->GetLookupTable( )
- );
- if( lut == NULL )
- return;
-
- if( w < this->m_MinWindow )
- w = this->m_MinWindow;
- if( w > this->m_MaxWindow )
- w = this->m_MaxWindow;
+ if( this->m_ImageBlender.GetPointer( ) != NULL )
+ {
+ this->m_ImageBlender->SetWindow( w );
+ this->Modified( );
- lut->SetWindow( w );
- lut->Build( );
- this->m_ImageMaps[ 0 ]->Modified( );
- this->Modified( );
+ } // fi
}
// -------------------------------------------------------------------------
void cpExtensions::Visualization::ImageSliceActors::
SetLevel( double l )
{
- if( this->m_ImageMaps.size( ) == 0 )
- return;
- if( this->m_ImageMaps[ 0 ].GetPointer( ) == NULL )
- return;
- vtkWindowLevelLookupTable* lut =
- dynamic_cast< vtkWindowLevelLookupTable* >(
- this->m_ImageMaps[ 0 ]->GetLookupTable( )
- );
- if( lut == NULL )
- return;
-
- if( l < this->m_MinLevel )
- l = this->m_MinLevel;
- if( l > this->m_MaxLevel )
- l = this->m_MaxLevel;
+ if( this->m_ImageBlender.GetPointer( ) != NULL )
+ {
+ this->m_ImageBlender->SetLevel( l );
+ this->Modified( );
- lut->SetLevel( l );
- lut->Build( );
- this->m_ImageMaps[ 0 ]->Modified( );
- this->Modified( );
+ } // fi
}
// -------------------------------------------------------------------------
void cpExtensions::Visualization::ImageSliceActors::
SetWindowLevel( double w, double l )
{
- if( this->m_ImageMaps.size( ) == 0 )
- return;
- if( this->m_ImageMaps[ 0 ].GetPointer( ) == NULL )
- return;
- vtkWindowLevelLookupTable* lut =
- dynamic_cast< vtkWindowLevelLookupTable* >(
- this->m_ImageMaps[ 0 ]->GetLookupTable( )
- );
- if( lut == NULL )
- return;
-
- if( w < this->m_MinWindow )
- w = this->m_MinWindow;
- if( w > this->m_MaxWindow )
- w = this->m_MaxWindow;
- if( l < this->m_MinLevel )
- l = this->m_MinLevel;
- if( l > this->m_MaxLevel )
- l = this->m_MaxLevel;
-
- lut->SetWindow( w );
- lut->SetLevel( l );
- lut->Build( );
- this->m_ImageMaps[ 0 ]->Modified( );
- this->UpdateText( w, l );
- this->Modified( );
-}
-
-// -------------------------------------------------------------------------
-void cpExtensions::Visualization::ImageSliceActors::
-ResetWindowLevel( )
-{
- static const double _2 = double( 2 );
- this->SetWindowLevel(
- this->m_MaxWindow, ( this->m_MaxLevel + this->m_MinLevel ) / _2
- );
-}
-
-// -------------------------------------------------------------------------
-void cpExtensions::Visualization::ImageSliceActors::
-SetLookupTable( unsigned int id, vtkLookupTable* lut )
-{
- if( id < this->m_ImageMaps.size( ) && id > 0 )
+ if( this->m_ImageBlender.GetPointer( ) != NULL )
{
- if( this->m_ImageMaps[ id ].GetPointer( ) != NULL )
- {
- this->m_ImageMaps[ id ]->SetLookupTable( lut );
- this->m_ImageMaps[ id ]->Modified( );
- this->Modified( );
-
- } // fi
+ this->m_ImageBlender->SetWindowLevel( w, l );
+ this->UpdateText( w, l );
+ this->Modified( );
} // fi
}
// -------------------------------------------------------------------------
void cpExtensions::Visualization::ImageSliceActors::
-SetLookupTableAsColor( unsigned int id, double r, double g, double b )
+ResetWindowLevel( )
{
- static const double _0 = double( 0 );
- 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 ID consistency
- if( id == 0 || id >= this->m_ImageMaps.size( ) )
- return;
-
- // Get image scalar range
- vtkAlgorithmOutput* aout = this->m_ImageMaps[ id ]->GetOutputPort( );
- vtkImageData* image = dynamic_cast< vtkImageData* >(
- aout->GetProducer( )->GetOutputDataObject( aout->GetIndex( ) )
- );
- 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 /= _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( id, lut );
+ std::cerr << "ACA Resetear" << std::endl;
+ std::exit( 1 );
}
// -------------------------------------------------------------------------
int cpExtensions::Visualization::ImageSliceActors::
GetAxis( ) const
{
- if( this->m_SliceMappers.size( ) > 0 )
- return( this->m_SliceMappers[ 0 ]->GetOrientation( ) );
+ if( this->m_ImageMapper.GetPointer( ) != NULL )
+ return( this->m_ImageMapper->GetOrientation( ) );
else
return( -1 );
}
int cpExtensions::Visualization::ImageSliceActors::
GetSliceNumber( ) const
{
- if( this->m_SliceMappers.size( ) > 0 )
- return( this->m_SliceMappers[ 0 ]->GetSliceNumber( ) );
+ if( this->m_ImageMapper.GetPointer( ) != NULL )
+ return( this->m_ImageMapper->GetSliceNumber( ) );
else
return( -1 );
}
int cpExtensions::Visualization::ImageSliceActors::
GetSliceNumberMinValue( ) const
{
- if( this->m_SliceMappers.size( ) > 0 )
- return( this->m_SliceMappers[ 0 ]->GetSliceNumberMinValue( ) );
+ if( this->m_ImageMapper.GetPointer( ) != NULL )
+ return( this->m_ImageMapper->GetSliceNumberMinValue( ) );
else
return( -1 );
}
int cpExtensions::Visualization::ImageSliceActors::
GetSliceNumberMaxValue( ) const
{
- if( this->m_SliceMappers.size( ) > 0 )
- return( this->m_SliceMappers[ 0 ]->GetSliceNumberMaxValue( ) );
+ if( this->m_ImageMapper.GetPointer( ) != NULL )
+ return( this->m_ImageMapper->GetSliceNumberMaxValue( ) );
else
return( -1 );
}
void cpExtensions::Visualization::ImageSliceActors::
SetSliceNumber( const int& slice )
{
- unsigned int nImages = this->m_SliceMappers.size( );
- if( nImages == 0 )
+ if( this->m_ImageMapper.GetPointer( ) == NULL )
return;
int axis = this->GetAxis( );
double prev_pos = this->m_VisibleBounds[ axis << 1 ];
- // Change visualization extent
- for( unsigned int i = 0; i < nImages; ++i )
- {
- // Update mappers and display bounds
- this->m_SliceMappers[ i ]->SetSliceNumber( slice );
- this->m_SliceMappers[ i ]->Modified( );
- this->m_ImageActors[ i ]->Modified( );
- this->m_SliceMappers[ i ]->Update( );
-
- // Update display extent (this isn't done automatically)
- if( i == 0 )
- {
- this->m_SliceMappers[ i ]->GetInput( )->
- GetExtent( this->m_VisibleExtent );
- this->m_VisibleExtent[ axis << 1 ] = slice;
- this->m_VisibleExtent[ ( axis << 1 ) + 1 ] = slice;
-
- } // fi
- this->m_ImageActors[ i ]->SetDisplayExtent( this->m_VisibleExtent );
+ // Update mappers and display bounds
+ this->m_ImageMapper->SetSliceNumber( slice );
+ this->m_ImageMapper->Modified( );
+ this->m_ImageActor->Modified( );
+ this->m_ImageMapper->Update( );
- } // rof
+ // Update display extent (this isn't done automatically)
+ this->m_ImageMapper->GetInput( )->GetExtent( this->m_VisibleExtent );
+ this->m_VisibleExtent[ axis << 1 ] = slice;
+ this->m_VisibleExtent[ ( axis << 1 ) + 1 ] = slice;
+ this->m_ImageActor->SetDisplayExtent( this->m_VisibleExtent );
- this->m_SliceMappers[ 0 ]->GetBounds( this->m_VisibleBounds );
+ // Prepare plane data
+ this->m_ImageMapper->GetBounds( this->m_VisibleBounds );
double x0[][ 3 ] =
- {
- {
- this->m_VisibleBounds[ 0 ],
- this->m_VisibleBounds[ 2 ],
- this->m_VisibleBounds[ 4 ]
- },
{
- this->m_VisibleBounds[ 1 ],
- this->m_VisibleBounds[ 3 ],
- this->m_VisibleBounds[ 5 ]
- }
- };
+ {
+ this->m_VisibleBounds[ 0 ],
+ this->m_VisibleBounds[ 2 ],
+ this->m_VisibleBounds[ 4 ]
+ },
+ {
+ this->m_VisibleBounds[ 1 ],
+ this->m_VisibleBounds[ 3 ],
+ this->m_VisibleBounds[ 5 ]
+ }
+ };
double p0[ 2 ][ 3 ];
- vtkPlane* plane = this->m_SliceMappers[ 0 ]->GetSlicePlane( );
+ vtkPlane* plane = this->m_ImageMapper->GetSlicePlane( );
plane->GeneralizedProjectPoint( x0[ 0 ], p0[ 0 ] );
plane->GeneralizedProjectPoint( x0[ 1 ], p0[ 1 ] );
void cpExtensions::Visualization::ImageSliceActors::
SetSlice( double* pos )
{
- vtkImageData* image;
- if( this->m_ImageMaps[ 0 ] != NULL )
- image =
- dynamic_cast< vtkImageData* >( this->m_ImageMaps[ 0 ]->GetInput( ) );
- else
- image = this->m_SliceMappers[ 0 ]->GetInput( );
+ vtkImageData* image = this->GetInputImage( 0 );
+ if( image == NULL )
+ return;
int ijk[ 3 ];
double pcoords[ 3 ];
void cpExtensions::Visualization::ImageSliceActors::
UpdateText( )
{
- if( this->m_SliceMappers.size( ) > 0 )
+ if( this->m_ImageMapper.GetPointer( ) != NULL )
{
char axis;
- int axId = this->m_SliceMappers[ 0 ]->GetOrientation( );
+ int axId = this->m_ImageMapper->GetOrientation( );
if ( axId == 0 ) axis = 'X';
else if( axId == 1 ) axis = 'Y';
else if( axId == 2 ) axis = 'Z';
std::sprintf(
this->m_TextBuffer, "Axis: %c (%d)",
- axis, this->m_SliceMappers[ 0 ]->GetSliceNumber( )
+ axis, this->m_ImageMapper->GetSliceNumber( )
);
}
else
void cpExtensions::Visualization::ImageSliceActors::
UpdateText( double pos[ 3 ] )
{
- if( this->m_SliceMappers.size( ) > 0 )
+ if( this->m_ImageMapper.GetPointer( ) != NULL )
{
char axis;
- int axId = this->m_SliceMappers[ 0 ]->GetOrientation( );
+ int axId = this->m_ImageMapper->GetOrientation( );
if ( axId == 0 ) axis = 'X';
else if( axId == 1 ) axis = 'Y';
else if( axId == 2 ) axis = 'Z';
int slice = this->GetSliceNumber( );
- vtkImageData* image;
- if( this->m_ImageMaps[ 0 ] != NULL )
- image =
- dynamic_cast< vtkImageData* >( this->m_ImageMaps[ 0 ]->GetInput( ) );
- else
- image = this->m_SliceMappers[ 0 ]->GetInput( );
-
+ vtkImageData* image = this->GetInputImage( 0 );
int ijk[ 3 ];
double pcoords[ 3 ];
image->ComputeStructuredCoordinates( pos, ijk, pcoords );
void cpExtensions::Visualization::ImageSliceActors::
UpdateText( const double& w, const double& l )
{
- if( this->m_SliceMappers.size( ) > 0 )
+ if( this->m_ImageMapper.GetPointer( ) != NULL )
{
char axis;
- int axId = this->m_SliceMappers[ 0 ]->GetOrientation( );
+ int axId = this->m_ImageMapper->GetOrientation( );
if ( axId == 0 ) axis = 'X';
else if( axId == 1 ) axis = 'Y';
else if( axId == 2 ) axis = 'Z';
std::sprintf(
this->m_TextBuffer, "Axis: %c (%d)\nW/L (%.2f/%.2f)",
- axis, this->m_SliceMappers[ 0 ]->GetSliceNumber( ), w, l
+ axis, this->m_ImageMapper->GetSliceNumber( ), w, l
);
}
else
this->m_Style->AddLeaveCommand( Self::_LeaveCommand, this );
}
-// -------------------------------------------------------------------------
-void cpExtensions::Visualization::ImageSliceActors::
-_ConfigureNewLUT( vtkImageData* data )
-{
- // Does the new LUT is a window-level one?
- unsigned int nImgs = this->m_ImageMaps.size( );
- unsigned int nCmps = data->GetNumberOfScalarComponents( );
-
- if( nCmps > 1 )
- {
- this->m_ImageMaps.push_back( NULL );
- return;
-
- } // fi
-
- // Create LUT filter
- this->m_ImageMaps.push_back( vtkSmartPointer< vtkImageMapToColors >::New( ) );
- if( nImgs == 0 )
- {
- double range[ 2 ];
- data->GetScalarRange( range );
- vtkSmartPointer< vtkWindowLevelLookupTable > lut =
- vtkSmartPointer< vtkWindowLevelLookupTable >::New( );
- lut->SetScaleToLinear( );
- lut->SetTableRange( range );
- lut->SetWindow( range[ 1 ] - range[ 0 ] );
- lut->SetLevel( ( range[ 1 ] + range[ 0 ] ) / double( 2 ) );
- lut->Build( );
- this->m_ImageMaps[ 0 ]->SetLookupTable( lut );
- }
- else
- this->SetLookupTableAsColor( nImgs, 1, 0, 0 );
-}
-
-// -------------------------------------------------------------------------
-void cpExtensions::Visualization::ImageSliceActors::
-_ConfigureNewInput( int axis )
-{
- unsigned int nImages = this->m_ImageActors.size( );
-
- // Configure mapper
- vtkImageSliceMapper* mapper = this->m_SliceMappers[ nImages ];
- if( nImages == 0 )
- mapper->SetOrientation( axis );
- else
- mapper->SetOrientation( this->m_SliceMappers[ 0 ]->GetOrientation( ) );
- mapper->Update( );
-
- // Create actor
- vtkSmartPointer< vtkImageActor > actor =
- vtkSmartPointer< vtkImageActor >::New( );
- this->m_ImageActors.push_back( actor );
- actor->SetMapper( mapper );
- actor->SetInterpolate( this->m_Interpolate );
- actor->Modified( );
-
- if( nImages == 0 )
- this->m_Style->AssociateImageActor( actor );
- this->AddItem( actor );
-
- if( nImages > 1 )
- this->SetSliceNumber( this->GetSliceNumber( ) );
- else
- this->SetSliceNumber( this->GetSliceNumberMaxValue( ) );
- this->ResetCursor( );
- this->Modified( );
-}
-
// -------------------------------------------------------------------------
void cpExtensions::Visualization::ImageSliceActors::
_MouseMoveCommand(
{
// Change image window level
double bounds[ 6 ];
- actors->m_SliceMappers[ 0 ]->GetBounds( bounds );
+ actors->m_ImageMapper->GetBounds( bounds );
int a0 = actors->GetAxis( );
int a1 = ( a0 + 1 ) % 3;