20 #include "vtkCommand.h"
21 #include <vtkRenderWindowInteractor.h>
23 #include "vtkCamera.h"
24 #include "vtkRenderer.h"
25 #include <vtkSmartPointer.h>
26 #include <vtkTransform.h>
38 double widthInMM = this->GetRenderer()->GetCurrentWorldPlaneGeometry()->GetExtentInMM(0);
39 double heightInMM = this->GetRenderer()->GetCurrentWorldPlaneGeometry()->GetExtentInMM(1);
41 double dispHeight = this->GetRenderer()->GetViewportSize()[1];
42 double dispWidth = this->GetRenderer()->GetViewportSize()[0];
51 if ((dispWidth / widthInMM) < (dispHeight / heightInMM))
53 heightInMM = widthInMM / dispWidth * dispHeight;
56 return heightInMM * 0.5;
59 void mitk::CameraController::AdjustConstrainedCameraPosition(
mitk::Point2D &planePoint)
62 double widthInMM = this->GetRenderer()->GetCurrentWorldPlaneGeometry()->GetExtentInMM(0);
63 double heightInMM = this->GetRenderer()->GetCurrentWorldPlaneGeometry()->GetExtentInMM(1);
65 mitk::Point2D dispSizeInMM = this->GetRenderer()->GetViewportSizeInMM();
67 double xMin, xMax, yMin, yMax;
72 if (dispSizeInMM[0] > widthInMM)
74 xMin = widthInMM - 0.5 * dispSizeInMM[0];
75 xMax = 0.5 * dispSizeInMM[0];
79 xMin = 0.5 * dispSizeInMM[0];
80 xMax = widthInMM - 0.5 * dispSizeInMM[0];
83 if (dispSizeInMM[1] > heightInMM)
85 yMin = heightInMM - 0.5 * dispSizeInMM[1];
86 yMax = 0.5 * dispSizeInMM[1];
90 yMin = 0.5 * dispSizeInMM[1];
91 yMax = heightInMM - 0.5 * dispSizeInMM[1];
94 if (planePoint[0] < xMin)
98 if (planePoint[1] < yMin)
100 planePoint[1] = yMin;
102 if (planePoint[0] > xMax)
104 planePoint[0] = xMax;
106 if (planePoint[1] > yMax)
108 planePoint[1] = yMax;
114 this->SetStandardView(ANTERIOR);
119 this->SetStandardView(POSTERIOR);
124 this->SetStandardView(SINISTER);
129 this->SetStandardView(DEXTER);
134 this->SetStandardView(CRANIAL);
139 this->SetStandardView(CAUDAL);
145 if (glRenderer == NULL)
161 vtkRenderer->GetActiveCamera()->SetFocalPoint(middle[0], middle[1], middle[2]);
168 vtkRenderer->GetActiveCamera()->SetViewUp(0, 0, 1);
172 vtkRenderer->GetActiveCamera()->SetViewUp(0, -1, 0);
178 vtkRenderer->GetActiveCamera()->SetPosition(middle[0], -100000, middle[2]);
181 vtkRenderer->GetActiveCamera()->SetPosition(middle[0], +100000, middle[2]);
184 vtkRenderer->GetActiveCamera()->SetPosition(+100000, middle[1], middle[2]);
187 vtkRenderer->GetActiveCamera()->SetPosition(-100000, middle[1], middle[2]);
190 vtkRenderer->GetActiveCamera()->SetPosition(middle[0], middle[1], 100000);
193 vtkRenderer->GetActiveCamera()->SetPosition(middle[0], middle[1], -100000);
196 vtkRenderer->ResetCamera();
198 vtkRenderer->ResetCameraClippingRange();
207 Point2D moveToPoint = planePoint;
208 AdjustCameraToPlane(moveToPoint);
215 MoveCameraToPoint(GetCameraPositionOnPlane() + moveVectorInMM);
224 double parallelScale = this->GetRenderer()->GetVtkRenderer()->GetActiveCamera()->GetParallelScale() / factor;
225 if (this->GetRenderer()->GetConstrainZoomingAndPanning() && factor < 1.0)
227 double maxParallelScale = ComputeMaxParallelScale();
228 if (maxParallelScale - parallelScale * factor <
232 if (parallelScale > maxParallelScale)
234 parallelScale = maxParallelScale;
237 this->GetRenderer()->GetVtkRenderer()->GetActiveCamera()->SetParallelScale(parallelScale);
239 Point2D planePoint = GetCameraPositionOnPlane();
240 MoveCameraToPoint(planePoint + ((zoomPointInMM - planePoint) * (factor - 1)));
247 CamPosOnPlane[0] = this->GetRenderer()->GetVtkRenderer()->GetCenter()[0];
248 CamPosOnPlane[1] = this->GetRenderer()->GetVtkRenderer()->GetCenter()[1];
249 this->GetRenderer()->DisplayToPlane(CamPosOnPlane, CamPosOnPlane);
250 return CamPosOnPlane;
257 AdjustCameraToPlane(GetCameraPositionOnPlane());
265 Point2D _planePoint = PlanePoint;
266 if (this->GetRenderer()->GetConstrainZoomingAndPanning())
268 double parallelScale = this->GetRenderer()->GetVtkRenderer()->GetActiveCamera()->GetParallelScale();
269 double maxParallelScale = ComputeMaxParallelScale();
270 if (parallelScale > maxParallelScale)
272 this->GetRenderer()->GetVtkRenderer()->GetActiveCamera()->SetParallelScale(maxParallelScale);
274 AdjustConstrainedCameraPosition(_planePoint);
276 const PlaneGeometry *planeGeometry = this->GetRenderer()->GetCurrentWorldPlaneGeometry();
277 if (planeGeometry != NULL)
279 this->GetRenderer()->GetVtkRenderer()->GetActiveCamera()->SetViewUp(0, 1, 0);
280 this->GetRenderer()->GetVtkRenderer()->GetActiveCamera()->SetPosition(_planePoint[0], _planePoint[1], 900000);
281 this->GetRenderer()->GetVtkRenderer()->GetActiveCamera()->SetFocalPoint(_planePoint[0], _planePoint[1], 0);
290 origin = planeGeometry->GetOrigin();
291 right = planeGeometry->GetAxisVector(0);
292 bottom = planeGeometry->GetAxisVector(1);
293 normal = planeGeometry->GetNormal();
299 matrix->SetElement(0, 0, right[0]);
300 matrix->SetElement(1, 0, right[1]);
301 matrix->SetElement(2, 0, right[2]);
302 matrix->SetElement(0, 1, bottom[0]);
303 matrix->SetElement(1, 1, bottom[1]);
304 matrix->SetElement(2, 1, bottom[2]);
305 matrix->SetElement(0, 2, normal[0]);
306 matrix->SetElement(1, 2, normal[1]);
307 matrix->SetElement(2, 2, normal[2]);
308 matrix->SetElement(0, 3, origin[0]);
309 matrix->SetElement(1, 3, origin[1]);
310 matrix->SetElement(2, 3, origin[2]);
311 matrix->SetElement(3, 0, 0.0);
312 matrix->SetElement(3, 1, 0.0);
313 matrix->SetElement(3, 2, 0.0);
314 matrix->SetElement(3, 3, 1.0);
316 trans->SetMatrix(matrix);
318 this->GetRenderer()->GetVtkRenderer()->GetActiveCamera()->ApplyTransform(trans);
327 this->GetRenderer()->GetVtkRenderer()->GetActiveCamera()->SetParallelScale(ComputeMaxParallelScale());
329 this->GetRenderer()->GetVtkRenderer()->GetActiveCamera()->SetClippingRange(0.1, 1000000);
334 planePoint[0] = this->GetRenderer()->GetCurrentWorldPlaneGeometry()->GetExtentInMM(0) * 0.5;
335 planePoint[1] = this->GetRenderer()->GetCurrentWorldPlaneGeometry()->GetExtentInMM(1) * 0.5;
336 MoveCameraToPoint(planePoint);
347 this->GetRenderer()->GetVtkRenderer()->GetActiveCamera()->SetParallelScale(this->GetRenderer()->GetViewportSize()[1] *
ScalarType ComputeMaxParallelScale()
Data management class that handles 'was created by' relations.
itk::SmartPointer< Self > Pointer
Baseclass for renderer slice-/camera-control.
virtual void SetViewToPosterior()
CameraController()
Default Constructor.
void Zoom(ScalarType factor, const Point2D &zoomPointInMM)
virtual void SetViewToAnterior()
void MoveBy(const Vector2D &moveVectorInMM)
virtual void SetViewToDexter()
Vector< ScalarType, 3 > Vector3D
Manager for coordinating the rendering process.
virtual void SetViewToSinister()
void SetScaleFactorInMMPerDisplayUnit(ScalarType scale)
Set the desired zoom-level to the absolute value given.
virtual void SetViewToCaudal()
Point< ScalarType, 3 > Point3D
mitk::BoundingBox::Pointer ComputeBoundingBox(const char *boolPropertyKey=nullptr, const mitk::BaseRenderer *renderer=nullptr, const char *boolPropertyKey2=nullptr)
Compute the bounding box of data tree structure it -> an iterator to a data tree structure.
Point2D GetCameraPositionOnPlane()
virtual void SetViewToCranial()
virtual void SetStandardView(StandardView view)
MITKCORE_EXPORT const ScalarType eps
void MoveCameraToPoint(const Point2D &planePoint)
MoveCameraToPoint Move camera so that the point on the plane is in the view center.
void AdjustCameraToPlane()
AdjustCameraToPlane Moves the camera of a 2D Renderwindow without panning or zooming, eg. only rotate the camera.
vtkRenderer * GetVtkRenderer() const
void Fit()
Fit Adjust the camera, so that the world bounding box is fully visible.
virtual ~CameraController()
Default Destructor.
void RequestUpdateAll(RequestType type=REQUEST_UPDATE_ALL)
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.