X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;ds=sidebyside;f=lib%2FcpExtensions%2FVisualization%2FMPRActors.cxx;h=a7803b2ad77864d2ed9ce81bd316a6d827ff1e10;hb=106a56bfe6a48067380089ffd61a518e40d77933;hp=90fdb7d83c7f68842d4d356191b61bdeedbe03c0;hpb=1d735deae0ae5e8bff643a59370a03c961ef780c;p=cpPlugins.git diff --git a/lib/cpExtensions/Visualization/MPRActors.cxx b/lib/cpExtensions/Visualization/MPRActors.cxx index 90fdb7d..a7803b2 100644 --- a/lib/cpExtensions/Visualization/MPRActors.cxx +++ b/lib/cpExtensions/Visualization/MPRActors.cxx @@ -2,11 +2,11 @@ #include #include -#include #include #include #include -#include +#include +#include // ------------------------------------------------------------------------- cpExtensions::Visualization::MPRActors* @@ -31,337 +31,151 @@ GetSliceActors( const int& i ) const int cpExtensions::Visualization::MPRActors:: AddInputConnection( vtkAlgorithmOutput* aout ) { - int N = this->ImageMaps.size( ); - if( N == 0 ) + ImageBlender* blender = this->Slices[ 0 ][ 0 ]->GetBlender( ); + if( blender == NULL ) { - this->ImageMaps.push_back( - vtkSmartPointer< vtkImageMapToColors >::New( ) - ); - this->ImageMaps[ 0 ]->SetInputConnection( aout ); - 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 = - 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->Slices[ 0 ][ 0 ]->AddInputConnection( aout ); + blender = this->Slices[ 0 ][ 0 ]->GetBlender( ); + for( unsigned int i = 0; i < 2; ++i ) { - this->ImageMaps.push_back( - vtkSmartPointer< vtkImageMapToColors >::New( ) - ); - this->ImageMaps[ N ]->SetInputConnection( aout ); - this->SetLookupTableToWindowLevel( N ); - this->_Update( N ); - return( N ); - } - else - return( -1 ); + for( unsigned int j = 0; j < 3; ++j ) + { + if( i != 0 || j != 0 ) + this->Slices[ i ][ j ]->SetBlender( blender ); + this->Slices[ i ][ j ]->SetAxis( j ); - } // fi -} + } // rof -// ------------------------------------------------------------------------- -int cpExtensions::Visualization::MPRActors:: -AddInputData( vtkImageData* image ) -{ - 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 ); + } // rof + this->_CreateBoundingBox( ); } 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 + blender->AddInputConnection( aout ); + return( blender->GetNumberOfImages( ) - 1 ); } // ------------------------------------------------------------------------- -void cpExtensions::Visualization::MPRActors:: -PushDataInto( vtkRenderer* x, vtkRenderer* y, vtkRenderer* z, vtkRenderer* w ) +int cpExtensions::Visualization::MPRActors:: +AddInputData( vtkImageData* new_image ) { - vtkRenderer* rends[] = { x, y, z }; - for( int i = 0; i < 3; ++i ) + ImageBlender* blender = this->Slices[ 0 ][ 0 ]->GetBlender( ); + if( blender == NULL ) { - 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 ) + this->Slices[ 0 ][ 0 ]->AddInputData( new_image ); + blender = this->Slices[ 0 ][ 0 ]->GetBlender( ); + for( unsigned int i = 0; i < 2; ++i ) { - 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( ) ); + for( unsigned int j = 0; j < 3; ++j ) + { + if( i != 0 || j != 0 ) + this->Slices[ i ][ j ]->SetBlender( blender ); + this->Slices[ i ][ j ]->SetAxis( j ); - } // fi + } // rof - } // rof - if( w != NULL ) - w->AddActor( this->ImageOutlineActor ); + } // rof + this->_CreateBoundingBox( ); + } + else + blender->AddInputData( new_image ); + return( blender->GetNumberOfImages( ) - 1 ); } // ------------------------------------------------------------------------- -void cpExtensions::Visualization::MPRActors:: -PopDataFrom( - vtkRenderer* x, - vtkRenderer* y, - vtkRenderer* z, - vtkRenderer* w - ) +unsigned int cpExtensions::Visualization::MPRActors:: +GetNumberOfImages( ) const { - 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( ) ); - - } // 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 ); + ImageBlender* blender = this->Slices[ 0 ][ 0 ]->GetBlender( ); + if( blender != NULL ) + return( blender->GetNumberOfImages( ) ); + else + return( 0 ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::MPRActors:: -SetLookupTable( unsigned int i, vtkScalarsToColors* lut ) +PushActorsInto( + vtkRenderWindow* x, vtkRenderWindow* y, vtkRenderWindow* z, + vtkRenderWindow* w + ) { - if( i < this->ImageMaps.size( ) ) + 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* xren = + ( x != NULL )? x->GetRenderers( )->GetFirstRenderer( ): NULL; + vtkRenderer* yren = + ( y != NULL )? y->GetRenderers( )->GetFirstRenderer( ): NULL; + vtkRenderer* zren = + ( z != NULL )? z->GetRenderers( )->GetFirstRenderer( ): NULL; + vtkRenderer* wren = + ( w != NULL )? w->GetRenderers( )->GetFirstRenderer( ): NULL; + + if( xren != NULL ) { - this->ImageMaps[ i ]->SetLookupTable( lut ); - this->ImageMaps[ i ]->Update( ); - this->Modified( ); + xren->AddActor( this->Slices[ 0 ][ 1 ]->GetPlaneActor( ) ); + xren->AddActor( this->Slices[ 0 ][ 2 ]->GetPlaneActor( ) ); } // 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 ] ); -} + if( yren != NULL ) + { + yren->AddActor( this->Slices[ 0 ][ 0 ]->GetPlaneActor( ) ); + yren->AddActor( this->Slices[ 0 ][ 2 ]->GetPlaneActor( ) ); -// ------------------------------------------------------------------------- -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 ) ); + } // fi + if( zren != NULL ) + { + zren->AddActor( this->Slices[ 0 ][ 0 ]->GetPlaneActor( ) ); + zren->AddActor( this->Slices[ 0 ][ 1 ]->GetPlaneActor( ) ); - double r[ 2 ]; - image->GetScalarRange( r ); - return( r[ 0 ] ); + } // fi + if( wren != NULL ) + wren->AddActor( this->ImageOutlineActor ); } // ------------------------------------------------------------------------- -double cpExtensions::Visualization::MPRActors:: -GetMaxLevel( unsigned int i ) const +void cpExtensions::Visualization::MPRActors:: +PopActorsFrom( + vtkRenderWindow* x, vtkRenderWindow* y, vtkRenderWindow* z, + vtkRenderWindow* w + ) { - // 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 ] ); + 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->RemoveActor( this->ImageOutlineActor ); + + 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( ); } // ------------------------------------------------------------------------- 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 ) ); -} - -// ------------------------------------------------------------------------- -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:: -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->Build( ); - this->ImageMaps[ i ]->Modified( ); - this->Modified( ); - - } // fi + return( this->Slices[ 0 ][ 0 ]->GetLevel( ) ); } // ------------------------------------------------------------------------- @@ -389,7 +203,11 @@ GetSlice( const int& axis ) const void cpExtensions::Visualization::MPRActors:: SetSlice( const int& axis, const int& slice ) { - vtkImageData* image = this->_Image( 0 ); + ImageBlender* blender = this->Slices[ 0 ][ 0 ]->GetBlender( ); + if( blender == NULL ) + return; + vtkImageData* image = + dynamic_cast< vtkImageData* >( blender->GetInput( ) ); if( image == NULL ) return; @@ -414,7 +232,11 @@ SetSlice( const int& axis, const int& slice ) void cpExtensions::Visualization::MPRActors:: SetSlice( const int& axis, const double& slice ) { - vtkImageData* image = this->_Image( 0 ); + ImageBlender* blender = this->Slices[ 0 ][ 0 ]->GetBlender( ); + if( blender == NULL ) + return; + vtkImageData* image = + dynamic_cast< vtkImageData* >( blender->GetInput( ) ); if( image == NULL ) return; @@ -447,6 +269,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 } // ------------------------------------------------------------------------- @@ -455,47 +293,18 @@ 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 ); - if( image == NULL ) + ImageBlender* blender = this->Slices[ 0 ][ 0 ]->GetBlender( ); + if( blender == NULL ) return; - this->ImageMaps[ i ]->Update( ); - - for( int j = 0; j < 2; ++j ) + if( blender->GetNumberOfImages( ) == 1 ) { - for( int k = 0; k < 3; ++k ) - { - this->Slices[ j ][ k ]->AddInputConnection( - this->ImageMaps[ i ]->GetOutputPort( ), k - ); - this->Slices[ j ][ k ]->UpdateText( ); - - } // rof - - } // rof + vtkImageData* image = + dynamic_cast< vtkImageData* >( blender->GetInput( ) ); - if( i == 0 ) - { // Create 3D outline double bb[ 6 ]; image->GetBounds( bb ); @@ -516,4 +325,55 @@ _Update( unsigned int i ) } // fi } +// ------------------------------------------------------------------------- +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 ) + { + if( actors->Slices[ 0 ][ j ]->GetAxis( ) != axis ) + { + actors->Slices[ 0 ][ j ]->SetSlice( pos ); + actors->Slices[ 1 ][ j ]->SetSlice( pos ); + actors->Slices[ 0 ][ j ]->Render( 1e-3 ); + actors->Slices[ 1 ][ j ]->Render( 1e-3 ); + + } // fi + + } // rof +} + +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::MPRActors:: +_WindowLevelCommand( double window, double level, void* data ) +{ + MPRActors* actors = reinterpret_cast< MPRActors* >( data ); + if( actors == NULL ) + return; + actors->Slices[ 0 ][ 0 ]->Render( 1e-3 ); + actors->Slices[ 0 ][ 1 ]->Render( 1e-3 ); + actors->Slices[ 0 ][ 2 ]->Render( 1e-3 ); + actors->Slices[ 1 ][ 0 ]->Render( 1e-3 ); + actors->Slices[ 1 ][ 1 ]->Render( 1e-3 ); + actors->Slices[ 1 ][ 2 ]->Render( 1e-3 ); +} + +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::MPRActors:: +_RenderCommand( void* data ) +{ + MPRActors* actors = reinterpret_cast< MPRActors* >( data ); + if( actors == NULL ) + return; + actors->Slices[ 0 ][ 0 ]->Render( 1e-3 ); + actors->Slices[ 0 ][ 1 ]->Render( 1e-3 ); + actors->Slices[ 0 ][ 2 ]->Render( 1e-3 ); + actors->Slices[ 1 ][ 0 ]->Render( 1e-3 ); + actors->Slices[ 1 ][ 1 ]->Render( 1e-3 ); + actors->Slices[ 1 ][ 2 ]->Render( 1e-3 ); +} + // eof - $RCSfile$