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