]> Creatis software - cpPlugins.git/blob - lib/cpExtensions/Visualization/ImageSliceActors.h
Merge ssh://git.creatis.insa-lyon.fr/cpPlugins
[cpPlugins.git] / lib / cpExtensions / Visualization / ImageSliceActors.h
1 #ifndef __CPEXTENSIONS__VISUALIZATION__IMAGESLICEACTORS__H__
2 #define __CPEXTENSIONS__VISUALIZATION__IMAGESLICEACTORS__H__
3
4 #include <cpExtensions/cpExtensions_Export.h>
5
6 #include <vtkSmartPointer.h>
7 #include <vtkActor.h>
8 #include <vtkImageActor.h>
9 #include <vtkImageSliceMapper.h>
10 #include <vtkPlane.h>
11 #include <vtkPolyData.h>
12 #include <vtkPolyDataMapper.h>
13 #include <vtkPropCollection.h>
14 #include <vtkTextActor.h>
15
16 #include <cpExtensions/Interaction/ImageInteractorStyle.h>
17
18 // -------------------------------------------------------------------------
19 class vtkAlgorithmOutput;
20 class vtkImageData;
21 class vtkLookupTable;
22 class vtkRenderer;
23
24 // -------------------------------------------------------------------------
25 namespace cpExtensions
26 {
27   namespace Visualization
28   {
29     /**
30      */
31     class cpExtensions_EXPORT ImageSliceActors
32       : public vtkPropCollection
33     {
34     public:
35       typedef ImageSliceActors Self;
36
37       typedef cpExtensions::Interaction::ImageInteractorStyle TStyle;
38       typedef TStyle::TMouseCommand            TMouseCommand;
39       typedef TStyle::TMouseWheelCommand       TMouseWheelCommand;
40       typedef TStyle::TKeyCommand              TKeyCommand;
41       typedef TStyle::TVoidCommand             TVoidCommand;
42       typedef TStyle::TMouseMoveCommand        TMouseMoveCommand;
43       typedef TStyle::TMouseClickCommand       TMouseClickCommand;
44       typedef TStyle::TMouseDoubleClickCommand TMouseDoubleClickCommand;
45       typedef TStyle::TExposeCommand           TExposeCommand;
46       typedef TStyle::TConfigureCommand        TConfigureCommand;
47       typedef TStyle::TEnterCommand            TEnterCommand;
48       typedef TStyle::TLeaveCommand            TLeaveCommand;
49       typedef void ( *TSlicesCommand )( double*, int, void* );
50       typedef void ( *TWindowLevelCommand )( double, double, void* );
51       typedef TVoidCommand TRenderCommand;
52
53     public:
54       vtkTypeMacro( ImageSliceActors, vtkPropCollection );
55
56       cpExtensions_BaseInteractorStyle_Commands( Slices );
57       cpExtensions_BaseInteractorStyle_Commands( WindowLevel );
58       cpExtensions_BaseInteractorStyle_Commands( Render );
59
60     public:
61       // Creation
62       static ImageSliceActors* New( );
63
64       void SetAxis( int axis );
65       void AddInputConnection( vtkAlgorithmOutput* aout );
66       void AddInputData( vtkImageData* data );
67       void Clear( );
68
69       void AssociateSlice( Self* slice );
70
71       vtkImageData* GetInputImage( );
72       const vtkImageData* GetInputImage( ) const;
73
74       vtkInteractorStyle* GetStyle( );
75       const vtkInteractorStyle* GetStyle( ) const;
76
77       void PushActorsInto( vtkRenderWindow* window, bool force_style = true );
78       void PopActorsFrom( vtkRenderWindow* window );
79       unsigned int GetNumberOfImages( ) const;
80       vtkImageActor* GetImageActor( );
81       const vtkImageActor* GetImageActor( ) const;
82       vtkTextActor* GetTextActor( );
83       const vtkTextActor* GetTextActor( ) const;
84       vtkActor* GetPlaneActor( );
85       const vtkActor* GetPlaneActor( ) const;
86       vtkPlane* GetPlaneFunction( );
87       const vtkPlane* GetPlaneFunction( ) const;
88
89       void SetInterpolate( bool v );
90       void InterpolateOn( );
91       void InterpolateOff( );
92
93       double* GetDisplayBounds( ) const;
94       void GetDisplayBounds( double bounds[ 6 ] ) const;
95
96       void ResetCursor( );
97       void SetCursor( double pos[ 3 ] );
98
99       double GetMinWindow( ) const;
100       double GetMaxWindow( ) const;
101       double GetMinLevel( ) const;
102       double GetMaxLevel( ) const;
103       double GetWindow( ) const;
104       double GetLevel( ) const;
105       void SetWindow( double w );
106       void SetLevel( double l );
107       void SetWindowLevel( double w, double l );
108       void ResetWindowLevel( );
109
110       int GetAxis( ) const;
111       int GetSliceNumber( ) const;
112       int GetSliceNumberMinValue( ) const;
113       int GetSliceNumberMaxValue( ) const;
114       void SetSliceNumber( const int& slice );
115       void SetSlice( double* pos );
116       void UpdateText( );
117       void UpdateText( double pos[ 3 ] );
118       void UpdateText( const double& w, const double& l );
119
120       void Render( const double& t );
121       void ResetCamera( );
122
123     protected:
124       ImageSliceActors( );
125       virtual ~ImageSliceActors( );
126
127       void _ConfigureStyle( );
128
129       // Events
130       static void _MouseMoveCommand(
131         void* data,
132         const TStyle::ButtonID& btn,
133         int* idx, double* pos,
134         bool alt, bool ctr, bool sft
135         );
136       static void _MouseClickCommand(
137         void* data,
138         const TStyle::ButtonID& btn,
139         int* idx, double* pos,
140         bool alt, bool ctr, bool sft
141         );
142       static void _MouseWheelCommand(
143         void* data,
144         const int& dir, bool alt, bool ctr, bool sft
145         );
146       static void _KeyCommand(
147         void* data,
148         const char& key
149         );
150       static void _EnterCommand( void* data );
151       static void _LeaveCommand( void* data );
152
153     private:
154       // Purposely not implemented
155       ImageSliceActors( const Self& );
156       Self& operator=( const Self& );
157
158     protected:
159       vtkSmartPointer< TStyle > m_Style;
160       vtkRenderWindow* m_Window;
161
162       // Multiple actors
163       vtkSmartPointer< vtkImageSliceMapper > m_ImageMapper;
164       vtkSmartPointer< vtkImageActor >       m_ImageActor;
165       bool m_Interpolate;
166
167       double m_WLRange[ 4 ];
168
169       int    m_VisibleExtent[ 6 ];
170       double m_VisibleBounds[ 6 ];
171
172       // Associated slices
173       std::vector< Self* > m_AssociatedSlices;
174
175       // Unique objects
176       vtkSmartPointer< vtkPolyData >       m_Cursor;
177       vtkSmartPointer< vtkPolyDataMapper > m_CursorMapper;
178       vtkSmartPointer< vtkActor >          m_CursorActor;
179
180       vtkSmartPointer< vtkPolyData >       m_HorizontalLine;
181       vtkSmartPointer< vtkPolyDataMapper > m_HorizontalLineMapper;
182       vtkSmartPointer< vtkActor >          m_HorizontalLineActor;
183
184       vtkSmartPointer< vtkPolyData >       m_VerticalLine;
185       vtkSmartPointer< vtkPolyDataMapper > m_VerticalLineMapper;
186       vtkSmartPointer< vtkActor >          m_VerticalLineActor;
187
188       vtkSmartPointer< vtkPolyData >       m_Plane;
189       vtkSmartPointer< vtkPolyDataMapper > m_PlaneMapper;
190       vtkSmartPointer< vtkActor >          m_PlaneActor;
191
192       char                                 m_TextBuffer[ 1024 ];
193       vtkSmartPointer< vtkTextActor >      m_TextActor;
194
195       double m_StartWindowLevelPos[ 3 ];
196       double m_StartWindowLevel[ 2 ];
197     };
198
199   } // ecapseman
200
201 } // ecapseman
202
203 #endif //  __CPEXTENSIONS__VISUALIZATION__IMAGESLICEACTORS__H__
204
205 // eof - $RCSfile$