1 #include <cpExtensions/Interaction/ImageInteractorStyle.h>
3 #include <vtkCommand.h>
4 #include <vtkImageActor.h>
5 #include <vtkPropCollection.h>
6 #include <vtkProperty.h>
7 #include <vtkRenderWindowInteractor.h>
9 // -------------------------------------------------------------------------
10 cpExtensions::Interaction::ImageInteractorStyle::TSeedWidget::
11 TSeedWidget( vtkRenderWindowInteractor* interactor, vtkImageActor* actor )
13 this->Placer = vtkSmartPointer< vtkImageActorPointPlacer >::New( );
14 this->Handle = vtkSmartPointer< vtkPointHandleRepresentation3D >::New( );
15 this->Representation = vtkSmartPointer< vtkSeedRepresentation >::New( );
16 this->Widget = vtkSmartPointer< SeedWidget >::New( );
18 this->Placer->SetImageActor( actor );
19 this->Handle->GetProperty( )->SetColor( 1, 0, 0 );
20 this->Handle->SetPointPlacer( this->Placer );
21 this->Representation->SetHandleRepresentation( this->Handle );
22 this->Widget->SetRepresentation( this->Representation );
23 this->Widget->SetInteractor( interactor );
26 // -------------------------------------------------------------------------
27 void cpExtensions::Interaction::ImageInteractorStyle::TSeedWidget::
33 // -------------------------------------------------------------------------
34 void cpExtensions::Interaction::ImageInteractorStyle::TSeedWidget::
40 // -------------------------------------------------------------------------
41 cpExtensions::Interaction::ImageInteractorStyle::
42 Self* cpExtensions::Interaction::ImageInteractorStyle::
48 // -------------------------------------------------------------------------
49 void cpExtensions::Interaction::ImageInteractorStyle::
50 AssociateImageActor( vtkImageActor* actor )
54 this->m_PropPicker->AddPickList( actor );
60 // -------------------------------------------------------------------------
61 void cpExtensions::Interaction::ImageInteractorStyle::
64 if( this->m_SeedWidget != NULL ) delete this->m_SeedWidget;
66 this->m_PropPicker->GetPickList( )->InitTraversal( );
67 this->m_SeedWidget = new TSeedWidget(
69 dynamic_cast< vtkImageActor* >(
70 this->m_PropPicker->GetPickList( )->GetNextProp( )
73 this->m_SeedWidget->On( );
76 // -------------------------------------------------------------------------
77 void cpExtensions::Interaction::ImageInteractorStyle::
80 if( this->m_SeedWidget != NULL )
82 this->m_SeedWidget->Off( );
83 delete this->m_SeedWidget;
84 this->m_SeedWidget = NULL;
89 // -------------------------------------------------------------------------
90 void cpExtensions::Interaction::ImageInteractorStyle::
91 SetSeedWidgetCommand( vtkCommand* cmd )
93 if( cmd == NULL || this->m_SeedWidget == NULL )
95 this->m_SeedWidget->Widget->
96 AddObserver( vtkCommand::PlacePointEvent, cmd );
99 // -------------------------------------------------------------------------
100 unsigned int cpExtensions::Interaction::ImageInteractorStyle::
101 GetNumberOfSeeds( ) const
103 if( this->m_SeedWidget != NULL )
104 return( this->m_SeedWidget->Representation->GetNumberOfSeeds( ) );
109 // -------------------------------------------------------------------------
110 void cpExtensions::Interaction::ImageInteractorStyle::
111 GetSeedAsPoint( unsigned int id, double pos[ 3 ] ) const
113 if( this->m_SeedWidget != NULL )
114 this->m_SeedWidget->Representation->GetSeedWorldPosition( id, pos );
117 // -------------------------------------------------------------------------
118 void cpExtensions::Interaction::ImageInteractorStyle::
119 GetSeedAsIndex( unsigned int id, int idx[ 3 ] ) const
122 if( this->m_SeedWidget != NULL )
123 this->m_SeedWidget->Representation->GetSeedWorldPosition( id, pos );
127 // -------------------------------------------------------------------------
128 cpExtensions::Interaction::ImageInteractorStyle::
129 ImageInteractorStyle( )
133 this->m_PropPicker = vtkSmartPointer< vtkPropPicker >::New( );
134 this->m_PropPicker->PickFromListOn( );
137 // -------------------------------------------------------------------------
138 cpExtensions::Interaction::ImageInteractorStyle::
139 ~ImageInteractorStyle( )
141 if( this->m_SeedWidget != NULL ) delete this->m_SeedWidget;
144 // -------------------------------------------------------------------------
145 bool cpExtensions::Interaction::ImageInteractorStyle::
146 _PickPosition( int idx[ 2 ], double pos[ 3 ] )
148 vtkRenderWindowInteractor* rwi = this->GetInteractor( );
152 // Find the renderer where the event has been raised
153 idx[ 0 ] = rwi->GetEventPosition( )[ 0 ];
154 idx[ 1 ] = rwi->GetEventPosition( )[ 1 ];
155 this->FindPokedRenderer( double( idx[ 0 ] ), double( idx[ 1 ] ) );
157 // Pick a 3D position
158 int r = this->m_PropPicker->Pick(
159 double( idx[ 0 ] ), double( idx[ 1 ] ), double( 0 ),
160 this->CurrentRenderer
164 this->m_PropPicker->GetPickPosition( pos );