]> Creatis software - cpPlugins.git/blob - lib/cpExtensions/Visualization/ImageSliceActors.h
Merge branch 'master' of 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 <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 class vtkRenderer;
27
28 // -------------------------------------------------------------------------
29 namespace cpExtensions
30 {
31   namespace Visualization
32   {
33     /**
34      */
35     class cpExtensions_EXPORT ImageSliceActors
36       : public vtkPropCollection
37     {
38     public:
39       typedef ImageSliceActors Self;
40
41       typedef cpExtensions::Interaction::BaseInteractorStyle  TBaseStyle;
42       typedef cpExtensions::Interaction::ImageInteractorStyle TStyle;
43       typedef void ( *TSlicesCommand )( double*, int, void* );
44       typedef void ( *TWindowLevelCommand )( double, double, void* );
45       typedef TBaseStyle::TMouseCommand      TMouseCommand;
46       typedef TBaseStyle::TMouseWheelCommand TMouseWheelCommand;
47       typedef TBaseStyle::TKeyCommand        TKeyCommand;
48       typedef TBaseStyle::TVoidCommand       TVoidCommand;
49
50     public:
51       vtkTypeMacro( ImageSliceActors, vtkPropCollection );
52
53     public:
54       // Creation
55       static ImageSliceActors* New( );
56
57       void AddSlicesCommand( TSlicesCommand command, void* data );
58       void AddWindowLevelCommand( TWindowLevelCommand command, void* data );
59       void AddRenderCommand( TVoidCommand command, void* data );
60
61       void RemoveSlicesCommand( TSlicesCommand command );
62       void RemoveWindowLevelCommand( TWindowLevelCommand command );
63       void RemoveRenderCommand( TVoidCommand command );
64
65       void AddInputConnection( vtkAlgorithmOutput* aout, int axis = 2 );
66       void AddInputData( vtkImageData* data, int axis = 2 );
67       void Clear( );
68
69       void AssociateSlice( Self* slice );
70
71       vtkImageData* GetInputImage( unsigned int id );
72       const vtkImageData* GetInputImage( unsigned int id ) 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 GetNumberOfImageActors( ) const;
80       vtkImageActor* GetImageActor( unsigned int id );
81       const vtkImageActor* GetImageActor( unsigned int id ) 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       vtkImageMapToColors* GetImageMap( unsigned int id );
100       const vtkImageMapToColors* GetImageMap( unsigned int id ) const;
101
102       double GetMinWindow( ) const;
103       double GetMaxWindow( ) const;
104       double GetMinLevel( ) const;
105       double GetMaxLevel( ) const;
106       double GetWindow( ) const;
107       double GetLevel( ) const;
108       void SetWindow( double w );
109       void SetLevel( double l );
110       void SetWindowLevel( double w, double l );
111       void ResetWindowLevel( );
112
113       void SetLookupTable( unsigned int id, vtkLookupTable* lut );
114       void SetLookupTableAsColor(
115         unsigned int id, double r, double g, double b
116         );
117
118       int GetAxis( ) const;
119       int GetSliceNumber( ) const;
120       int GetSliceNumberMinValue( ) const;
121       int GetSliceNumberMaxValue( ) const;
122       void SetSliceNumber( const int& slice );
123       void SetSlice( double* pos );
124       void UpdateText( );
125       void UpdateText( double pos[ 3 ] );
126       void UpdateText( const double& w, const double& l );
127
128       void Render( );
129       void ResetCamera( );
130
131     protected:
132       ImageSliceActors( );
133       virtual ~ImageSliceActors( );
134
135       void _ConfigureStyle( );
136       void _ConfigureNewLUT( vtkImageData* data );
137       void _ConfigureNewInput( int axis );
138
139       // Events
140       static void _MouseMoveCommand(
141         void* data,
142         const TBaseStyle::ButtonID& btn,
143         int* idx, double* pos,
144         bool alt, bool ctr, bool sft
145         );
146       static void _MouseClickCommand(
147         void* data,
148         const TBaseStyle::ButtonID& btn,
149         int* idx, double* pos,
150         bool alt, bool ctr, bool sft
151         );
152       static void _MouseWheelCommand(
153         void* data,
154         const int& dir, bool alt, bool ctr, bool sft
155         );
156       static void _KeyCommand(
157         void* data,
158         const char& key
159         );
160
161     private:
162       // Purposely not implemented
163       ImageSliceActors( const Self& );
164       Self& operator=( const Self& );
165
166     protected:
167       vtkSmartPointer< TStyle > m_Style;
168       vtkRenderWindow* m_Window;
169
170       // Multiple actors
171       std::vector< vtkSmartPointer< vtkImageMapToColors > > m_ImageMaps;
172       std::vector< vtkSmartPointer< vtkImageSliceMapper > > m_SliceMappers;
173       std::vector< vtkSmartPointer< vtkImageActor > >       m_ImageActors;
174       bool m_Interpolate;
175
176       // Associated slices
177       std::vector< Self* > m_AssociatedSlices;
178
179       // Window-Level values
180       double m_MinWindow, m_MaxWindow;
181       double m_MinLevel, m_MaxLevel;
182
183       // Associated commands
184       std::map< TSlicesCommand, void* >      m_SlicesCommands;
185       std::map< TWindowLevelCommand, void* > m_WindowLevelCommands;
186       std::map< TVoidCommand, void* >        m_RenderCommands;
187
188       // Unique objects
189       vtkSmartPointer< vtkPolyData >       m_Cursor;
190       vtkSmartPointer< vtkPolyDataMapper > m_CursorMapper;
191       vtkSmartPointer< vtkActor >          m_CursorActor;
192       vtkSmartPointer< vtkPlane >          m_PlaneFunction;
193       vtkSmartPointer< vtkPolyData >       m_Plane;
194       vtkSmartPointer< vtkPolyDataMapper > m_PlaneMapper;
195       char                                 m_TextBuffer[ 1024 ];
196       vtkSmartPointer< vtkTextActor >      m_TextActor;
197       vtkSmartPointer< vtkActor >          m_PlaneActor;
198
199       double m_StartWindowLevelPos[ 3 ];
200       double m_StartWindowLevel[ 2 ];
201     };
202
203   } // ecapseman
204
205 } // ecapseman
206
207 #endif //  __CPEXTENSIONS__VISUALIZATION__IMAGESLICEACTORS__H__
208
209 // eof - $RCSfile$