CustusX  22.04-rc5
An IGT application
cxViewContainerItem.cpp
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
12 #include "cxViewContainerItem.h"
13 
14 #include <QApplication>
15 #include <QDesktopWidget>
16 #include "vtkRenderer.h"
17 #include "cxBoundingBox3D.h"
19 
20 namespace cx
21 {
22 
23 ViewItem::ViewItem(QString uid, QString name, QWidget *parent, vtkRenderWindowPtr renderWindow, QRect rect) :
24  QObject(parent),
25  mGeometry(rect),
26  mParent(parent)
27 {
28  mZoomFactor = -1.0;
29  mView = ViewLinkingViewContainerItem::create(this, renderWindow);
30  mView->clear();
31 }
32 
34 {
35 }
36 
37 void ViewItem::setZoomFactor(double factor)
38 {
39  if (similar(factor, mZoomFactor))
40  {
41  return;
42  }
43  mZoomFactor = factor;
44  emit resized(this->size());
45 }
46 
47 void ViewItem::setGeometry(const QRect &r)
48 {
49  mGeometry = r;
50  QSize parentSize = mParent->size();
51  double xMin = r.left()/(double)parentSize.width();
52  double xMax = (r.right() + 1)/(double)parentSize.width();
53  double yMin = (parentSize.height() - r.bottom() - 1) / (double)parentSize.height();
54  double yMax = (parentSize.height() - r.top()) / (double)parentSize.height();
55  this->getView()->getRenderer()->SetViewport(xMin, yMin, xMax, yMax);
56  emit resized(r.size());
57 }
58 
60 {
61  return transform(this->get_vpMs().inv(), this->getViewport());
62 }
63 
65 {
66  Vector3D center_vp = this->getViewport().center();
67  double scale = mZoomFactor / this->mmPerPix(); // double zoomFactor = 0.3; // real magnification
68  Transform3D S = createTransformScale(Vector3D(scale, scale, scale));
69  Transform3D T = createTransformTranslate(center_vp);// center of viewport in viewport coordinates
70  Transform3D M_vp_w = T * S; // first scale , then translate to center.
71  return M_vp_w;
72 }
73 
77 {
78  return DoubleBoundingBox3D(0, size().width(), 0, size().height(), 0, 0);
79 }
80 
81 double ViewItem::mmPerPix() const
82 {
83  // use mean mm/pix over entire screen. DONT use the height of the widget in mm,
84  // this is truncated to the nearest integer.
85  QDesktopWidget* desktop = dynamic_cast<QApplication*>(QApplication::instance())->desktop();
86  QWidget* screen = desktop->screen(desktop->screenNumber(mParent));
87  double r_h = (double) screen->heightMM() / (double) screen->geometry().height();
88  double r_w = (double) screen->widthMM() / (double) screen->geometry().width();
89  double retval = (r_h + r_w) / 2.0;
90  return retval;
91 }
92 
93 
94 } /* namespace cx */
DoubleBoundingBox3D transform(const Transform3D &m, const DoubleBoundingBox3D &bb)
virtual DoubleBoundingBox3D getViewport_s() const
Transform3D createTransformScale(const Vector3D &scale_)
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
virtual void setGeometry(const QRect &r)
vtkSmartPointer< class vtkRenderWindow > vtkRenderWindowPtr
virtual void setZoomFactor(double factor)
static ViewRepCollectionPtr create(ViewItem *base, vtkRenderWindowPtr renderWindow)
ViewItem(QString uid, QString name, QWidget *parent, vtkRenderWindowPtr renderWindow, QRect rect)
Transform3D createTransformTranslate(const Vector3D &translation)
virtual DoubleBoundingBox3D getViewport() const
virtual Transform3D get_vpMs() const
Representation of a floating-point bounding box in 3D. The data are stored as {xmin,xmax,ymin,ymax,zmin,zmax}, in order to simplify communication with vtk.
void resized(QSize size)
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:42
Vector3D center() const
bool similar(const CameraInfo &lhs, const CameraInfo &rhs, double tol)
ViewRepCollectionPtr getView()
virtual QSize size() const
Namespace for all CustusX production code.