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=55f271c44c7026cc30f710b1ba0537f7fa1ea759;hpb=8db7a40f2ef8530457959a51a4d2a7f012d0b7a3;p=cpPlugins.git diff --git a/lib/cpExtensions/Visualization/MPRActors.cxx b/lib/cpExtensions/Visualization/MPRActors.cxx index 55f271c..a7803b2 100644 --- a/lib/cpExtensions/Visualization/MPRActors.cxx +++ b/lib/cpExtensions/Visualization/MPRActors.cxx @@ -2,6 +2,8 @@ #include #include +#include +#include #include #include #include @@ -29,135 +31,65 @@ GetSliceActors( const int& i ) const int cpExtensions::Visualization::MPRActors:: AddInputConnection( vtkAlgorithmOutput* aout ) { - int N = this->Slices[ 0 ][ 0 ]->GetNumberOfImageActors( ); - if( N == 0 ) + ImageBlender* blender = this->Slices[ 0 ][ 0 ]->GetBlender( ); + if( blender == NULL ) { - this->Slices[ 0 ][ 0 ]->AddInputConnection( aout, 0 ); - vtkImageMapToColors* imap = this->Slices[ 0 ][ 0 ]->GetImageMap( 0 ); + this->Slices[ 0 ][ 0 ]->AddInputConnection( aout ); + blender = this->Slices[ 0 ][ 0 ]->GetBlender( ); 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 - ); + this->Slices[ i ][ j ]->SetBlender( blender ); + this->Slices[ i ][ j ]->SetAxis( j ); + + } // rof + + } // rof + this->_CreateBoundingBox( ); } else - { - // Check if the image share the same space - vtkImageData* new_image = dynamic_cast< vtkImageData* >( - aout->GetProducer( )->GetOutputDataObject( aout->GetIndex( ) ) - ); - if( new_image != NULL ) - { - 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 ) - { - 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; - - } // fi - return( N ); + blender->AddInputConnection( aout ); + return( blender->GetNumberOfImages( ) - 1 ); } // ------------------------------------------------------------------------- int cpExtensions::Visualization::MPRActors:: AddInputData( vtkImageData* new_image ) { - int N = this->Slices[ 0 ][ 0 ]->GetNumberOfImageActors( ); - if( N == 0 ) + ImageBlender* blender = this->Slices[ 0 ][ 0 ]->GetBlender( ); + if( blender == NULL ) { - this->Slices[ 0 ][ 0 ]->AddInputData( new_image, 0 ); - vtkImageMapToColors* imap = this->Slices[ 0 ][ 0 ]->GetImageMap( 0 ); + this->Slices[ 0 ][ 0 ]->AddInputData( new_image ); + blender = this->Slices[ 0 ][ 0 ]->GetBlender( ); 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 + this->Slices[ i ][ j ]->SetBlender( blender ); + this->Slices[ i ][ j ]->SetAxis( j ); + + } // rof + + } // rof + this->_CreateBoundingBox( ); } else - { - // Check if the image share the same space - 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 ) - { - 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 - N = -1; - - } // fi - return( N ); + blender->AddInputData( new_image ); + return( blender->GetNumberOfImages( ) - 1 ); } // ------------------------------------------------------------------------- unsigned int cpExtensions::Visualization::MPRActors:: GetNumberOfImages( ) const { - return( this->Slices[ 0 ][ 0 ]->GetNumberOfImageActors( ) ); + ImageBlender* blender = this->Slices[ 0 ][ 0 ]->GetBlender( ); + if( blender != NULL ) + return( blender->GetNumberOfImages( ) ); + else + return( 0 ); } // ------------------------------------------------------------------------- @@ -170,50 +102,39 @@ PushActorsInto( 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; - 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( int j = 0; j < 3; ++j ) - if( i != j ) - rends[ i ]->AddActor( this->Slices[ 0 ][ j ]->GetPlaneActor( ) ); - if( wren != NULL ) - { - for( - unsigned int k = 0; - k < this->Slices[ 1 ][ i ]->GetNumberOfImageActors( ); - ++k - ) - wren->AddActor( this->Slices[ 1 ][ i ]->GetImageActor( k ) ); - wren->AddActor( this->Slices[ 1 ][ i ]->GetPlaneActor( ) ); - } // fi + if( xren != NULL ) + { + xren->AddActor( this->Slices[ 0 ][ 1 ]->GetPlaneActor( ) ); + xren->AddActor( this->Slices[ 0 ][ 2 ]->GetPlaneActor( ) ); - } // rof - if( wren != NULL ) - wren->AddActor( this->ImageOutlineActor ); + } // fi + if( yren != NULL ) + { + yren->AddActor( this->Slices[ 0 ][ 0 ]->GetPlaneActor( ) ); + yren->AddActor( this->Slices[ 0 ][ 2 ]->GetPlaneActor( ) ); - for( unsigned int j = 0; j < 3; ++j ) + } // fi + if( zren != NULL ) { - ImageInteractorStyle* st = - dynamic_cast< ImageInteractorStyle* >( this->Slices[ 0 ][ j ]->GetStyle( ) ); - if( w != NULL ) - st->AssociateInteractor( w->GetInteractor( ) ); - for( unsigned int l = 0; l < 3; ++l ) - if( j != l ) - st->AssociateInteractor( - this->Slices[ 0 ][ l ]->GetStyle( )->GetInteractor( ) - ); + zren->AddActor( this->Slices[ 0 ][ 0 ]->GetPlaneActor( ) ); + zren->AddActor( this->Slices[ 0 ][ 1 ]->GetPlaneActor( ) ); - } // rof + } // fi + if( wren != NULL ) + wren->AddActor( this->ImageOutlineActor ); } // ------------------------------------------------------------------------- @@ -226,34 +147,12 @@ PopActorsFrom( 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; - 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( int j = 0; j < 3; ++j ) - 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 - ) - wren->RemoveActor( this->Slices[ 1 ][ i ]->GetImageActor( k ) ); - wren->RemoveActor( this->Slices[ 1 ][ i ]->GetPlaneActor( ) ); - - } // fi - - } // rof if( wren != NULL ) wren->RemoveActor( this->ImageOutlineActor ); @@ -266,16 +165,17 @@ PopActorsFrom( } // ------------------------------------------------------------------------- -void cpExtensions::Visualization::MPRActors:: -SetLookupTableAsColor( unsigned int i, double r, double g, double b ) +double cpExtensions::Visualization::MPRActors:: +GetWindow( ) { - 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( ); + return( this->Slices[ 0 ][ 0 ]->GetWindow( ) ); +} + +// ------------------------------------------------------------------------- +double cpExtensions::Visualization::MPRActors:: +GetLevel( ) +{ + return( this->Slices[ 0 ][ 0 ]->GetLevel( ) ); } // ------------------------------------------------------------------------- @@ -303,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; @@ -328,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; @@ -366,9 +274,17 @@ MPRActors( ) this->Slices[ 0 ][ 1 ]->AssociateSlice( this->Slices[ 1 ][ 1 ] ); this->Slices[ 0 ][ 2 ]->AssociateSlice( this->Slices[ 1 ][ 2 ] ); - this->Slices[ 0 ][ 0 ]->SetSlicesCommand( Self::_SetSlices, this ); - this->Slices[ 0 ][ 1 ]->SetSlicesCommand( Self::_SetSlices, this ); - this->Slices[ 0 ][ 2 ]->SetSlicesCommand( Self::_SetSlices, this ); + 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 } // ------------------------------------------------------------------------- @@ -377,62 +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( ); - - // 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( ); - - } // elihw - - } // rof + vtkImageData* image = + dynamic_cast< vtkImageData* >( blender->GetInput( ) ); - } // rof - - if( i == 0 ) - { // Create 3D outline double bb[ 6 ]; image->GetBounds( bb ); @@ -451,20 +323,57 @@ _Update( unsigned int i ) this->AddItem( this->ImageOutlineActor ); } // fi - */ } // ------------------------------------------------------------------------- void cpExtensions::Visualization::MPRActors:: -_SetSlices( double* pos, int axis, void* data ) +_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->Modified( ); + 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$