]> Creatis software - cpPlugins.git/blob - lib/cpExtensions/Visualization/ImageSliceActors.h
Binary image visualization improved.
[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 <vtkSmartPointer.h>
7 #include <vtkActor.h>
8 #include <vtkImageActor.h>
9 #include <vtkImageSliceMapper.h>
10 #include <vtkPlane.h>
11 #include <vtkPolyData.h>
12 #include <vtkPolyDataMapper.h>
13 #include <vtkPropCollection.h>
14 #include <vtkTextActor.h>
15
16 #include <cpExtensions/Interaction/ImageInteractorStyle.h>
17 #include <cpExtensions/Visualization/ImageBlender.h>
18
19 // -------------------------------------------------------------------------
20 class vtkAlgorithmOutput;
21 class vtkImageData;
22 class vtkLookupTable;
23 class vtkRenderer;
24
25 // -------------------------------------------------------------------------
26 namespace cpExtensions
27 {
28   namespace Visualization
29   {
30     /**
31      */
32     class cpExtensions_EXPORT ImageSliceActors
33       : public vtkPropCollection
34     {
35     public:
36       typedef ImageSliceActors Self;
37
38       typedef cpExtensions::Interaction::ImageInteractorStyle TStyle;
39       typedef TStyle::TMouseCommand            TMouseCommand;
40       typedef TStyle::TMouseWheelCommand       TMouseWheelCommand;
41       typedef TStyle::TKeyCommand              TKeyCommand;
42       typedef TStyle::TVoidCommand             TVoidCommand;
43       typedef TStyle::TMouseMoveCommand        TMouseMoveCommand;
44       typedef TStyle::TMouseClickCommand       TMouseClickCommand;
45       typedef TStyle::TMouseDoubleClickCommand TMouseDoubleClickCommand;
46       typedef TStyle::TExposeCommand           TExposeCommand;
47       typedef TStyle::TConfigureCommand        TConfigureCommand;
48       typedef TStyle::TEnterCommand            TEnterCommand;
49       typedef TStyle::TLeaveCommand            TLeaveCommand;
50       typedef void ( *TSlicesCommand )( double*, int, void* );
51       typedef void ( *TWindowLevelCommand )( double, double, void* );
52       typedef TVoidCommand TRenderCommand;
53
54     public:
55       vtkTypeMacro( ImageSliceActors, vtkPropCollection );
56
57       cpExtensions_BaseInteractorStyle_Commands( Slices );
58       cpExtensions_BaseInteractorStyle_Commands( WindowLevel );
59       cpExtensions_BaseInteractorStyle_Commands( Render );
60
61     public:
62       // Creation
63       static ImageSliceActors* New( );
64
65       ImageBlender* GetBlender( );
66       const ImageBlender* GetBlender( ) const;
67       void SetBlender( ImageBlender* blender );
68       void SetAxis( int axis );
69       void AddInputConnection( vtkAlgorithmOutput* aout );
70       void AddInputData( vtkImageData* data );
71       void Clear( );
72
73       void AssociateSlice( Self* slice );
74
75       vtkImageData* GetInputImage( unsigned int id );
76       const vtkImageData* GetInputImage( unsigned int id ) const;
77
78       vtkInteractorStyle* GetStyle( );
79       const vtkInteractorStyle* GetStyle( ) const;
80
81       void PushActorsInto( vtkRenderWindow* window, bool force_style = true );
82       void PopActorsFrom( vtkRenderWindow* window );
83       unsigned int GetNumberOfImages( ) const;
84       vtkImageActor* GetImageActor( );
85       const vtkImageActor* GetImageActor( ) const;
86       vtkTextActor* GetTextActor( );
87       const vtkTextActor* GetTextActor( ) const;
88       vtkActor* GetPlaneActor( );
89       const vtkActor* GetPlaneActor( ) const;
90       vtkPlane* GetPlaneFunction( );
91       const vtkPlane* GetPlaneFunction( ) const;
92
93       void SetInterpolate( bool v );
94       void InterpolateOn( );
95       void InterpolateOff( );
96
97       double* GetDisplayBounds( ) const;
98       void GetDisplayBounds( double bounds[ 6 ] ) const;
99
100       void ResetCursor( );
101       void SetCursor( double pos[ 3 ] );
102
103       double GetMinWindow( ) const;
104       double GetMaxWindow( ) const;
105       double GetMinLevel( ) const;
106       double GetMaxLevel( ) const;
107       double GetWindow( ) const;
108       double GetLevel( ) const;
109       void SetWindow( double w );
110       void SetLevel( double l );
111       void SetWindowLevel( double w, double l );
112       void ResetWindowLevel( );
113
114       int GetAxis( ) const;
115       int GetSliceNumber( ) const;
116       int GetSliceNumberMinValue( ) const;
117       int GetSliceNumberMaxValue( ) const;
118       void SetSliceNumber( const int& slice );
119       void SetSlice( double* pos );
120       void UpdateText( );
121       void UpdateText( double pos[ 3 ] );
122       void UpdateText( const double& w, const double& l );
123
124       void Render( const double& t );
125       void ResetCamera( );
126
127     protected:
128       ImageSliceActors( );
129       virtual ~ImageSliceActors( );
130
131       void _ConfigureStyle( );
132
133       // Events
134       static void _MouseMoveCommand(
135         void* data,
136         const TStyle::ButtonID& btn,
137         int* idx, double* pos,
138         bool alt, bool ctr, bool sft
139         );
140       static void _MouseClickCommand(
141         void* data,
142         const TStyle::ButtonID& btn,
143         int* idx, double* pos,
144         bool alt, bool ctr, bool sft
145         );
146       static void _MouseWheelCommand(
147         void* data,
148         const int& dir, bool alt, bool ctr, bool sft
149         );
150       static void _KeyCommand(
151         void* data,
152         const char& key
153         );
154       static void _EnterCommand( void* data );
155       static void _LeaveCommand( void* data );
156
157     private:
158       // Purposely not implemented
159       ImageSliceActors( const Self& );
160       Self& operator=( const Self& );
161
162     protected:
163       vtkSmartPointer< TStyle > m_Style;
164       vtkRenderWindow* m_Window;
165
166       // Multiple actors
167       vtkSmartPointer< ImageBlender >        m_ImageBlender;
168       vtkSmartPointer< vtkImageSliceMapper > m_ImageMapper;
169       vtkSmartPointer< vtkImageActor >       m_ImageActor;
170       bool m_Interpolate;
171
172       int    m_VisibleExtent[ 6 ];
173       double m_VisibleBounds[ 6 ];
174
175       // Associated slices
176       std::vector< Self* > m_AssociatedSlices;
177
178       // Unique objects
179       vtkSmartPointer< vtkPolyData >       m_Cursor;
180       vtkSmartPointer< vtkPolyDataMapper > m_CursorMapper;
181       vtkSmartPointer< vtkActor >          m_CursorActor;
182
183       vtkSmartPointer< vtkPolyData >       m_HorizontalLine;
184       vtkSmartPointer< vtkPolyDataMapper > m_HorizontalLineMapper;
185       vtkSmartPointer< vtkActor >          m_HorizontalLineActor;
186
187       vtkSmartPointer< vtkPolyData >       m_VerticalLine;
188       vtkSmartPointer< vtkPolyDataMapper > m_VerticalLineMapper;
189       vtkSmartPointer< vtkActor >          m_VerticalLineActor;
190
191       vtkSmartPointer< vtkPolyData >       m_Plane;
192       vtkSmartPointer< vtkPolyDataMapper > m_PlaneMapper;
193       vtkSmartPointer< vtkActor >          m_PlaneActor;
194
195       char                                 m_TextBuffer[ 1024 ];
196       vtkSmartPointer< vtkTextActor >      m_TextActor;
197
198       double m_StartWindowLevelPos[ 3 ];
199       double m_StartWindowLevel[ 2 ];
200     };
201
202   } // ecapseman
203
204 } // ecapseman
205
206 #endif //  __CPEXTENSIONS__VISUALIZATION__IMAGESLICEACTORS__H__
207
208 // eof - $RCSfile$