X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpExtensions%2FInteraction%2FImageInteractorStyle.cxx;h=c037193fe97097b0d960316109a6dd0ae477f0aa;hb=1b0022070ff3b5f80f6f8c8b87f73032f5685eaf;hp=d0a313760b8bac6e1c8096b8eed35f85a8b78dda;hpb=fdd4f2cec18107de380ebd350cb1019eed7c294c;p=cpPlugins.git diff --git a/lib/cpExtensions/Interaction/ImageInteractorStyle.cxx b/lib/cpExtensions/Interaction/ImageInteractorStyle.cxx index d0a3137..c037193 100644 --- a/lib/cpExtensions/Interaction/ImageInteractorStyle.cxx +++ b/lib/cpExtensions/Interaction/ImageInteractorStyle.cxx @@ -1,8 +1,42 @@ #include +#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 +57,78 @@ 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 +} + +// ------------------------------------------------------------------------- +void cpExtensions::Interaction::ImageInteractorStyle:: +SetSeedWidgetCommand( vtkCommand* cmd ) +{ + if( cmd == NULL || this->m_SeedWidget == NULL ) + return; + this->m_SeedWidget->Widget-> + AddObserver( vtkCommand::PlacePointEvent, cmd ); +} + +// ------------------------------------------------------------------------- +unsigned int cpExtensions::Interaction::ImageInteractorStyle:: +GetNumberOfSeeds( ) const +{ + if( this->m_SeedWidget != NULL ) + return( this->m_SeedWidget->Representation->GetNumberOfSeeds( ) ); + else + return( 0 ); +} + +// ------------------------------------------------------------------------- +void cpExtensions::Interaction::ImageInteractorStyle:: +GetSeedAsPoint( unsigned int id, double pos[ 3 ] ) const +{ + if( this->m_SeedWidget != NULL ) + this->m_SeedWidget->Representation->GetSeedWorldPosition( id, pos ); +} + +// ------------------------------------------------------------------------- +void cpExtensions::Interaction::ImageInteractorStyle:: +GetSeedAsIndex( unsigned int id, int idx[ 3 ] ) const +{ + /* TODO + if( this->m_SeedWidget != NULL ) + this->m_SeedWidget->Representation->GetSeedWorldPosition( id, pos ); + */ +} + // ------------------------------------------------------------------------- cpExtensions::Interaction::ImageInteractorStyle:: ImageInteractorStyle( ) - : Superclass( ) + : Superclass( ), + m_SeedWidget( NULL ) { this->m_PropPicker = vtkSmartPointer< vtkPropPicker >::New( ); this->m_PropPicker->PickFromListOn( ); @@ -36,6 +138,7 @@ ImageInteractorStyle( ) cpExtensions::Interaction::ImageInteractorStyle:: ~ImageInteractorStyle( ) { + if( this->m_SeedWidget != NULL ) delete this->m_SeedWidget; } // -------------------------------------------------------------------------