From 00b54bc0344d74f31df8b93f7c28a07cfc8d6873 Mon Sep 17 00:00:00 2001 From: Leonardo Florez-Valencia Date: Fri, 20 Nov 2015 18:24:14 -0500 Subject: [PATCH] MPR finished --- appli/ImageMPR/ImageMPR.cxx | 1 + .../Visualization/ImageSliceActors.cxx | 59 ++++++------ .../Visualization/ImageSliceActors.h | 7 +- lib/cpExtensions/Visualization/MPRActors.cxx | 93 ++++++++++++++++--- lib/cpExtensions/Visualization/MPRActors.h | 6 ++ lib/cpExtensions/Visualization/MPRObjects.cxx | 18 ++++ lib/cpExtensions/Visualization/MPRObjects.h | 2 + lib/cpPlugins/Interface/BaseMPRWidget.cxx | 7 +- 8 files changed, 146 insertions(+), 47 deletions(-) diff --git a/appli/ImageMPR/ImageMPR.cxx b/appli/ImageMPR/ImageMPR.cxx index c18fcd2..5a9e414 100644 --- a/appli/ImageMPR/ImageMPR.cxx +++ b/appli/ImageMPR/ImageMPR.cxx @@ -173,6 +173,7 @@ _AssociatePluginsToMenu( ) return; \ TImage* image = this->m_Plugins.GetData< TImage >( name ); \ this->m_UI->MPR->AddData( image, name, "" ); \ + this->m_UI->MPR->SetMainImage( name ); \ this->m_UI->MPR->ShowData( name ); \ } \ catch( std::exception& err ) \ diff --git a/lib/cpExtensions/Visualization/ImageSliceActors.cxx b/lib/cpExtensions/Visualization/ImageSliceActors.cxx index 1c032d2..0081175 100644 --- a/lib/cpExtensions/Visualization/ImageSliceActors.cxx +++ b/lib/cpExtensions/Visualization/ImageSliceActors.cxx @@ -129,9 +129,6 @@ Clear( ) this->m_BlenderActor->GetProperty( )->SetLookupTable( this->m_BlenderLUT ); this->m_BlenderActor->GetProperty( )->UseLookupTableScalarRangeOn( ); - // Remove associated objects - this->m_AssociatedSlices.clear( ); - // White cursor vtkSmartPointer< vtkPoints > cursor_points = vtkSmartPointer< vtkPoints >::New( ); @@ -1016,26 +1013,9 @@ UpdateText( const double& w, const double& l ) this->Modified( ); } -// ------------------------------------------------------------------------- -cpExtensions::Visualization::ImageSliceActors:: -ImageSliceActors( ) - : Superclass( ), - m_Window( NULL ), - m_Interpolate( false ) -{ - this->Clear( ); - this->_ConfigureStyle( ); -} - -// ------------------------------------------------------------------------- -cpExtensions::Visualization::ImageSliceActors:: -~ImageSliceActors( ) -{ -} - // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageSliceActors:: -_Render( ) +Render( ) { if( this->m_Window == NULL ) return; @@ -1049,7 +1029,7 @@ _Render( ) // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageSliceActors:: -_ResetCamera( ) +ResetCamera( ) { if( this->m_Window == NULL ) return; @@ -1060,6 +1040,23 @@ _ResetCamera( ) renderer->ResetCamera( ); } +// ------------------------------------------------------------------------- +cpExtensions::Visualization::ImageSliceActors:: +ImageSliceActors( ) + : Superclass( ), + m_Window( NULL ), + m_Interpolate( false ) +{ + this->Clear( ); + this->_ConfigureStyle( ); +} + +// ------------------------------------------------------------------------- +cpExtensions::Visualization::ImageSliceActors:: +~ImageSliceActors( ) +{ +} + // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageSliceActors:: _ConfigureStyle( ) @@ -1156,7 +1153,7 @@ _MouseMoveCommand( // Just show the pixel information actors->SetCursor( pos ); actors->UpdateText( pos ); - actors->_Render( ); + actors->Render( ); } else if( btn == TStyle::ButtonID_Left ) { @@ -1164,7 +1161,7 @@ _MouseMoveCommand( { // Show axes in current renderer actors->SetAxesCursor( pos ); - actors->_Render( ); + actors->Render( ); // Interactively move slices auto i = actors->m_SlicesCommands.begin( ); @@ -1194,7 +1191,7 @@ _MouseMoveCommand( dx += actors->m_StartWindowLevel[ 0 ]; dy += actors->m_StartWindowLevel[ 1 ]; actors->SetWindowLevel( dx, dy ); - actors->_Render( ); + actors->Render( ); // Associate objects auto i = actors->m_WindowLevelCommands.begin( ); @@ -1243,7 +1240,7 @@ _MouseWheelCommand( if( slice > actors->GetSliceNumberMaxValue( ) ) slice = actors->GetSliceNumberMaxValue( ); actors->SetSliceNumber( slice ); - actors->_Render( ); + actors->Render( ); auto a = actors->m_AssociatedSlices.begin( ); for( ; a != actors->m_AssociatedSlices.end( ); ++a ) @@ -1269,8 +1266,8 @@ _KeyCommand( void* data, const char& key ) { case 'r': case 'R': { - actors->_ResetCamera( ); - actors->_Render( ); + actors->ResetCamera( ); + actors->Render( ); // Associate objects auto i = actors->m_RenderCommands.begin( ); @@ -1281,7 +1278,7 @@ _KeyCommand( void* data, const char& key ) case 'w': case 'W': { actors->ResetWindowLevel( ); - actors->_Render( ); + actors->Render( ); // Associate objects auto i = actors->m_RenderCommands.begin( ); @@ -1304,7 +1301,7 @@ _EnterCommand( void* data ) actors->ResetCursor( ); actors->m_CursorActor->VisibilityOn( ); - actors->_Render( ); + actors->Render( ); } // ------------------------------------------------------------------------- @@ -1317,7 +1314,7 @@ _LeaveCommand( void* data ) actors->ResetCursor( ); actors->m_CursorActor->VisibilityOff( ); - actors->_Render( ); + actors->Render( ); } // eof - $RCSfile$ diff --git a/lib/cpExtensions/Visualization/ImageSliceActors.h b/lib/cpExtensions/Visualization/ImageSliceActors.h index 396d2ae..81fc0e1 100644 --- a/lib/cpExtensions/Visualization/ImageSliceActors.h +++ b/lib/cpExtensions/Visualization/ImageSliceActors.h @@ -51,6 +51,7 @@ namespace cpExtensions typedef void ( *TSlicesCommand )( double*, int, void* ); typedef void ( *TWindowLevelCommand )( double, double, void* ); typedef TVoidCommand TRenderCommand; + typedef TSlicesCommand TCursorAxesCommand; typedef cpExtensions::Visualization::ImageBlender TBlender; @@ -60,6 +61,7 @@ namespace cpExtensions cpExtensions_BaseInteractorStyle_Commands( Slices ); cpExtensions_BaseInteractorStyle_Commands( WindowLevel ); cpExtensions_BaseInteractorStyle_Commands( Render ); + cpExtensions_BaseInteractorStyle_Commands( CursorAxes ); public: // Creation @@ -135,12 +137,13 @@ namespace cpExtensions void UpdateText( double pos[ 3 ] ); void UpdateText( const double& w, const double& l ); + void Render( ); + void ResetCamera( ); + protected: ImageSliceActors( ); virtual ~ImageSliceActors( ); - void _Render( ); - void _ResetCamera( ); void _ConfigureStyle( ); void _ConfigureInputImage( ); void _ConfigureBinaryImage( diff --git a/lib/cpExtensions/Visualization/MPRActors.cxx b/lib/cpExtensions/Visualization/MPRActors.cxx index 25151ab..47f1251 100644 --- a/lib/cpExtensions/Visualization/MPRActors.cxx +++ b/lib/cpExtensions/Visualization/MPRActors.cxx @@ -31,24 +31,34 @@ GetSliceActors( const int& i ) const void cpExtensions::Visualization::MPRActors:: SetInputConnection( vtkAlgorithmOutput* aout ) { - this->Slices[ 0 ][ 0 ]->SetInputConnection( aout ); - this->Slices[ 0 ][ 1 ]->SetInputConnection( aout ); - this->Slices[ 0 ][ 2 ]->SetInputConnection( aout ); - this->Slices[ 1 ][ 0 ]->SetInputConnection( aout ); - this->Slices[ 1 ][ 1 ]->SetInputConnection( aout ); - this->Slices[ 1 ][ 2 ]->SetInputConnection( aout ); + for( int i = 0; i < 2; ++i ) + { + for( int j = 0; j < 3; ++j ) + { + this->Slices[ i ][ j ]->SetInputConnection( aout ); + this->Slices[ i ][ j ]->SetAxis( j ); + + } // rof + + } // rof + this->_CreateBoundingBox( ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::MPRActors:: SetInputImage( vtkImageData* data ) { - this->Slices[ 0 ][ 0 ]->SetInputImage( data ); - this->Slices[ 0 ][ 1 ]->SetInputImage( data ); - this->Slices[ 0 ][ 2 ]->SetInputImage( data ); - this->Slices[ 1 ][ 0 ]->SetInputImage( data ); - this->Slices[ 1 ][ 1 ]->SetInputImage( data ); - this->Slices[ 1 ][ 2 ]->SetInputImage( data ); + for( int i = 0; i < 2; ++i ) + { + for( int j = 0; j < 3; ++j ) + { + this->Slices[ i ][ j ]->SetInputImage( data ); + this->Slices[ i ][ j ]->SetAxis( j ); + + } // rof + + } // rof + this->_CreateBoundingBox( ); } // ------------------------------------------------------------------------- @@ -159,7 +169,13 @@ PushActorsInto( 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( ) ); + + } // fi } // ------------------------------------------------------------------------- @@ -181,7 +197,13 @@ PopActorsFrom( 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( ) ); + + } // fi } // ------------------------------------------------------------------------- @@ -328,6 +350,44 @@ SetSlice( const int& axis, double* pos ) } // fi } +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::MPRActors:: +Render( const int& axis ) +{ + if( axis < 3 ) + { + this->Slices[ 0 ][ axis ]->Render( ); + this->Slices[ 1 ][ axis ]->Render( ); + + } // fi +} + +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::MPRActors:: +Render( ) +{ + this->Render( 0 ); + this->Render( 1 ); + this->Render( 2 ); +} + +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::MPRActors:: +ResetCamera( const int& axis ) +{ + if( axis < 3 ) + this->Slices[ 0 ][ axis ]->ResetCamera( ); +} + +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::MPRActors:: +ResetCameras( ) +{ + this->ResetCamera( 0 ); + this->ResetCamera( 1 ); + this->ResetCamera( 2 ); +} + // ------------------------------------------------------------------------- cpExtensions::Visualization::MPRActors:: MPRActors( ) @@ -396,8 +456,15 @@ _SlicesCommand( double* pos, int axis, void* data ) if( actors == NULL ) return; for( unsigned int j = 0; j < 3; ++j ) + { if( actors->Slices[ 0 ][ j ]->GetAxis( ) != axis ) + { actors->SetSlice( j, pos ); + actors->Render( j ); + + } // fi + + } // rof } // ------------------------------------------------------------------------- @@ -408,6 +475,7 @@ _WindowLevelCommand( double window, double level, void* data ) if( actors == NULL ) return; actors->SetWindowLevel( window, level ); + actors->Render( ); } // ------------------------------------------------------------------------- @@ -417,6 +485,7 @@ _RenderCommand( void* data ) MPRActors* actors = reinterpret_cast< MPRActors* >( data ); if( actors == NULL ) return; + actors->Render( ); } // eof - $RCSfile$ diff --git a/lib/cpExtensions/Visualization/MPRActors.h b/lib/cpExtensions/Visualization/MPRActors.h index 34f373c..e4d7bf6 100644 --- a/lib/cpExtensions/Visualization/MPRActors.h +++ b/lib/cpExtensions/Visualization/MPRActors.h @@ -90,6 +90,12 @@ namespace cpExtensions void SetSliceNumber( const int& axis, const int& slice ); void SetSlice( const int& axis, double* pos ); + // Rendering controls + void Render( const int& axis ); + void Render( ); + void ResetCamera( const int& axis ); + void ResetCameras( ); + protected: MPRActors( ); virtual ~MPRActors( ); diff --git a/lib/cpExtensions/Visualization/MPRObjects.cxx b/lib/cpExtensions/Visualization/MPRObjects.cxx index ccc3dc4..0727f22 100644 --- a/lib/cpExtensions/Visualization/MPRObjects.cxx +++ b/lib/cpExtensions/Visualization/MPRObjects.cxx @@ -74,6 +74,24 @@ AddBinaryImage( return( this->m_MPRActors->AddBinaryImage( data, r, g, b ) ); } +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::MPRObjects:: +Show( ) +{ + this->m_MPRActors->PushActorsInto( + this->m_Windows[ 0 ], + this->m_Windows[ 1 ], + this->m_Windows[ 2 ], + this->m_Windows[ 3 ] + ); +} + +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::MPRObjects:: +Hide( ) +{ +} + // ------------------------------------------------------------------------- void cpExtensions::Visualization::MPRObjects:: Clear( ) diff --git a/lib/cpExtensions/Visualization/MPRObjects.h b/lib/cpExtensions/Visualization/MPRObjects.h index a1ed436..c800fc1 100644 --- a/lib/cpExtensions/Visualization/MPRObjects.h +++ b/lib/cpExtensions/Visualization/MPRObjects.h @@ -76,6 +76,8 @@ namespace cpExtensions vtkImageData* data, const double& r, const double& g, const double& b ); + void Show( ); + void Hide( ); void Clear( ); vtkImageData* GetInputImage( ); diff --git a/lib/cpPlugins/Interface/BaseMPRWidget.cxx b/lib/cpPlugins/Interface/BaseMPRWidget.cxx index ee6e586..b84d75c 100644 --- a/lib/cpPlugins/Interface/BaseMPRWidget.cxx +++ b/lib/cpPlugins/Interface/BaseMPRWidget.cxx @@ -180,8 +180,11 @@ ShowData( const std::string& name ) if( iIt->second.Tag == Data::IMAGE ) { - // TODO: this->m_MPRObjects->AddImage( iIt->second.Image ); -#error ACA VOY + if( name == this->m_MainImage ) + this->m_MPRObjects->SetInputImage( iIt->second.Image ); + else + this->m_MPRObjects->AddBinaryImage( iIt->second.Image, 1, 0, 0 ); + this->m_MPRObjects->Show( ); } else if( iIt->second.Tag == Data::MESH ) { -- 2.47.1