]> Creatis software - cpPlugins.git/blob - lib/cpExtensions/Visualization/SeedWidgetCorrector.cxx
f76cc9f41c66ca5bc21f2b61fbad7b85773fdd83
[cpPlugins.git] / lib / cpExtensions / Visualization / SeedWidgetCorrector.cxx
1 #include <cpExtensions/Visualization/SeedWidgetCorrector.h>
2
3 #include <vtkCellPicker.h>
4 #include <vtkSeedWidget.h>
5
6 #include <vtkHandleRepresentation.h>
7 #include <vtkHandleWidget.h>
8 #include <vtkRenderWindowInteractor.h>
9
10 // -------------------------------------------------------------------------
11 cpExtensions::Visualization::SeedWidgetCorrector*
12 cpExtensions::Visualization::SeedWidgetCorrector::
13 New( )
14 {
15   return( new cpExtensions::Visualization::SeedWidgetCorrector );
16 }
17
18 // -------------------------------------------------------------------------
19 void cpExtensions::Visualization::SeedWidgetCorrector::
20 Configure( vtkCellPicker* picker )
21 {
22   this->m_Picker = picker;
23 }
24
25 // -------------------------------------------------------------------------
26 void cpExtensions::Visualization::SeedWidgetCorrector::
27 Execute( vtkObject* caller, unsigned long eventId, void* arguments )
28 {
29   vtkSeedWidget* wdg = dynamic_cast< vtkSeedWidget* >( caller );
30   if( wdg == NULL || this->m_Picker == NULL )
31     return;
32
33   if( eventId == vtkCommand::PlacePointEvent )
34   {
35     // Get newly added handle and its associated objects
36     int hId = *( reinterpret_cast< int* >( arguments ) );
37     vtkHandleWidget* hWdg = wdg->GetSeed( hId );
38     if( hWdg == NULL )
39       return;
40     vtkHandleRepresentation* hRep =
41       dynamic_cast< vtkHandleRepresentation* >( hWdg->GetRepresentation( ) );
42     if( hRep == NULL )
43       return;
44
45     // Get clicked point and 3D scene
46     double p[ 3 ];
47     hRep->GetDisplayPosition( p );
48     vtkRenderWindowInteractor* iren = wdg->GetInteractor( );
49     if( iren == NULL )
50       return;
51     vtkRenderer* ren =
52       iren->FindPokedRenderer( int( p[ 0 ] ), int( p[ 1 ] ) );
53     if( ren == NULL )
54       return;
55
56     // Correct point with given picker
57     double q[ 3 ];
58     this->m_Picker->Pick( p[ 0 ], p[ 1 ], p[ 2 ], ren );
59     this->m_Picker->GetPickPosition( q );
60     hRep->SetWorldPosition( q );
61
62   } // fi
63 }
64
65 // -------------------------------------------------------------------------
66 cpExtensions::Visualization::SeedWidgetCorrector::
67 SeedWidgetCorrector( )
68   : vtkCommand( ),
69     m_Picker( NULL )
70 {
71 }
72
73 // -------------------------------------------------------------------------
74 cpExtensions::Visualization::SeedWidgetCorrector::
75 ~SeedWidgetCorrector( )
76 {
77 }
78
79 // eof - $RCSfile$