X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpExtensions%2FVisualization%2FMPRActors.cxx;h=e26651b4dd24098b7df304e741041789419694b0;hb=dbc5b32e13cf4a299ce29a5666a8e0a2ff5e62a8;hp=a7803b2ad77864d2ed9ce81bd316a6d827ff1e10;hpb=ce7d718b88d08f559ca8328b335c4fe8fbfb9b9a;p=cpPlugins.git diff --git a/lib/cpExtensions/Visualization/MPRActors.cxx b/lib/cpExtensions/Visualization/MPRActors.cxx index a7803b2..e26651b 100644 --- a/lib/cpExtensions/Visualization/MPRActors.cxx +++ b/lib/cpExtensions/Visualization/MPRActors.cxx @@ -28,74 +28,134 @@ GetSliceActors( const int& i ) const } // ------------------------------------------------------------------------- -int cpExtensions::Visualization::MPRActors:: -AddInputConnection( vtkAlgorithmOutput* aout ) +void cpExtensions::Visualization::MPRActors:: +SetInputConnection( vtkAlgorithmOutput* aout ) { - ImageBlender* blender = this->Slices[ 0 ][ 0 ]->GetBlender( ); - if( blender == NULL ) + for( int i = 0; i < 2; ++i ) { - this->Slices[ 0 ][ 0 ]->AddInputConnection( aout ); - blender = this->Slices[ 0 ][ 0 ]->GetBlender( ); - for( unsigned int i = 0; i < 2; ++i ) + for( int j = 0; j < 3; ++j ) { - 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 ); - - } // rof + this->Slices[ i ][ j ]->SetInputConnection( aout ); + this->Slices[ i ][ j ]->SetAxis( j ); } // rof - this->_CreateBoundingBox( ); - } - else - blender->AddInputConnection( aout ); - return( blender->GetNumberOfImages( ) - 1 ); + + } // rof + this->_CreateBoundingBox( ); } // ------------------------------------------------------------------------- -int cpExtensions::Visualization::MPRActors:: -AddInputData( vtkImageData* new_image ) +void cpExtensions::Visualization::MPRActors:: +SetInputImage( vtkImageData* data ) { - ImageBlender* blender = this->Slices[ 0 ][ 0 ]->GetBlender( ); - if( blender == NULL ) + for( int i = 0; i < 2; ++i ) { - this->Slices[ 0 ][ 0 ]->AddInputData( new_image ); - blender = this->Slices[ 0 ][ 0 ]->GetBlender( ); - for( unsigned int i = 0; i < 2; ++i ) + for( int j = 0; j < 3; ++j ) { - 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 ); - - } // rof + this->Slices[ i ][ j ]->SetInputImage( data ); + this->Slices[ i ][ j ]->SetAxis( j ); } // rof - this->_CreateBoundingBox( ); - } - else - blender->AddInputData( new_image ); - return( blender->GetNumberOfImages( ) - 1 ); + + } // rof + this->_CreateBoundingBox( ); +} + +// ------------------------------------------------------------------------- +int cpExtensions::Visualization::MPRActors:: +AddBinaryConnection( + vtkAlgorithmOutput* aout, + const double& r, const double& g, const double& b + ) +{ + 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 ) ); +} + +// ------------------------------------------------------------------------- +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:: +Clear( ) +{ + 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( ); +} + +// ------------------------------------------------------------------------- +vtkImageData* cpExtensions::Visualization::MPRActors:: +GetInputImage( ) +{ + return( this->Slices[ 0 ][ 0 ]->GetInputImage( ) ); +} + +// ------------------------------------------------------------------------- +const vtkImageData* cpExtensions::Visualization::MPRActors:: +GetInputImage( ) const +{ + return( this->Slices[ 0 ][ 0 ]->GetInputImage( ) ); } // ------------------------------------------------------------------------- unsigned int cpExtensions::Visualization::MPRActors:: GetNumberOfImages( ) const { - ImageBlender* blender = this->Slices[ 0 ][ 0 ]->GetBlender( ); - if( blender != NULL ) - return( blender->GetNumberOfImages( ) ); - else - return( 0 ); + return( this->Slices[ 0 ][ 0 ]->GetNumberOfImages( ) ); +} + +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::MPRActors:: +SetInterpolate( bool v ) +{ + 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:: +InterpolateOn( ) +{ + this->SetInterpolate( true ); +} + +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::MPRActors:: +InterpolateOff( ) +{ + this->SetInterpolate( false ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::MPRActors:: PushActorsInto( - vtkRenderWindow* x, vtkRenderWindow* y, vtkRenderWindow* z, + vtkRenderWindow* x, + vtkRenderWindow* y, + vtkRenderWindow* z, vtkRenderWindow* w ) { @@ -106,41 +166,24 @@ PushActorsInto( 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 ) - { - xren->AddActor( this->Slices[ 0 ][ 1 ]->GetPlaneActor( ) ); - xren->AddActor( this->Slices[ 0 ][ 2 ]->GetPlaneActor( ) ); - - } // fi - if( yren != NULL ) - { - yren->AddActor( this->Slices[ 0 ][ 0 ]->GetPlaneActor( ) ); - yren->AddActor( this->Slices[ 0 ][ 2 ]->GetPlaneActor( ) ); - - } // fi - if( zren != NULL ) + if( wren != NULL ) { - zren->AddActor( this->Slices[ 0 ][ 0 ]->GetPlaneActor( ) ); - zren->AddActor( this->Slices[ 0 ][ 1 ]->GetPlaneActor( ) ); + 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( ) ); } // fi - if( wren != NULL ) - wren->AddActor( this->ImageOutlineActor ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::MPRActors:: PopActorsFrom( - vtkRenderWindow* x, vtkRenderWindow* y, vtkRenderWindow* z, + vtkRenderWindow* x, + vtkRenderWindow* y, + vtkRenderWindow* z, vtkRenderWindow* w ) { @@ -154,14 +197,41 @@ PopActorsFrom( vtkRenderer* wren = ( w != NULL )? w->GetRenderers( )->GetFirstRenderer( ): NULL; if( wren != NULL ) - wren->RemoveActor( this->ImageOutlineActor ); + { + 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->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 +} + +// ------------------------------------------------------------------------- +double cpExtensions::Visualization::MPRActors:: +GetMinWindow( ) const +{ + return( this->Slices[ 0 ][ 0 ]->GetMinWindow( ) ); +} + +// ------------------------------------------------------------------------- +double cpExtensions::Visualization::MPRActors:: +GetMaxWindow( ) const +{ + return( this->Slices[ 0 ][ 0 ]->GetMaxWindow( ) ); +} + +// ------------------------------------------------------------------------- +double cpExtensions::Visualization::MPRActors:: +GetMinLevel( ) const +{ + return( this->Slices[ 0 ][ 0 ]->GetMinLevel( ) ); +} + +// ------------------------------------------------------------------------- +double cpExtensions::Visualization::MPRActors:: +GetMaxLevel( ) const +{ + return( this->Slices[ 0 ][ 0 ]->GetMaxLevel( ) ); } // ------------------------------------------------------------------------- @@ -178,86 +248,152 @@ GetLevel( ) return( this->Slices[ 0 ][ 0 ]->GetLevel( ) ); } +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::MPRActors:: +SetWindow( double w ) +{ + 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( double l ) +{ + 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( double w, double l ) +{ + 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( ) +{ + 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( ); +} + // ------------------------------------------------------------------------- int cpExtensions::Visualization::MPRActors:: -GetSliceNumberMinValue( const int& axis ) const +GetSliceNumber( const int& axis ) const { - return( this->Slices[ 0 ][ axis ]->GetSliceNumberMinValue( ) ); + if( axis < 3 ) + return( this->Slices[ 0 ][ axis ]->GetSliceNumber( ) ); + else + return( -1 ); } // ------------------------------------------------------------------------- int cpExtensions::Visualization::MPRActors:: -GetSliceNumberMaxValue( const int& axis ) const +GetSliceNumberMinValue( const int& axis ) const { - return( this->Slices[ 0 ][ axis ]->GetSliceNumberMaxValue( ) ); + if( axis < 3 ) + return( this->Slices[ 0 ][ axis ]->GetSliceNumberMinValue( ) ); + else + return( -1 ); } // ------------------------------------------------------------------------- int cpExtensions::Visualization::MPRActors:: -GetSlice( const int& axis ) const +GetSliceNumberMaxValue( const int& axis ) const { - return( this->Slices[ 0 ][ axis ]->GetSliceNumber( ) ); + if( axis < 3 ) + return( this->Slices[ 0 ][ axis ]->GetSliceNumberMaxValue( ) ); + else + return( -1 ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::MPRActors:: -SetSlice( const int& axis, const int& slice ) +SetSliceNumber( const int& axis, const int& slice ) { - ImageBlender* blender = this->Slices[ 0 ][ 0 ]->GetBlender( ); - if( blender == NULL ) - return; - vtkImageData* image = - dynamic_cast< vtkImageData* >( blender->GetInput( ) ); - if( image == NULL ) - return; + if( axis < 3 ) + { + this->Slices[ 0 ][ axis ]->SetSliceNumber( slice ); + this->Slices[ 1 ][ axis ]->SetSliceNumber( slice ); - // Get image data extent - int ext[ 6 ]; - image->GetExtent( ext ); + } // fi +} - // 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 ]; +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::MPRActors:: +SetSlice( const int& axis, double* pos ) +{ + if( axis < 3 ) + { + this->Slices[ 0 ][ axis ]->SetSlice( pos ); + this->Slices[ 1 ][ axis ]->SetSlice( pos ); - // Change slice - this->Slices[ 0 ][ axis ]->SetSliceNumber( real ); - this->Slices[ 1 ][ axis ]->SetSliceNumber( real ); - this->Modified( ); + } // fi } // ------------------------------------------------------------------------- void cpExtensions::Visualization::MPRActors:: -SetSlice( const int& axis, const double& slice ) +SetAxesCursor( const int& axis, double* pos ) { - ImageBlender* blender = this->Slices[ 0 ][ 0 ]->GetBlender( ); - if( blender == NULL ) - return; - vtkImageData* image = - dynamic_cast< vtkImageData* >( blender->GetInput( ) ); - if( image == NULL ) - return; + if( axis < 3 ) + this->Slices[ 0 ][ axis ]->SetAxesCursor( pos ); +} + +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::MPRActors:: +Render( const int& axis ) +{ + 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 ); } // ------------------------------------------------------------------------- @@ -297,32 +433,27 @@ cpExtensions::Visualization::MPRActors:: void cpExtensions::Visualization::MPRActors:: _CreateBoundingBox( ) { - ImageBlender* blender = this->Slices[ 0 ][ 0 ]->GetBlender( ); - if( blender == NULL ) + vtkImageData* image = + dynamic_cast< vtkImageData* >( this->Slices[ 0 ][ 0 ]->GetInputImage( ) ); + if( image == NULL ) return; - if( blender->GetNumberOfImages( ) == 1 ) - { - vtkImageData* image = - dynamic_cast< vtkImageData* >( blender->GetInput( ) ); - // Create 3D outline - double bb[ 6 ]; - image->GetBounds( bb ); + // Create 3D outline + double bb[ 6 ]; + image->GetBounds( bb ); - vtkSmartPointer< vtkOutlineSource > img_ol = - vtkSmartPointer< vtkOutlineSource >::New( ); - img_ol->SetBounds( bb ); + vtkSmartPointer< vtkOutlineSource > img_ol = + vtkSmartPointer< vtkOutlineSource >::New( ); + img_ol->SetBounds( bb ); - 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 ); + 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 ); - this->AddItem( this->ImageOutlineActor ); - - } // fi + this->AddItem( this->ImageOutlineActor ); } // ------------------------------------------------------------------------- @@ -336,10 +467,9 @@ _SlicesCommand( double* pos, int axis, void* data ) { 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 ); + actors->SetSlice( j, pos ); + actors->SetAxesCursor( j, pos ); + actors->Render( j ); } // fi @@ -353,12 +483,8 @@ _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 ); + actors->SetWindowLevel( window, level ); + actors->Render( ); } // ------------------------------------------------------------------------- @@ -368,12 +494,7 @@ _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 ); + actors->Render( ); } // eof - $RCSfile$