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