NorMIT-nav  2023.01.05-dev+develop.0da12
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 */
cx::ViewLinkingViewContainerItem::create
static ViewRepCollectionPtr create(ViewItem *base, vtkRenderWindowPtr renderWindow)
Definition: cxViewLinkingViewContainerItem.cpp:17
cxViewContainerItem.h
cx::DoubleBoundingBox3D
Representation of a floating-point bounding box in 3D. The data are stored as {xmin,...
Definition: cxBoundingBox3D.h:63
cx::DoubleBoundingBox3D::center
Vector3D center() const
Definition: cxBoundingBox3D.cpp:196
vtkRenderWindowPtr
vtkSmartPointer< class vtkRenderWindow > vtkRenderWindowPtr
Definition: vtkForwardDeclarations.h:124
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::createTransformScale
Transform3D createTransformScale(const Vector3D &scale_)
Definition: cxTransform3D.cpp:157
cxViewLinkingViewContainerItem.h
cx::ViewItem::size
virtual QSize size() const
Definition: cxViewContainerItem.h:50
cxBoundingBox3D.h
cx::ViewItem::resized
void resized(QSize size)
cx::ViewItem::getViewport_s
virtual DoubleBoundingBox3D getViewport_s() const
Definition: cxViewContainerItem.cpp:59
cx::ViewItem::getView
ViewRepCollectionPtr getView()
Definition: cxViewContainerItem.h:43
cx::Transform3D
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
Definition: cxLandmarkPatientRegistrationWidget.h:33
cx::ViewItem::get_vpMs
virtual Transform3D get_vpMs() const
Definition: cxViewContainerItem.cpp:64
cx::ViewItem::setGeometry
virtual void setGeometry(const QRect &r)
Definition: cxViewContainerItem.cpp:47
cx::ViewItem::setZoomFactor
virtual void setZoomFactor(double factor)
Definition: cxViewContainerItem.cpp:37
cx::createTransformTranslate
Transform3D createTransformTranslate(const Vector3D &translation)
Definition: cxTransform3D.cpp:164
cx::transform
DoubleBoundingBox3D transform(const Transform3D &m, const DoubleBoundingBox3D &bb)
Definition: cxTransform3D.cpp:150
cx::ViewItem::~ViewItem
virtual ~ViewItem()
Definition: cxViewContainerItem.cpp:33
cx::similar
bool similar(const CameraInfo &lhs, const CameraInfo &rhs, double tol)
Definition: cxCameraStyleForView.cpp:506
cx::Vector3D
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:42
cx::ViewItem::getViewport
virtual DoubleBoundingBox3D getViewport() const
Definition: cxViewContainerItem.cpp:76
cx::ViewItem::ViewItem
ViewItem(QString uid, QString name, QWidget *parent, vtkRenderWindowPtr renderWindow, QRect rect)
Definition: cxViewContainerItem.cpp:23