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