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 <vtkSmartPointer.h>
12 #include <vtkPoints.h>
13 #include <vtkPolyLine.h>
14 #include <vtkCellArray.h>
15 #include <vtkPolyData.h>
16 #include <vtkPolyDataMapper.h>
19 #include "vtkMyInteractorStyleTrackballCameraOpenHeartXY.h"
25 void vtkMyInteractorStyleTrackballCameraOpenHeartXY::OnMouseWheelForward()
28 /// Get picker position
30 this->GetPickerPosition(pos);
32 /// Go back to the initial coordinate system before reslicing
34 for (int i=0; i<3; i++)
36 this->window->ComputePointBeforeRotation(posXYZ);
38 /// Update Slice image
39 if ( this->IsInside(posXYZ) )
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] ) )
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];
58 if ( this->window->GetFlagDisplayText() )
60 int slice = (int)( (this->window->GetRendererProperties()->position[2] -
61 this->window->GetCurrentImageData()->GetOrigin()[2]) /
62 this->window->GetCurrentImageData()->GetSpacing()[2] + 0.5f );
64 strSlice.sprintf("Slice: %d",slice);
65 this->window->GetRendererProperties()->TextMapperSlice->SetInput(strSlice.toStdString().c_str());
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();
79 void vtkMyInteractorStyleTrackballCameraOpenHeartXY::OnMouseWheelBackward()
82 /// Get picker position
84 this->GetPickerPosition(pos);
86 /// Go back to the initial coordinate system before reslicing
88 for (int i=0; i<3; i++)
90 this->window->ComputePointBeforeRotation(posXYZ);
92 /// Update Slice image
93 if ( this->IsInside(posXYZ) )
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] ) )
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];
110 /// Update Slice text
111 if ( this->window->GetFlagDisplayText() )
113 int slice = (int)( (this->window->GetRendererProperties()->position[2] -
114 this->window->GetCurrentImageData()->GetOrigin()[2]) /
115 this->window->GetCurrentImageData()->GetSpacing()[2] + 0.5f );
117 strSlice.sprintf("Slice: %d",slice);
118 this->window->GetRendererProperties()->TextMapperSlice->SetInput(strSlice.toStdString().c_str());
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();
132 void vtkMyInteractorStyleTrackballCameraOpenHeartXY::OnEnter()
135 if ( !this->FlagFirstTime )
138 /// Set flag to 1 to never enter again in this part of the code
139 this->FlagFirstTime = 1;
141 this->window->GetCurrentImageData()->GetWholeBoundingBox(extend);
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];
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;
165 vtkInteractorStyleTrackballCamera::OnEnter();
170 void vtkMyInteractorStyleTrackballCameraOpenHeartXY::OnLeave()
173 vtkInteractorStyleTrackballCamera::OnLeave();
177 void vtkMyInteractorStyleTrackballCameraOpenHeartXY::GetPickerPosition(double *pos)
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);
186 bool vtkMyInteractorStyleTrackballCameraOpenHeartXY::IsInside(double *pos)
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]) )