]> Creatis software - openheart.git/blob - Applications/vtkMyInteractorStyleTrackballCameraOpenHeart.cxx
d7e031bf28e0f23c1cd27bb75002ae5b057f25a3
[openheart.git] / Applications / vtkMyInteractorStyleTrackballCameraOpenHeart.cxx
1 /**
2 * Progam made by Olivier Bernard, associate professor
3 * at Institut National des Sciences Appliquees (INSA) Lyon,
4 * CREATIS-LRMN Laboratory,
5 * 69621 Villeurbanne, France,
6 * 20th of May 2014
7 */
8
9 #include <vtkRenderer.h>
10 #include <vtkRenderWindow.h>
11 #include "vtkMyInteractorStyleTrackballCameraOpenHeart.h"
12
13
14 using namespace std;
15
16
17 void vtkMyInteractorStyleTrackballCameraOpenHeart::OnChar()
18 {
19     vtkRenderWindowInteractor *rwi = this->Interactor;
20     switch (rwi->GetKeyCode())
21     {
22     case 'f':
23     {
24         int val = this->window->GetCurrentFrame();
25         if ( val < (this->window->GetNumberOfFrames()-1) )
26             this->window->scrollBar->setSliderPosition(val+1);
27         else {
28             this->window->SetFlagLoopEndToBegin(1);
29             this->window->scrollBar->setSliderPosition(0);
30         }
31         break;
32     }
33     case 'b':
34     {
35         int val = this->window->GetCurrentFrame();
36         if ( val > 0 )
37             this->window->scrollBar->setSliderPosition(val-1);
38         else {
39             this->window->SetFlagLoopBeginToEnd(1);
40             this->window->scrollBar->setSliderPosition(this->window->GetNumberOfFrames()-1);
41         }
42         break;
43     }
44     case 'o':
45     {
46         /// Deal with the display of a mask overlayed on the volume data
47         this->window->InterpolationManagement();
48         break;
49     }
50     case 'm':
51     {
52         /// Reset the sphere display
53         this->window->DisplayMeshManagement();
54         break;
55     }
56     case 'd':
57     {
58         /// Set the display mode
59         this->window->DisplayModeManagement();
60         break;
61     }
62     case 'h':
63     {
64         this->window->HidePlanModeManagement();
65         break;
66     }
67     case 'a':
68     {
69         this->window->DisplayMainAxisManagement();
70     }
71     default:
72         cout << "";
73     }
74
75 }
76
77
78 void vtkMyInteractorStyleTrackballCameraOpenHeart::OnMouseWheelForward()
79 {
80
81     switch ( this->window->GetSelectedButton() ) {
82
83     case 1 :
84         this->MoveForwardYZPlan();
85         break;
86
87     case 2:
88
89         this->MoveForwardXZPlan();
90         break;
91
92     case 3:
93
94         this->MoveForwardXYPlan();
95         break;
96
97     default:
98
99         this->MoveForward();
100
101     }
102
103 }
104
105
106 void vtkMyInteractorStyleTrackballCameraOpenHeart::OnMouseWheelBackward()
107 {
108
109     switch ( this->window->GetSelectedButton() )
110     {
111
112         case 1 :
113             this->MoveBackwardYZPlan();
114             break;
115
116         case 2:
117
118             this->MoveBackwardXZPlan();
119             break;
120
121         case 3:
122
123             this->MoveBackwardXYPlan();
124             break;
125
126         default:
127
128             this->MoveBackward();
129
130     }
131
132 }
133
134
135 void vtkMyInteractorStyleTrackballCameraOpenHeart::MoveForward()
136 {
137
138     /// Get picker position
139     double pos[3];
140     this->GetPickerPosition(pos);
141
142     /// Go back to the initial coordinate system before reslicing
143     double posXYZ[3];
144     for (int i=0; i<3; i++)
145         posXYZ[i] = pos[i];
146     this->window->ComputePointBeforeRotation(posXYZ);
147
148     /// Compute point of interest for checking which plan is selected
149     double RefX[3];
150     for (int i=0; i<3; i++)
151         RefX[i] = this->window->GetRendererProperties()->xIPW->GetCenter()[i];
152     this->window->ComputePointBeforeRotation(RefX);
153     double RefY[3];
154     for (int i=0; i<3; i++)
155         RefY[i] = this->window->GetRendererProperties()->yIPW->GetCenter()[i];
156     this->window->ComputePointBeforeRotation(RefY);
157     double RefZ[3];
158     for (int i=0; i<3; i++)
159         RefZ[i] = this->window->GetRendererProperties()->zIPW->GetCenter()[i];
160     this->window->ComputePointBeforeRotation(RefZ);
161
162     /// Update Slice image
163     if ( this->IsInside(posXYZ) )
164     {
165
166         if ( fabs(posXYZ[0]-RefX[0]) < this->PadSliceDetection[0] )
167         {
168
169             /// Compute corresponding step
170             if ( (posXYZ[1] >= this->Limits[2] ) &&
171                  (posXYZ[1] <= this->Limits[3] ) &&
172                  (posXYZ[2] >= this->Limits[4] ) &&
173                  (posXYZ[2] <= this->Limits[5] ) )
174                 this->Step = 1;
175             else
176                 this->Step = 5;
177
178             /// Compute new slice position
179             double limit = this->Bounds[1];
180             posXYZ[0] += this->Step * this->SpacingImg[0];
181             if ( posXYZ[0] <= limit )
182                 this->window->GetRendererProperties()->position[0] += this->Step * this->SpacingImg[0];
183
184             /// Update Slice text
185             if ( this->window->GetFlagDisplayText() )
186             {
187                 int slice = (int)( (this->window->GetRendererProperties()->position[0] -
188                                     this->OriginImg[0]) /
189                                     this->SpacingImg[0] + 0.5f );
190                 QString strSlice;
191                 strSlice.sprintf("Slice: %d",slice);
192                 this->window->GetRendererProperties()->TextMapperSlice->SetInput(strSlice.toStdString().c_str());
193             }
194
195             /// Update renderers
196             this->window->GetRendererProperties()->xIPW->SetSlicePosition(this->window->GetRendererProperties()->position[0]);
197             this->window->GetRendererProperties()->yzIPW->SetSlicePosition(this->window->GetRendererProperties()->position[0]);
198             this->window->GetRenderWindow()->Render();
199             this->window->GetYZRenderer()->ResetCameraClippingRange();
200             this->window->GetRenderWindowYZ()->Render();
201         }
202
203         if ( fabs(posXYZ[1]-RefY[1]) < this->PadSliceDetection[1] )
204         {
205
206             /// Compute corresponding step
207             if ( (posXYZ[0] >= this->Limits[0] ) &&
208                  (posXYZ[0] <= this->Limits[1] ) &&
209                  (posXYZ[2] >= this->Limits[4] ) &&
210                  (posXYZ[2] <= this->Limits[5] ) )
211                 this->Step = 1;
212             else
213                 this->Step = 5;
214
215             /// Compute new slice position
216             double limit = this->Bounds[3];
217             posXYZ[1] += this->Step * this->SpacingImg[1];
218             if ( posXYZ[1] <= limit )
219                 this->window->GetRendererProperties()->position[1] += this->Step * this->SpacingImg[1];
220
221             /// Update Slice text
222             if ( this->window->GetFlagDisplayText() )
223             {
224                 int slice = (int)( (this->window->GetRendererProperties()->position[1] -
225                                     this->OriginImg[1]) /
226                                     this->SpacingImg[1] + 0.5f );
227                 QString strSlice;
228                 strSlice.sprintf("Slice: %d",slice);
229                 this->window->GetRendererProperties()->TextMapperSlice->SetInput(strSlice.toStdString().c_str());
230             }
231
232             /// Update renderers
233             this->window->GetRendererProperties()->yIPW->SetSlicePosition(this->window->GetRendererProperties()->position[1]);
234             this->window->GetRendererProperties()->xzIPW->SetSlicePosition(this->window->GetRendererProperties()->position[1]);
235             this->window->GetRenderWindow()->Render();
236             this->window->GetXZRenderer()->ResetCameraClippingRange();
237             this->window->GetRenderWindowXZ()->Render();
238         }
239
240         if ( fabs(posXYZ[2]-RefZ[2]) < this->PadSliceDetection[2] )
241         {
242
243             /// Compute corresponding step
244             if ( (posXYZ[0] >= this->Limits[0] ) &&
245                  (posXYZ[0] <= this->Limits[1] ) &&
246                  (posXYZ[1] >= this->Limits[2] ) &&
247                  (posXYZ[1] <= this->Limits[3] ) )
248                 this->Step = 1;
249             else
250                 this->Step = 5;
251
252             /// Compute new slice position
253             double limit = this->Bounds[5];
254             posXYZ[2] += this->Step * this->SpacingImg[2];
255             if ( posXYZ[2] <= limit )
256                 this->window->GetRendererProperties()->position[2] += this->Step * this->SpacingImg[2];
257
258             /// Update Slice text
259             if ( this->window->GetFlagDisplayText() )
260             {
261                 int slice = (int)( (this->window->GetRendererProperties()->position[2] -
262                                     this->OriginImg[2]) /
263                                     this->SpacingImg[2] + 0.5f );
264                 QString strSlice;
265                 strSlice.sprintf("Slice: %d",slice);
266                 this->window->GetRendererProperties()->TextMapperSlice->SetInput(strSlice.toStdString().c_str());
267             }
268
269             /// Update renderers
270             this->window->GetRendererProperties()->zIPW->SetSlicePosition(this->window->GetRendererProperties()->position[2]);
271             this->window->GetRendererProperties()->xyIPW->SetSlicePosition(this->window->GetRendererProperties()->position[2]);
272             this->window->GetRenderWindow()->Render();
273             this->window->GetXYRenderer()->ResetCameraClippingRange();
274             this->window->GetRenderWindowXY()->Render();
275         }
276
277     }
278
279     /// Update text display
280     this->window->UpdateCoords(pos);
281
282 }
283
284
285 void vtkMyInteractorStyleTrackballCameraOpenHeart::MoveForwardXYPlan()
286 {
287
288     /// Get picker position
289     double pos[3];
290     this->GetPickerPosition(pos);
291
292     /// Go back to the initial coordinate system before reslicing
293     double posXYZ[3];
294     for (int i=0; i<3; i++)
295         posXYZ[i] = pos[i];
296     this->window->ComputePointBeforeRotation(posXYZ);
297
298     /// Update Slice image
299     if ( this->IsInside(posXYZ) )
300     {
301         /// Compute corresponding step
302         if ( (posXYZ[0] >= this->Limits[0] ) &&
303              (posXYZ[0] <= this->Limits[1] ) &&
304              (posXYZ[1] >= this->Limits[2] ) &&
305              (posXYZ[1] <= this->Limits[3] ) )
306             this->Step = 1;
307         else
308             this->Step = 5;
309
310         /// Compute new slice position
311         double limit = this->Bounds[5];
312         posXYZ[2] += this->Step * this->window->GetCurrentImageData()->GetSpacing()[2];
313         if ( posXYZ[2] <= limit )
314             this->window->GetRendererProperties()->position[2] += this->Step * this->window->GetCurrentImageData()->GetSpacing()[2];
315
316         /// Update Slice text
317         if ( this->window->GetFlagDisplayText() )
318         {
319             int slice = (int)( (this->window->GetRendererProperties()->position[2] -
320                                 this->window->GetCurrentImageData()->GetOrigin()[2]) /
321                                 this->window->GetCurrentImageData()->GetSpacing()[2] + 0.5f );
322             QString strSlice;
323             strSlice.sprintf("Slice: %d",slice);
324             this->window->GetRendererProperties()->TextMapperSlice->SetInput(strSlice.toStdString().c_str());
325         }
326
327         /// Update renderers
328         this->window->GetRendererProperties()->zIPW->SetSlicePosition(this->window->GetRendererProperties()->position[2]);
329         this->window->GetRendererProperties()->xyIPW->SetSlicePosition(this->window->GetRendererProperties()->position[2]);
330         this->window->GetRenderWindow()->Render();
331         this->window->GetXYRenderer()->ResetCameraClippingRange();
332         this->window->GetRenderWindowXY()->Render();
333
334     }
335
336 }
337
338
339 void vtkMyInteractorStyleTrackballCameraOpenHeart::MoveForwardXZPlan()
340 {
341
342     /// Get picker position
343     double pos[3];
344     this->GetPickerPosition(pos);
345
346     /// Go back to the initial coordinate system before reslicing
347     double posXYZ[3];
348     for (int i=0; i<3; i++)
349         posXYZ[i] = pos[i];
350     this->window->ComputePointBeforeRotation(posXYZ);
351
352     /// Update Slice image
353     if ( this->IsInside(posXYZ) )
354     {
355         /// Compute corresponding step
356         if ( (posXYZ[0] >= this->Limits[0] ) &&
357              (posXYZ[0] <= this->Limits[1] ) &&
358              (posXYZ[2] >= this->Limits[4] ) &&
359              (posXYZ[2] <= this->Limits[5] ) )
360             this->Step = 1;
361         else
362             this->Step = 5;
363
364         /// Compute new slice position
365         double limit = this->Bounds[3];
366         posXYZ[1] += this->Step * this->window->GetCurrentImageData()->GetSpacing()[1];
367         if ( posXYZ[1] <= limit )
368             this->window->GetRendererProperties()->position[1] += this->Step * this->window->GetCurrentImageData()->GetSpacing()[1];
369
370         /// Update Slice text
371         if ( this->window->GetFlagDisplayText() )
372         {
373             int slice = (int)( (this->window->GetRendererProperties()->position[1] -
374                                 this->window->GetCurrentImageData()->GetOrigin()[1]) /
375                                 this->window->GetCurrentImageData()->GetSpacing()[1] + 0.5f );
376             QString strSlice;
377             strSlice.sprintf("Slice: %d",slice);
378             this->window->GetRendererProperties()->TextMapperSlice->SetInput(strSlice.toStdString().c_str());
379         }
380
381         /// Update renderers
382         this->window->GetRendererProperties()->yIPW->SetSlicePosition(this->window->GetRendererProperties()->position[1]);
383         this->window->GetRendererProperties()->xzIPW->SetSlicePosition(this->window->GetRendererProperties()->position[1]);
384         this->window->GetRenderWindow()->Render();
385         this->window->GetXZRenderer()->ResetCameraClippingRange();
386         this->window->GetRenderWindowXZ()->Render();
387
388     }
389
390 }
391
392
393 void vtkMyInteractorStyleTrackballCameraOpenHeart::MoveForwardYZPlan()
394 {
395
396     /// Get picker position
397     double pos[3];
398     this->GetPickerPosition(pos);
399
400     /// Go back to the initial coordinate system before reslicing
401     double posXYZ[3];
402     for (int i=0; i<3; i++)
403         posXYZ[i] = pos[i];
404     this->window->ComputePointBeforeRotation(posXYZ);
405
406     /// Update Slice image
407     if ( this->IsInside(posXYZ) )
408     {
409         /// Compute corresponding step
410         if ( (posXYZ[1] >= this->Limits[2] ) &&
411              (posXYZ[1] <= this->Limits[3] ) &&
412              (posXYZ[2] >= this->Limits[4] ) &&
413              (posXYZ[2] <= this->Limits[5] ) )
414             this->Step = 1;
415         else
416             this->Step = 5;
417
418         /// Compute new slice position
419         double limit = this->Bounds[1];
420         posXYZ[0] += this->Step * this->window->GetCurrentImageData()->GetSpacing()[0];
421         if ( posXYZ[0] <= limit )
422             this->window->GetRendererProperties()->position[0] += this->Step * this->window->GetCurrentImageData()->GetSpacing()[0];
423
424         /// Update Slice text
425         if ( this->window->GetFlagDisplayText() )
426         {
427             int slice = (int)( (this->window->GetRendererProperties()->position[0] -
428                                 this->window->GetCurrentImageData()->GetOrigin()[0]) /
429                                 this->window->GetCurrentImageData()->GetSpacing()[0] + 0.5f );
430             QString strSlice;
431             strSlice.sprintf("Slice: %d",slice);
432             this->window->GetRendererProperties()->TextMapperSlice->SetInput(strSlice.toStdString().c_str());
433         }
434
435         /// Update renderers
436         this->window->GetRendererProperties()->xIPW->SetSlicePosition(this->window->GetRendererProperties()->position[0]);
437         this->window->GetRendererProperties()->yzIPW->SetSlicePosition(this->window->GetRendererProperties()->position[0]);
438         this->window->GetRenderWindow()->Render();
439         this->window->GetYZRenderer()->ResetCameraClippingRange();
440         this->window->GetRenderWindowYZ()->Render();
441
442     }
443
444 }
445
446
447 void vtkMyInteractorStyleTrackballCameraOpenHeart::MoveBackwardXYPlan()
448 {
449
450     /// Get picker position
451     double pos[3];
452     this->GetPickerPosition(pos);
453
454     /// Go back to the initial coordinate system before reslicing
455     double posXYZ[3];
456     for (int i=0; i<3; i++)
457         posXYZ[i] = pos[i];
458     this->window->ComputePointBeforeRotation(posXYZ);
459
460     /// Update Slice image
461     if ( this->IsInside(posXYZ) )
462     {
463         /// Compute corresponding step
464         if ( (posXYZ[0] >= this->Limits[0] ) &&
465              (posXYZ[0] <= this->Limits[1] ) &&
466              (posXYZ[1] >= this->Limits[2] ) &&
467              (posXYZ[1] <= this->Limits[3] ) )
468             this->Step = 1;
469         else
470             this->Step = 5;
471
472         /// Compute new slice position
473         posXYZ[2] -= this->Step * this->window->GetCurrentImageData()->GetSpacing()[2];
474         if ( posXYZ[2] >= 0 )
475             this->window->GetRendererProperties()->position[2] -= this->Step * this->window->GetCurrentImageData()->GetSpacing()[2];
476
477         /// Update Slice text
478         if ( this->window->GetFlagDisplayText() )
479         {
480             int slice = (int)( (this->window->GetRendererProperties()->position[2] -
481                                 this->window->GetCurrentImageData()->GetOrigin()[2]) /
482                                 this->window->GetCurrentImageData()->GetSpacing()[2] + 0.5f );
483             QString strSlice;
484             strSlice.sprintf("Slice: %d",slice);
485             this->window->GetRendererProperties()->TextMapperSlice->SetInput(strSlice.toStdString().c_str());
486         }
487
488         /// Update renderers
489         this->window->GetRendererProperties()->zIPW->SetSlicePosition(this->window->GetRendererProperties()->position[2]);
490         this->window->GetRendererProperties()->xyIPW->SetSlicePosition(this->window->GetRendererProperties()->position[2]);
491         this->window->GetRenderWindow()->Render();
492         this->window->GetXYRenderer()->ResetCameraClippingRange();
493         this->window->GetRenderWindowXY()->Render();
494
495     }
496
497 }
498
499
500 void vtkMyInteractorStyleTrackballCameraOpenHeart::MoveBackwardXZPlan()
501 {
502
503     /// Get picker position
504     double pos[3];
505     this->GetPickerPosition(pos);
506
507     /// Go back to the initial coordinate system before reslicing
508     double posXYZ[3];
509     for (int i=0; i<3; i++)
510         posXYZ[i] = pos[i];
511     this->window->ComputePointBeforeRotation(posXYZ);
512
513     /// Update Slice image
514     if ( this->IsInside(posXYZ) )
515     {
516         /// Compute corresponding step
517         if ( (posXYZ[0] >= this->Limits[0] ) &&
518              (posXYZ[0] <= this->Limits[1] ) &&
519              (posXYZ[2] >= this->Limits[4] ) &&
520              (posXYZ[2] <= this->Limits[5] ) )
521             this->Step = 1;
522         else
523             this->Step = 5;
524
525         /// Compute new slice position
526         posXYZ[1] -= this->Step * this->window->GetCurrentImageData()->GetSpacing()[1];
527         if ( posXYZ[1] >= 0 )
528             this->window->GetRendererProperties()->position[1] -= this->Step * this->window->GetCurrentImageData()->GetSpacing()[1];
529
530         /// Update Slice text
531         if ( this->window->GetFlagDisplayText() )
532         {
533             int slice = (int)( (this->window->GetRendererProperties()->position[1] -
534                                 this->window->GetCurrentImageData()->GetOrigin()[1]) /
535                                 this->window->GetCurrentImageData()->GetSpacing()[1] + 0.5f );
536             QString strSlice;
537             strSlice.sprintf("Slice: %d",slice);
538             this->window->GetRendererProperties()->TextMapperSlice->SetInput(strSlice.toStdString().c_str());
539         }
540
541         /// Update renderers
542         this->window->GetRendererProperties()->yIPW->SetSlicePosition(this->window->GetRendererProperties()->position[1]);
543         this->window->GetRendererProperties()->xzIPW->SetSlicePosition(this->window->GetRendererProperties()->position[1]);
544         this->window->GetRenderWindow()->Render();
545         this->window->GetXZRenderer()->ResetCameraClippingRange();
546         this->window->GetRenderWindowXZ()->Render();
547
548     }
549
550 }
551
552
553 void vtkMyInteractorStyleTrackballCameraOpenHeart::MoveBackwardYZPlan()
554 {
555
556     /// Get picker position
557     double pos[3];
558     this->GetPickerPosition(pos);
559
560     /// Go back to the initial coordinate system before reslicing
561     double posXYZ[3];
562     for (int i=0; i<3; i++)
563         posXYZ[i] = pos[i];
564     this->window->ComputePointBeforeRotation(posXYZ);
565
566     /// Update Slice image
567     if ( this->IsInside(posXYZ) )
568     {
569         /// Compute corresponding step
570         if ( (posXYZ[1] >= this->Limits[2] ) &&
571              (posXYZ[1] <= this->Limits[3] ) &&
572              (posXYZ[2] >= this->Limits[4] ) &&
573              (posXYZ[2] <= this->Limits[5] ) )
574             this->Step = 1;
575         else
576             this->Step = 5;
577
578         /// Compute new slice position
579         posXYZ[0] -= this->Step * this->window->GetCurrentImageData()->GetSpacing()[0];
580         if ( posXYZ[0] >= 0 )
581             this->window->GetRendererProperties()->position[0] -= this->Step * this->window->GetCurrentImageData()->GetSpacing()[0];
582
583         /// Update Slice text
584         if ( this->window->GetFlagDisplayText() )
585         {
586             int slice = (int)( (this->window->GetRendererProperties()->position[0] -
587                                 this->window->GetCurrentImageData()->GetOrigin()[0]) /
588                                 this->window->GetCurrentImageData()->GetSpacing()[0] + 0.5f );
589             QString strSlice;
590             strSlice.sprintf("Slice: %d",slice);
591             this->window->GetRendererProperties()->TextMapperSlice->SetInput(strSlice.toStdString().c_str());
592         }
593
594         /// Update renderers
595         this->window->GetRendererProperties()->xIPW->SetSlicePosition(this->window->GetRendererProperties()->position[0]);
596         this->window->GetRendererProperties()->yzIPW->SetSlicePosition(this->window->GetRendererProperties()->position[0]);
597         this->window->GetRenderWindow()->Render();
598         this->window->GetYZRenderer()->ResetCameraClippingRange();
599         this->window->GetRenderWindowYZ()->Render();
600
601     }
602
603 }
604
605
606 void vtkMyInteractorStyleTrackballCameraOpenHeart::MoveBackward()
607 {
608
609     /// Get picker position
610     double pos[3];
611     this->GetPickerPosition(pos);
612
613     /// Go back to the initial coordinate system before reslicing
614     double posXYZ[3];
615     for (int i=0; i<3; i++)
616         posXYZ[i] = pos[i];
617     this->window->ComputePointBeforeRotation(posXYZ);
618
619     /// Compute point of interest for checking which plan is selected
620     double RefX[3];
621     for (int i=0; i<3; i++)
622         RefX[i] = this->window->GetRendererProperties()->xIPW->GetCenter()[i];
623     this->window->ComputePointBeforeRotation(RefX);
624     double RefY[3];
625     for (int i=0; i<3; i++)
626         RefY[i] = this->window->GetRendererProperties()->yIPW->GetCenter()[i];
627     this->window->ComputePointBeforeRotation(RefY);
628     double RefZ[3];
629     for (int i=0; i<3; i++)
630         RefZ[i] = this->window->GetRendererProperties()->zIPW->GetCenter()[i];
631     this->window->ComputePointBeforeRotation(RefZ);
632
633     /// Update Slice image
634     if ( this->IsInside(posXYZ) )
635     {
636
637         if ( fabs(posXYZ[0]-RefX[0]) < this->PadSliceDetection[0] )
638         {
639
640             /// Compute corresponding step
641             if ( (posXYZ[1] >= this->Limits[2] ) &&
642                  (posXYZ[1] <= this->Limits[3] ) &&
643                  (posXYZ[2] >= this->Limits[4] ) &&
644                  (posXYZ[2] <= this->Limits[5] ) )
645                 this->Step = 1;
646             else
647                 this->Step = 5;
648
649             /// Compute new slice position
650             posXYZ[0] -= this->Step * this->SpacingImg[0];
651             if ( posXYZ[0] >= 0 )
652                 this->window->GetRendererProperties()->position[0] -= this->Step * this->SpacingImg[0];
653
654             /// Update Slice text
655             if ( this->window->GetFlagDisplayText() )
656             {
657                 int slice = (int)( (this->window->GetRendererProperties()->position[0] -
658                                     this->OriginImg[0]) /
659                                     this->SpacingImg[0] + 0.5f );
660                 QString strSlice;
661                 strSlice.sprintf("Slice: %d",slice);
662                 this->window->GetRendererProperties()->TextMapperSlice->SetInput(strSlice.toStdString().c_str());
663             }
664
665             /// Update renderers
666             this->window->GetRendererProperties()->xIPW->SetSlicePosition(this->window->GetRendererProperties()->position[0]);
667             this->window->GetRendererProperties()->yzIPW->SetSlicePosition(this->window->GetRendererProperties()->position[0]);
668             this->window->GetRenderWindow()->Render();
669             this->window->GetYZRenderer()->ResetCameraClippingRange();
670             this->window->GetRenderWindowYZ()->Render();
671         }
672
673         if ( fabs(posXYZ[1]-RefY[1]) < this->PadSliceDetection[1] )
674         {
675
676             /// Compute corresponding step
677             if ( (posXYZ[0] >= this->Limits[0] ) &&
678                  (posXYZ[0] <= this->Limits[1] ) &&
679                  (posXYZ[2] >= this->Limits[4] ) &&
680                  (posXYZ[2] <= this->Limits[5] ) )
681                 this->Step = 1;
682             else
683                 this->Step = 5;
684
685             /// Compute new slice position
686             posXYZ[1] -= this->Step * this->SpacingImg[1];
687             if ( posXYZ[1] >= 0 )
688                 this->window->GetRendererProperties()->position[1] -= this->Step * this->SpacingImg[1];
689
690             /// Update Slice text
691             if ( this->window->GetFlagDisplayText() )
692             {
693                 int slice = (int)( (this->window->GetRendererProperties()->position[1] -
694                                     this->OriginImg[1]) /
695                                     this->SpacingImg[1] + 0.5f );
696                 QString strSlice;
697                 strSlice.sprintf("Slice: %d",slice);
698                 this->window->GetRendererProperties()->TextMapperSlice->SetInput(strSlice.toStdString().c_str());
699             }
700
701             /// Update renderers
702             this->window->GetRendererProperties()->yIPW->SetSlicePosition(this->window->GetRendererProperties()->position[1]);
703             this->window->GetRendererProperties()->xzIPW->SetSlicePosition(this->window->GetRendererProperties()->position[1]);
704             this->window->GetRenderWindow()->Render();
705             this->window->GetXZRenderer()->ResetCameraClippingRange();
706             this->window->GetRenderWindowXZ()->Render();
707         }
708
709         if ( fabs(posXYZ[2]-RefZ[2]) < this->PadSliceDetection[2] )
710         {
711
712             /// Compute corresponding step
713             if ( (posXYZ[0] >= this->Limits[0] ) &&
714                  (posXYZ[0] <= this->Limits[1] ) &&
715                  (posXYZ[1] >= this->Limits[2] ) &&
716                  (posXYZ[1] <= this->Limits[3] ) )
717                 this->Step = 1;
718             else
719                 this->Step = 5;
720
721             /// Compute new slice position
722             posXYZ[2] -= this->Step * this->SpacingImg[2];
723             if ( posXYZ[2] >= 0 )
724                 this->window->GetRendererProperties()->position[2] -= this->Step * this->SpacingImg[2];
725
726             /// Update Slice text
727             if ( this->window->GetFlagDisplayText() )
728             {
729                 int slice = (int)( (this->window->GetRendererProperties()->position[2] -
730                                     this->OriginImg[2]) /
731                                     this->SpacingImg[2] + 0.5f );
732                 QString strSlice;
733                 strSlice.sprintf("Slice: %d",slice);
734                 this->window->GetRendererProperties()->TextMapperSlice->SetInput(strSlice.toStdString().c_str());
735             }
736
737             /// Update renderers
738             this->window->GetRendererProperties()->zIPW->SetSlicePosition(this->window->GetRendererProperties()->position[2]);
739             this->window->GetRendererProperties()->xyIPW->SetSlicePosition(this->window->GetRendererProperties()->position[2]);
740             this->window->GetRenderWindow()->Render();
741             this->window->GetXYRenderer()->ResetCameraClippingRange();
742             this->window->GetRenderWindowXY()->Render();
743         }
744
745         /// Update text display
746         this->window->UpdateCoords(this->window->GetRendererProperties()->position);
747
748     }
749
750 }
751
752
753 void vtkMyInteractorStyleTrackballCameraOpenHeart::OnEnter()
754 {
755
756     if ( !this->FlagFirstTime )
757     {
758
759         /// Set flag to 1 to never enter again in this part of the code
760         this->FlagFirstTime = 1;
761         double extend[6];
762         this->window->GetCurrentImageData()->GetWholeBoundingBox(extend);
763
764         /// Save the boundary of the volume in world coordinates
765         this->Bounds[0] = this->window->GetCurrentImageData()->GetExtent()[0] * this->window->GetCurrentImageData()->GetSpacing()[0] +
766                 this->window->GetCurrentImageData()->GetOrigin()[0];
767         this->Bounds[1] = this->window->GetCurrentImageData()->GetExtent()[1] * this->window->GetCurrentImageData()->GetSpacing()[0] +
768                 this->window->GetCurrentImageData()->GetOrigin()[0];
769         this->Bounds[2] = this->window->GetCurrentImageData()->GetExtent()[2] * this->window->GetCurrentImageData()->GetSpacing()[1] +
770                 this->window->GetCurrentImageData()->GetOrigin()[1];
771         this->Bounds[3] = this->window->GetCurrentImageData()->GetExtent()[3] * this->window->GetCurrentImageData()->GetSpacing()[1] +
772                 this->window->GetCurrentImageData()->GetOrigin()[1];
773         this->Bounds[4] = this->window->GetCurrentImageData()->GetExtent()[4] * this->window->GetCurrentImageData()->GetSpacing()[2] +
774                 this->window->GetCurrentImageData()->GetOrigin()[2];
775         this->Bounds[5] = this->window->GetCurrentImageData()->GetExtent()[5] * this->window->GetCurrentImageData()->GetSpacing()[2] +
776                 this->window->GetCurrentImageData()->GetOrigin()[2];
777
778         /// Save the limit of the box to increase the scolling effect
779         this->Limits[0] = (this->Bounds[1] - this->Bounds[0]) * this->PadBound;
780         this->Limits[1] = this->Bounds[1] - (this->Bounds[1] - this->Bounds[0]) * this->PadBound;
781         this->Limits[2] = (this->Bounds[3] - this->Bounds[2]) * this->PadBound;
782         this->Limits[3] = this->Bounds[3] - (this->Bounds[3] - this->Bounds[2]) * this->PadBound;
783         this->Limits[4] = (this->Bounds[5] - this->Bounds[4]) * this->PadBound;
784         this->Limits[5] = this->Bounds[5] - (this->Bounds[5] - this->Bounds[4]) * this->PadBound;
785
786         /// Save usefull information
787         for ( int i=0; i<3; i++)
788         {
789             this->SpacingImg[i] = this->window->GetCurrentImageData()->GetSpacing()[i];
790             this->OriginImg[i] = this->window->GetCurrentImageData()->GetOrigin()[i];
791             this->LimitImg[i] = this->OriginImg[i] + (this->window->GetDimensions()[i]-1) *
792                     this->SpacingImg[i];
793             this->PadSliceDetection[i] = 0.01 * this->SpacingImg[i];
794         }
795
796     }
797
798     vtkInteractorStyleTrackballCamera::OnEnter();
799
800 }
801
802
803 void vtkMyInteractorStyleTrackballCameraOpenHeart::OnLeave()
804 {
805     this->Step = 1;
806     vtkInteractorStyleTrackballCamera::OnLeave();
807 }
808
809
810 void vtkMyInteractorStyleTrackballCameraOpenHeart::OnLeftButtonDown()
811 {
812     this->FlagLeftClick = true;
813     if ( this->window->GetSelectedButton() == 0 )
814     {
815         this->window->GetMainRenderer()->AddActor(this->window->GetRendererProperties()->BoundingBoxActor);
816         this->window->GetRenderWindow()->Render();
817     }
818     vtkInteractorStyleTrackballCamera::OnLeftButtonDown();
819 }
820
821
822 void vtkMyInteractorStyleTrackballCameraOpenHeart::OnLeftButtonUp()
823 {
824     this->FlagLeftClick = false;
825     if ( this->window->GetSelectedButton() == 0 ) {
826         this->window->GetMainRenderer()->RemoveActor(this->window->GetRendererProperties()->BoundingBoxActor);
827         this->window->GetRenderWindow()->Render();
828     }
829     vtkInteractorStyleTrackballCamera::OnLeftButtonUp();
830 }
831
832
833 void vtkMyInteractorStyleTrackballCameraOpenHeart::GetPickerPosition(double *pos)
834 {
835     int X = this->Interactor->GetEventPosition()[0];
836     int Y = this->Interactor->GetEventPosition()[1];
837     this->window->GetPicker()->Pick(X,Y,0.0,this->window->GetMainRenderer());
838     this->window->GetPicker()->GetPickPosition(pos);
839 }
840
841
842 bool vtkMyInteractorStyleTrackballCameraOpenHeart::IsInside(double *pos)
843 {
844     if ( (pos[0]>=this->Bounds[0]) && (pos[0]<=this->Bounds[1]) &&
845          (pos[1]>=this->Bounds[2]) && (pos[1]<=this->Bounds[3]) &&
846          (pos[2]>=this->Bounds[4]) && (pos[2]<=this->Bounds[5]) )
847         return true;
848     else
849         return false;
850 }
851
852