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