Fraxinus  18.10
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 
170 void SliceProxy::initializeFromPlane(PLANE_TYPE plane, bool useGravity, bool useViewOffset, double viewportHeight, double toolViewOffset)
171 {
172  Vector3D gravityDir = -mDataManager->getOperatingTable().getVectorUp();
173 
174  if (plane==ptTOOLSIDEPLANE)
175  {
176  useGravity = true;
177  }
178 
179  mCutplane->initializeFromPlane(plane,
180  useGravity, gravityDir,
181  useViewOffset, viewportHeight, toolViewOffset,
182  mDataManager->getClinicalApplication());
183 
184  changed();
185 }
186 
188 {
189  return *mCutplane;
190 }
191 
193 {
194  mCutplane.reset(new SliceComputer(val));
195  changed();
196 }
197 
198 void SliceProxy::setOrientation(ORIENTATION_TYPE orientation)
199 {
200  mCutplane->setOrientationType(orientation);
201  changed();
202 }
203 
204 void SliceProxy::setPlane(PLANE_TYPE plane)
205 {
206  mCutplane->setPlaneType(plane);
207  changed();
208 }
209 
210 void SliceProxy::setFollowType(FOLLOW_TYPE followType)
211 {
212  mCutplane->setFollowType(followType);
213  changed();
214 }
215 
216 void SliceProxy::setGravity(bool use, const Vector3D& dir)
217 {
218  mCutplane->setGravity(use, dir);
219  this->changed();
220 }
221 void SliceProxy::setToolViewOffset(bool use, double viewportHeight, double toolViewOffset)
222 {
223  mCutplane->setToolViewOffset(use, viewportHeight, toolViewOffset);
224  this->changed();
225 }
226 
227 void SliceProxy::setToolViewportHeight(double viewportHeight)
228 {
229  mCutplane->setToolViewportHeight(viewportHeight);
230  this->changed();
231 }
232 
234 {
235  return mTool;
236 }
237 
239 {
240  SlicePlane plane = mCutplane->getPlane();
241  //std::cout << "---" << " proxy get transform.c : " << plane.c << std::endl;
242  //std::cout << "proxy get transform -" << getName() <<":\n" << plane << std::endl;
243  return createTransformIJC(plane.i, plane.j, plane.c).inv();
244 }
245 
246 void SliceProxy::changed()
247 {
248  SlicePlane plane = mCutplane->getPlane();
249  if (similar(plane, mLastEmittedSlicePlane))
250  return;
251  mLastEmittedSlicePlane = plane;
252  emit transformChanged(get_sMr());
253 }
254 
255 void SliceProxy::printSelf(std::ostream & os, Indent indent)
256 {
257  os << indent << "sliceproxy" << std::endl;
258  os << indent << "sMr: " << std::endl;
259  get_sMr().put(os, indent.getIndent()+3);
260  os << std::endl;
261 }
262 
263 } // 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)
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:38
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