Fraxinus  17.12-rc4
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) 2008-2014, SINTEF Department of Medical Technology
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11  this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 3. Neither the name of the copyright holder nor the names of its contributors
18  may be used to endorse or promote products derived from this software
19  without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 =========================================================================*/
32 
33 #include "cxViewFollower.h"
34 
35 #include <QTimer>
36 #include "cxSliceProxy.h"
37 #include "cxSettings.h"
38 #include "cxSliceComputer.h"
39 #include "cxTool.h"
40 #include "cxUtilHelpers.h"
41 #include "cxDefinitionStrings.h"
42 
43 #include "cxPatientModelService.h"
44 #include "cxLogger.h"
47 
48 namespace cx
49 {
50 
52 {
53  return ViewFollowerPtr(new ViewFollower(dataManager));
54 }
55 
56 ViewFollower::ViewFollower(PatientModelServicePtr dataManager) :
57  mDataManager(dataManager)
58 {
59 // mROI_s = DoubleBoundingBox3D::zero();
60  mCalculator.reset(new SliceAutoViewportCalculator);
61 }
62 
64 {
65 
66 }
67 
69 {
70 // if (mSliceProxy)
71 // {
72 // disconnect(mSliceProxy.get(), SIGNAL(toolTransformAndTimestamp(Transform3D, double)), this, SLOT(ensureCenterWithinView()));
73 // }
74 
75  mSliceProxy = sliceProxy;
76 
77 // if (mSliceProxy)
78 // {
79 // connect(mSliceProxy.get(), SIGNAL(toolTransformAndTimestamp(Transform3D, double)), this, SLOT(updateView()));
80 // }
81 }
82 
84 {
85  mBB_s = bb_s;
86 // this->updateView();
87 }
88 
90 {
91  mRoi = uid;
92 // if (mRoi)
93 // disconnect(mRoi.get(), &Data::transformChanged, this, &ViewFollower::updateView);
94 
95 // DataPtr data = mDataManager->getData(uid);
96 // mRoi = boost::dynamic_pointer_cast<RegionOfInterestMetric>(data);
97 
98 // if (mRoi)
99 // connect(mRoi.get(), &Data::transformChanged, this, &ViewFollower::updateView);
100 
101 // this->updateView();
102 }
103 
105 {
106  if (!mSliceProxy)
108  if (!mSliceProxy->getTool())
110 
111  mCalculator->mFollowTooltip = settings()->value("Navigation/followTooltip").value<bool>();
112  mCalculator->mFollowTooltipBoundary = settings()->value("Navigation/followTooltipBoundary").toDouble();
113  mCalculator->mBB_s = mBB_s;
114  mCalculator->mTooltip_s = this->findVirtualTooltip_s();
115  mCalculator->mFollowType = mSliceProxy->getComputer().getFollowType();
116  mCalculator->mROI_s = this->getROI_BB_s();
117 
118  SliceAutoViewportCalculator::ReturnType result = mCalculator->calculate();
119  return result;
120 
121 // if (!similar(result.zoom, 1.0))
122 // {
123 // CX_LOG_CHANNEL_DEBUG("CA") << this << " autozoom zoom " << result.zoom;
124 // emit newZoom(1.0/result.zoom);
125 // }
126 // if (!similar(result.center_shift_s, Vector3D::Zero()))
127 // {
128 // Vector3D newcenter_r = this->findCenter_r_fromShift_s(result.center_shift_s);
129 // CX_LOG_CHANNEL_DEBUG("CA") << this << "autozoom shift " << result.center_shift_s;
130 // mDataManager->setCenter(newcenter_r);
131 // }
132 }
133 
134 DoubleBoundingBox3D ViewFollower::getROI_BB_s()
135 {
136  DataPtr data = mDataManager->getData(mRoi);
137  RegionOfInterestMetricPtr roi = boost::dynamic_pointer_cast<RegionOfInterestMetric>(data);
138 
139  if (!roi)
140  {
141  return DoubleBoundingBox3D::zero();
142  }
143 
144 // CX_LOG_CHANNEL_DEBUG("CA") << "generate bb_roi_s";
145  Transform3D sMr = mSliceProxy->get_sMr();
146  DoubleBoundingBox3D bb_s = roi->getROI().getBox(sMr);
147  return bb_s;
148 }
149 
150 Vector3D ViewFollower::findVirtualTooltip_s()
151 {
152  ToolPtr tool = mSliceProxy->getTool();
153  Transform3D sMr = mSliceProxy->get_sMr();
154  Transform3D rMpr = mDataManager->get_rMpr();
155  Transform3D prMt = tool->get_prMt();
156  Vector3D pt_s = sMr * rMpr * prMt.coord(Vector3D(0,0,tool->getTooltipOffset()));
157  pt_s[2] = 0; // project into plane
158  return pt_s;
159 }
160 
162 {
163  Transform3D sMr = mSliceProxy->get_sMr();
164  Vector3D c_s = sMr.coord(mDataManager->getCenter());
165 
166  Vector3D newcenter_s = c_s + shift_s;
167 
168  Vector3D newcenter_r = sMr.inv().coord(newcenter_s);
169  return newcenter_r;
170 }
171 
172 } // namespace cx
173 
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:87
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:42
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:63
static ViewFollowerPtr create(PatientModelServicePtr dataManager)
void setAutoZoomROI(QString uid)
Namespace for all CustusX production code.
boost::shared_ptr< class Tool > ToolPtr