]> Creatis software - clitk.git/blob - vv/vvSlicerManagerCommand.cxx
Merge branch 'master' of tux.creatis.insa-lyon.fr:clitk
[clitk.git] / vv / vvSlicerManagerCommand.cxx
1 /*=========================================================================
2   Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
3
4   Authors belong to:
5   - University of LYON              http://www.universite-lyon.fr/
6   - Léon Bérard cancer center       http://www.centreleonberard.fr
7   - CREATIS CNRS laboratory         http://www.creatis.insa-lyon.fr
8
9   This software is distributed WITHOUT ANY WARRANTY; without even
10   the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11   PURPOSE.  See the copyright notices for more information.
12
13   It is distributed under dual licence
14
15   - BSD        See included LICENSE.txt file
16   - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ===========================================================================**/
18 #include "vvSlicerManagerCommand.h"
19 #include "vvSlicerManager.h"
20
21 #include <vtkTextProperty.h>
22 #include <vtkRenderer.h>
23 #include <vtkImageActor.h>
24 #include <vtkRenderWindowInteractor.h>
25 #include <vtkPropPicker.h>
26 #include <vtkCamera.h>
27 #include <vtkImageMapToWindowLevelColors.h>
28 #include <vtkLookupTable.h>
29 #include <vtkMath.h>
30 #include <vtkAbstractPropPicker.h>
31 #include <vtkAssemblyPath.h>
32 #include <vtkCornerAnnotation.h>
33 #include <vtkRenderWindow.h>
34 #include <vvImage.h>
35 #include <vtkImageReslice.h>
36 #include "vvSlicer.h"
37 #include "vvInteractorStyleNavigator.h"
38 #include "vtkTransform.h"
39
40 #include <cmath>
41
42 //------------------------------------------------------------------------------
43 vvSlicerManagerCommand::vvSlicerManagerCommand()
44 {
45   mStartSlicer = -1;
46   mSlicerNumber=-1;
47 }
48 //------------------------------------------------------------------------------
49
50
51 //------------------------------------------------------------------------------
52 //return the num of the current slicer if visible (-1 else)
53 int vvSlicerManagerCommand::FindSlicerNumber(vtkRenderWindow* renwin)
54 {
55   int rvalue;
56   if (renwin != SM->GetSlicer(mSlicerNumber)->GetRenderWindow() ||
57       !SM->GetSlicer(mSlicerNumber)->GetRenderer()->GetDraw())
58     rvalue = -1;
59   else rvalue = mSlicerNumber;
60   //std::cerr << this << ":" << mSlicerNumber << ": " << rvalue << endl;
61   return rvalue;
62 }
63 //------------------------------------------------------------------------------
64
65
66 //------------------------------------------------------------------------------
67 void vvSlicerManagerCommand::Execute(vtkObject *caller,
68                                      unsigned long event,
69                                      void *vtkNotUsed(callData))
70 {
71   //KeyPress event
72   vvInteractorStyleNavigator *isi =
73     dynamic_cast<vvInteractorStyleNavigator *>(caller);
74   if (isi) {
75     double x = isi->GetInteractor()->GetEventPosition()[0];
76     double y = isi->GetInteractor()->GetEventPosition()[1];
77     double z;
78
79     int VisibleInWindow = this->FindSlicerNumber(isi->GetInteractor()->GetRenderWindow());
80     vtkRenderer* renderer=NULL;
81     if (VisibleInWindow>-1)
82       renderer=this->SM->GetSlicer(VisibleInWindow)->GetRenderer();
83     newLandmark = false;
84
85
86
87     if (event == vtkCommand::StartPickEvent && VisibleInWindow == -1) {
88       for (int i = 0; i < this->SM->GetNumberOfSlicers(); i++) {
89         if (this->SM->GetSlicer(i)->GetCursorVisibility() && !this->SM->IsLinked()) {
90           this->SM->GetSlicer(i)->SetCursorVisibility(0);
91           this->SM->GetSlicer(i)->SetCornerAnnotationVisibility(0);
92           this->SM->GetSlicer(i)->Render();
93         }
94       }
95     }
96     if ( VisibleInWindow > -1 ) {
97       if (event == vtkCommand::KeyPressEvent) {
98         std::string KeyPress = isi->GetInteractor()->GetKeySym();
99         bool bCtrlKey = isi->GetInteractor()->GetControlKey();
100         if (KeyPress == "Tab") {
101           if(isi->GetInteractor()->GetShiftKey())
102             this->SM->PrevImage(VisibleInWindow);
103           else
104             this->SM->NextImage(VisibleInWindow);
105           return;
106         }
107         if (KeyPress == "f" || KeyPress == "F") {
108           FlyToPosition(isi->GetInteractor(),this->SM->GetSlicer(VisibleInWindow));
109           return;
110         }
111         if (KeyPress == "w") {
112           this->SM->SetLocalColorWindowing(VisibleInWindow, bCtrlKey);
113           return;
114         }
115         if (KeyPress == "0") {
116           this->SM->SetPreset(WL_AUTO);
117           this->SM->UpdateWindowLevel();
118           return;
119         }
120         if (KeyPress == "1") {
121           this->SM->SetPreset(WL_HOUNSFIELD);
122           this->SM->UpdateWindowLevel();
123           return;
124         }
125         if (KeyPress == "2") {
126           this->SM->SetPreset(WL_SOFTTISSUE);
127           this->SM->UpdateWindowLevel();
128
129           return;
130         }
131         if (KeyPress == "3") {
132           this->SM->SetPreset(WL_LUNGS);
133           this->SM->UpdateWindowLevel();
134           return;
135         }
136         if (KeyPress == "4") {
137           this->SM->SetPreset(WL_BONES);
138           this->SM->UpdateWindowLevel();
139           return;
140         }
141         if (KeyPress == "5") {
142           this->SM->SetPreset(WL_HEAD);
143           this->SM->UpdateWindowLevel();
144           return;
145         }
146         if (KeyPress == "6") {
147           this->SM->SetColorMap(0);
148           this->SM->UpdateWindowLevel();
149           return;
150         }
151         if (KeyPress == "7") {
152           this->SM->SetColorMap(1);
153           this->SM->UpdateWindowLevel();
154           return;
155         }
156         if (KeyPress == "8") {
157           this->SM->SetColorMap(2);
158           this->SM->UpdateWindowLevel();
159           return;
160         }
161         if (KeyPress == "9") {
162           this->SM->SetColorMap(3);
163           this->SM->UpdateWindowLevel();
164           return;
165         }
166         if (KeyPress == "equal") { //keycodes are in vtkWin32RenderWindowInteractor
167           this->SM->SetPreset(WL_VENTILATION);
168           //this->SM->SetColorMap(1);
169           this->SM->UpdateWindowLevel();
170           return;
171         }
172         if (KeyPress == "minus") {
173           this->SM->SetColorWindow(-this->SM->GetColorWindow());
174           this->SM->SetColorMap(-1);
175           this->SM->UpdateWindowLevel();
176           return;
177         }
178         if (KeyPress == "c") {
179           this->SM->ToggleContourSuperposition();
180           this->SM->Render();
181           return;
182         }
183         if (KeyPress == "l") {
184           this->SM->ToggleInterpolation();
185           this->SM->Render();
186           return;
187         }
188         if (KeyPress == "h") {
189           this->SM->SetCursorAndCornerAnnotationVisibility(0);
190           this->SM->Render();
191           return;
192         }
193         if (KeyPress == "x") {
194           for(int i=0; i<SM->GetNumberOfSlicers(); i++) {
195             SM->RemoveActor("overlay",0);
196             SM->SetColorMap(0);
197             SM->Render();
198           }
199           return;
200         }
201         if (KeyPress == "u") {
202           this->SM->Reload();
203           this->SM->Render();
204           return;
205         }
206         if (KeyPress == "r" || KeyPress=="R") {
207           this->SM->GetSlicer(VisibleInWindow)->ResetCamera();
208           this->SM->GetSlicer(VisibleInWindow)->Render();
209           this->SM->UpdateLinkedNavigation( this->SM->GetSlicer(VisibleInWindow) );
210           return;
211         }
212         if (KeyPress == "g") {
213           if(bCtrlKey)
214             this->SM->GetSlicer(VisibleInWindow)->SetCurrentPosition(0,0,0,0);
215           else {
216             double* cursorPos = this->SM->GetSlicer(VisibleInWindow)->GetCursorPosition();
217             this->SM->GetSlicer(VisibleInWindow)->SetCurrentPosition(
218               cursorPos[0],cursorPos[1],cursorPos[2],cursorPos[3]);
219           }
220           this->SM->UpdateViews(1,VisibleInWindow);
221           this->SM->UpdateLinked(VisibleInWindow);
222           return;
223         }
224         if (KeyPress == "F5") {
225           this->SM->GetSlicer(VisibleInWindow)->FlipHorizontalView();
226           this->SM->GetSlicer(VisibleInWindow)->Render();
227           return;
228         }
229         if (KeyPress == "F6") {
230           this->SM->GetSlicer(VisibleInWindow)->FlipVerticalView();
231           this->SM->GetSlicer(VisibleInWindow)->Render();
232           return;
233         }
234         if (KeyPress == "Up") {
235           this->SM->GetSlicer(VisibleInWindow)->SetSlice(this->SM->GetSlicer(VisibleInWindow)->GetSlice()+1);
236           this->SM->UpdateSlice(VisibleInWindow);
237         }
238         if (KeyPress == "Down") {
239           this->SM->GetSlicer(VisibleInWindow)->SetSlice(this->SM->GetSlicer(VisibleInWindow)->GetSlice()-1);
240           this->SM->UpdateSlice(VisibleInWindow);
241         }
242         if (KeyPress == "space") {
243           newLandmark = true;
244         }
245         if (KeyPress == "Left")
246           this->SM->SetPreviousTSlice(VisibleInWindow);
247         if (KeyPress == "Right")
248           this->SM->SetNextTSlice(VisibleInWindow);
249
250         if (KeyPress == "F2") {
251           this->SM->GetSlicer(VisibleInWindow)->GetAnnotation()->SetText(2,"Sagital\n<slice>");
252           //this->SM->GetSlicer(VisibleInWindow)->SetSliceOrientation(0);
253           this->SM->SetSliceOrientation(VisibleInWindow, 0);
254           this->SM->UpdateSliceRange(VisibleInWindow);
255         }
256         if (KeyPress == "F3") {
257           this->SM->GetSlicer(VisibleInWindow)->GetAnnotation()->SetText(2,"Coronal\n<slice>");
258           //this->SM->GetSlicer(VisibleInWindow)->SetSliceOrientation(1);
259           this->SM->SetSliceOrientation(VisibleInWindow, 1);
260           this->SM->UpdateSliceRange(VisibleInWindow);
261         }
262         if (KeyPress == "F4") {
263           this->SM->GetSlicer(VisibleInWindow)->GetAnnotation()->SetText(2,"Axial\n<slice>");
264           //this->SM->GetSlicer(VisibleInWindow)->SetSliceOrientation(2);
265           this->SM->SetSliceOrientation(VisibleInWindow, 2);
266           this->SM->UpdateSliceRange(VisibleInWindow);
267         }
268
269         this->SM->EmitKeyPressed(KeyPress);
270       }
271
272       //All type of mouse events
273       if (event == vtkCommand::LeaveEvent) {
274         this->SM->GetSlicer(VisibleInWindow)->SetCurrentPosition(-VTK_DOUBLE_MAX,-VTK_DOUBLE_MAX,
275             -VTK_DOUBLE_MAX,this->SM->GetSlicer(VisibleInWindow)->GetMaxCurrentTSlice());
276         this->SM->GetSlicer(VisibleInWindow)->Render();
277         return;
278       }
279
280       // Mouse release HERE
281       if (event == vtkCommand::EndPickEvent) {
282         //            DD(VisibleInWindow);
283         if (VisibleInWindow > -1)
284           this->SM->LeftButtonReleaseEvent(VisibleInWindow);
285         return; // no return !!!! ???
286       }
287
288       if (event == vtkCommand::StartWindowLevelEvent) {
289         mStartSlicer = -1;
290         this->InitialWindow = this->SM->GetColorWindow();
291         this->InitialLevel = this->SM->GetColorLevel();
292
293         if (VisibleInWindow > -1) {
294           mStartSlicer = VisibleInWindow;
295         }
296         return;
297       }
298
299       if (event == vtkCommand::EndWindowLevelEvent) {
300         mStartSlicer = -1;
301       }
302
303       if (event == vtkCommand::EndInteractionEvent) {
304         this->SM->Picked();
305         this->SM->UpdateLinkedNavigation(this->SM->GetSlicer(VisibleInWindow),true);
306         return;
307       }
308     }
309     if (VisibleInWindow > -1) {
310       this->SM->Activated();
311       this->SM->GetSlicer(VisibleInWindow)->SetCornerAnnotationVisibility(1);
312
313       if (event == vtkCommand::MouseWheelForwardEvent && !isi->GetInteractor()->GetControlKey()) {
314         this->SM->Picked();
315         this->SM->GetSlicer(VisibleInWindow)->SetSlice(this->SM->GetSlicer(VisibleInWindow)->GetSlice()+1);
316         this->SM->UpdateSlice(VisibleInWindow);
317       } else if (event == vtkCommand::MouseWheelForwardEvent && isi->GetInteractor()->GetControlKey()) {
318         double factor = 2;
319         this->Dolly(pow((double)1.1, factor),isi->GetInteractor());
320         Execute(caller, vtkCommand::EndInteractionEvent, NULL);
321       } else if (event == vtkCommand::MouseWheelBackwardEvent && !isi->GetInteractor()->GetControlKey()) {
322         this->SM->Picked();
323         this->SM->GetSlicer(VisibleInWindow)->SetSlice(this->SM->GetSlicer(VisibleInWindow)->GetSlice()-1);
324         this->SM->UpdateSlice(VisibleInWindow);
325       } else if (event == vtkCommand::MouseWheelBackwardEvent && isi->GetInteractor()->GetControlKey()) {
326         double factor = -2;
327         this->Dolly(pow((double)1.1, factor),isi->GetInteractor());
328         Execute(caller, vtkCommand::EndInteractionEvent, NULL);
329       }
330       double xWorld=0;
331       double yWorld=0;
332       double zWorld=0;
333
334       //Move into World Coordinate
335       renderer->DisplayToNormalizedDisplay(x,y);
336       renderer->NormalizedDisplayToViewport(x,y);
337       renderer->ViewportToNormalizedViewport(x,y);
338       renderer->NormalizedViewportToView(x,y,z);
339       renderer->ViewToWorld(x,y,z);
340       switch (this->SM->GetSlicer(VisibleInWindow)->GetSliceOrientation()) {
341       case vtkImageViewer2::SLICE_ORIENTATION_XY:
342         xWorld = x;
343         yWorld = y;
344         zWorld = this->SM->GetSlicer(VisibleInWindow)->GetSlice()*
345                  this->SM->GetSlicer(VisibleInWindow)->GetInput()->GetSpacing()[2] +
346                  this->SM->GetSlicer(VisibleInWindow)->GetInput()->GetOrigin()[2];
347         break;
348
349       case vtkImageViewer2::SLICE_ORIENTATION_XZ:
350         xWorld = x;
351         yWorld = this->SM->GetSlicer(VisibleInWindow)->GetSlice()*
352                  this->SM->GetSlicer(VisibleInWindow)->GetInput()->GetSpacing()[1] +
353                  this->SM->GetSlicer(VisibleInWindow)->GetInput()->GetOrigin()[1];
354         zWorld = z;
355         break;
356
357       case vtkImageViewer2::SLICE_ORIENTATION_YZ:
358         xWorld = this->SM->GetSlicer(VisibleInWindow)->GetSlice()*
359                  this->SM->GetSlicer(VisibleInWindow)->GetInput()->GetSpacing()[0] +
360                  this->SM->GetSlicer(VisibleInWindow)->GetInput()->GetOrigin()[0];
361         yWorld = y;
362         zWorld = z;
363         break;
364       }
365
366       // <<<<<<< HEAD
367       //       this->SM->GetSlicer(VisibleInWindow)->SetCurrentPosition(xWorld,yWorld,zWorld,
368       //                           this->SM->GetSlicer(VisibleInWindow)->GetTSlice());
369       //       // We propagate the mouse position
370       //       this->SM->EmitMousePositionUpdated(VisibleInWindow);      
371       // =======
372       double p[3]; p[0] = xWorld; p[1] = yWorld; p[2] = zWorld;
373       double pt[3];
374       this->SM->GetSlicer(VisibleInWindow)->GetSlicingTransform()->TransformPoint(p, pt);
375
376       this->SM->GetSlicer(VisibleInWindow)->SetCurrentPosition(pt[0],pt[1],pt[2],
377           this->SM->GetSlicer(VisibleInWindow)->GetMaxCurrentTSlice());
378
379       // We propagate the mouse position
380       this->SM->EmitMousePositionUpdated(VisibleInWindow);
381
382       //>>>>>>> 921642d767beba2442dacc8fdb40dc36396e1b7d
383
384       if (newLandmark) {
385         this->SM->AddLandmark(xWorld,yWorld,zWorld,
386                               this->SM->GetSlicer(VisibleInWindow)->GetTSlice());
387         this->SM->GetSlicer(VisibleInWindow)->UpdateLandmarks();
388         this->SM->Render();
389       }
390       if (event == vtkCommand::PickEvent || event == vtkCommand::StartPickEvent) {
391         this->SM->Picked();
392         this->SM->UpdateViews(1,VisibleInWindow);
393         this->SM->UpdateLinked(VisibleInWindow);
394         this->SM->UpdateInfoOnCursorPosition(VisibleInWindow);
395       } else {
396         this->SM->GetSlicer(VisibleInWindow)->Render();
397       }
398       //this->SM->GetSlicer(VisibleInWindow)->SetCurrentPosition(-VTK_DOUBLE_MAX,-VTK_DOUBLE_MAX,
399       //-VTK_DOUBLE_MAX,this->SM->GetSlicer(VisibleInWindow)->GetTSlice());
400       //this->SM->GetSlicer(VisibleInWindow)->Render();
401     }
402
403     if (event == vtkCommand::WindowLevelEvent && mStartSlicer > -1) {
404       this->SM->GetSlicer(mStartSlicer)->SetCornerAnnotationVisibility(1);
405       // Adjust the window level here
406       int *size = isi->GetInteractor()->GetRenderWindow()->GetSize();
407       double window = this->InitialWindow;
408       double level = this->InitialLevel;
409       double range[2];
410       this->SM->GetImage()->GetScalarRange(range);
411
412       // Compute normalized delta
413       double dx = static_cast<double>(isi->GetWindowLevelCurrentPosition()[0] -
414                                       isi->GetWindowLevelStartPosition()[0]) / size[0];
415       double dy = static_cast<double>(isi->GetWindowLevelStartPosition()[1] -
416                                       isi->GetWindowLevelCurrentPosition()[1]) / size[1];
417       //Window is exponential in nature, use exponential to avoid falling into negative numbers
418       dx = std::exp(1.0 * (dx*fabs(dx) + dx)) ; //Quadratic behavior for more reactive interface
419       dy = 0.15 * (dy*fabs(dy) + dy) * (range[1]-range[0]);//Quadratic behavior for more reactive interface
420
421       this->SM->SetColorWindow(window*dx);
422       this->SM->SetColorLevel(level-dy);
423       this->SM->SetPreset(WL_USER);
424       this->SM->Render();
425       this->SM->UpdateWindowLevel();
426       return;
427     }
428   }
429 }
430 //------------------------------------------------------------------------------
431
432
433 //------------------------------------------------------------------------------
434 void vvSlicerManagerCommand::Dolly(double factor, vtkRenderWindowInteractor *interactor)
435 {
436   int VisibleInWindow = this->FindSlicerNumber(interactor->GetRenderWindow());
437   vtkRenderer* renderer;
438   if (VisibleInWindow>-1)
439     renderer=this->SM->GetSlicer(VisibleInWindow)->GetRenderer();
440   else {
441     return;
442   }
443
444   double viewFocus[4],viewPoint[4],motionVector[3], focalDepth;
445   double oldPos[3], newPos[3], distance[2];
446   vtkCamera *camera = renderer->GetActiveCamera();
447   camera->GetFocalPoint(viewFocus);
448
449   renderer->SetWorldPoint(viewFocus[0], viewFocus[0], viewFocus[0], 1.0);
450   renderer->WorldToDisplay();
451   renderer->GetDisplayPoint(viewFocus);
452
453   focalDepth = viewFocus[2];
454
455   oldPos[0] = renderer->GetCenter()[0];
456   oldPos[1] = renderer->GetCenter()[1];
457   oldPos[2] = focalDepth;
458
459   distance[0] = 1/factor*
460                 (interactor->GetEventPosition()[0]-renderer->GetCenter()[0]);
461   distance[1] = 1/factor*
462                 (interactor->GetEventPosition()[1]-renderer->GetCenter()[1]);
463
464   newPos[0] = interactor->GetEventPosition()[0] - distance[0];
465   newPos[1] = interactor->GetEventPosition()[1] - distance[1];
466   newPos[2] = focalDepth;
467
468   renderer->DisplayToNormalizedDisplay(oldPos[0],oldPos[1]);
469   renderer->NormalizedDisplayToViewport(oldPos[0],oldPos[1]);
470   renderer->ViewportToNormalizedViewport(oldPos[0],oldPos[1]);
471   renderer->NormalizedViewportToView(oldPos[0],oldPos[1],oldPos[2]);
472   renderer->ViewToWorld(oldPos[0],oldPos[1],oldPos[2]);
473
474   renderer->DisplayToNormalizedDisplay(newPos[0],newPos[1]);
475   renderer->NormalizedDisplayToViewport(newPos[0],newPos[1]);
476   renderer->ViewportToNormalizedViewport(newPos[0],newPos[1]);
477   renderer->NormalizedViewportToView(newPos[0],newPos[1],newPos[2]);
478   renderer->ViewToWorld(newPos[0],newPos[1],newPos[2]);
479
480   motionVector[0] = newPos[0] - oldPos[0];
481   motionVector[1] = newPos[1] - oldPos[1];
482   motionVector[2] = newPos[2] - oldPos[2];
483
484   camera->GetFocalPoint(viewFocus);
485   camera->GetPosition(viewPoint);
486   camera->SetFocalPoint(motionVector[0] + viewFocus[0],
487                         motionVector[1] + viewFocus[1],
488                         motionVector[2] + viewFocus[2]);
489
490   camera->SetPosition(motionVector[0] + viewPoint[0],
491                       motionVector[1] + viewPoint[1],
492                       motionVector[2] + viewPoint[2]);
493
494   if (camera->GetParallelProjection()) {
495     camera->SetParallelScale(camera->GetParallelScale() / factor);
496   } else {
497     camera->Dolly(factor);
498   }
499
500   if (interactor->GetLightFollowCamera()) {
501     renderer->UpdateLightsGeometryToFollowCamera();
502   }
503   renderer->ResetCameraClippingRange();
504   //interactor->Render();
505 }
506 //------------------------------------------------------------------------------
507
508
509 //------------------------------------------------------------------------------
510 void vvSlicerManagerCommand::FlyToPosition(vtkRenderWindowInteractor *interactor,vvSlicer* slicer)
511 {
512   double flyFrom[3], flyTo[3];
513   double d[3], focalPt[3], position[3], positionFrom[3];
514   int i, j;
515   int VisibleInWindow = this->FindSlicerNumber(interactor->GetRenderWindow());
516   vtkRenderer* renderer=NULL;
517   if (VisibleInWindow>-1)
518     renderer=this->SM->GetSlicer(VisibleInWindow)->GetRenderer();
519   else
520     return;
521
522   interactor->GetPicker()->Pick(interactor->GetEventPosition()[0],
523                                 interactor->GetEventPosition()[1], 0.0,
524                                 renderer);
525
526   vtkAssemblyPath *path=NULL;
527   vtkAbstractPropPicker *picker;
528   if ( (picker=vtkAbstractPropPicker::SafeDownCast(interactor->GetPicker()))) {
529     path = picker->GetPath();
530   }
531   if ( path != NULL ) {
532     flyTo[0] = picker->GetPickPosition()[0];
533     flyTo[1] = picker->GetPickPosition()[1];
534     flyTo[2] = picker->GetPickPosition()[2];
535     renderer->GetActiveCamera()->GetFocalPoint(flyFrom);
536     renderer->GetActiveCamera()->GetPosition(positionFrom);
537
538     switch (slicer->GetSliceOrientation()) {
539     case vtkImageViewer2::SLICE_ORIENTATION_XY:
540       flyTo[2] = flyFrom[2];
541       break;
542
543     case vtkImageViewer2::SLICE_ORIENTATION_XZ:
544       flyTo[1] = flyFrom[1];
545       break;
546
547     case vtkImageViewer2::SLICE_ORIENTATION_YZ:
548       flyTo[0] = flyFrom[0];
549       break;
550     }
551
552
553     for (i=0; i<3; i++) {
554       d[i] = flyTo[i] - flyFrom[i];
555     }
556     double distance = vtkMath::Normalize(d);
557     double delta = distance/15;
558
559     for (i=1; i<=15; i++) {
560       for (j=0; j<3; j++) {
561         focalPt[j] = flyFrom[j] + d[j]*i*delta;
562         position[j] = positionFrom[j] + d[j]*i*delta;
563       }
564       renderer->GetActiveCamera()->SetFocalPoint(focalPt);
565       renderer->GetActiveCamera()->SetPosition(position);
566       renderer->GetActiveCamera()->Dolly(0.3/15 + 1.0);
567       renderer->ResetCameraClippingRange();
568       interactor->Render();
569     }
570   }
571 }
572 //------------------------------------------------------------------------------