]> Creatis software - cpPlugins.git/blob - lib/cpExtensions/Visualization/ImageSliceActors.h
Tree data updated.
[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::ImageInteractorStyle TStyle;
42       typedef TStyle::TMouseCommand            TMouseCommand;
43       typedef TStyle::TMouseWheelCommand       TMouseWheelCommand;
44       typedef TStyle::TKeyCommand              TKeyCommand;
45       typedef TStyle::TVoidCommand             TVoidCommand;
46       typedef TStyle::TMouseMoveCommand        TMouseMoveCommand;
47       typedef TStyle::TMouseClickCommand       TMouseClickCommand;
48       typedef TStyle::TMouseDoubleClickCommand TMouseDoubleClickCommand;
49       typedef TStyle::TExposeCommand           TExposeCommand;
50       typedef TStyle::TConfigureCommand        TConfigureCommand;
51       typedef TStyle::TEnterCommand            TEnterCommand;
52       typedef TStyle::TLeaveCommand            TLeaveCommand;
53       typedef void ( *TSlicesCommand )( double*, int, void* );
54       typedef void ( *TWindowLevelCommand )( double, double, void* );
55       typedef TVoidCommand TRenderCommand;
56
57     public:
58       vtkTypeMacro( ImageSliceActors, vtkPropCollection );
59
60       cpExtensions_BaseInteractorStyle_Commands( Slices );
61       cpExtensions_BaseInteractorStyle_Commands( WindowLevel );
62       cpExtensions_BaseInteractorStyle_Commands( Render );
63
64     public:
65       // Creation
66       static ImageSliceActors* New( );
67
68       void AddInputConnection( vtkAlgorithmOutput* aout, int axis = 2 );
69       void AddInputData( vtkImageData* data, int axis = 2 );
70       void Clear( );
71
72       void AssociateSlice( Self* slice );
73
74       vtkImageData* GetInputImage( unsigned int id );
75       const vtkImageData* GetInputImage( unsigned int id ) const;
76
77       vtkInteractorStyle* GetStyle( );
78       const vtkInteractorStyle* GetStyle( ) const;
79
80       void PushActorsInto( vtkRenderWindow* window, bool force_style = true );
81       void PopActorsFrom( vtkRenderWindow* window );
82       unsigned int GetNumberOfImageActors( ) const;
83       vtkImageActor* GetImageActor( unsigned int id );
84       const vtkImageActor* GetImageActor( unsigned int id ) const;
85       vtkTextActor* GetTextActor( );
86       const vtkTextActor* GetTextActor( ) const;
87       vtkActor* GetPlaneActor( );
88       const vtkActor* GetPlaneActor( ) const;
89       vtkPlane* GetPlaneFunction( );
90       const vtkPlane* GetPlaneFunction( ) const;
91
92       void SetInterpolate( bool v );
93       void InterpolateOn( );
94       void InterpolateOff( );
95
96       double* GetDisplayBounds( ) const;
97       void GetDisplayBounds( double bounds[ 6 ] ) const;
98
99       void ResetCursor( );
100       void SetCursor( double pos[ 3 ] );
101
102       vtkImageMapToColors* GetImageMap( unsigned int id );
103       const vtkImageMapToColors* GetImageMap( unsigned int id ) const;
104
105       double GetMinWindow( ) const;
106       double GetMaxWindow( ) const;
107       double GetMinLevel( ) const;
108       double GetMaxLevel( ) const;
109       double GetWindow( ) const;
110       double GetLevel( ) const;
111       void SetWindow( double w );
112       void SetLevel( double l );
113       void SetWindowLevel( double w, double l );
114       void ResetWindowLevel( );
115
116       void SetLookupTable( unsigned int id, vtkLookupTable* lut );
117       void SetLookupTableAsColor(
118         unsigned int id, double r, double g, double b
119         );
120
121       int GetAxis( ) const;
122       int GetSliceNumber( ) const;
123       int GetSliceNumberMinValue( ) const;
124       int GetSliceNumberMaxValue( ) const;
125       void SetSliceNumber( const int& slice );
126       void SetSlice( double* pos );
127       void UpdateText( );
128       void UpdateText( double pos[ 3 ] );
129       void UpdateText( const double& w, const double& l );
130
131       void Render( const double& t );
132       void ResetCamera( );
133
134     protected:
135       ImageSliceActors( );
136       virtual ~ImageSliceActors( );
137
138       void _ConfigureStyle( );
139       void _ConfigureNewLUT( vtkImageData* data );
140       void _ConfigureNewInput( int axis );
141
142       // Events
143       static void _MouseMoveCommand(
144         void* data,
145         const TStyle::ButtonID& btn,
146         int* idx, double* pos,
147         bool alt, bool ctr, bool sft
148         );
149       static void _MouseClickCommand(
150         void* data,
151         const TStyle::ButtonID& btn,
152         int* idx, double* pos,
153         bool alt, bool ctr, bool sft
154         );
155       static void _MouseWheelCommand(
156         void* data,
157         const int& dir, bool alt, bool ctr, bool sft
158         );
159       static void _KeyCommand(
160         void* data,
161         const char& key
162         );
163       static void _EnterCommand( void* data );
164       static void _LeaveCommand( void* data );
165
166     private:
167       // Purposely not implemented
168       ImageSliceActors( const Self& );
169       Self& operator=( const Self& );
170
171     protected:
172       vtkSmartPointer< TStyle > m_Style;
173       vtkRenderWindow* m_Window;
174
175       // Multiple actors
176       std::vector< vtkSmartPointer< vtkImageMapToColors > > m_ImageMaps;
177       std::vector< vtkSmartPointer< vtkImageSliceMapper > > m_SliceMappers;
178       std::vector< vtkSmartPointer< vtkImageActor > >       m_ImageActors;
179       bool m_Interpolate;
180
181       // Associated slices
182       std::vector< Self* > m_AssociatedSlices;
183
184       // Window-Level values
185       double m_MinWindow, m_MaxWindow;
186       double m_MinLevel, m_MaxLevel;
187
188       // Unique objects
189       vtkSmartPointer< vtkPolyData >       m_Cursor;
190       vtkSmartPointer< vtkPolyDataMapper > m_CursorMapper;
191       vtkSmartPointer< vtkActor >          m_CursorActor;
192       vtkSmartPointer< vtkPolyData >       m_Plane;
193       vtkSmartPointer< vtkPolyDataMapper > m_PlaneMapper;
194       char                                 m_TextBuffer[ 1024 ];
195       vtkSmartPointer< vtkTextActor >      m_TextActor;
196       vtkSmartPointer< vtkActor >          m_PlaneActor;
197
198       double m_StartWindowLevelPos[ 3 ];
199       double m_StartWindowLevel[ 2 ];
200     };
201
202   } // ecapseman
203
204 } // ecapseman
205
206 #endif //  __CPEXTENSIONS__VISUALIZATION__IMAGESLICEACTORS__H__
207
208 // eof - $RCSfile$