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