]> Creatis software - cpPlugins.git/blob - lib/cpExtensions/Visualization/ImageInteractorStyle.h
Widget integration (step 5/6): Just one step leftgit shortlog !
[cpPlugins.git] / lib / cpExtensions / Visualization / ImageInteractorStyle.h
1 #ifndef __CPEXTENSIONS__VISUALIZATION__IMAGEINTERACTORSTYLE__H__
2 #define __CPEXTENSIONS__VISUALIZATION__IMAGEINTERACTORSTYLE__H__
3
4 #include <cpExtensions/Visualization/BaseInteractorStyle.h>
5
6 #include <vector>
7
8 #include <vtkSmartPointer.h>
9 #include <vtkPropPicker.h>
10
11 /* TODO
12    #include <vtkInteractorStyleImage.h>
13    #include <vtkOrientationMarkerWidget.h>
14
15    #include <cpExtensions/cpExtensions_Export.h>
16
17    // -------------------------------------------------------------------------
18    #define cpPlugins_ImageInteractorStyle_ObserverMacro( e )  \
19    inline unsigned long Add##e##Observer( vtkCommand* observer )        \
20    { return( this->AddObserver( Self::e##Event, observer ) ); }         \
21    inline void Remove##e##Observer( unsigned long tag )                 \
22    { this->RemoveObserver( tag ); }                                     \
23    inline void Remove##e##Observer( vtkCommand* observer )              \
24    { this->RemoveObserver( observer ); }                                \
25    inline void Remove##e##Observers( )                                  \
26    { this->RemoveObservers( Self::e##Event ); }
27 */
28
29 // Forward definitions
30 class vtkImageActor;
31
32 namespace cpExtensions
33 {
34   namespace Visualization
35   {
36     /**
37      */
38     class cpExtensions_EXPORT ImageInteractorStyle
39       : public BaseInteractorStyle
40     {
41     public:
42       typedef ImageInteractorStyle Self;
43       vtkTypeMacro( ImageInteractorStyle, BaseInteractorStyle );
44
45     public:
46       typedef void ( *TMouseCommand )( void*, const ButtonID&, double*, bool, bool, bool );
47       typedef void ( *TMouseWheelCommand )( void*, const int&, bool, bool, bool );
48       typedef void ( *TKeyCommand )( void*, const char& );
49
50       vtkGetMacro( MouseMoveCommand, TMouseCommand );
51       vtkGetMacro( MouseClickCommand, TMouseCommand );
52       vtkGetMacro( MouseDoubleClickCommand, TMouseCommand );
53       vtkGetMacro( MouseWheelCommand, TMouseWheelCommand );
54       vtkGetMacro( KeyCommand, TKeyCommand );
55
56       vtkSetMacro( MouseMoveCommand, TMouseCommand );
57       vtkSetMacro( MouseClickCommand, TMouseCommand );
58       vtkSetMacro( MouseDoubleClickCommand, TMouseCommand );
59       vtkSetMacro( MouseWheelCommand, TMouseWheelCommand );
60       vtkSetMacro( KeyCommand, TKeyCommand );
61
62     public:
63       static Self* New( );
64
65       virtual void AssociateView( void* data );
66       virtual void AssociateImageActor( vtkImageActor* actor );
67       virtual void AssociateInteractor( vtkRenderWindowInteractor* rwi );
68
69       // Possible mouse motion events
70       virtual void OnMouseMove( );
71       virtual void OnMouseWheelForward( );
72       virtual void OnMouseWheelBackward( );
73
74       // Possible mouse click-related events
75       virtual void OnLeftClick( );
76       virtual void OnLeftDoubleClick( );
77       virtual void OnMiddleClick( );
78       virtual void OnMiddleDoubleClick( );
79       virtual void OnRightClick( );
80       virtual void OnRightDoubleClick( );
81
82       // Keyboard-related events
83       virtual void OnChar( );
84
85       // Other events
86       virtual void OnExpose( );
87       virtual void OnConfigure( );
88       virtual void OnEnter( );
89       virtual void OnLeave( );
90
91     protected:
92       ImageInteractorStyle( );
93       virtual ~ImageInteractorStyle( );
94
95       bool _PickPosition( double pos[ 3 ] );
96       void _RenderAssociatedInteractors( );
97
98     private:
99       // Purposely not implemented
100       ImageInteractorStyle( const Self& );
101       Self& operator=( const Self& );
102
103     protected:
104       vtkSmartPointer< vtkPropPicker > PropPicker;
105
106       std::vector< vtkSmartPointer< vtkRenderWindowInteractor > >
107       AssociatedInteractors;
108
109       // Commands
110       void* Data;
111       TMouseCommand      MouseMoveCommand;
112       TMouseCommand      MouseClickCommand;
113       TMouseCommand      MouseDoubleClickCommand;
114       TMouseWheelCommand MouseWheelCommand;
115       TKeyCommand        KeyCommand;
116     };
117
118     /*
119       class ImageSliceActors;
120       class MPRActors;
121     */
122
123     /**
124      */
125     /*
126       class cpExtensions_EXPORT ImageInteractorStyle
127       : public vtkInteractorStyleImage
128       {
129       public:
130       typedef ImageInteractorStyle Self;
131
132       enum InteractionMode
133       {
134       NavigationMode = 0,
135       DeformationMode
136       };
137
138       public:
139       vtkTypeMacro( ImageInteractorStyle, vtkInteractorStyleImage );
140
141       cpPlugins_ImageInteractorStyle_ObserverMacro( DoubleClick );
142       cpPlugins_ImageInteractorStyle_ObserverMacro( Cursor );
143       cpPlugins_ImageInteractorStyle_ObserverMacro( Radius );
144
145       public:
146       static Self* New( );
147
148       void Configure(
149       ImageSliceActors* slice_actors,
150       MPRActors* mpr_actors = NULL
151       );
152       void AssociateInteractor( vtkRenderWindowInteractor* interactor );
153
154       void SetModeToNavigation( );
155       void SetModeToDeformation( );
156       virtual void SetInteractor(
157       vtkRenderWindowInteractor* interactor, const int& axis
158       );
159
160       // Description:
161       // Event bindings controlling the effects of pressing mouse buttons
162       // or moving the mouse.
163       virtual void OnMouseMove( );
164       virtual void OnLeftButtonDown( );
165       virtual void OnLeftButtonUp( );
166       virtual void OnMiddleButtonDown( );
167       virtual void OnMiddleButtonUp( );
168       virtual void OnRightButtonDown( );
169       virtual void OnRightButtonUp( );
170       virtual void OnMouseWheelForward( );
171       virtual void OnMouseWheelBackward( );
172
173       // Description:
174       // Override the "fly-to" (f keypress) for images.
175       virtual void OnChar( );
176
177       // These methods for the different interactions in different modes
178       // are overridden in subclasses to perform the correct motion. Since
179       // they might be called from OnTimer, they do not have mouse coord
180       // parameters (use interactor's GetEventPosition and
181       // GetLastEventPosition)
182
183       virtual void Rotate( ) { }
184       virtual void Spin( )   { }
185       virtual void Zoom( )   { }
186       virtual void Pick( )   { }
187       virtual void Slice( )  { }
188       virtual void WindowLevel( );
189
190       // Interaction mode entry points used internally.
191       virtual void StartPick( )  { }
192       virtual void EndPick( )    { }
193       virtual void StartSlice( ) { }
194       virtual void EndSlice( )   { }
195       virtual void StartWindowLevel( );
196       virtual void EndWindowLevel( );
197
198       // New events
199       virtual void StartCursorMoving( );
200       virtual void EndCursorMoving( );
201       virtual void StartRadiusMoving( );
202       virtual void EndRadiusMoving( );
203
204       protected:
205       ImageInteractorStyle( );
206       virtual ~ImageInteractorStyle( );
207
208       void _RenderAssociateInteractors( );
209       void _UpdateCursor( );
210       void _UpdateRadius( );
211
212       private:
213       // Purposely not implemented
214       ImageInteractorStyle( const Self& );
215       Self& operator=( const Self& );
216
217       protected:
218       Self::InteractionMode Mode;
219
220       ImageSliceActors* m_SliceActors;
221       MPRActors*        m_MPRActors;
222
223       vtkSmartPointer< vtkOrientationMarkerWidget > OrientationWidget;
224
225       std::vector< vtkRenderWindowInteractor* > AssociatedInteractors;
226
227       bool CursorMoving;
228       double Cursor[ 3 ];
229
230       bool RadiusMoving;
231       double Radius[ 3 ];
232       vtkSmartPointer< vtkPolyData > Circle;
233       vtkSmartPointer< vtkPolyDataMapper > CircleMapper;
234       vtkSmartPointer< vtkActor > CircleActor;
235
236       public:
237       static const int CursorEvent;
238       static const int RadiusEvent;
239       static const int DoubleClickEvent;
240       };
241     */
242
243   } // ecapseman
244
245 } // ecapseman
246
247 #endif // __CPEXTENSIONS__VISUALIZATION__IMAGEINTERACTORSTYLE__H__
248
249 // eof - $RCSfile$