X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpExtensions%2FVisualization%2FMPRActors.cxx;h=e26651b4dd24098b7df304e741041789419694b0;hb=d87f7bee6741e5211324dfb72ccc0e2e59e91dd7;hp=54e689afab091f6f9317c2f3e708c223ce8f3687;hpb=b23970017af98ef6617ddf40f225d4d15fa65854;p=cpPlugins.git diff --git a/lib/cpExtensions/Visualization/MPRActors.cxx b/lib/cpExtensions/Visualization/MPRActors.cxx index 54e689a..e26651b 100644 --- a/lib/cpExtensions/Visualization/MPRActors.cxx +++ b/lib/cpExtensions/Visualization/MPRActors.cxx @@ -1,15 +1,12 @@ #include -#include - #include #include -#include -#include #include #include #include -#include +#include +#include // ------------------------------------------------------------------------- cpExtensions::Visualization::MPRActors* @@ -31,510 +28,372 @@ GetSliceActors( const int& i ) const } // ------------------------------------------------------------------------- -int cpExtensions::Visualization::MPRActors:: -AddInputConnection( vtkAlgorithmOutput* aout ) +void cpExtensions::Visualization::MPRActors:: +SetInputConnection( vtkAlgorithmOutput* aout ) { - 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 ); - this->ResetWindowLevel( 0 ); - return( 0 ); - } - else + for( int i = 0; i < 2; ++i ) { - // 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 ] - ) + for( int j = 0; j < 3; ++j ) { - this->ImageMaps.push_back( - vtkSmartPointer< vtkImageMapToColors >::New( ) - ); - this->ImageMaps[ N ]->SetInputConnection( aout ); - this->SetLookupTableToColor( - N, double( 1 ), double( 0 ), double( 0 ) - ); - this->_Update( N ); - return( N ); - } - else - return( -1 ); + this->Slices[ i ][ j ]->SetInputConnection( aout ); + this->Slices[ i ][ j ]->SetAxis( j ); - } // fi + } // rof + + } // rof + this->_CreateBoundingBox( ); } // ------------------------------------------------------------------------- -int cpExtensions::Visualization::MPRActors:: -AddInputData( vtkImageData* image ) +void cpExtensions::Visualization::MPRActors:: +SetInputImage( vtkImageData* data ) { - int N = this->ImageMaps.size( ); - if( N == 0 ) + for( int i = 0; i < 2; ++i ) { - 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 ] - ) + for( int j = 0; j < 3; ++j ) { - 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 ); - } - else - return( -1 ); + this->Slices[ i ][ j ]->SetInputImage( data ); + this->Slices[ i ][ j ]->SetAxis( j ); - } // fi + } // rof + + } // rof + this->_CreateBoundingBox( ); } // ------------------------------------------------------------------------- -void cpExtensions::Visualization::MPRActors:: -PushDataInto( vtkRenderer* x, vtkRenderer* y, vtkRenderer* z, vtkRenderer* w ) +int cpExtensions::Visualization::MPRActors:: +AddBinaryConnection( + vtkAlgorithmOutput* aout, + const double& r, const double& g, const double& b + ) { - vtkRenderer* rends[] = { x, y, z }; - 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 ]->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 ) - { - 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 + this->Slices[ 0 ][ 0 ]->AddBinaryConnection( aout, r, g, b ); + this->Slices[ 0 ][ 1 ]->AddBinaryConnection( aout, r, g, b ); + this->Slices[ 0 ][ 2 ]->AddBinaryConnection( aout, r, g, b ); + this->Slices[ 1 ][ 0 ]->AddBinaryConnection( aout, r, g, b ); + this->Slices[ 1 ][ 1 ]->AddBinaryConnection( aout, r, g, b ); + return( this->Slices[ 1 ][ 2 ]->AddBinaryConnection( aout, r, g, b ) ); +} - } // rof - if( w != NULL ) - w->AddActor( this->ImageOutlineActor ); +// ------------------------------------------------------------------------- +int cpExtensions::Visualization::MPRActors:: +AddBinaryImage( + vtkImageData* data, + const double& r, const double& g, const double& b + ) +{ + this->Slices[ 0 ][ 0 ]->AddBinaryImage( data, r, g, b ); + this->Slices[ 0 ][ 1 ]->AddBinaryImage( data, r, g, b ); + this->Slices[ 0 ][ 2 ]->AddBinaryImage( data, r, g, b ); + this->Slices[ 1 ][ 0 ]->AddBinaryImage( data, r, g, b ); + this->Slices[ 1 ][ 1 ]->AddBinaryImage( data, r, g, b ); + return( this->Slices[ 1 ][ 2 ]->AddBinaryImage( data, r, g, b ) ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::MPRActors:: -PopDataFrom( - vtkRenderer* x, - vtkRenderer* y, - vtkRenderer* z, - vtkRenderer* w - ) +Clear( ) { - vtkRenderer* rends[] = { x, y, z }; - 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( ) ); + 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( ); +} - } // 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( ) ); +// ------------------------------------------------------------------------- +vtkImageData* cpExtensions::Visualization::MPRActors:: +GetInputImage( ) +{ + return( this->Slices[ 0 ][ 0 ]->GetInputImage( ) ); +} - } // fi +// ------------------------------------------------------------------------- +const vtkImageData* cpExtensions::Visualization::MPRActors:: +GetInputImage( ) const +{ + return( this->Slices[ 0 ][ 0 ]->GetInputImage( ) ); +} - } // rof - if( w != NULL ) - w->RemoveActor( this->ImageOutlineActor ); +// ------------------------------------------------------------------------- +unsigned int cpExtensions::Visualization::MPRActors:: +GetNumberOfImages( ) const +{ + return( this->Slices[ 0 ][ 0 ]->GetNumberOfImages( ) ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::MPRActors:: -LinkInteractors( ) +SetInterpolate( bool v ) { - this->_Update( 0 ); - this->_Update( 1 ); - this->_Update( 2 ); + this->Slices[ 0 ][ 0 ]->SetInterpolate( v ); + this->Slices[ 0 ][ 1 ]->SetInterpolate( v ); + this->Slices[ 0 ][ 2 ]->SetInterpolate( v ); + this->Slices[ 1 ][ 0 ]->SetInterpolate( v ); + this->Slices[ 1 ][ 1 ]->SetInterpolate( v ); + this->Slices[ 1 ][ 2 ]->SetInterpolate( v ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::MPRActors:: -SetLookupTable( unsigned int i, vtkScalarsToColors* lut ) +InterpolateOn( ) { - if( i < this->ImageMaps.size( ) ) - { - this->ImageMaps[ i ]->SetLookupTable( lut ); - this->ImageMaps[ i ]->Update( ); - this->Modified( ); - - } // fi + this->SetInterpolate( true ); } // ------------------------------------------------------------------------- -vtkScalarsToColors* cpExtensions::Visualization::MPRActors:: -GetLookupTable( unsigned int i ) const +void cpExtensions::Visualization::MPRActors:: +InterpolateOff( ) { - if( i < this->ImageMaps.size( ) ) - return( this->ImageMaps[ i ]->GetLookupTable( ) ); - else - return( NULL ); + this->SetInterpolate( false ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::MPRActors:: -SetLookupTableToWindowLevel( unsigned int i ) +PushActorsInto( + vtkRenderWindow* x, + vtkRenderWindow* y, + vtkRenderWindow* z, + vtkRenderWindow* w + ) { - // Check if the input has been configured - vtkImageData* image = this->_Image( i ); - if( image == NULL ) - return; + this->Slices[ 0 ][ 0 ]->PushActorsInto( x, true ); + this->Slices[ 0 ][ 1 ]->PushActorsInto( y, true ); + this->Slices[ 0 ][ 2 ]->PushActorsInto( z, true ); + this->Slices[ 1 ][ 0 ]->PushActorsInto( w, false ); + this->Slices[ 1 ][ 1 ]->PushActorsInto( w, false ); + this->Slices[ 1 ][ 2 ]->PushActorsInto( w, false ); + + vtkRenderer* wren = + ( w != NULL )? w->GetRenderers( )->GetFirstRenderer( ): NULL; + if( wren != NULL ) + { + wren->AddViewProp( this->ImageOutlineActor ); + wren->AddViewProp( this->Slices[ 1 ][ 0 ]->GetPlaneActor( ) ); + wren->AddViewProp( this->Slices[ 1 ][ 1 ]->GetPlaneActor( ) ); + wren->AddViewProp( this->Slices[ 1 ][ 2 ]->GetPlaneActor( ) ); - double r[ 2 ]; - image->GetScalarRange( r ); + } // fi +} - vtkSmartPointer< vtkWindowLevelLookupTable > lut = - vtkSmartPointer< vtkWindowLevelLookupTable >::New( ); - lut->SetScaleToLinear( ); - lut->SetTableRange( r ); - lut->Build( ); +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::MPRActors:: +PopActorsFrom( + vtkRenderWindow* x, + vtkRenderWindow* y, + vtkRenderWindow* z, + vtkRenderWindow* w + ) +{ + this->Slices[ 0 ][ 0 ]->PopActorsFrom( x ); + this->Slices[ 0 ][ 1 ]->PopActorsFrom( y ); + this->Slices[ 0 ][ 2 ]->PopActorsFrom( z ); + this->Slices[ 1 ][ 0 ]->PopActorsFrom( w ); + this->Slices[ 1 ][ 1 ]->PopActorsFrom( w ); + this->Slices[ 1 ][ 2 ]->PopActorsFrom( w ); + + vtkRenderer* wren = + ( w != NULL )? w->GetRenderers( )->GetFirstRenderer( ): NULL; + if( wren != NULL ) + { + wren->RemoveViewProp( this->ImageOutlineActor ); + wren->RemoveViewProp( this->Slices[ 1 ][ 0 ]->GetPlaneActor( ) ); + wren->RemoveViewProp( this->Slices[ 1 ][ 1 ]->GetPlaneActor( ) ); + wren->RemoveViewProp( this->Slices[ 1 ][ 2 ]->GetPlaneActor( ) ); - this->SetLookupTable( i, lut ); + } // fi } // ------------------------------------------------------------------------- double cpExtensions::Visualization::MPRActors:: -GetMinWindow( unsigned int i ) const +GetMinWindow( ) const { - return( 0 ); + return( this->Slices[ 0 ][ 0 ]->GetMinWindow( ) ); } // ------------------------------------------------------------------------- double cpExtensions::Visualization::MPRActors:: -GetMaxWindow( unsigned int i ) const +GetMaxWindow( ) 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 ] ); + return( this->Slices[ 0 ][ 0 ]->GetMaxWindow( ) ); } // ------------------------------------------------------------------------- double cpExtensions::Visualization::MPRActors:: -GetMinLevel( unsigned int i ) const +GetMinLevel( ) 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 ] ); + return( this->Slices[ 0 ][ 0 ]->GetMinLevel( ) ); } // ------------------------------------------------------------------------- double cpExtensions::Visualization::MPRActors:: -GetMaxLevel( unsigned int i ) const +GetMaxLevel( ) 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 ] ); + return( this->Slices[ 0 ][ 0 ]->GetMaxLevel( ) ); } // ------------------------------------------------------------------------- double cpExtensions::Visualization::MPRActors:: -GetWindow( unsigned int i ) const +GetWindow( ) { - vtkWindowLevelLookupTable* lut = - dynamic_cast< vtkWindowLevelLookupTable* >( this->GetLookupTable( i ) ); - if( lut != NULL ) - return( lut->GetWindow( ) ); - else - return( double( 0 ) ); + return( this->Slices[ 0 ][ 0 ]->GetWindow( ) ); } // ------------------------------------------------------------------------- double cpExtensions::Visualization::MPRActors:: -GetLevel( unsigned int i ) const +GetLevel( ) { - vtkWindowLevelLookupTable* lut = - dynamic_cast< vtkWindowLevelLookupTable* >( this->GetLookupTable( i ) ); - if( lut != NULL ) - return( lut->GetLevel( ) ); - else - return( double( 0 ) ); + return( this->Slices[ 0 ][ 0 ]->GetLevel( ) ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::MPRActors:: -SetWindow( unsigned int i, const double& w ) +SetWindow( 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 + this->Slices[ 0 ][ 0 ]->SetWindow( w ); + this->Slices[ 0 ][ 1 ]->SetWindow( w ); + this->Slices[ 0 ][ 2 ]->SetWindow( w ); + this->Slices[ 1 ][ 0 ]->SetWindow( w ); + this->Slices[ 1 ][ 1 ]->SetWindow( w ); + this->Slices[ 1 ][ 2 ]->SetWindow( w ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::MPRActors:: -SetLevel( unsigned int i, const double& l ) +SetLevel( 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 + this->Slices[ 0 ][ 0 ]->SetLevel( l ); + this->Slices[ 0 ][ 1 ]->SetLevel( l ); + this->Slices[ 0 ][ 2 ]->SetLevel( l ); + this->Slices[ 1 ][ 0 ]->SetLevel( l ); + this->Slices[ 1 ][ 1 ]->SetLevel( l ); + this->Slices[ 1 ][ 2 ]->SetLevel( l ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::MPRActors:: -SetWindowLevel( unsigned int i, const double& w, const double& l ) +SetWindowLevel( double w, 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 + this->Slices[ 0 ][ 0 ]->SetWindowLevel( w, l ); + this->Slices[ 0 ][ 1 ]->SetWindowLevel( w, l ); + this->Slices[ 0 ][ 2 ]->SetWindowLevel( w, l ); + this->Slices[ 1 ][ 0 ]->SetWindowLevel( w, l ); + this->Slices[ 1 ][ 1 ]->SetWindowLevel( w, l ); + this->Slices[ 1 ][ 2 ]->SetWindowLevel( w, l ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::MPRActors:: -ResetWindowLevel( unsigned int i ) +ResetWindowLevel( ) { - 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( ); - - } // fi + this->Slices[ 0 ][ 0 ]->ResetWindowLevel( ); + this->Slices[ 0 ][ 1 ]->ResetWindowLevel( ); + this->Slices[ 0 ][ 2 ]->ResetWindowLevel( ); + this->Slices[ 1 ][ 0 ]->ResetWindowLevel( ); + this->Slices[ 1 ][ 1 ]->ResetWindowLevel( ); + this->Slices[ 1 ][ 2 ]->ResetWindowLevel( ); } // ------------------------------------------------------------------------- -void cpExtensions::Visualization::MPRActors:: -SetLookupTableToColor( - unsigned int i, const double& r, const double& g, const double& b - ) +int cpExtensions::Visualization::MPRActors:: +GetSliceNumber( const int& axis ) const { - 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->SetAboveRangeColor( _0, _0, _0, _0 ); - lut->SetBelowRangeColor( _0, _0, _0, _0 ); - 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 ); + if( axis < 3 ) + return( this->Slices[ 0 ][ axis ]->GetSliceNumber( ) ); + else + return( -1 ); } // ------------------------------------------------------------------------- int cpExtensions::Visualization::MPRActors:: GetSliceNumberMinValue( const int& axis ) const { - return( this->Slices[ 0 ][ axis ]->GetSliceNumberMinValue( ) ); + if( axis < 3 ) + return( this->Slices[ 0 ][ axis ]->GetSliceNumberMinValue( ) ); + else + return( -1 ); } // ------------------------------------------------------------------------- int cpExtensions::Visualization::MPRActors:: GetSliceNumberMaxValue( const int& axis ) const { - return( this->Slices[ 0 ][ axis ]->GetSliceNumberMaxValue( ) ); + if( axis < 3 ) + return( this->Slices[ 0 ][ axis ]->GetSliceNumberMaxValue( ) ); + else + return( -1 ); } // ------------------------------------------------------------------------- -int cpExtensions::Visualization::MPRActors:: -GetSlice( const int& axis ) const +void cpExtensions::Visualization::MPRActors:: +SetSliceNumber( const int& axis, const int& slice ) { - return( this->Slices[ 0 ][ axis ]->GetSliceNumber( ) ); + if( axis < 3 ) + { + this->Slices[ 0 ][ axis ]->SetSliceNumber( slice ); + this->Slices[ 1 ][ axis ]->SetSliceNumber( slice ); + + } // fi } // ------------------------------------------------------------------------- void cpExtensions::Visualization::MPRActors:: -SetSlice( const int& axis, const int& slice ) +SetSlice( const int& axis, double* pos ) { - vtkImageData* image = this->_Image( 0 ); - if( image == NULL ) - return; - - // Get image data extent - int ext[ 6 ]; - image->GetExtent( ext ); + if( axis < 3 ) + { + this->Slices[ 0 ][ axis ]->SetSlice( pos ); + this->Slices[ 1 ][ axis ]->SetSlice( pos ); - // Check if the slice is valid - int real = slice; - if( slice < ext[ axis << 1 ] ) - real = ext[ axis << 1 ]; - if( ext[ ( axis << 1 ) + 1 ] < slice ) - real = ext[ ( axis << 1 ) + 1 ]; + } // fi +} - // Change slice - this->Slices[ 0 ][ axis ]->SetSliceNumber( real ); - this->Slices[ 1 ][ axis ]->SetSliceNumber( real ); - this->Modified( ); +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::MPRActors:: +SetAxesCursor( const int& axis, double* pos ) +{ + if( axis < 3 ) + this->Slices[ 0 ][ axis ]->SetAxesCursor( pos ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::MPRActors:: -SetSlice( const int& axis, const double& slice ) +Render( const int& axis ) { - vtkImageData* image = this->_Image( 0 ); - if( image == NULL ) - return; + if( axis < 3 ) + { + this->Slices[ 0 ][ axis ]->Render( ); + this->Slices[ 1 ][ axis ]->Render( ); - double x[ 3 ] = { double( 0 ) }; - double pcoords[ 3 ]; - int ijk[ 3 ]; + } // fi +} - x[ axis ] = slice; - image->ComputeStructuredCoordinates( x, ijk, pcoords ); - this->SetSlice( axis, ijk[ axis ] ); +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::MPRActors:: +Render( ) +{ + this->Render( 0 ); + this->Render( 1 ); + this->Render( 2 ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::MPRActors:: -ResetSlices( ) +ResetCamera( const int& axis ) { - for( unsigned int i = 0; i < 2; ++i ) - for( unsigned int j = 0; j < 3; ++j ) - this->Slices[ i ][ j ]->SetSliceNumber( - this->Slices[ i ][ j ]->GetSliceNumberMinValue( ) - ); + if( axis < 3 ) + this->Slices[ 0 ][ axis ]->ResetCamera( ); +} + +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::MPRActors:: +ResetCameras( ) +{ + this->ResetCamera( 0 ); + this->ResetCamera( 1 ); + this->ResetCamera( 2 ); } // ------------------------------------------------------------------------- @@ -546,6 +405,22 @@ MPRActors( ) for( unsigned int i = 0; i < 2; ++i ) for( unsigned int j = 0; j < 3; ++j ) this->Slices[ i ][ j ] = vtkSmartPointer< ImageSliceActors >::New( ); + + this->Slices[ 0 ][ 0 ]->AssociateSlice( this->Slices[ 1 ][ 0 ] ); + this->Slices[ 0 ][ 1 ]->AssociateSlice( this->Slices[ 1 ][ 1 ] ); + this->Slices[ 0 ][ 2 ]->AssociateSlice( this->Slices[ 1 ][ 2 ] ); + + for( unsigned int i = 0; i < 3; ++ i ) + { + this->Slices[ 0 ][ i ]->AddRenderCommand( + Self::_RenderCommand, this + ); + this->Slices[ 0 ][ i ]->AddWindowLevelCommand( + Self::_WindowLevelCommand, this + ); + this->Slices[ 0 ][ i ]->AddSlicesCommand( Self::_SlicesCommand, this ); + + } // rof } // ------------------------------------------------------------------------- @@ -554,77 +429,72 @@ cpExtensions::Visualization::MPRActors:: { } -// ------------------------------------------------------------------------- -vtkImageData* cpExtensions::Visualization::MPRActors:: -_Image( unsigned int i ) const -{ - 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:: -_Update( unsigned int i ) +_CreateBoundingBox( ) { - // Check if the input has been configured - vtkImageData* image = this->_Image( i ); + vtkImageData* image = + dynamic_cast< vtkImageData* >( this->Slices[ 0 ][ 0 ]->GetInputImage( ) ); if( image == NULL ) return; - this->ImageMaps[ i ]->Update( ); - - for( int j = 0; j < 2; ++j ) - { - for( int k = 0; k < 3; ++k ) - { - this->Slices[ j ][ k ]->AddInputConnection( - this->ImageMaps[ i ]->GetOutputPort( ), k - ); - this->Slices[ j ][ k ]->UpdateText( ); - // Add all of slice's props - this->Slices[ j ][ k ]->InitTraversal( ); - vtkProp* prop = this->Slices[ j ][ k ]->GetNextProp( ); - while( prop != NULL ) - { - this->AddItem( prop ); - prop = this->Slices[ j ][ k ]->GetNextProp( ); + // Create 3D outline + double bb[ 6 ]; + image->GetBounds( bb ); - } // elihw + vtkSmartPointer< vtkOutlineSource > img_ol = + vtkSmartPointer< vtkOutlineSource >::New( ); + img_ol->SetBounds( bb ); - } // rof + 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 ); - } // rof + this->AddItem( this->ImageOutlineActor ); +} - if( i == 0 ) +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::MPRActors:: +_SlicesCommand( double* pos, int axis, void* data ) +{ + MPRActors* actors = reinterpret_cast< MPRActors* >( data ); + if( actors == NULL ) + return; + for( unsigned int j = 0; j < 3; ++j ) { - // Create 3D outline - double bb[ 6 ]; - image->GetBounds( bb ); + if( actors->Slices[ 0 ][ j ]->GetAxis( ) != axis ) + { + actors->SetSlice( j, pos ); + actors->SetAxesCursor( j, pos ); + actors->Render( j ); - vtkSmartPointer< vtkOutlineSource > img_ol = - vtkSmartPointer< vtkOutlineSource >::New( ); - img_ol->SetBounds( bb ); + } // fi - 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 ); + } // rof +} - this->AddItem( this->ImageOutlineActor ); +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::MPRActors:: +_WindowLevelCommand( double window, double level, void* data ) +{ + MPRActors* actors = reinterpret_cast< MPRActors* >( data ); + if( actors == NULL ) + return; + actors->SetWindowLevel( window, level ); + actors->Render( ); +} - } // fi +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::MPRActors:: +_RenderCommand( void* data ) +{ + MPRActors* actors = reinterpret_cast< MPRActors* >( data ); + if( actors == NULL ) + return; + actors->Render( ); } // eof - $RCSfile$