]> Creatis software - cpPlugins.git/blob - lib/cpExtensions/Visualization/ImageSliceActors.h
Intermediary commit
[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 <utility>
7 #include <vector>
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/Visualization/ImageInteractorStyle.h>
21
22 // -------------------------------------------------------------------------
23 class vtkAlgorithmOutput;
24 class vtkImageData;
25
26 // -------------------------------------------------------------------------
27 namespace cpExtensions
28 {
29   namespace Visualization
30   {
31     /**
32      */
33     class cpExtensions_EXPORT ImageSliceActors
34       : public vtkPropCollection
35     {
36     public:
37       typedef ImageSliceActors Self;
38
39     public:
40       vtkTypeMacro( ImageSliceActors, vtkPropCollection );
41
42       enum LUTType
43       {
44         LUTType_None = 0,
45         LUTType_WindowLevel,
46         LUTType_Colors
47       };
48
49     public:
50       // Creation
51       static ImageSliceActors* New( );
52
53       void AddInputConnection(
54         vtkAlgorithmOutput* aout,
55         int axis = 2,
56         LUTType lut = Self::LUTType_None
57         );
58       void AddInputData(
59         vtkImageData* data,
60         int axis = 2,
61         LUTType lut = Self::LUTType_None );
62       void Clear( );
63
64       vtkInteractorStyle* GetStyle( );
65       const vtkInteractorStyle* GetStyle( ) const;
66
67       void PushActorsInto( vtkRenderWindow* window, bool force_style = true );
68       void PopActorsFrom( vtkRenderWindow* window );
69       unsigned int GetNumberOfImageActors( ) const;
70       vtkImageActor* GetImageActor( unsigned int id );
71       const vtkImageActor* GetImageActor( unsigned int id ) const;
72       vtkTextActor* GetTextActor( );
73       const vtkTextActor* GetTextActor( ) const;
74       vtkActor* GetPlaneActor( );
75       const vtkActor* GetPlaneActor( ) const;
76       vtkPlane* GetPlaneFunction( );
77       const vtkPlane* GetPlaneFunction( ) const;
78
79       void AddActor( vtkAlgorithm* algorithm, vtkActor* actor );
80       void AddActor( vtkActor* actor );
81
82       void SetInterpolate( bool v );
83       void InterpolateOn( );
84       void InterpolateOff( );
85
86       double* GetDisplayBounds( ) const;
87       void GetDisplayBounds( double bounds[ 6 ] ) const;
88
89       void ResetCursor( );
90       void SetCursor( double pos[ 3 ] );
91
92       vtkImageMapToColors* GetImageMap( unsigned int id );
93       const vtkImageMapToColors* GetImageMap( unsigned int id ) const;
94
95       double GetWindow( unsigned int id ) const;
96       double GetLevel( unsigned int id ) const;
97       void SetWindow( unsigned int id, double w );
98       void SetLevel( unsigned int id, double l );
99       void SetWindowLevel( unsigned int id, double w, double l );
100       void ResetWindowLevel( unsigned int id );
101
102       int GetAxis( ) const;
103       int GetSliceNumber( ) const;
104       int GetSliceNumberMinValue( ) const;
105       int GetSliceNumberMaxValue( ) const;
106       void SetSliceNumber( const int& slice );
107       void UpdateText( );
108       void UpdateText( double pos[ 3 ] );
109       void UpdateText( const double& w, const double& l );
110
111     protected:
112       ImageSliceActors( );
113       virtual ~ImageSliceActors( );
114
115       void _ConfigureNewLUT( vtkImageData* data, LUTType lut_t );
116       void _ConfigureNewInput( int axis );
117
118       // Events
119       static void _MouseMoveCommand(
120         void* data,
121         const ImageInteractorStyle::ButtonID& btn, double* pos,
122         bool alt, bool ctr, bool sft
123         );
124       static void _MouseClickCommand(
125         void* data,
126         const ImageInteractorStyle::ButtonID& btn, double* pos,
127         bool alt, bool ctr, bool sft
128         );
129       static void _MouseDoubleClickCommand(
130         void* data,
131         const ImageInteractorStyle::ButtonID& btn, double* pos,
132         bool alt, bool ctr, bool sft
133         );
134       static void _MouseWheelCommand(
135         void* data,
136         const int& dir, bool alt, bool ctr, bool sft
137         );
138       static void _KeyCommand(
139         void* data,
140         const char& key
141         );
142
143     private:
144       // Purposely not implemented
145       ImageSliceActors( const Self& );
146       Self& operator=( const Self& );
147
148     protected:
149       vtkSmartPointer< ImageInteractorStyle > Style;
150
151       // Multiple actors
152       std::vector< vtkSmartPointer< vtkImageMapToColors > > ImageMaps;
153       std::vector< vtkSmartPointer< vtkImageSliceMapper > > SliceMappers;
154       std::vector< vtkSmartPointer< vtkImageActor > >       ImageActors;
155       bool Interpolate;
156
157       // Other associated actors
158       typedef std::pair< vtkAlgorithm*, vtkActor* > TAssociatedActor;
159       typedef std::vector< TAssociatedActor >       TAssociatedActors;
160       TAssociatedActors AssociatedActors;
161
162       // Unique objects
163       vtkSmartPointer< vtkPolyData >       Cursor;
164       vtkSmartPointer< vtkPolyDataMapper > CursorMapper;
165       vtkSmartPointer< vtkActor >          CursorActor;
166       vtkSmartPointer< vtkPlane >          PlaneFunction;
167       vtkSmartPointer< vtkPolyData >       PlaneSource;
168       vtkSmartPointer< vtkPolyDataMapper > PlaneMapper;
169       char                                 TextBuffer[ 1024 ];
170       vtkSmartPointer< vtkTextActor >      TextActor;
171       vtkSmartPointer< vtkActor >          PlaneActor;
172
173       double StartWindowLevelPos[ 3 ];
174       double StartWindowLevel[ 2 ];
175     };
176
177   } // ecapseman
178
179 } // ecapseman
180
181 #endif //  __CPEXTENSIONS__VISUALIZATION__IMAGESLICEACTORS__H__
182
183 // eof - $RCSfile$