From 326eb23859accf9fb1327966eba4dba475b4616f Mon Sep 17 00:00:00 2001 From: Leonardo Florez-Valencia Date: Thu, 29 Oct 2015 18:47:23 -0500 Subject: [PATCH] ... --- appli/examples/example_View2DImage.cxx | 6 ++ .../Interaction/ImageInteractorStyle.cxx | 66 ++++++++++++++++++- .../Interaction/ImageInteractorStyle.h | 46 +++++-------- lib/cpExtensions/Interaction/SeedWidget.cxx | 15 +++-- .../Visualization/ImageSliceActors.cxx | 14 +++- 5 files changed, 110 insertions(+), 37 deletions(-) diff --git a/appli/examples/example_View2DImage.cxx b/appli/examples/example_View2DImage.cxx index 4e7733b..cc8a3e6 100644 --- a/appli/examples/example_View2DImage.cxx +++ b/appli/examples/example_View2DImage.cxx @@ -93,6 +93,12 @@ int main( int argc, char* argv[] ) image_actors->AddInputData( image->GetVTK< vtkImageData >( ), 2 ); image_actors->PushActorsInto( window ); + // Activate seed widget + TSliceActors::TStyle* style = + dynamic_cast< TSliceActors::TStyle* >( image_actors->GetStyle( ) ); + if( style != NULL ) + style->SeedWidgetOn( ); + // Begin interaction renderer->ResetCamera( ); window->Render( ); diff --git a/lib/cpExtensions/Interaction/ImageInteractorStyle.cxx b/lib/cpExtensions/Interaction/ImageInteractorStyle.cxx index d0a3137..bf82ba6 100644 --- a/lib/cpExtensions/Interaction/ImageInteractorStyle.cxx +++ b/lib/cpExtensions/Interaction/ImageInteractorStyle.cxx @@ -1,8 +1,41 @@ #include #include +#include +#include #include +// ------------------------------------------------------------------------- +cpExtensions::Interaction::ImageInteractorStyle::TSeedWidget:: +TSeedWidget( vtkRenderWindowInteractor* interactor, vtkImageActor* actor ) +{ + this->Placer = vtkSmartPointer< vtkImageActorPointPlacer >::New( ); + this->Handle = vtkSmartPointer< vtkPointHandleRepresentation3D >::New( ); + this->Representation = vtkSmartPointer< vtkSeedRepresentation >::New( ); + this->Widget = vtkSmartPointer< SeedWidget >::New( ); + + this->Placer->SetImageActor( actor ); + this->Handle->GetProperty( )->SetColor( 1, 0, 0 ); + this->Handle->SetPointPlacer( this->Placer ); + this->Representation->SetHandleRepresentation( this->Handle ); + this->Widget->SetRepresentation( this->Representation ); + this->Widget->SetInteractor( interactor ); +} + +// ------------------------------------------------------------------------- +void cpExtensions::Interaction::ImageInteractorStyle::TSeedWidget:: +On( ) +{ + this->Widget->On( ); +} + +// ------------------------------------------------------------------------- +void cpExtensions::Interaction::ImageInteractorStyle::TSeedWidget:: +Off( ) +{ + this->Widget->Off( ); +} + // ------------------------------------------------------------------------- cpExtensions::Interaction::ImageInteractorStyle:: Self* cpExtensions::Interaction::ImageInteractorStyle:: @@ -23,10 +56,40 @@ AssociateImageActor( vtkImageActor* actor ) } // fi } +// ------------------------------------------------------------------------- +void cpExtensions::Interaction::ImageInteractorStyle:: +SeedWidgetOn( ) +{ + if( this->m_SeedWidget != NULL ) delete this->m_SeedWidget; + + this->m_PropPicker->GetPickList( )->InitTraversal( ); + this->m_SeedWidget = new TSeedWidget( + this->Interactor, + dynamic_cast< vtkImageActor* >( + this->m_PropPicker->GetPickList( )->GetNextProp( ) + ) + ); + this->m_SeedWidget->On( ); +} + +// ------------------------------------------------------------------------- +void cpExtensions::Interaction::ImageInteractorStyle:: +SeedWidgetOff( ) +{ + if( this->m_SeedWidget != NULL ) + { + this->m_SeedWidget->Off( ); + delete this->m_SeedWidget; + this->m_SeedWidget = NULL; + + } // fi +} + // ------------------------------------------------------------------------- cpExtensions::Interaction::ImageInteractorStyle:: ImageInteractorStyle( ) - : Superclass( ) + : Superclass( ), + m_SeedWidget( NULL ) { this->m_PropPicker = vtkSmartPointer< vtkPropPicker >::New( ); this->m_PropPicker->PickFromListOn( ); @@ -36,6 +99,7 @@ ImageInteractorStyle( ) cpExtensions::Interaction::ImageInteractorStyle:: ~ImageInteractorStyle( ) { + if( this->m_SeedWidget != NULL ) delete this->m_SeedWidget; } // ------------------------------------------------------------------------- diff --git a/lib/cpExtensions/Interaction/ImageInteractorStyle.h b/lib/cpExtensions/Interaction/ImageInteractorStyle.h index 99c0c1f..b63ca90 100644 --- a/lib/cpExtensions/Interaction/ImageInteractorStyle.h +++ b/lib/cpExtensions/Interaction/ImageInteractorStyle.h @@ -44,36 +44,16 @@ namespace cpExtensions // Widgets struct TSeedWidget { - vtkSmartPointer< vtkImageActorPointPlacer > Placer; - vtkSmartPointer< vtkPointHandleRepresentation3D > Handle; - vtkSmartPointer< vtkSeedRepresentation > Representation; - vtkSmartPointer< TSeedWidget > Widget; - - TSeedWidget( vtkRenderWindowInteractor* interactor, vtkImageActor* actor ) - { - this->Placer = vtkSmartPointer< vtkImageActorPointPlacer >::New( ); - this->Handle = vtkSmartPointer< vtkPointHandleRepresentation3D >::New( ); - this->Representation = vtkSmartPointer< vtkSeedRepresentation >::New( ); - this->Widget = vtkSmartPointer< TSeedWidget >::New( ); - - this->Placer->SetImageActor( actor ); - this->Handle->GetProperty( )->SetColor( 1, 0, 0 ); - this->Handle->SetPointPlacer( this->Placer ); - this->Representation->SetHandleRepresentation( this->Handle ); - this->Widget->SetRepresentation( this->Representation ); - this->Widget->SetInteractor( interactor ); - } - - void On( ) - { - this->Widget->On( ); - } - - void Off( ) - { - this->Widget->Off( ); - } -#error ACA VOY + vtkSmartPointer< vtkImageActorPointPlacer > Placer; + vtkSmartPointer< vtkPointHandleRepresentation3D > Handle; + vtkSmartPointer< vtkSeedRepresentation > Representation; + vtkSmartPointer< SeedWidget > Widget; + + TSeedWidget( + vtkRenderWindowInteractor* interactor, vtkImageActor* actor + ); + void On( ); + void Off( ); }; public: @@ -82,6 +62,10 @@ namespace cpExtensions // Data for local picker virtual void AssociateImageActor( vtkImageActor* actor ); + // Widgets + void SeedWidgetOn( ); + void SeedWidgetOff( ); + protected: ImageInteractorStyle( ); virtual ~ImageInteractorStyle( ); @@ -95,6 +79,8 @@ namespace cpExtensions protected: vtkSmartPointer< vtkPropPicker > m_PropPicker; + + TSeedWidget* m_SeedWidget; }; } // ecapseman diff --git a/lib/cpExtensions/Interaction/SeedWidget.cxx b/lib/cpExtensions/Interaction/SeedWidget.cxx index 3460532..73d13a5 100644 --- a/lib/cpExtensions/Interaction/SeedWidget.cxx +++ b/lib/cpExtensions/Interaction/SeedWidget.cxx @@ -20,11 +20,16 @@ void cpExtensions::Interaction::SeedWidget:: SetInteractor( vtkRenderWindowInteractor* rwi ) { this->Superclass::SetInteractor( rwi ); - TBaseStyle* s = dynamic_cast< TBaseStyle*>( rwi->GetInteractorStyle( ) ); - if( s != NULL ) + if( rwi != NULL ) { - s->AddMouseClickCommand( Self::_Click, this ); - s->AddMouseDoubleClickCommand( Self::_DoubleClick, this ); + TBaseStyle* s = + dynamic_cast< TBaseStyle* >( rwi->GetInteractorStyle( ) ); + if( s != NULL ) + { + s->AddMouseClickCommand( Self::_Click, this ); + s->AddMouseDoubleClickCommand( Self::_DoubleClick, this ); + + } // fi } // fi } @@ -55,6 +60,8 @@ _Click( ) { SeedWidget* self = reinterpret_cast< SeedWidget* >( data ); + if( self == NULL ) + return; if( self->WidgetState == vtkSeedWidget::MovingSeed ) return; diff --git a/lib/cpExtensions/Visualization/ImageSliceActors.cxx b/lib/cpExtensions/Visualization/ImageSliceActors.cxx index 450bdb6..0418c37 100644 --- a/lib/cpExtensions/Visualization/ImageSliceActors.cxx +++ b/lib/cpExtensions/Visualization/ImageSliceActors.cxx @@ -318,7 +318,7 @@ PushActorsInto( vtkRenderWindow* window, bool force_style ) } // fi } // fi - renderer->ResetCamera( ); + this->ResetCamera( ); rwi->Render( ); } @@ -839,13 +839,23 @@ SetSliceNumber( const int& slice ) return; // Change visualization extent + int axis = this->GetAxis( ); for( unsigned int i = 0; i < nImages; ++i ) { + // Update mappers and display bounds this->m_SliceMappers[ i ]->SetSliceNumber( slice ); this->m_SliceMappers[ i ]->Modified( ); this->m_ImageActors[ i ]->Modified( ); this->m_SliceMappers[ i ]->Update( ); + // Update display extent (this isn't done automatically) + vtkImageData* image = this->m_SliceMappers[ i ]->GetInput( ); + int ext[ 6 ]; + image->GetExtent( ext ); + ext[ axis << 1 ] = slice; + ext[ ( axis << 1 ) + 1 ] = slice; + this->m_ImageActors[ i ]->SetDisplayExtent( ext ); + } // rof double bnds[ 6 ]; @@ -861,7 +871,6 @@ SetSliceNumber( const int& slice ) plane->GeneralizedProjectPoint( x0[ 0 ], p0[ 0 ] ); plane->GeneralizedProjectPoint( x0[ 1 ], p0[ 1 ] ); - int axis = this->GetAxis( ); bnds[ 0 ] = p0[ 0 ][ 0 ]; bnds[ 1 ] = p0[ 1 ][ 0 ]; bnds[ 2 ] = p0[ 0 ][ 1 ]; @@ -1051,6 +1060,7 @@ ResetCamera( ) this->m_Window->GetRenderers( )->GetFirstRenderer( ); if( renderer != NULL ) renderer->ResetCamera( ); +#error ACA VOY: reconfigurar la camara alrededor únicamente del plano. } // ------------------------------------------------------------------------- -- 2.47.1