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