CustusX  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
void setTool(ToolPtr tool)
Vector3D j
defines the second axis of the plane. unit vector
Provides a slice matrix based on definition and tool.
Definition: cxSliceProxy.h:82
Transform3D createTransformRotateY(const double angle)
static SliceProxyPtr create(PatientModelServicePtr dataManager)
void setToolViewOffset(bool use, double viewportHeight, double toolViewOffset)
int getIndent() const
Definition: cxIndent.cpp:23
A 2D slice plane in 3D. i,j are perpendicular unit vectors.
void setToolViewportHeight(double viewportHeight)
virtual void printSelf(std::ostream &os, Indent indent)
void setPlane(PLANE_TYPE plane)
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
boost::shared_ptr< class SliceProxy > SliceProxyPtr
void setComputer(const SliceComputer &val)
void setAlwaysUseDefaultCenter(bool on)
void setGravity(bool use, const Vector3D &dir)
void setClinicalApplicationToFixedValue(CLINICAL_VIEW application)
SliceComputer getComputer() const
void setUseTooltipOffset(bool)
Enable or disable usage of the tools tool tip offset for this slice proxy.
void toolVisible(bool visible)
forwarding of visible in tool
Transform3D createTransformIJC(const Vector3D &ivec, const Vector3D &jvec, const Vector3D &center)
Vector3D c
defines the center of the plane
void initializeFromPlane(PLANE_TYPE plane, bool useGravity, bool useViewOffset, double viewportHeight, double toolViewOffset)
void transformChanged(Transform3D sMr)
emitted when transform is changed.
ptTOOLSIDEPLANE
z-rotated 90* relative to anyplane like side plane, but always kept oriented like the plane defined b...
Definition: cxDefinitions.h:39
virtual Transform3D get_sMr()
get slice transform, i.e. the matrix sMr transforming a point p in ref to slice space.
void setFollowType(FOLLOW_TYPE followType)
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
Formatting class for debug printing of the ssc library.
Definition: cxIndent.h:28
Transform3D createTransformTranslate(const Vector3D &translation)
virtual ~SliceProxy()
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:42
ToolPtr getTool()
Vector3D i
defines the first axis of the plane. unit vector
Calculates a slice plane given a definition.
void setOrientation(ORIENTATION_TYPE orientation)
bool similar(const CameraInfo &lhs, const CameraInfo &rhs, double tol)
Transform3D createTransformRotateZ(const double angle)
void setDefaultCenter(const Vector3D &c)
void toolTransformAndTimestamp(Transform3D prMt, double timestamp)
forwarded from tool
#define M_PI
Namespace for all CustusX production code.
boost::shared_ptr< class Tool > ToolPtr