CustusX  22.04-rc2
An IGT application
cxViewFollower.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 "cxViewFollower.h"
13 
14 #include <QTimer>
15 #include "cxSliceProxy.h"
16 #include "cxSettings.h"
17 #include "cxSliceComputer.h"
18 #include "cxTool.h"
19 #include "cxUtilHelpers.h"
20 
21 #include "cxPatientModelService.h"
22 #include "cxLogger.h"
25 
26 namespace cx
27 {
28 
30 {
31  return ViewFollowerPtr(new ViewFollower(dataManager));
32 }
33 
34 ViewFollower::ViewFollower(PatientModelServicePtr dataManager) :
35  mDataManager(dataManager)
36 {
37 // mROI_s = DoubleBoundingBox3D::zero();
38  mCalculator.reset(new SliceAutoViewportCalculator);
39 }
40 
42 {
43 
44 }
45 
47 {
48 // if (mSliceProxy)
49 // {
50 // disconnect(mSliceProxy.get(), SIGNAL(toolTransformAndTimestamp(Transform3D, double)), this, SLOT(ensureCenterWithinView()));
51 // }
52 
53  mSliceProxy = sliceProxy;
54 
55 // if (mSliceProxy)
56 // {
57 // connect(mSliceProxy.get(), SIGNAL(toolTransformAndTimestamp(Transform3D, double)), this, SLOT(updateView()));
58 // }
59 }
60 
62 {
63  mBB_s = bb_s;
64 // this->updateView();
65 }
66 
68 {
69  mRoi = uid;
70 // if (mRoi)
71 // disconnect(mRoi.get(), &Data::transformChanged, this, &ViewFollower::updateView);
72 
73 // DataPtr data = mDataManager->getData(uid);
74 // mRoi = boost::dynamic_pointer_cast<RegionOfInterestMetric>(data);
75 
76 // if (mRoi)
77 // connect(mRoi.get(), &Data::transformChanged, this, &ViewFollower::updateView);
78 
79 // this->updateView();
80 }
81 
83 {
84  if (!mSliceProxy)
86  if (!mSliceProxy->getTool())
88 
89  mCalculator->mFollowTooltip = settings()->value("Navigation/followTooltip").value<bool>();
90  mCalculator->mFollowTooltipBoundary = settings()->value("Navigation/followTooltipBoundary").toDouble();
91  mCalculator->mBB_s = mBB_s;
92  mCalculator->mTooltip_s = this->findVirtualTooltip_s();
93  mCalculator->mFollowType = mSliceProxy->getComputer().getFollowType();
94  mCalculator->mROI_s = this->getROI_BB_s();
95 
96  SliceAutoViewportCalculator::ReturnType result = mCalculator->calculate();
97  return result;
98 
99 // if (!similar(result.zoom, 1.0))
100 // {
101 // CX_LOG_CHANNEL_DEBUG("CA") << this << " autozoom zoom " << result.zoom;
102 // emit newZoom(1.0/result.zoom);
103 // }
104 // if (!similar(result.center_shift_s, Vector3D::Zero()))
105 // {
106 // Vector3D newcenter_r = this->findCenter_r_fromShift_s(result.center_shift_s);
107 // CX_LOG_CHANNEL_DEBUG("CA") << this << "autozoom shift " << result.center_shift_s;
108 // mDataManager->setCenter(newcenter_r);
109 // }
110 }
111 
112 DoubleBoundingBox3D ViewFollower::getROI_BB_s()
113 {
114  DataPtr data = mDataManager->getData(mRoi);
115  RegionOfInterestMetricPtr roi = boost::dynamic_pointer_cast<RegionOfInterestMetric>(data);
116 
117  if (!roi)
118  {
119  return DoubleBoundingBox3D::zero();
120  }
121 
122 // CX_LOG_CHANNEL_DEBUG("CA") << "generate bb_roi_s";
123  Transform3D sMr = mSliceProxy->get_sMr();
124  DoubleBoundingBox3D bb_s = roi->getROI().getBox(sMr);
125  return bb_s;
126 }
127 
128 Vector3D ViewFollower::findVirtualTooltip_s()
129 {
130  ToolPtr tool = mSliceProxy->getTool();
131  Transform3D sMr = mSliceProxy->get_sMr();
132  Transform3D rMpr = mDataManager->get_rMpr();
133  Transform3D prMt = tool->get_prMt();
134  Vector3D pt_s = sMr * rMpr * prMt.coord(Vector3D(0,0,tool->getTooltipOffset()));
135  pt_s[2] = 0; // project into plane
136  return pt_s;
137 }
138 
140 {
141  Transform3D sMr = mSliceProxy->get_sMr();
142  Vector3D c_s = sMr.coord(mDataManager->getCenter());
143 
144  Vector3D newcenter_s = c_s + shift_s;
145 
146  Vector3D newcenter_r = sMr.inv().coord(newcenter_s);
147  return newcenter_r;
148 }
149 
150 } // namespace cx
151 
boost::shared_ptr< class ViewFollower > ViewFollowerPtr
void setView(DoubleBoundingBox3D bb_s)
SliceAutoViewportCalculator::ReturnType calculate()
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
boost::shared_ptr< class SliceProxy > SliceProxyPtr
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
Definition: cxSettings.cpp:66
Vector3D findCenter_r_fromShift_s(Vector3D shift_s)
void setSliceProxy(SliceProxyPtr sliceProxy)
boost::shared_ptr< class Data > DataPtr
static DoubleBoundingBox3D zero()
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
Settings * settings()
Shortcut for accessing the settings instance.
Definition: cxSettings.cpp:21
boost::shared_ptr< class RegionOfInterestMetric > RegionOfInterestMetricPtr
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.
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:42
static ViewFollowerPtr create(PatientModelServicePtr dataManager)
void setAutoZoomROI(QString uid)
Namespace for all CustusX production code.
boost::shared_ptr< class Tool > ToolPtr