]> Creatis software - cpPlugins.git/blob - lib/cpExtensions/Visualization/ImageSliceActors.h
703a552c437cbe77566462c53b876d2a5e48c1c1
[cpPlugins.git] / lib / cpExtensions / Visualization / ImageSliceActors.h
1 #ifndef __CPEXTENSIONS__VISUALIZATION__IMAGESLICEACTORS__H__
2 #define __CPEXTENSIONS__VISUALIZATION__IMAGESLICEACTORS__H__
3
4 #include <cpExtensions/Config.h>
5
6 #include <cpExtensions/Interaction/ImageInteractorStyle.h>
7 #include <map>
8 #include <vtkActor.h>
9 #include <vtkCursor3D.h>
10 #include <vtkCutter.h>
11 #include <vtkImageActor.h>
12 #include <vtkImageSliceMapper.h>
13 #include <vtkPolyDataMapper.h>
14 #include <vtkPropCollection.h>
15 #include <vtkTextActor.h>
16 #include <vtkSmartPointer.h>
17
18 #define MAX_TEXT_BUFFER 1024
19
20 class vtkAlgorithmOutput;
21 class vtkImageData;
22 class vtkRenderer;
23
24 namespace cpExtensions
25 {
26   namespace Visualization
27   {
28     /**
29      */
30     class cpExtensions_EXPORT ImageSliceActors
31       : public vtkPropCollection
32     {
33     public:
34       typedef ImageSliceActors Self;
35       typedef cpExtensions::Interaction::ImageInteractorStyle TStyle;
36       typedef TStyle::TMouseCommand            TMouseCommand;
37       typedef TStyle::TMouseWheelCommand       TMouseWheelCommand;
38       typedef TStyle::TKeyCommand              TKeyCommand;
39       typedef TStyle::TVoidCommand             TVoidCommand;
40       typedef TStyle::TMouseMoveCommand        TMouseMoveCommand;
41       typedef TStyle::TMouseClickCommand       TMouseClickCommand;
42       typedef TStyle::TMouseDoubleClickCommand TMouseDoubleClickCommand;
43       typedef TStyle::TExposeCommand           TExposeCommand;
44       typedef TStyle::TConfigureCommand        TConfigureCommand;
45       typedef TStyle::TEnterCommand            TEnterCommand;
46       typedef TStyle::TLeaveCommand            TLeaveCommand;
47       typedef void ( *TSlicesCommand )( double*, int, void* );
48       typedef void ( *TWindowLevelCommand )( double, double, void* );
49       typedef TVoidCommand TRenderCommand;
50
51       template< class _TSource >
52         struct SourceActor
53       {
54         vtkSmartPointer< _TSource >          Source;
55         vtkSmartPointer< vtkPolyDataMapper > Mapper;
56         vtkSmartPointer< vtkActor >          Actor;
57         void Create( )
58           {
59             this->Source = vtkSmartPointer< _TSource >::New( );
60             this->Mapper = vtkSmartPointer< vtkPolyDataMapper >::New( );
61             this->Actor = vtkSmartPointer< vtkActor >::New( );
62             this->Mapper->SetInputConnection( this->Source->GetOutputPort( ) );
63             this->Actor->SetMapper( this->Mapper );
64           }
65         void Modified( )
66           {
67             this->Source->Modified( );
68             this->Mapper->Modified( );
69             this->Actor->Modified( );
70           }
71       };
72
73     public:
74       vtkTypeMacro( ImageSliceActors, vtkPropCollection );
75
76       cpExtensions_BaseInteractorStyle_Commands( Slices );
77       cpExtensions_BaseInteractorStyle_Commands( WindowLevel );
78       cpExtensions_BaseInteractorStyle_Commands( Render );
79
80     public:
81       static Self* New( );
82
83       void Clear( );
84       void SetInputConnection( vtkAlgorithmOutput* aout, int orientation );
85       void SetInputData( vtkImageData* data, int orientation );
86       void SetInputActor( vtkProp* actor, int orientation );
87       vtkImageData* GetInputData( );
88
89       vtkImageActor* GetImageActor( );
90       const vtkImageActor* GetImageActor( ) const;
91
92       void AddMesh( vtkPolyData* mesh );
93
94       void AssociateSlice( Self* slice );
95       void CleanAssociatedSlices( );
96
97       TStyle* GetStyle( );
98       void SetStyle( vtkInteractorStyle* st );
99
100       void PushInto( vtkRenderer* ren );
101       void PopFrom( vtkRenderer* ren );
102
103       long GetSliceNumber( ) const;
104       void SetSliceNumber( long slice );
105
106       void ShowPixelText( double* pos );
107
108       void GetScalarRange( double r[ 2 ] ) const;
109       void SetScalarRange( const double& a, const double& b );
110       void UnsetScalarRange( );
111       void SetWindowLevel( const double& w, const double& l );
112       double GetWindow( ) const;
113       double GetLevel( ) const;
114
115       void Render( );
116
117     protected:
118       ImageSliceActors( );
119       virtual ~ImageSliceActors( );
120
121       void _ConfigureInput( int orientation );
122       void _ConfigureCursor( );
123
124       // Events
125       static void _MouseMoveCommand(
126         void* data,
127         const TStyle::ButtonID& btn,
128         int* idx, double* pos,
129         bool alt, bool ctr, bool sft
130         );
131       static void _MouseClickCommand(
132         void* data,
133         const TStyle::ButtonID& btn,
134         int* idx, 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       static void _EnterCommand( void* data );
146       static void _LeaveCommand( void* data );
147
148     private:
149       // Purposely not implemented
150       ImageSliceActors( const Self& );
151       Self& operator=( const Self& );
152
153     protected:
154       // Main image
155       vtkSmartPointer< vtkImageSliceMapper > m_Mapper;
156       vtkSmartPointer< vtkImageActor >       m_Actor;
157
158       // Secondary slices
159       std::vector< vtkSmartPointer< Self > > m_AssociatedSlices;
160
161       // Associated meshes
162       std::map< vtkPolyData*, SourceActor< vtkCutter > > m_Meshes;
163
164       // Cursor
165       SourceActor< vtkCursor3D > m_Cursor;
166
167       // Text
168       char                            m_TextBuffer[ MAX_TEXT_BUFFER ];
169       vtkSmartPointer< vtkTextActor > m_TextActor;
170
171       // WindowLevel
172       double m_ScalarRange[ 2 ];
173       bool m_ManualScalarRange;
174
175       // Style
176       vtkSmartPointer< vtkInteractorStyle > m_Style;
177
178       // Events-related data
179       double m_StartMouseEvent[ 3 ];
180       double m_StartWindow;
181       double m_StartLevel;
182     };
183
184   } // ecapseman
185
186 } // ecapseman
187
188 #endif // __CPEXTENSIONS__VISUALIZATION__IMAGESLICEACTORS__H__
189
190 // eof - $RCSfile$