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