NorMIT-nav  2023.01.05-dev+develop.0da12
An IGT application
cxSliceProxy.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 
13 #include "cxSliceProxy.h"
14 
15 #include <math.h>
16 #include "cxTypeConversions.h"
17 #include "cxPatientModelService.h"
18 #include "cxSliceComputer.h"
19 #include "cxTool.h"
20 
21 namespace cx
22 {
23 
25 {
26  SliceProxyPtr retval(new SliceProxy(dataManager));
27  return retval;
28 }
29 
30 SliceProxy::SliceProxy(PatientModelServicePtr dataManager) :
31  mCutplane(new SliceComputer())
32 {
33  mDataManager = dataManager;
34  mAlwaysUseDefaultCenter = false;
35  mUseTooltipOffset = true;
36  connect(mDataManager.get(), SIGNAL(centerChanged()),this, SLOT(centerChangedSlot()) ) ;
37  connect(mDataManager.get(), SIGNAL(clinicalApplicationChanged()), this, SLOT(clinicalApplicationChangedSlot()));
38  //TODO connect to toolmanager rMpr changed
39  mDefaultCenter = mDataManager->getCenter();
40  this->centerChangedSlot();
41 
42  this->initCutplane();
43 }
44 
46 {
47 }
48 
49 void SliceProxy::initCutplane()
50 {
51  mCutplane->setFixedCenter(mDefaultCenter);
52  mCutplane->setToolPosition(getSyntheticToolPos(mDefaultCenter));
53 }
54 
56 {
57  if (mTool)
58  {
59  disconnect(mTool.get(), SIGNAL(toolTransformAndTimestamp(Transform3D,double)), this, SLOT(toolTransformAndTimestampSlot(Transform3D,double)));
60  disconnect(mTool.get(), SIGNAL(toolVisible(bool)), this, SLOT(toolVisibleSlot(bool)));
61  disconnect(mTool.get(), SIGNAL(tooltipOffset(double)), this, SLOT(tooltipOffsetSlot(double)));
62  disconnect(mTool.get(), SIGNAL(toolProbeSector()), this, SLOT(changed()));
63  }
64 
65  mTool = tool;
66 
67  if (mTool)
68  {
69  connect(mTool.get(), SIGNAL(toolTransformAndTimestamp(Transform3D,double)), this, SLOT(toolTransformAndTimestampSlot(Transform3D,double)));
70  connect(mTool.get(), SIGNAL(toolVisible(bool)), this, SLOT(toolVisibleSlot(bool)));
71  connect(mTool.get(), SIGNAL(tooltipOffset(double)), this, SLOT(tooltipOffsetSlot(double)));
72  connect(mTool.get(), SIGNAL(toolProbeSector()), this, SLOT(changed()));
73 
74  emit toolVisible(mTool->getVisible());
75  toolTransformAndTimestampSlot(mTool->get_prMt(), 0); // initial values
76  tooltipOffsetSlot(mTool->getTooltipOffset());
77  }
78 
79  this->centerChangedSlot(); // force center update for tool==0
80  this->changed();
81 }
82 
83 void SliceProxy::toolTransformAndTimestampSlot(Transform3D prMt, double timestamp)
84 {
85  //std::cout << "proxy get transform" << std::endl;
86  Transform3D rMpr = mDataManager->get_rMpr();
87  Transform3D rMt = rMpr*prMt;
88 // if (similar(rMt, mCutplane->getToolPosition()))
89 // {
90 // return;
91 // }
92  mCutplane->setToolPosition(rMt);
93  this->changed();
94  emit toolTransformAndTimestamp(prMt, timestamp);
95 
96 }
97 
98 void SliceProxy::tooltipOffsetSlot(double val)
99 {
100  if (mUseTooltipOffset)
101  {
102  mCutplane->setToolOffset(val);
103  this->changed();
104  }
105 }
106 
108 {
109  if (!use)
110  {
111  tooltipOffsetSlot(0);
112  }
113  mUseTooltipOffset = use;
114  if (use)
115  {
116  tooltipOffsetSlot(mTool->getTooltipOffset());
117  }
118 }
119 
120 void SliceProxy::toolVisibleSlot(bool visible)
121 {
122 
123 }
124 
127 Transform3D SliceProxy::getSyntheticToolPos(const Vector3D& center) const
128 {
131  return T_c * R_tq;
132 }
133 
135 {
136  mDefaultCenter = c;
137  this->centerChangedSlot();
138 }
139 
141 {
142  mAlwaysUseDefaultCenter = on;
143  this->centerChangedSlot();
144 }
145 
146 void SliceProxy::centerChangedSlot()
147 {
148  if (mAlwaysUseDefaultCenter)
149  {
150  mCutplane->setFixedCenter(mDefaultCenter);
151  }
152  else if (mTool)
153  {
154  Vector3D c = mDataManager->getCenter();
155  mCutplane->setFixedCenter(c);
156  //std::cout << "center changed: " + string_cast(c) << std::endl;
157  }
158 
159  changed();
160 }
161 
162 void SliceProxy::clinicalApplicationChangedSlot()
163 {
164  mCutplane->setClinicalApplication(mDataManager->getClinicalApplication());
165  changed();
166 }
167 
168 void SliceProxy::setClinicalApplicationToFixedValue(CLINICAL_VIEW application)
169 {
170  //Don't allow any changes to clinical application if this has been specifically set.
171  disconnect(mDataManager.get(), SIGNAL(clinicalApplicationChanged()), this, SLOT(clinicalApplicationChangedSlot()));
172 
173  mCutplane->setClinicalApplication(application);
174  changed();
175 }
176 
179 void SliceProxy::initializeFromPlane(PLANE_TYPE plane, bool useGravity, bool useViewOffset, double viewportHeight, double toolViewOffset)
180 {
181  Vector3D gravityDir = -mDataManager->getOperatingTable().getVectorUp();
182 
183  if (plane==ptTOOLSIDEPLANE)
184  {
185  useGravity = true;
186  }
187 
188  mCutplane->initializeFromPlane(plane,
189  useGravity, gravityDir,
190  useViewOffset, viewportHeight, toolViewOffset,
191  mDataManager->getClinicalApplication());
192 
193  changed();
194 }
195 
197 {
198  return *mCutplane;
199 }
200 
202 {
203  mCutplane.reset(new SliceComputer(val));
204  changed();
205 }
206 
207 void SliceProxy::setOrientation(ORIENTATION_TYPE orientation)
208 {
209  mCutplane->setOrientationType(orientation);
210  changed();
211 }
212 
213 void SliceProxy::setPlane(PLANE_TYPE plane)
214 {
215  mCutplane->setPlaneType(plane);
216  changed();
217 }
218 
219 void SliceProxy::setFollowType(FOLLOW_TYPE followType)
220 {
221  mCutplane->setFollowType(followType);
222  changed();
223 }
224 
225 void SliceProxy::setGravity(bool use, const Vector3D& dir)
226 {
227  mCutplane->setGravity(use, dir);
228  this->changed();
229 }
230 void SliceProxy::setToolViewOffset(bool use, double viewportHeight, double toolViewOffset)
231 {
232  mCutplane->setToolViewOffset(use, viewportHeight, toolViewOffset);
233  this->changed();
234 }
235 
236 void SliceProxy::setToolViewportHeight(double viewportHeight)
237 {
238  mCutplane->setToolViewportHeight(viewportHeight);
239  this->changed();
240 }
241 
243 {
244  return mTool;
245 }
246 
248 {
249  SlicePlane plane = mCutplane->getPlane();
250  //std::cout << "---" << " proxy get transform.c : " << plane.c << std::endl;
251  //std::cout << "proxy get transform -" << getName() <<":\n" << plane << std::endl;
252  return createTransformIJC(plane.i, plane.j, plane.c).inv();
253 }
254 
255 void SliceProxy::changed()
256 {
257  SlicePlane plane = mCutplane->getPlane();
258  if (similar(plane, mLastEmittedSlicePlane))
259  return;
260  mLastEmittedSlicePlane = plane;
261  emit transformChanged(get_sMr());
262 }
263 
264 void SliceProxy::printSelf(std::ostream & os, Indent indent)
265 {
266  os << indent << "sliceproxy" << std::endl;
267  os << indent << "sMr: " << std::endl;
268  get_sMr().put(os, indent.getIndent()+3);
269  os << std::endl;
270 }
271 
272 } // namespace cx
cx::SliceProxy::setComputer
void setComputer(const SliceComputer &val)
Definition: cxSliceProxy.cpp:201
ptTOOLSIDEPLANE
ptTOOLSIDEPLANE
z-rotated 90* relative to anyplane like side plane, but always kept oriented like the plane defined b...
Definition: cxDefinitions.h:46
cx::SliceProxy::get_sMr
virtual Transform3D get_sMr()
get slice transform, i.e. the matrix sMr transforming a point p in ref to slice space.
Definition: cxSliceProxy.cpp:247
cx::SliceProxy::setAlwaysUseDefaultCenter
void setAlwaysUseDefaultCenter(bool on)
Definition: cxSliceProxy.cpp:140
cx::createTransformRotateZ
Transform3D createTransformRotateZ(const double angle)
Definition: cxTransform3D.cpp:185
cx::SliceProxy::getComputer
SliceComputer getComputer() const
Definition: cxSliceProxy.cpp:196
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::SliceProxy::setClinicalApplicationToFixedValue
void setClinicalApplicationToFixedValue(CLINICAL_VIEW application)
Definition: cxSliceProxy.cpp:168
cx::Indent::getIndent
int getIndent() const
Definition: cxIndent.cpp:23
cxSliceComputer.h
cx::createTransformIJC
Transform3D createTransformIJC(const Vector3D &ivec, const Vector3D &jvec, const Vector3D &center)
Definition: cxTransform3D.cpp:255
cx::SliceProxy::setDefaultCenter
void setDefaultCenter(const Vector3D &c)
Definition: cxSliceProxy.cpp:134
cx::SliceProxyPtr
boost::shared_ptr< class SliceProxy > SliceProxyPtr
Definition: cxForwardDeclarations.h:96
cx::SliceProxy::setPlane
void setPlane(PLANE_TYPE plane)
Definition: cxSliceProxy.cpp:213
cx::SliceProxy::initializeFromPlane
void initializeFromPlane(PLANE_TYPE plane, bool useGravity, bool useViewOffset, double viewportHeight, double toolViewOffset)
Definition: cxSliceProxy.cpp:179
cx::SliceProxy::~SliceProxy
virtual ~SliceProxy()
Definition: cxSliceProxy.cpp:45
cx::Transform3D
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
Definition: cxLandmarkPatientRegistrationWidget.h:33
cx::SlicePlane::i
Vector3D i
defines the first axis of the plane. unit vector
Definition: cxSliceComputer.h:34
cx::SliceProxy::create
static SliceProxyPtr create(PatientModelServicePtr dataManager)
Definition: cxSliceProxy.cpp:24
cx::PatientModelServicePtr
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
Definition: cxLogicManager.h:25
cxTool.h
cxTypeConversions.h
cx::SliceProxy::getTool
ToolPtr getTool()
Definition: cxSliceProxy.cpp:242
cx::SliceProxy::setTool
void setTool(ToolPtr tool)
Definition: cxSliceProxy.cpp:55
cxPatientModelService.h
cx::SliceProxy::setToolViewportHeight
void setToolViewportHeight(double viewportHeight)
Definition: cxSliceProxy.cpp:236
cx::SliceProxy::toolVisible
void toolVisible(bool visible)
forwarding of visible in tool
cx::SliceProxy::toolTransformAndTimestamp
void toolTransformAndTimestamp(Transform3D prMt, double timestamp)
forwarded from tool
cx::SlicePlane::j
Vector3D j
defines the second axis of the plane. unit vector
Definition: cxSliceComputer.h:35
M_PI
#define M_PI
Definition: cxReconstructParams.cpp:25
cx::SliceProxy::setGravity
void setGravity(bool use, const Vector3D &dir)
Definition: cxSliceProxy.cpp:225
cx::ToolPtr
boost::shared_ptr< class Tool > ToolPtr
Definition: cxVideoConnectionWidget.h:43
cx::SliceProxy
Provides a slice matrix based on definition and tool.
Definition: cxSliceProxy.h:82
cx::createTransformTranslate
Transform3D createTransformTranslate(const Vector3D &translation)
Definition: cxTransform3D.cpp:164
cx::createTransformRotateY
Transform3D createTransformRotateY(const double angle)
Definition: cxTransform3D.cpp:178
cx::Indent
Formatting class for debug printing of the ssc library.
Definition: cxIndent.h:28
cx::SliceProxy::setToolViewOffset
void setToolViewOffset(bool use, double viewportHeight, double toolViewOffset)
Definition: cxSliceProxy.cpp:230
cxSliceProxy.h
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::SlicePlane
A 2D slice plane in 3D. i,j are perpendicular unit vectors.
Definition: cxSliceComputer.h:28
cx::SlicePlane::c
Vector3D c
defines the center of the plane
Definition: cxSliceComputer.h:33
cx::SliceProxy::setOrientation
void setOrientation(ORIENTATION_TYPE orientation)
Definition: cxSliceProxy.cpp:207
cx::SliceProxy::printSelf
virtual void printSelf(std::ostream &os, Indent indent)
Definition: cxSliceProxy.cpp:264
cx::SliceProxy::setUseTooltipOffset
void setUseTooltipOffset(bool)
Enable or disable usage of the tools tool tip offset for this slice proxy.
Definition: cxSliceProxy.cpp:107
cx::SliceProxyInterface::transformChanged
void transformChanged(Transform3D sMr)
emitted when transform is changed.
cx::SliceProxy::setFollowType
void setFollowType(FOLLOW_TYPE followType)
Definition: cxSliceProxy.cpp:219
cx::SliceComputer
Calculates a slice plane given a definition.
Definition: cxSliceComputer.h:53