1 #include <cpExtensions/Interaction/ImageInteractorStyle.h>
3 #include <vtkImageActor.h>
4 #include <vtkPropCollection.h>
5 #include <vtkProperty.h>
6 #include <vtkRenderWindowInteractor.h>
8 // -------------------------------------------------------------------------
9 cpExtensions::Interaction::ImageInteractorStyle::TSeedWidget::
10 TSeedWidget( vtkRenderWindowInteractor* interactor, vtkImageActor* actor )
12 this->Placer = vtkSmartPointer< vtkImageActorPointPlacer >::New( );
13 this->Handle = vtkSmartPointer< vtkPointHandleRepresentation3D >::New( );
14 this->Representation = vtkSmartPointer< vtkSeedRepresentation >::New( );
15 this->Widget = vtkSmartPointer< SeedWidget >::New( );
17 this->Placer->SetImageActor( actor );
18 this->Handle->GetProperty( )->SetColor( 1, 0, 0 );
19 this->Handle->SetPointPlacer( this->Placer );
20 this->Representation->SetHandleRepresentation( this->Handle );
21 this->Widget->SetRepresentation( this->Representation );
22 this->Widget->SetInteractor( interactor );
25 // -------------------------------------------------------------------------
26 void cpExtensions::Interaction::ImageInteractorStyle::TSeedWidget::
32 // -------------------------------------------------------------------------
33 void cpExtensions::Interaction::ImageInteractorStyle::TSeedWidget::
39 // -------------------------------------------------------------------------
40 cpExtensions::Interaction::ImageInteractorStyle::
41 Self* cpExtensions::Interaction::ImageInteractorStyle::
47 // -------------------------------------------------------------------------
48 void cpExtensions::Interaction::ImageInteractorStyle::
49 AssociateImageActor( vtkImageActor* actor )
53 this->m_PropPicker->AddPickList( actor );
59 // -------------------------------------------------------------------------
60 void cpExtensions::Interaction::ImageInteractorStyle::
63 if( this->m_SeedWidget != NULL ) delete this->m_SeedWidget;
65 this->m_PropPicker->GetPickList( )->InitTraversal( );
66 this->m_SeedWidget = new TSeedWidget(
68 dynamic_cast< vtkImageActor* >(
69 this->m_PropPicker->GetPickList( )->GetNextProp( )
72 this->m_SeedWidget->On( );
75 // -------------------------------------------------------------------------
76 void cpExtensions::Interaction::ImageInteractorStyle::
79 if( this->m_SeedWidget != NULL )
81 this->m_SeedWidget->Off( );
82 delete this->m_SeedWidget;
83 this->m_SeedWidget = NULL;
88 // -------------------------------------------------------------------------
89 cpExtensions::Interaction::ImageInteractorStyle::
90 ImageInteractorStyle( )
94 this->m_PropPicker = vtkSmartPointer< vtkPropPicker >::New( );
95 this->m_PropPicker->PickFromListOn( );
98 // -------------------------------------------------------------------------
99 cpExtensions::Interaction::ImageInteractorStyle::
100 ~ImageInteractorStyle( )
102 if( this->m_SeedWidget != NULL ) delete this->m_SeedWidget;
105 // -------------------------------------------------------------------------
106 bool cpExtensions::Interaction::ImageInteractorStyle::
107 _PickPosition( int idx[ 2 ], double pos[ 3 ] )
109 vtkRenderWindowInteractor* rwi = this->GetInteractor( );
113 // Find the renderer where the event has been raised
114 idx[ 0 ] = rwi->GetEventPosition( )[ 0 ];
115 idx[ 1 ] = rwi->GetEventPosition( )[ 1 ];
116 this->FindPokedRenderer( double( idx[ 0 ] ), double( idx[ 1 ] ) );
118 // Pick a 3D position
119 int r = this->m_PropPicker->Pick(
120 double( idx[ 0 ] ), double( idx[ 1 ] ), double( 0 ),
121 this->CurrentRenderer
125 this->m_PropPicker->GetPickPosition( pos );