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