]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Extensions/Visualization/ImageInteractorStyle.h
Updated to work on Windows
[cpPlugins.git] / lib / cpPlugins / Extensions / Visualization / ImageInteractorStyle.h
1 #ifndef __CPPLUGINS__EXTENSIONS__VISUALIZATION__IMAGEINTERACTORSTYLE__H__
2 #define __CPPLUGINS__EXTENSIONS__VISUALIZATION__IMAGEINTERACTORSTYLE__H__
3
4 #include <vector>
5
6 #include <vtkInteractorStyleImage.h>
7 #include <vtkOrientationMarkerWidget.h>
8 #include <vtkPropPicker.h>
9 #include <vtkSmartPointer.h>
10
11 #include <cpPlugins/Extensions/cpPlugins_Extensions_Export.h>
12
13 /* TODO
14    #include <vtkInteractorStyleImage.h>
15    #include <vtkLineWidget2.h>
16    #include <vtkLineRepresentation.h>
17    #include <vtkPlane.h>
18    class vtkImageData;
19 */
20
21 // -------------------------------------------------------------------------
22 #define cpPlugins_ImageInteractorStyle_ObserverMacro( e )               \
23   inline unsigned long Add##e##Observer( vtkCommand* observer )         \
24   { return( this->AddObserver( Self::e##Event, observer ) ); }          \
25   inline void Remove##e##Observer( unsigned long tag )                  \
26   { this->RemoveObserver( tag ); }                                      \
27   inline void Remove##e##Observer( vtkCommand* observer )               \
28   { this->RemoveObserver( observer ); }                                 \
29   inline void Remove##e##Observers( )                                   \
30   { this->RemoveObservers( Self::e##Event ); }
31
32 namespace cpPlugins
33 {
34   namespace Extensions
35   {
36     namespace Visualization
37     {
38       class ImageSliceActors;
39       class MPRActors;
40
41       /**
42        */
43       class cpPlugins_Extensions_EXPORT ImageInteractorStyle
44         : public vtkInteractorStyleImage
45       {
46       public:
47         typedef ImageInteractorStyle Self;
48
49         enum InteractionMode
50         {
51           NavigationMode = 0,
52           DeformationMode
53         };
54
55       public:
56         vtkTypeMacro( ImageInteractorStyle, vtkInteractorStyleImage );
57
58         cpPlugins_ImageInteractorStyle_ObserverMacro( DoubleClick );
59         cpPlugins_ImageInteractorStyle_ObserverMacro( Cursor );
60         cpPlugins_ImageInteractorStyle_ObserverMacro( Radius );
61
62       public:
63         static Self* New( );
64
65         void Configure(
66           ImageSliceActors* slice_actors,
67           MPRActors* mpr_actors = NULL
68           );
69         void AssociateInteractor( vtkRenderWindowInteractor* interactor );
70
71         void SetModeToNavigation( );
72         void SetModeToDeformation( );
73         virtual void SetInteractor(
74           vtkRenderWindowInteractor* interactor, const int& axis
75           );
76
77         // Description:
78         // Event bindings controlling the effects of pressing mouse buttons
79         // or moving the mouse.
80         virtual void OnMouseMove( );
81         virtual void OnLeftButtonDown( );
82         virtual void OnLeftButtonUp( );
83         virtual void OnMiddleButtonDown( );
84         virtual void OnMiddleButtonUp( );
85         virtual void OnRightButtonDown( );
86         virtual void OnRightButtonUp( );
87         virtual void OnMouseWheelForward( );
88         virtual void OnMouseWheelBackward( );
89
90         // Description:
91         // Override the "fly-to" (f keypress) for images.
92         virtual void OnChar( );
93
94         // These methods for the different interactions in different modes
95         // are overridden in subclasses to perform the correct motion. Since
96         // they might be called from OnTimer, they do not have mouse coord
97         // parameters (use interactor's GetEventPosition and
98         // GetLastEventPosition)
99
100         virtual void Rotate( ) { }
101         virtual void Spin( )   { }
102         virtual void Zoom( )   { }
103         virtual void Pick( )   { }
104         virtual void Slice( )  { }
105         virtual void WindowLevel( );
106
107         // Interaction mode entry points used internally.
108         virtual void StartPick( )  { }
109         virtual void EndPick( )    { }
110         virtual void StartSlice( ) { }
111         virtual void EndSlice( )   { }
112         virtual void StartWindowLevel( );
113         virtual void EndWindowLevel( );
114
115         // New events
116         virtual void StartCursorMoving( );
117         virtual void EndCursorMoving( );
118         virtual void StartRadiusMoving( );
119         virtual void EndRadiusMoving( );
120
121       protected:
122         ImageInteractorStyle( );
123         virtual ~ImageInteractorStyle( );
124
125         void _RenderAssociateInteractors( );
126         bool _PickPosition( double pos[ 3 ] );
127         void _UpdateCursor( );
128         void _UpdateRadius( );
129
130       private:
131         // Purposely not implemented
132         ImageInteractorStyle( const Self& );
133         Self& operator=( const Self& );
134
135       protected:
136         Self::InteractionMode Mode;
137
138         ImageSliceActors* m_SliceActors;
139         MPRActors*        m_MPRActors;
140
141         vtkSmartPointer< vtkOrientationMarkerWidget > OrientationWidget;
142         vtkSmartPointer< vtkPropPicker > PropPicker;
143
144         std::vector< vtkRenderWindowInteractor* > AssociatedInteractors;
145
146         bool CursorMoving;
147         double Cursor[ 3 ];
148
149         bool RadiusMoving;
150         double Radius[ 3 ];
151         vtkSmartPointer< vtkPolyData > Circle;
152         vtkSmartPointer< vtkPolyDataMapper > CircleMapper;
153         vtkSmartPointer< vtkActor > CircleActor;
154
155       public:
156         static const int CursorEvent;
157         static const int RadiusEvent;
158         static const int DoubleClickEvent;
159       };
160
161     } // ecapseman
162
163   } // ecapseman
164
165 } // ecapseman
166
167 #endif // __CPPLUGINS__EXTENSIONS__VISUALIZATION__IMAGEINTERACTORSTYLE__H__
168
169 // eof - $RCSfile$