]> Creatis software - cpPlugins.git/blob - lib/cpExtensions/Visualization/ImageSliceActors.h
075c6ec0edabea6a31daff54e18a7d7322338d62
[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 <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       vtkImageData* GetInputData( );
87
88       vtkImageActor* GetImageActor( );
89       const vtkImageActor* GetImageActor( ) const;
90
91       void AddMesh( vtkPolyData* mesh );
92
93       void AssociateSlice( Self* slice );
94       void CleanAssociatedSlices( );
95
96       TStyle* GetStyle( );
97       void SetStyle( vtkInteractorStyle* st );
98
99       void PushInto( vtkRenderer* ren );
100       void PopFrom( vtkRenderer* ren );
101
102       long GetSliceNumber( ) const;
103       void SetSliceNumber( long slice );
104
105       void ShowPixelText( double* pos );
106
107       void GetScalarRange( double r[ 2 ] ) const;
108       void SetScalarRange( const double& a, const double& b );
109       void UnsetScalarRange( );
110       void SetWindowLevel( const double& w, const double& l );
111       double GetWindow( ) const;
112       double GetLevel( ) const;
113
114       void Render( );
115
116     protected:
117       ImageSliceActors( );
118       virtual ~ImageSliceActors( );
119
120       void _ConfigureInput( int orientation );
121       void _ConfigureCursor( );
122
123       // Events
124       static void _MouseMoveCommand(
125         void* data,
126         const TStyle::ButtonID& btn,
127         int* idx, double* pos,
128         bool alt, bool ctr, bool sft
129         );
130       static void _MouseClickCommand(
131         void* data,
132         const TStyle::ButtonID& btn,
133         int* idx, double* pos,
134         bool alt, bool ctr, bool sft
135         );
136       static void _MouseWheelCommand(
137         void* data,
138         const int& dir, bool alt, bool ctr, bool sft
139         );
140       static void _KeyCommand(
141         void* data,
142         const char& key
143         );
144       static void _EnterCommand( void* data );
145       static void _LeaveCommand( void* data );
146
147     private:
148       // Purposely not implemented
149       ImageSliceActors( const Self& );
150       Self& operator=( const Self& );
151
152     protected:
153       // Main image
154       vtkSmartPointer< vtkImageSliceMapper > m_Mapper;
155       vtkSmartPointer< vtkImageActor >       m_Actor;
156
157       // Secondary slices
158       std::vector< vtkSmartPointer< Self > > m_AssociatedSlices;
159
160       // Associated meshes
161       std::map< vtkPolyData*, SourceActor< vtkCutter > > m_Meshes;
162
163       // Cursor
164       SourceActor< vtkCursor3D > m_Cursor;
165
166       // Text
167       char                            m_TextBuffer[ MAX_TEXT_BUFFER ];
168       vtkSmartPointer< vtkTextActor > m_TextActor;
169
170       // WindowLevel
171       double m_ScalarRange[ 2 ];
172       bool m_ManualScalarRange;
173
174       // Style
175       vtkSmartPointer< vtkInteractorStyle > m_Style;
176
177       // Events-related data
178       double m_StartMouseEvent[ 3 ];
179       double m_StartWindow;
180       double m_StartLevel;
181     };
182
183   } // ecapseman
184
185 } // ecapseman
186
187 #endif // __CPEXTENSIONS__VISUALIZATION__IMAGESLICEACTORS__H__
188
189 // eof - $RCSfile$