1 #include <cpPlugins/Extensions/Visualization/SeedWidgetCorrector.h>
3 #include <vtkCellPicker.h>
4 #include <vtkSeedWidget.h>
6 #include <vtkHandleRepresentation.h>
7 #include <vtkHandleWidget.h>
8 #include <vtkRenderWindowInteractor.h>
10 // -------------------------------------------------------------------------
11 cpPlugins::Extensions::Visualization::SeedWidgetCorrector*
12 cpPlugins::Extensions::Visualization::SeedWidgetCorrector::
15 return( new cpPlugins::Extensions::Visualization::SeedWidgetCorrector );
18 // -------------------------------------------------------------------------
19 void cpPlugins::Extensions::Visualization::SeedWidgetCorrector::
20 Configure( vtkCellPicker* picker )
22 this->m_Picker = picker;
25 // -------------------------------------------------------------------------
26 void cpPlugins::Extensions::Visualization::SeedWidgetCorrector::
27 Execute( vtkObject* caller, unsigned long eventId, void* arguments )
29 vtkSeedWidget* wdg = dynamic_cast< vtkSeedWidget* >( caller );
30 if( wdg == NULL || this->m_Picker == NULL )
33 if( eventId == vtkCommand::PlacePointEvent )
35 // Get newly added handle and its associated objects
36 int hId = *( reinterpret_cast< int* >( arguments ) );
37 vtkHandleWidget* hWdg = wdg->GetSeed( hId );
40 vtkHandleRepresentation* hRep =
41 dynamic_cast< vtkHandleRepresentation* >( hWdg->GetRepresentation( ) );
45 // Get clicked point and 3D scene
47 hRep->GetDisplayPosition( p );
48 vtkRenderWindowInteractor* iren = wdg->GetInteractor( );
52 iren->FindPokedRenderer( int( p[ 0 ] ), int( p[ 1 ] ) );
56 // Correct point with given picker
58 this->m_Picker->Pick( p[ 0 ], p[ 1 ], p[ 2 ], ren );
59 this->m_Picker->GetPickPosition( q );
60 hRep->SetWorldPosition( q );
65 // -------------------------------------------------------------------------
66 cpPlugins::Extensions::Visualization::SeedWidgetCorrector::
67 SeedWidgetCorrector( )
73 // -------------------------------------------------------------------------
74 cpPlugins::Extensions::Visualization::SeedWidgetCorrector::
75 ~SeedWidgetCorrector( )