]> Creatis software - cpPlugins.git/blob - lib/cpExtensions/Visualization/ImageSliceActors.h
More widgets added
[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 <map>
7 #include <utility>
8
9 #include <vtkSmartPointer.h>
10 #include <vtkActor.h>
11 #include <vtkImageActor.h>
12 #include <vtkImageMapToColors.h>
13 #include <vtkImageSliceMapper.h>
14 #include <vtkPlane.h>
15 #include <vtkPolyData.h>
16 #include <vtkPolyDataMapper.h>
17 #include <vtkPropCollection.h>
18 #include <vtkTextActor.h>
19
20 #include <cpExtensions/Interaction/ImageInteractorStyle.h>
21
22 // -------------------------------------------------------------------------
23 class vtkAlgorithmOutput;
24 class vtkImageData;
25 class vtkLookupTable;
26
27 // -------------------------------------------------------------------------
28 namespace cpExtensions
29 {
30   namespace Visualization
31   {
32     /**
33      */
34     class cpExtensions_EXPORT ImageSliceActors
35       : public vtkPropCollection
36     {
37     public:
38       typedef ImageSliceActors Self;
39
40       typedef cpExtensions::Interaction::BaseInteractorStyle  TBaseStyle;
41       typedef cpExtensions::Interaction::ImageInteractorStyle TStyle;
42       typedef void ( *TSlicesCommand )( double*, int, void* );
43       typedef void ( *TWindowLevelCommand )( double, double, void* );
44       typedef TBaseStyle::TMouseCommand      TMouseCommand;
45       typedef TBaseStyle::TMouseWheelCommand TMouseWheelCommand;
46       typedef TBaseStyle::TKeyCommand        TKeyCommand;
47       typedef TBaseStyle::TVoidCommand       TVoidCommand;
48
49     public:
50       vtkTypeMacro( ImageSliceActors, vtkPropCollection );
51
52     public:
53       // Creation
54       static ImageSliceActors* New( );
55
56       void AddSlicesCommand( TSlicesCommand command, void* data );
57       void AddWindowLevelCommand( TWindowLevelCommand command, void* data );
58       void AddRenderCommand( TVoidCommand command, void* data );
59
60       void RemoveSlicesCommand( TSlicesCommand command );
61       void RemoveWindowLevelCommand( TWindowLevelCommand command );
62       void RemoveRenderCommand( TVoidCommand command );
63
64       void AddInputConnection( vtkAlgorithmOutput* aout, int axis = 2 );
65       void AddInputData( vtkImageData* data, int axis = 2 );
66       void Clear( );
67
68       vtkInteractorStyle* GetStyle( );
69       const vtkInteractorStyle* GetStyle( ) const;
70
71       void PushActorsInto( vtkRenderWindow* window, bool force_style = true );
72       void PopActorsFrom( vtkRenderWindow* window );
73       unsigned int GetNumberOfImageActors( ) const;
74       vtkImageActor* GetImageActor( unsigned int id );
75       const vtkImageActor* GetImageActor( unsigned int id ) const;
76       vtkTextActor* GetTextActor( );
77       const vtkTextActor* GetTextActor( ) const;
78       vtkActor* GetPlaneActor( );
79       const vtkActor* GetPlaneActor( ) const;
80       vtkPlane* GetPlaneFunction( );
81       const vtkPlane* GetPlaneFunction( ) const;
82
83       void SetInterpolate( bool v );
84       void InterpolateOn( );
85       void InterpolateOff( );
86
87       double* GetDisplayBounds( ) const;
88       void GetDisplayBounds( double bounds[ 6 ] ) const;
89
90       void ResetCursor( );
91       void SetCursor( double pos[ 3 ] );
92
93       vtkImageMapToColors* GetImageMap( unsigned int id );
94       const vtkImageMapToColors* GetImageMap( unsigned int id ) const;
95
96       double GetMinWindow( ) const;
97       double GetMaxWindow( ) const;
98       double GetMinLevel( ) const;
99       double GetMaxLevel( ) const;
100       double GetWindow( ) const;
101       double GetLevel( ) const;
102       void SetWindow( double w );
103       void SetLevel( double l );
104       void SetWindowLevel( double w, double l );
105       void ResetWindowLevel( );
106
107       void SetLookupTable( unsigned int id, vtkLookupTable* lut );
108       void SetLookupTableAsColor(
109         unsigned int id, double r, double g, double b
110         );
111
112       int GetAxis( ) const;
113       int GetSliceNumber( ) const;
114       int GetSliceNumberMinValue( ) const;
115       int GetSliceNumberMaxValue( ) const;
116       void SetSliceNumber( const int& slice );
117       void SetSlice( double* pos );
118       void UpdateText( );
119       void UpdateText( double pos[ 3 ] );
120       void UpdateText( const double& w, const double& l );
121
122       void Render( );
123       void ResetCamera( );
124
125     protected:
126       ImageSliceActors( );
127       virtual ~ImageSliceActors( );
128
129       void _ConfigureStyle( );
130       void _ConfigureNewLUT( vtkImageData* data );
131       void _ConfigureNewInput( int axis );
132
133       // Events
134       static void _MouseMoveCommand(
135         void* data,
136         const TBaseStyle::ButtonID& btn,
137         int* idx, double* pos,
138         bool alt, bool ctr, bool sft
139         );
140       static void _MouseClickCommand(
141         void* data,
142         const TBaseStyle::ButtonID& btn,
143         int* idx, double* pos,
144         bool alt, bool ctr, bool sft
145         );
146       static void _MouseWheelCommand(
147         void* data,
148         const int& dir, bool alt, bool ctr, bool sft
149         );
150       static void _KeyCommand(
151         void* data,
152         const char& key
153         );
154
155     private:
156       // Purposely not implemented
157       ImageSliceActors( const Self& );
158       Self& operator=( const Self& );
159
160     protected:
161       vtkSmartPointer< TStyle > m_Style;
162
163       // Multiple actors
164       std::vector< vtkSmartPointer< vtkImageMapToColors > > m_ImageMaps;
165       std::vector< vtkSmartPointer< vtkImageSliceMapper > > m_SliceMappers;
166       std::vector< vtkSmartPointer< vtkImageActor > >       m_ImageActors;
167       bool m_Interpolate;
168
169       // Window-Level values
170       double m_MinWindow, m_MaxWindow;
171       double m_MinLevel, m_MaxLevel;
172
173       // Associated commands
174       std::map< TSlicesCommand, void* >      m_SlicesCommands;
175       std::map< TWindowLevelCommand, void* > m_WindowLevelCommands;
176       std::map< TVoidCommand, void* >        m_RenderCommands;
177
178       // Unique objects
179       vtkSmartPointer< vtkPolyData >       m_Cursor;
180       vtkSmartPointer< vtkPolyDataMapper > m_CursorMapper;
181       vtkSmartPointer< vtkActor >          m_CursorActor;
182       vtkSmartPointer< vtkPlane >          m_PlaneFunction;
183       vtkSmartPointer< vtkPolyData >       m_Plane;
184       vtkSmartPointer< vtkPolyDataMapper > m_PlaneMapper;
185       char                                 m_TextBuffer[ 1024 ];
186       vtkSmartPointer< vtkTextActor >      m_TextActor;
187       vtkSmartPointer< vtkActor >          m_PlaneActor;
188
189       double m_StartWindowLevelPos[ 3 ];
190       double m_StartWindowLevel[ 2 ];
191     };
192
193   } // ecapseman
194
195 } // ecapseman
196
197 #endif //  __CPEXTENSIONS__VISUALIZATION__IMAGESLICEACTORS__H__
198
199 // eof - $RCSfile$