]> Creatis software - clitk.git/blob - vv/vvSlicerManagerCommand.cxx
try to debug camera position bug with large image
[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" || KeyPress == "KP_0") {
115           this->SM->SetPreset(WL_AUTO);
116           this->SM->UpdateWindowLevel();
117           return;
118         }
119         if (KeyPress == "1" || KeyPress == "KP_1") {
120           this->SM->SetPreset(WL_HOUNSFIELD);
121           this->SM->UpdateWindowLevel();
122           return;
123         }
124         if (KeyPress == "2" || KeyPress == "KP_2") {
125           this->SM->SetPreset(WL_SOFTTISSUE);
126           this->SM->UpdateWindowLevel();
127
128           return;
129         }
130         if (KeyPress == "3" || KeyPress == "KP_3") {
131           this->SM->SetPreset(WL_LUNGS);
132           this->SM->UpdateWindowLevel();
133           return;
134         }
135         if (KeyPress == "4" || KeyPress == "KP_4") {
136           this->SM->SetPreset(WL_BONES);
137           this->SM->UpdateWindowLevel();
138           return;
139         }
140         if (KeyPress == "5" || KeyPress == "KP_5") {
141           this->SM->SetPreset(WL_HEAD);
142           this->SM->UpdateWindowLevel();
143           return;
144         }
145         if (KeyPress == "6" || KeyPress == "KP_6") {
146           this->SM->SetColorMap(0);
147           this->SM->UpdateWindowLevel();
148           return;
149         }
150         if (KeyPress == "7" || KeyPress == "KP_7") {
151           this->SM->SetColorMap(1);
152           this->SM->UpdateWindowLevel();
153           return;
154         }
155         if (KeyPress == "8" || KeyPress == "KP_8") {
156           this->SM->SetColorMap(2);
157           this->SM->UpdateWindowLevel();
158           return;
159         }
160         if (KeyPress == "9" || KeyPress == "KP_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       std::cout << "coucou End" << std::endl;
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         double pLand[3]; pLand[0] = xWorld; pLand[1] = yWorld; pLand[2] = zWorld;
386         double ptLand[3];
387         this->SM->GetSlicer(VisibleInWindow)->GetConcatenatedTransform()->TransformPoint(pLand, ptLand);
388         this->SM->AddNewLandmark(ptLand[0],ptLand[1],ptLand[2],
389                               this->SM->GetSlicer(VisibleInWindow)->GetTSlice());
390         this->SM->GetSlicer(VisibleInWindow)->RemoveLandmarks();
391         //this->SM->GetSlicer(VisibleInWindow)->DisplayLandmarks();
392         this->SM->Render();
393       }
394       if (event == vtkCommand::PickEvent || event == vtkCommand::StartPickEvent) {
395       std::cout << "coucou Start" << std::endl;
396         this->SM->Picked();
397         this->SM->UpdateViews(1,VisibleInWindow);
398         this->SM->UpdateLinked(VisibleInWindow);
399         this->SM->ForceUpdateDisplayExtent();
400         this->SM->Render();
401         this->SM->UpdateInfoOnCursorPosition(VisibleInWindow);
402       } else {
403         this->SM->GetSlicer(VisibleInWindow)->Render();
404       }
405       //this->SM->GetSlicer(VisibleInWindow)->SetCurrentPosition(-VTK_DOUBLE_MAX,-VTK_DOUBLE_MAX,
406       //-VTK_DOUBLE_MAX,this->SM->GetSlicer(VisibleInWindow)->GetTSlice());
407       //this->SM->GetSlicer(VisibleInWindow)->Render();
408     }
409
410     if (event == vtkCommand::WindowLevelEvent && mStartSlicer > -1) {
411       this->SM->GetSlicer(mStartSlicer)->SetCornerAnnotationVisibility(1);
412       // Adjust the window level here
413       int *size = isi->GetInteractor()->GetRenderWindow()->GetSize();
414       double window = this->InitialWindow;
415       double level = this->InitialLevel;
416       double range[2];
417       this->SM->GetImage()->GetScalarRange(range);
418
419       // Compute normalized delta
420       double dx = static_cast<double>(isi->GetWindowLevelCurrentPosition()[0] -
421                                       isi->GetWindowLevelStartPosition()[0]) / size[0];
422       double dy = static_cast<double>(isi->GetWindowLevelStartPosition()[1] -
423                                       isi->GetWindowLevelCurrentPosition()[1]) / size[1];
424       //Window is exponential in nature, use exponential to avoid falling into negative numbers
425       dx = std::exp(1.0 * (dx*fabs(dx) + dx)) ; //Quadratic behavior for more reactive interface
426       dy = 0.15 * (dy*fabs(dy) + dy) * (range[1]-range[0]);//Quadratic behavior for more reactive interface
427
428       this->SM->SetColorWindow(window*dx);
429       this->SM->SetColorLevel(level-dy);
430       this->SM->SetPreset(WL_USER);
431       this->SM->Render();
432       this->SM->UpdateWindowLevel();
433       return;
434     }
435   }
436 }
437 //------------------------------------------------------------------------------
438
439
440 //------------------------------------------------------------------------------
441 void vvSlicerManagerCommand::Dolly(double factor, vtkRenderWindowInteractor *interactor)
442 {
443   int VisibleInWindow = this->FindSlicerNumber(interactor->GetRenderWindow());
444   vtkRenderer* renderer;
445   if (VisibleInWindow>-1)
446     renderer=this->SM->GetSlicer(VisibleInWindow)->GetRenderer();
447   else {
448     return;
449   }
450
451   double viewFocus[4],viewPoint[4],motionVector[3], focalDepth;
452   double oldPos[3], newPos[3], distance[2];
453   vtkCamera *camera = renderer->GetActiveCamera();
454   camera->GetFocalPoint(viewFocus);
455
456   renderer->SetWorldPoint(viewFocus[0], viewFocus[0], viewFocus[0], 1.0);
457   renderer->WorldToDisplay();
458   renderer->GetDisplayPoint(viewFocus);
459
460   focalDepth = viewFocus[2];
461
462   oldPos[0] = renderer->GetCenter()[0];
463   oldPos[1] = renderer->GetCenter()[1];
464   oldPos[2] = focalDepth;
465
466   distance[0] = 1/factor*
467                 (interactor->GetEventPosition()[0]-renderer->GetCenter()[0]);
468   distance[1] = 1/factor*
469                 (interactor->GetEventPosition()[1]-renderer->GetCenter()[1]);
470
471   newPos[0] = interactor->GetEventPosition()[0] - distance[0];
472   newPos[1] = interactor->GetEventPosition()[1] - distance[1];
473   newPos[2] = focalDepth;
474
475   renderer->DisplayToNormalizedDisplay(oldPos[0],oldPos[1]);
476   renderer->NormalizedDisplayToViewport(oldPos[0],oldPos[1]);
477   renderer->ViewportToNormalizedViewport(oldPos[0],oldPos[1]);
478   renderer->NormalizedViewportToView(oldPos[0],oldPos[1],oldPos[2]);
479   renderer->ViewToWorld(oldPos[0],oldPos[1],oldPos[2]);
480
481   renderer->DisplayToNormalizedDisplay(newPos[0],newPos[1]);
482   renderer->NormalizedDisplayToViewport(newPos[0],newPos[1]);
483   renderer->ViewportToNormalizedViewport(newPos[0],newPos[1]);
484   renderer->NormalizedViewportToView(newPos[0],newPos[1],newPos[2]);
485   renderer->ViewToWorld(newPos[0],newPos[1],newPos[2]);
486
487   motionVector[0] = newPos[0] - oldPos[0];
488   motionVector[1] = newPos[1] - oldPos[1];
489   motionVector[2] = newPos[2] - oldPos[2];
490
491   camera->GetFocalPoint(viewFocus);
492   camera->GetPosition(viewPoint);
493   camera->SetFocalPoint(motionVector[0] + viewFocus[0],
494                         motionVector[1] + viewFocus[1],
495                         motionVector[2] + viewFocus[2]);
496
497   camera->SetPosition(motionVector[0] + viewPoint[0],
498                       motionVector[1] + viewPoint[1],
499                       motionVector[2] + viewPoint[2]);
500
501   if (camera->GetParallelProjection()) {
502     camera->SetParallelScale(camera->GetParallelScale() / factor);
503   } else {
504     camera->Dolly(factor);
505   }
506
507   if (interactor->GetLightFollowCamera()) {
508     renderer->UpdateLightsGeometryToFollowCamera();
509   }
510   renderer->ResetCameraClippingRange();
511   //interactor->Render();
512 }
513 //------------------------------------------------------------------------------
514
515
516 //------------------------------------------------------------------------------
517 void vvSlicerManagerCommand::FlyToPosition(vtkRenderWindowInteractor *interactor,vvSlicer* slicer)
518 {
519   double flyFrom[3], flyTo[3];
520   double d[3], focalPt[3], position[3], positionFrom[3];
521   int i, j;
522   int VisibleInWindow = this->FindSlicerNumber(interactor->GetRenderWindow());
523   vtkRenderer* renderer=NULL;
524   if (VisibleInWindow>-1)
525     renderer=this->SM->GetSlicer(VisibleInWindow)->GetRenderer();
526   else
527     return;
528
529   interactor->GetPicker()->Pick(interactor->GetEventPosition()[0],
530                                 interactor->GetEventPosition()[1], 0.0,
531                                 renderer);
532
533   vtkAssemblyPath *path=NULL;
534   vtkAbstractPropPicker *picker;
535   if ( (picker=vtkAbstractPropPicker::SafeDownCast(interactor->GetPicker()))) {
536     path = picker->GetPath();
537   }
538   if ( path != NULL ) {
539     flyTo[0] = picker->GetPickPosition()[0];
540     flyTo[1] = picker->GetPickPosition()[1];
541     flyTo[2] = picker->GetPickPosition()[2];
542     renderer->GetActiveCamera()->GetFocalPoint(flyFrom);
543     renderer->GetActiveCamera()->GetPosition(positionFrom);
544
545     switch (slicer->GetSliceOrientation()) {
546     case vtkImageViewer2::SLICE_ORIENTATION_XY:
547       flyTo[2] = flyFrom[2];
548       break;
549
550     case vtkImageViewer2::SLICE_ORIENTATION_XZ:
551       flyTo[1] = flyFrom[1];
552       break;
553
554     case vtkImageViewer2::SLICE_ORIENTATION_YZ:
555       flyTo[0] = flyFrom[0];
556       break;
557     }
558
559
560     for (i=0; i<3; i++) {
561       d[i] = flyTo[i] - flyFrom[i];
562     }
563     double distance = vtkMath::Normalize(d);
564     double delta = distance/15;
565
566     for (i=1; i<=15; i++) {
567       for (j=0; j<3; j++) {
568         focalPt[j] = flyFrom[j] + d[j]*i*delta;
569         position[j] = positionFrom[j] + d[j]*i*delta;
570       }
571       renderer->GetActiveCamera()->SetFocalPoint(focalPt);
572       renderer->GetActiveCamera()->SetPosition(position);
573       renderer->GetActiveCamera()->Dolly(0.3/15 + 1.0);
574       renderer->ResetCameraClippingRange();
575       interactor->Render();
576     }
577   }
578 }
579 //------------------------------------------------------------------------------