]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Extensions/Visualization/ImageInteractorStyle.cxx
0c44df1743c95c1ddd3d1d92a9768976fb72ef56
[cpPlugins.git] / lib / cpPlugins / Extensions / Visualization / ImageInteractorStyle.cxx
1 #include <cpPlugins/Extensions/Visualization/ImageInteractorStyle.h>
2
3 #include <vtkAnnotatedCubeActor.h>
4 #include <vtkAxesActor.h>
5 #include <vtkCamera.h>
6 #include <vtkCommand.h>
7 #include <vtkPropAssembly.h>
8 #include <vtkProperty.h>
9 #include <vtkRendererCollection.h>
10 #include <vtkRenderWindow.h>
11 #include <vtkRenderWindowInteractor.h>
12
13 #include <cpPlugins/Extensions/Visualization/ImageSliceActors.h>
14 #include <cpPlugins/Extensions/Visualization/MPRActors.h>
15
16 // -------------------------------------------------------------------------
17 const int cpPlugins::Extensions::Visualization::
18 ImageInteractorStyle::SliceEvent = vtkCommand::UserEvent + 1;
19
20 // -------------------------------------------------------------------------
21 cpPlugins::Extensions::Visualization::ImageInteractorStyle::
22 Self* cpPlugins::Extensions::Visualization::ImageInteractorStyle::
23 New( )
24 {
25   return( new Self( ) );
26 }
27
28 // -------------------------------------------------------------------------
29 void cpPlugins::Extensions::Visualization::ImageInteractorStyle::
30 Configure( ImageSliceActors* slice_actors, MPRActors* mpr_actors )
31 {
32   this->m_SliceActors = slice_actors;
33   this->m_MPRActors = mpr_actors;
34   this->SetModeToNavigation( );
35   this->PropPicker->AddPickList( slice_actors->GetImageActor( ) );
36   this->Modified( );
37 }
38
39 // -------------------------------------------------------------------------
40 void cpPlugins::Extensions::Visualization::ImageInteractorStyle::
41 SetModeToNavigation( )
42 {
43   this->Mode = Self::NavigationMode;
44 }
45
46 // -------------------------------------------------------------------------
47 void cpPlugins::Extensions::Visualization::ImageInteractorStyle::
48 SetModeToDeformation( )
49 {
50   this->Mode = Self::DeformationMode;
51 }
52
53 // -------------------------------------------------------------------------
54 void cpPlugins::Extensions::Visualization::ImageInteractorStyle::
55 SetInteractor( vtkRenderWindowInteractor* interactor, const int& axis )
56 {
57   this->Superclass::SetInteractor( interactor );
58   this->OrientationWidget->SetInteractor( interactor );
59   interactor->SetInteractorStyle( this );
60   if( interactor == NULL )
61     return;
62
63   // TODO: interactor->SetPicker( this->PropPicker );
64
65   // Get camera, avoiding segfaults
66   vtkRenderer* ren =
67     interactor->GetRenderWindow( )->GetRenderers( )->GetFirstRenderer( );
68   if( ren == NULL )
69     return;
70   vtkCamera* cam = ren->GetActiveCamera( );
71   if( cam == NULL )
72     return;
73
74   // Parallel projections are better when displaying 2D images
75   cam->ParallelProjectionOn( );
76   cam->SetFocalPoint( double( 0 ), double( 0 ), double( 0 ) );
77   if( axis == 0 )
78   {
79     cam->SetPosition( double( 1 ), double( 0 ), double( 0 ) );
80     cam->SetViewUp  ( double( 0 ), double( 1 ), double( 0 ) );
81   }
82   else if( axis == 1 )
83   {
84     cam->SetPosition( double( 0 ), double( 1 ), double(  0 ) );
85     cam->SetViewUp  ( double( 0 ), double( 0 ), double( -1 ) );
86   }
87   else // if( axis == 2 )
88   {
89     cam->SetPosition( double( 0 ), double( 0 ), double( 1 ) );
90     cam->SetViewUp  ( double( 0 ), double( 1 ), double( 0 ) );
91
92   } // fi
93   ren->ResetCamera( );
94
95   // Enable 2D orientation widget
96   this->OrientationWidget->SetEnabled( 1 );
97   this->OrientationWidget->InteractiveOff( );
98 }
99
100 // -------------------------------------------------------------------------
101 void cpPlugins::Extensions::Visualization::ImageInteractorStyle::
102 OnMouseMove( )
103 {
104   std::cout << "moumov" << std::endl;
105 }
106
107 // -------------------------------------------------------------------------
108 void cpPlugins::Extensions::Visualization::ImageInteractorStyle::
109 OnLeftButtonDown( )
110 {
111   std::cout << "leftdown" << std::endl;
112 }
113
114 // -------------------------------------------------------------------------
115 void cpPlugins::Extensions::Visualization::ImageInteractorStyle::
116 OnLeftButtonUp( )
117 {
118   std::cout << "leftup" << std::endl;
119 }
120
121 // -------------------------------------------------------------------------
122 void cpPlugins::Extensions::Visualization::ImageInteractorStyle::
123 OnMiddleButtonDown( )
124 {
125   std::cout << "middown" << std::endl;
126 }
127
128 // -------------------------------------------------------------------------
129 void cpPlugins::Extensions::Visualization::ImageInteractorStyle::
130 OnMiddleButtonUp( )
131 {
132   std::cout << "midup" << std::endl;
133 }
134
135 // -------------------------------------------------------------------------
136 void cpPlugins::Extensions::Visualization::ImageInteractorStyle::
137 OnRightButtonDown( )
138 {
139   std::cout << "ridown" << std::endl;
140 }
141
142 // -------------------------------------------------------------------------
143 void cpPlugins::Extensions::Visualization::ImageInteractorStyle::
144 OnRightButtonUp( )
145 {
146   std::cout << "riup" << std::endl;
147 }
148
149 // -------------------------------------------------------------------------
150 void cpPlugins::Extensions::Visualization::ImageInteractorStyle::
151 OnMouseWheelForward( )
152 {
153   std::cout << "whfwd" << std::endl;
154 }
155
156 // -------------------------------------------------------------------------
157 void cpPlugins::Extensions::Visualization::ImageInteractorStyle::
158 OnMouseWheelBackward( )
159 {
160   std::cout << "whbwd" << std::endl;
161 }
162
163 // -------------------------------------------------------------------------
164 void cpPlugins::Extensions::Visualization::ImageInteractorStyle::
165 OnChar( )
166 {
167   std::cout << "char" << std::endl;
168 }
169
170 // -------------------------------------------------------------------------
171 void cpPlugins::Extensions::Visualization::ImageInteractorStyle::
172 Rotate( )
173 {
174   std::cout << "Rotate" << std::endl;
175 }
176
177 // -------------------------------------------------------------------------
178 void cpPlugins::Extensions::Visualization::ImageInteractorStyle::
179 Pan( )
180 {
181   std::cout << "pan" << std::endl;
182 }
183
184 // -------------------------------------------------------------------------
185 void cpPlugins::Extensions::Visualization::ImageInteractorStyle::
186 Spin( )
187 {
188   std::cout << "spin" << std::endl;
189 }
190
191 // -------------------------------------------------------------------------
192 void cpPlugins::Extensions::Visualization::ImageInteractorStyle::
193 Zoom( )
194 {
195   std::cout << "Zoom" << std::endl;
196 }
197
198 // -------------------------------------------------------------------------
199 void cpPlugins::Extensions::Visualization::ImageInteractorStyle::
200 WindowLevel( )
201 {
202   std::cout << "wl" << std::endl;
203 }
204
205 // -------------------------------------------------------------------------
206 void cpPlugins::Extensions::Visualization::ImageInteractorStyle::
207 Pick( )
208 {
209   std::cout << "Pick" << std::endl;
210 }
211
212 // -------------------------------------------------------------------------
213 void cpPlugins::Extensions::Visualization::ImageInteractorStyle::
214 Slice( )
215 {
216   std::cout << "Slice" << std::endl;
217 }
218
219 // -------------------------------------------------------------------------
220 void cpPlugins::Extensions::Visualization::ImageInteractorStyle::
221 StartWindowLevel( )
222 {
223   std::cout << "swl" << std::endl;
224 }
225
226 // -------------------------------------------------------------------------
227 void cpPlugins::Extensions::Visualization::ImageInteractorStyle::
228 EndWindowLevel( )
229 {
230   std::cout << "ewl" << std::endl;
231 }
232
233 // -------------------------------------------------------------------------
234 void cpPlugins::Extensions::Visualization::ImageInteractorStyle::
235 StartPick( )
236 {
237   std::cout << "sp" << std::endl;
238 }
239
240 // -------------------------------------------------------------------------
241 void cpPlugins::Extensions::Visualization::ImageInteractorStyle::
242 EndPick( )
243 {
244   std::cout << "ep" << std::endl;
245 }
246
247 // -------------------------------------------------------------------------
248 void cpPlugins::Extensions::Visualization::ImageInteractorStyle::
249 StartSlice( )
250 {
251   std::cout << "ss" << std::endl;
252 }
253
254 // -------------------------------------------------------------------------
255 void cpPlugins::Extensions::Visualization::ImageInteractorStyle::
256 EndSlice( )
257 {
258   std::cout << "es" << std::endl;
259 }
260
261 // -------------------------------------------------------------------------
262 cpPlugins::Extensions::Visualization::ImageInteractorStyle::
263 ImageInteractorStyle( )
264   : Superclass( ),
265     Mode( Self::NavigationMode ),
266     m_SliceActors( NULL ),
267     m_MPRActors( NULL )
268 {
269   // Orientation marks
270   vtkSmartPointer< vtkAnnotatedCubeActor > cube =
271     vtkSmartPointer< vtkAnnotatedCubeActor >::New( );
272   cube->GetCubeProperty( )->SetColor( 0.9, 0.7, 0.2 );
273   cube->GetTextEdgesProperty( )->SetLineWidth( 1 );
274   cube->GetTextEdgesProperty( )->SetDiffuse( 0 );
275   cube->GetTextEdgesProperty( )->SetAmbient( 1 );
276   cube->GetTextEdgesProperty( )->SetColor( 0.18, 0.28, 0.23 );
277   cube->GetXPlusFaceProperty( )->SetColor( 1, 0, 0 );
278   cube->GetXPlusFaceProperty( )->SetInterpolationToFlat( );
279   cube->GetXMinusFaceProperty( )->SetColor( 1, 0, 0 );
280   cube->GetXMinusFaceProperty( )->SetInterpolationToFlat( );
281   cube->GetYPlusFaceProperty( )->SetColor( 0, 1, 0 );
282   cube->GetYPlusFaceProperty( )->SetInterpolationToFlat( );
283   cube->GetYMinusFaceProperty( )->SetColor( 0, 1, 0 );
284   cube->GetYMinusFaceProperty( )->SetInterpolationToFlat( );
285   cube->GetZPlusFaceProperty( )->SetColor( 0, 0, 1 );
286   cube->GetZPlusFaceProperty( )->SetInterpolationToFlat( );
287   cube->GetZMinusFaceProperty( )->SetColor( 0, 0, 1 );
288   cube->GetZMinusFaceProperty( )->SetInterpolationToFlat( );
289
290   vtkSmartPointer< vtkAxesActor > axes =
291     vtkSmartPointer< vtkAxesActor >::New( );
292   axes->AxisLabelsOff( );
293   axes->SetShaftTypeToCylinder( );
294   axes->SetTotalLength( 2, 2, 2 );
295
296   vtkSmartPointer< vtkPropAssembly > actors =
297     vtkSmartPointer< vtkPropAssembly >::New( );
298   actors->AddPart( cube );
299   actors->AddPart( axes );
300
301   this->OrientationWidget =
302     vtkSmartPointer< vtkOrientationMarkerWidget >::New( );
303   this->OrientationWidget->SetOutlineColor( 0.93, 0.57, 0.13 );
304   this->OrientationWidget->SetOrientationMarker( actors );
305   this->OrientationWidget->SetViewport( 0.0, 0.0, 0.2, 0.2 );
306
307   this->PropPicker = vtkSmartPointer< vtkPropPicker >::New( );
308   this->PropPicker->PickFromListOn( );
309 }
310
311 // -------------------------------------------------------------------------
312 cpPlugins::Extensions::Visualization::ImageInteractorStyle::
313 ~ImageInteractorStyle( )
314 {
315   std::cout << "destructor" << std::endl;
316 }
317
318 // -------------------------------------------------------------------------
319 bool cpPlugins::Extensions::Visualization::ImageInteractorStyle::
320 _PickPosition( double pos[ 3 ] )
321 {
322   std::cout << "pickpos" << std::endl;
323 }
324
325 // -------------------------------------------------------------------------
326 void cpPlugins::Extensions::Visualization::ImageInteractorStyle::
327 _UpdateCursor( )
328 {
329   std::cout << "upcur" << std::endl;
330 }
331
332 // eof - $RCSfile$