Fraxinus  18.10
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 #include "cxDefinitionStrings.h"
21 
22 #include "cxPatientModelService.h"
23 #include "cxLogger.h"
26 
27 namespace cx
28 {
29 
31 {
32  return ViewFollowerPtr(new ViewFollower(dataManager));
33 }
34 
35 ViewFollower::ViewFollower(PatientModelServicePtr dataManager) :
36  mDataManager(dataManager)
37 {
38 // mROI_s = DoubleBoundingBox3D::zero();
39  mCalculator.reset(new SliceAutoViewportCalculator);
40 }
41 
43 {
44 
45 }
46 
48 {
49 // if (mSliceProxy)
50 // {
51 // disconnect(mSliceProxy.get(), SIGNAL(toolTransformAndTimestamp(Transform3D, double)), this, SLOT(ensureCenterWithinView()));
52 // }
53 
54  mSliceProxy = sliceProxy;
55 
56 // if (mSliceProxy)
57 // {
58 // connect(mSliceProxy.get(), SIGNAL(toolTransformAndTimestamp(Transform3D, double)), this, SLOT(updateView()));
59 // }
60 }
61 
63 {
64  mBB_s = bb_s;
65 // this->updateView();
66 }
67 
69 {
70  mRoi = uid;
71 // if (mRoi)
72 // disconnect(mRoi.get(), &Data::transformChanged, this, &ViewFollower::updateView);
73 
74 // DataPtr data = mDataManager->getData(uid);
75 // mRoi = boost::dynamic_pointer_cast<RegionOfInterestMetric>(data);
76 
77 // if (mRoi)
78 // connect(mRoi.get(), &Data::transformChanged, this, &ViewFollower::updateView);
79 
80 // this->updateView();
81 }
82 
84 {
85  if (!mSliceProxy)
87  if (!mSliceProxy->getTool())
89 
90  mCalculator->mFollowTooltip = settings()->value("Navigation/followTooltip").value<bool>();
91  mCalculator->mFollowTooltipBoundary = settings()->value("Navigation/followTooltipBoundary").toDouble();
92  mCalculator->mBB_s = mBB_s;
93  mCalculator->mTooltip_s = this->findVirtualTooltip_s();
94  mCalculator->mFollowType = mSliceProxy->getComputer().getFollowType();
95  mCalculator->mROI_s = this->getROI_BB_s();
96 
97  SliceAutoViewportCalculator::ReturnType result = mCalculator->calculate();
98  return result;
99 
100 // if (!similar(result.zoom, 1.0))
101 // {
102 // CX_LOG_CHANNEL_DEBUG("CA") << this << " autozoom zoom " << result.zoom;
103 // emit newZoom(1.0/result.zoom);
104 // }
105 // if (!similar(result.center_shift_s, Vector3D::Zero()))
106 // {
107 // Vector3D newcenter_r = this->findCenter_r_fromShift_s(result.center_shift_s);
108 // CX_LOG_CHANNEL_DEBUG("CA") << this << "autozoom shift " << result.center_shift_s;
109 // mDataManager->setCenter(newcenter_r);
110 // }
111 }
112 
113 DoubleBoundingBox3D ViewFollower::getROI_BB_s()
114 {
115  DataPtr data = mDataManager->getData(mRoi);
116  RegionOfInterestMetricPtr roi = boost::dynamic_pointer_cast<RegionOfInterestMetric>(data);
117 
118  if (!roi)
119  {
120  return DoubleBoundingBox3D::zero();
121  }
122 
123 // CX_LOG_CHANNEL_DEBUG("CA") << "generate bb_roi_s";
124  Transform3D sMr = mSliceProxy->get_sMr();
125  DoubleBoundingBox3D bb_s = roi->getROI().getBox(sMr);
126  return bb_s;
127 }
128 
129 Vector3D ViewFollower::findVirtualTooltip_s()
130 {
131  ToolPtr tool = mSliceProxy->getTool();
132  Transform3D sMr = mSliceProxy->get_sMr();
133  Transform3D rMpr = mDataManager->get_rMpr();
134  Transform3D prMt = tool->get_prMt();
135  Vector3D pt_s = sMr * rMpr * prMt.coord(Vector3D(0,0,tool->getTooltipOffset()));
136  pt_s[2] = 0; // project into plane
137  return pt_s;
138 }
139 
141 {
142  Transform3D sMr = mSliceProxy->get_sMr();
143  Vector3D c_s = sMr.coord(mDataManager->getCenter());
144 
145  Vector3D newcenter_s = c_s + shift_s;
146 
147  Vector3D newcenter_r = sMr.inv().coord(newcenter_s);
148  return newcenter_r;
149 }
150 
151 } // namespace cx
152 
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