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,
9 #include <vtkRenderer.h>
10 #include <vtkRenderWindow.h>
11 #include "vtkMyInteractorStyleTrackballCameraOpenHeartXZ.h"
17 void vtkMyInteractorStyleTrackballCameraOpenHeartXZ::OnMouseWheelForward()
20 /// Get picker position
22 this->GetPickerPosition(pos);
24 /// Go back to the initial coordinate system before reslicing
26 for (int i=0; i<3; i++)
28 this->window->ComputePointBeforeRotation(posXYZ);
30 /// Update Slice image
31 if ( this->IsInside(posXYZ) )
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] ) )
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];
49 if ( this->window->GetFlagDisplayText() )
51 int slice = (int)( (this->window->GetRendererProperties()->position[1] -
52 this->window->GetCurrentImageData()->GetOrigin()[1]) /
53 this->window->GetCurrentImageData()->GetSpacing()[1] + 0.5f );
55 strSlice.sprintf("Slice: %d",slice);
56 this->window->GetRendererProperties()->TextMapperSlice->SetInput(strSlice.toStdString().c_str());
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();
70 void vtkMyInteractorStyleTrackballCameraOpenHeartXZ::OnMouseWheelBackward()
73 /// Get picker position
75 this->GetPickerPosition(pos);
77 /// Go back to the initial coordinate system before reslicing
79 for (int i=0; i<3; i++)
81 this->window->ComputePointBeforeRotation(posXYZ);
83 /// Update Slice image
84 if ( this->IsInside(posXYZ) )
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] ) )
95 /// Compute new slice position
96 posXYZ[1] -= this->Step * this->window->GetCurrentImageData()->GetSpacing()[1];
98 this->window->GetRendererProperties()->position[1] -= this->Step * this->window->GetCurrentImageData()->GetSpacing()[1];
100 /// Update Slice text
101 if ( this->window->GetFlagDisplayText() )
103 int slice = (int)( (this->window->GetRendererProperties()->position[1] -
104 this->window->GetCurrentImageData()->GetOrigin()[1]) /
105 this->window->GetCurrentImageData()->GetSpacing()[1] + 0.5f );
107 strSlice.sprintf("Slice: %d",slice);
108 this->window->GetRendererProperties()->TextMapperSlice->SetInput(strSlice.toStdString().c_str());
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();
122 void vtkMyInteractorStyleTrackballCameraOpenHeartXZ::OnEnter()
125 if ( !this->FlagFirstTime )
128 /// Set flag to 1 to never enter again in this part of the code
129 this->FlagFirstTime = 1;
131 this->window->GetCurrentImageData()->GetWholeBoundingBox(extend);
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];
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;
155 vtkInteractorStyleTrackballCamera::OnEnter();
160 void vtkMyInteractorStyleTrackballCameraOpenHeartXZ::OnLeave()
163 vtkInteractorStyleTrackballCamera::OnLeave();
167 void vtkMyInteractorStyleTrackballCameraOpenHeartXZ::GetPickerPosition(double *pos)
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);
176 bool vtkMyInteractorStyleTrackballCameraOpenHeartXZ::IsInside(double *pos)
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]) )