X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpExtensions%2FVisualization%2FMPRActors.cxx;h=b04194484b71dcbaf4b3d2eb670cf308b480f82a;hb=31e4cf1f3580efa059d3ffad14ba6a15d2372f5c;hp=00d27dc6e8411c62388b6f29a4487f2719cc1a5d;hpb=4a793c6b8f400b2303a3f69680aea22948d8ecc6;p=cpPlugins.git diff --git a/lib/cpExtensions/Visualization/MPRActors.cxx b/lib/cpExtensions/Visualization/MPRActors.cxx index 00d27dc..b041944 100644 --- a/lib/cpExtensions/Visualization/MPRActors.cxx +++ b/lib/cpExtensions/Visualization/MPRActors.cxx @@ -31,174 +31,43 @@ GetSliceActors( const int& i ) const int cpExtensions::Visualization::MPRActors:: AddInputConnection( vtkAlgorithmOutput* aout ) { - int N = this->Slices[ 0 ][ 0 ]->GetNumberOfImageActors( ); - if( N == 0 ) + for( unsigned int i = 0; i < 2; ++i ) { - this->Slices[ 0 ][ 0 ]->AddInputConnection( aout, 0 ); - vtkImageMapToColors* imap = this->Slices[ 0 ][ 0 ]->GetImageMap( 0 ); - 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 - ); - - // Create bounding box - vtkImageData* new_image = dynamic_cast< vtkImageData* >( - aout->GetProducer( )->GetOutputDataObject( aout->GetIndex( ) ) - ); - - // Create 3D outline - double bb[ 6 ]; - new_image->GetBounds( bb ); - - vtkSmartPointer< vtkOutlineSource > img_ol = - vtkSmartPointer< vtkOutlineSource >::New( ); - img_ol->SetBounds( bb ); + for( unsigned int j = 0; j < 3; ++j ) + { + this->Slices[ i ][ j ]->SetInputConnection( aout ); + this->Slices[ i ][ j ]->SetAxis( j ); - 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 ); - } - 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 ); + } // rof + this->_CreateBoundingBox( ); + return( 0 ); } // ------------------------------------------------------------------------- int cpExtensions::Visualization::MPRActors:: AddInputData( vtkImageData* new_image ) { - int N = this->Slices[ 0 ][ 0 ]->GetNumberOfImageActors( ); - if( N == 0 ) - { - this->Slices[ 0 ][ 0 ]->AddInputData( new_image, 0 ); - vtkImageMapToColors* imap = this->Slices[ 0 ][ 0 ]->GetImageMap( 0 ); - 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 - - // Create 3D outline - double bb[ 6 ]; - new_image->GetBounds( 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 ); - - this->AddItem( this->ImageOutlineActor ); - } - else + for( unsigned int i = 0; i < 2; ++i ) { - // 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 ) + for( unsigned int j = 0; j < 3; ++j ) { - 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 ); + this->Slices[ i ][ j ]->SetInputImage( new_image ); + this->Slices[ i ][ j ]->SetAxis( j ); + + } // rof + + } // rof + this->_CreateBoundingBox( ); + return( 0 ); } // ------------------------------------------------------------------------- unsigned int cpExtensions::Visualization::MPRActors:: GetNumberOfImages( ) const { - return( this->Slices[ 0 ][ 0 ]->GetNumberOfImageActors( ) ); + return( this->Slices[ 0 ][ 0 ]->GetNumberOfImages( ) ); } // ------------------------------------------------------------------------- @@ -215,33 +84,8 @@ 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 ) - { - zren->AddActor( this->Slices[ 0 ][ 0 ]->GetPlaneActor( ) ); - zren->AddActor( this->Slices[ 0 ][ 1 ]->GetPlaneActor( ) ); - - } // fi if( wren != NULL ) wren->AddActor( this->ImageOutlineActor ); } @@ -273,19 +117,6 @@ PopActorsFrom( this->Slices[ 1 ][ 2 ]->Clear( ); } -// ------------------------------------------------------------------------- -void cpExtensions::Visualization::MPRActors:: -SetLookupTableAsColor( unsigned int i, double r, double g, double b ) -{ - 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( ); -} - // ------------------------------------------------------------------------- double cpExtensions::Visualization::MPRActors:: GetWindow( ) @@ -325,7 +156,8 @@ GetSlice( const int& axis ) const void cpExtensions::Visualization::MPRActors:: SetSlice( const int& axis, const int& slice ) { - vtkImageData* image = this->Slices[ 0 ][ 0 ]->GetInputImage( 0 ); + vtkImageData* image = + dynamic_cast< vtkImageData* >( this->Slices[ 0 ][ 0 ]->GetInputImage( ) ); if( image == NULL ) return; @@ -350,7 +182,8 @@ SetSlice( const int& axis, const int& slice ) void cpExtensions::Visualization::MPRActors:: SetSlice( const int& axis, const double& slice ) { - vtkImageData* image = this->Slices[ 0 ][ 0 ]->GetInputImage( 0 ); + vtkImageData* image = + dynamic_cast< vtkImageData* >( this->Slices[ 0 ][ 0 ]->GetInputImage( ) ); if( image == NULL ) return; @@ -370,7 +203,7 @@ ResetSlices( ) 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 ]->GetSliceNumberMaxValue( ) + this->Slices[ i ][ j ]->GetSliceNumberMinValue( ) ); } @@ -407,6 +240,33 @@ cpExtensions::Visualization::MPRActors:: { } +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::MPRActors:: +_CreateBoundingBox( ) +{ + vtkImageData* image = + dynamic_cast< vtkImageData* >( this->Slices[ 0 ][ 0 ]->GetInputImage( ) ); + if( image == NULL ) + return; + + // Create 3D outline + double bb[ 6 ]; + image->GetBounds( 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 ); + + this->AddItem( this->ImageOutlineActor ); +} + // ------------------------------------------------------------------------- void cpExtensions::Visualization::MPRActors:: _SlicesCommand( double* pos, int axis, void* data ) @@ -435,6 +295,14 @@ _WindowLevelCommand( double window, double level, void* data ) MPRActors* actors = reinterpret_cast< MPRActors* >( data ); if( actors == NULL ) return; + + actors->Slices[ 0 ][ 0 ]->SetWindowLevel( window, level ); + actors->Slices[ 0 ][ 1 ]->SetWindowLevel( window, level ); + actors->Slices[ 0 ][ 2 ]->SetWindowLevel( window, level ); + actors->Slices[ 1 ][ 0 ]->SetWindowLevel( window, level ); + actors->Slices[ 1 ][ 1 ]->SetWindowLevel( window, level ); + actors->Slices[ 1 ][ 2 ]->SetWindowLevel( window, level ); + actors->Slices[ 0 ][ 0 ]->Render( 1e-3 ); actors->Slices[ 0 ][ 1 ]->Render( 1e-3 ); actors->Slices[ 0 ][ 2 ]->Render( 1e-3 );