]> Creatis software - cpPlugins.git/blob - lib/cpExtensions/Visualization/ImageSliceActors.h
Minor refactoring and errors solved
[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     public:
50       // Creation
51       static ImageSliceActors* New( );
52
53       void AddSlicesCommand( TCursorCommand command, void* data );
54       void AddSeedCommand( TCursorCommand command, void* data );
55
56       void AddInputConnection( vtkAlgorithmOutput* aout, int axis = 2 );
57       void AddInputData( vtkImageData* data, int axis = 2 );
58       void Clear( );
59
60       void AssociateSlice( Self* other );
61
62       vtkInteractorStyle* GetStyle( );
63       const vtkInteractorStyle* GetStyle( ) const;
64
65       void PushActorsInto( vtkRenderWindow* window, bool force_style = true );
66       void PopActorsFrom( vtkRenderWindow* window );
67       unsigned int GetNumberOfImageActors( ) const;
68       vtkImageActor* GetImageActor( unsigned int id );
69       const vtkImageActor* GetImageActor( unsigned int id ) const;
70       vtkTextActor* GetTextActor( );
71       const vtkTextActor* GetTextActor( ) const;
72       vtkActor* GetPlaneActor( );
73       const vtkActor* GetPlaneActor( ) const;
74       vtkPlane* GetPlaneFunction( );
75       const vtkPlane* GetPlaneFunction( ) const;
76
77       void AddActor( vtkAlgorithm* algorithm, vtkActor* actor );
78       void AddActor( vtkActor* actor );
79
80       void SetInterpolate( bool v );
81       void InterpolateOn( );
82       void InterpolateOff( );
83
84       double* GetDisplayBounds( ) const;
85       void GetDisplayBounds( double bounds[ 6 ] ) const;
86
87       void ResetCursor( );
88       void SetCursor( double pos[ 3 ] );
89
90       vtkImageMapToColors* GetImageMap( unsigned int id );
91       const vtkImageMapToColors* GetImageMap( unsigned int id ) const;
92
93       double GetMinWindow( ) const;
94       double GetMaxWindow( ) const;
95       double GetMinLevel( ) const;
96       double GetMaxLevel( ) const;
97       double GetWindow( ) const;
98       double GetLevel( ) const;
99       void SetWindow( double w );
100       void SetLevel( double l );
101       void SetWindowLevel( double w, double l );
102       void ResetWindowLevel( );
103
104       void SetLookupTable( unsigned int id, vtkLookupTable* lut );
105       void SetLookupTableAsColor(
106         unsigned int id, double r, double g, double b
107         );
108
109       int GetAxis( ) const;
110       int GetSliceNumber( ) const;
111       int GetSliceNumberMinValue( ) const;
112       int GetSliceNumberMaxValue( ) const;
113       void SetSliceNumber( const int& slice );
114       void SetSlice( double* pos );
115       void UpdateText( );
116       void UpdateText( double pos[ 3 ] );
117       void UpdateText( const double& w, const double& l );
118
119     protected:
120       ImageSliceActors( );
121       virtual ~ImageSliceActors( );
122
123       void _ConfigureStyle( );
124       void _ConfigureNewLUT( vtkImageData* data );
125       void _ConfigureNewInput( int axis );
126
127       // Events
128       static void _MouseMoveCommand(
129         void* data,
130         const BaseInteractorStyle::ButtonID& btn, double* pos,
131         bool alt, bool ctr, bool sft
132         );
133       static void _MouseClickCommand(
134         void* data,
135         const BaseInteractorStyle::ButtonID& btn, double* pos,
136         bool alt, bool ctr, bool sft
137         );
138       static void _MouseDoubleClickCommand(
139         void* data,
140         const BaseInteractorStyle::ButtonID& btn, double* pos,
141         bool alt, bool ctr, bool sft
142         );
143       static void _MouseWheelCommand(
144         void* data,
145         const int& dir, bool alt, bool ctr, bool sft
146         );
147       static void _KeyCommand(
148         void* data,
149         const char& key
150         );
151
152     private:
153       // Purposely not implemented
154       ImageSliceActors( const Self& );
155       Self& operator=( const Self& );
156
157     protected:
158       vtkSmartPointer< ImageInteractorStyle > m_Style;
159
160       // Multiple actors
161       std::vector< vtkSmartPointer< vtkImageMapToColors > > m_ImageMaps;
162       std::vector< vtkSmartPointer< vtkImageSliceMapper > > m_SliceMappers;
163       std::vector< vtkSmartPointer< vtkImageActor > >       m_ImageActors;
164       bool m_Interpolate;
165
166       // Window-Level values
167       double m_MinWindow, m_MaxWindow;
168       double m_MinLevel, m_MaxLevel;
169
170       // Other associated slices
171       std::vector< vtkSmartPointer< Self > > m_AssociatedSlices;
172
173       // Associated commands
174       std::vector< std::pair< TCursorCommand, void* > > m_SlicesCommands;
175       std::vector< std::pair< TCursorCommand, void* > > m_SeedCommands;
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$