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