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