]> Creatis software - openheart.git/blob - Applications/vtkMyInteractorStyleTrackballCameraOpenHeartXZ.cxx
03148acc94803c2e302afb5c6093aade60811f0a
[openheart.git] / Applications / vtkMyInteractorStyleTrackballCameraOpenHeartXZ.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 "vtkMyInteractorStyleTrackballCameraOpenHeartXZ.h"
12
13
14 using namespace std;
15
16
17 void vtkMyInteractorStyleTrackballCameraOpenHeartXZ::OnMouseWheelForward()
18 {
19
20     /// Get picker position
21     double pos[3];
22     this->GetPickerPosition(pos);
23
24     /// Go back to the initial coordinate system before reslicing
25     double posXYZ[3];
26     for (int i=0; i<3; i++)
27         posXYZ[i] = pos[i];
28     this->window->ComputePointBeforeRotation(posXYZ);
29
30     /// Update Slice image
31     if ( this->IsInside(posXYZ) )
32     {
33         /// Compute corresponding step
34         if ( (posXYZ[0] >= this->Limits[0] ) &&
35              (posXYZ[0] <= this->Limits[1] ) &&
36              (posXYZ[2] >= this->Limits[2] ) &&
37              (posXYZ[2] <= this->Limits[3] ) )
38             this->Step = 1;
39         else
40             this->Step = 5;
41
42         /// Compute new slice position
43         double limit = this->Bounds[3];
44         posXYZ[1] += this->Step * this->window->GetCurrentImageData()->GetSpacing()[1];
45         if ( posXYZ[1] <= limit )
46             this->window->GetRendererProperties()->position[1] += this->Step * this->window->GetCurrentImageData()->GetSpacing()[1];
47
48         /// Update Slice text
49         if ( this->window->GetFlagDisplayText() )
50         {
51             int slice = (int)( (this->window->GetRendererProperties()->position[1] -
52                                 this->window->GetCurrentImageData()->GetOrigin()[1]) /
53                                 this->window->GetCurrentImageData()->GetSpacing()[1] + 0.5f );
54             QString strSlice;
55             strSlice.sprintf("Slice: %d",slice);
56             this->window->GetRendererProperties()->TextMapperSlice->SetInput(strSlice.toStdString().c_str());
57         }
58
59         /// Update renderers
60         this->window->GetRendererProperties()->yIPW->SetSlicePosition(this->window->GetRendererProperties()->position[1]);
61         this->window->GetRendererProperties()->xzIPW->SetSlicePosition(this->window->GetRendererProperties()->position[1]);
62         this->window->GetRenderWindow()->Render();
63         this->window->GetXZRenderer()->ResetCameraClippingRange();
64         this->window->GetRenderWindowXZ()->Render();
65     }
66
67 }
68
69
70 void vtkMyInteractorStyleTrackballCameraOpenHeartXZ::OnMouseWheelBackward()
71 {
72
73     /// Get picker position
74     double pos[3];
75     this->GetPickerPosition(pos);
76
77     /// Go back to the initial coordinate system before reslicing
78     double posXYZ[3];
79     for (int i=0; i<3; i++)
80         posXYZ[i] = pos[i];
81     this->window->ComputePointBeforeRotation(posXYZ);
82
83     /// Update Slice image
84     if ( this->IsInside(posXYZ) )
85     {
86         /// Compute corresponding step
87         if ( (posXYZ[0] >= this->Limits[0] ) &&
88              (posXYZ[0] <= this->Limits[1] ) &&
89              (posXYZ[2] >= this->Limits[2] ) &&
90              (posXYZ[2] <= this->Limits[3] ) )
91             this->Step = 1;
92         else
93             this->Step = 5;
94
95         /// Compute new slice position
96         posXYZ[1] -= this->Step * this->window->GetCurrentImageData()->GetSpacing()[1];
97         if ( posXYZ[1] >= 0 )
98             this->window->GetRendererProperties()->position[1] -= this->Step * this->window->GetCurrentImageData()->GetSpacing()[1];
99
100         /// Update Slice text
101         if ( this->window->GetFlagDisplayText() )
102         {
103             int slice = (int)( (this->window->GetRendererProperties()->position[1] -
104                                 this->window->GetCurrentImageData()->GetOrigin()[1]) /
105                                 this->window->GetCurrentImageData()->GetSpacing()[1] + 0.5f );
106             QString strSlice;
107             strSlice.sprintf("Slice: %d",slice);
108             this->window->GetRendererProperties()->TextMapperSlice->SetInput(strSlice.toStdString().c_str());
109         }
110
111         /// Update renderers
112         this->window->GetRendererProperties()->yIPW->SetSlicePosition(this->window->GetRendererProperties()->position[1]);
113         this->window->GetRendererProperties()->xzIPW->SetSlicePosition(this->window->GetRendererProperties()->position[1]);
114         this->window->GetRenderWindow()->Render();
115         this->window->GetXZRenderer()->ResetCameraClippingRange();
116         this->window->GetRenderWindowXZ()->Render();
117     }
118
119 }
120
121
122 void vtkMyInteractorStyleTrackballCameraOpenHeartXZ::OnEnter()
123 {
124
125     if ( !this->FlagFirstTime )
126     {
127
128         /// Set flag to 1 to never enter again in this part of the code
129         this->FlagFirstTime = 1;
130         double extend[6];
131         this->window->GetCurrentImageData()->GetWholeBoundingBox(extend);
132
133         /// Save the boundary of the volume in world coordinates
134         this->Bounds[0] = this->window->GetCurrentImageData()->GetExtent()[0] * this->window->GetCurrentImageData()->GetSpacing()[0] +
135                 this->window->GetCurrentImageData()->GetOrigin()[0];
136         this->Bounds[1] = this->window->GetCurrentImageData()->GetExtent()[1] * this->window->GetCurrentImageData()->GetSpacing()[0] +
137                 this->window->GetCurrentImageData()->GetOrigin()[0];
138         this->Bounds[2] = this->window->GetCurrentImageData()->GetExtent()[2] * this->window->GetCurrentImageData()->GetSpacing()[1] +
139                 this->window->GetCurrentImageData()->GetOrigin()[1];
140         this->Bounds[3] = this->window->GetCurrentImageData()->GetExtent()[3] * this->window->GetCurrentImageData()->GetSpacing()[1] +
141                 this->window->GetCurrentImageData()->GetOrigin()[1];
142         this->Bounds[4] = this->window->GetCurrentImageData()->GetExtent()[4] * this->window->GetCurrentImageData()->GetSpacing()[2] +
143                 this->window->GetCurrentImageData()->GetOrigin()[2];
144         this->Bounds[5] = this->window->GetCurrentImageData()->GetExtent()[5] * this->window->GetCurrentImageData()->GetSpacing()[2] +
145                 this->window->GetCurrentImageData()->GetOrigin()[2];
146
147         /// Save the limit of the box to increase the scolling effect
148         this->Limits[0] = (this->Bounds[1] - this->Bounds[0]) * this->PadBound;
149         this->Limits[1] = this->Bounds[1] - (this->Bounds[1] - this->Bounds[0]) * this->PadBound;
150         this->Limits[2] = (this->Bounds[5] - this->Bounds[4]) * this->PadBound;
151         this->Limits[3] = this->Bounds[5] - (this->Bounds[5] - this->Bounds[4]) * this->PadBound;
152
153     }
154
155     vtkInteractorStyleTrackballCamera::OnEnter();
156
157 }
158
159
160 void vtkMyInteractorStyleTrackballCameraOpenHeartXZ::OnLeave()
161 {
162     this->Step = 1;
163     vtkInteractorStyleTrackballCamera::OnLeave();
164 }
165
166
167 void vtkMyInteractorStyleTrackballCameraOpenHeartXZ::GetPickerPosition(double *pos)
168 {
169     int X = this->Interactor->GetEventPosition()[0];
170     int Y = this->Interactor->GetEventPosition()[1];
171     this->window->GetPickerXZ()->Pick(X,Y,0.0,this->window->GetXZRenderer());
172     this->window->GetPickerXZ()->GetPickPosition(pos);
173 }
174
175
176 bool vtkMyInteractorStyleTrackballCameraOpenHeartXZ::IsInside(double *pos)
177 {
178     if ( (pos[0]>=this->Bounds[0]) && (pos[0]<=this->Bounds[1]) &&
179          (pos[1]>=this->Bounds[2]) && (pos[1]<=this->Bounds[3]) &&
180          (pos[2]>=this->Bounds[4]) && (pos[2]<=this->Bounds[5]) )
181         return true;
182     else
183         return false;
184 }
185