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