Fraxinus  17.12-rc1
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) 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 
34 #include "cxSliceProxy.h"
35 
36 #include <math.h>
37 #include "cxTypeConversions.h"
38 #include "cxPatientModelService.h"
39 #include "cxSliceComputer.h"
40 #include "cxTool.h"
41 
42 namespace cx
43 {
44 
46 {
47  SliceProxyPtr retval(new SliceProxy(dataManager));
48  return retval;
49 }
50 
51 SliceProxy::SliceProxy(PatientModelServicePtr dataManager) :
52  mCutplane(new SliceComputer())
53 {
54  mDataManager = dataManager;
55  mAlwaysUseDefaultCenter = false;
56  mUseTooltipOffset = true;
57  connect(mDataManager.get(), SIGNAL(centerChanged()),this, SLOT(centerChangedSlot()) ) ;
58  connect(mDataManager.get(), SIGNAL(clinicalApplicationChanged()), this, SLOT(clinicalApplicationChangedSlot()));
59  //TODO connect to toolmanager rMpr changed
60  mDefaultCenter = mDataManager->getCenter();
61  this->centerChangedSlot();
62 
63  this->initCutplane();
64 }
65 
67 {
68 }
69 
70 void SliceProxy::initCutplane()
71 {
72  mCutplane->setFixedCenter(mDefaultCenter);
73  mCutplane->setToolPosition(getSyntheticToolPos(mDefaultCenter));
74 }
75 
77 {
78  if (mTool)
79  {
80  disconnect(mTool.get(), SIGNAL(toolTransformAndTimestamp(Transform3D,double)), this, SLOT(toolTransformAndTimestampSlot(Transform3D,double)));
81  disconnect(mTool.get(), SIGNAL(toolVisible(bool)), this, SLOT(toolVisibleSlot(bool)));
82  disconnect(mTool.get(), SIGNAL(tooltipOffset(double)), this, SLOT(tooltipOffsetSlot(double)));
83  disconnect(mTool.get(), SIGNAL(toolProbeSector()), this, SLOT(changed()));
84  }
85 
86  mTool = tool;
87 
88  if (mTool)
89  {
90  connect(mTool.get(), SIGNAL(toolTransformAndTimestamp(Transform3D,double)), this, SLOT(toolTransformAndTimestampSlot(Transform3D,double)));
91  connect(mTool.get(), SIGNAL(toolVisible(bool)), this, SLOT(toolVisibleSlot(bool)));
92  connect(mTool.get(), SIGNAL(tooltipOffset(double)), this, SLOT(tooltipOffsetSlot(double)));
93  connect(mTool.get(), SIGNAL(toolProbeSector()), this, SLOT(changed()));
94 
95  emit toolVisible(mTool->getVisible());
96  toolTransformAndTimestampSlot(mTool->get_prMt(), 0); // initial values
97  tooltipOffsetSlot(mTool->getTooltipOffset());
98  }
99 
100  this->centerChangedSlot(); // force center update for tool==0
101  this->changed();
102 }
103 
104 void SliceProxy::toolTransformAndTimestampSlot(Transform3D prMt, double timestamp)
105 {
106  //std::cout << "proxy get transform" << std::endl;
107  Transform3D rMpr = mDataManager->get_rMpr();
108  Transform3D rMt = rMpr*prMt;
109 // if (similar(rMt, mCutplane->getToolPosition()))
110 // {
111 // return;
112 // }
113  mCutplane->setToolPosition(rMt);
114  this->changed();
115  emit toolTransformAndTimestamp(prMt, timestamp);
116 
117 }
118 
119 void SliceProxy::tooltipOffsetSlot(double val)
120 {
121  if (mUseTooltipOffset)
122  {
123  mCutplane->setToolOffset(val);
124  this->changed();
125  }
126 }
127 
129 {
130  if (!use)
131  {
132  tooltipOffsetSlot(0);
133  }
134  mUseTooltipOffset = use;
135  if (use)
136  {
137  tooltipOffsetSlot(mTool->getTooltipOffset());
138  }
139 }
140 
141 void SliceProxy::toolVisibleSlot(bool visible)
142 {
143 
144 }
145 
148 Transform3D SliceProxy::getSyntheticToolPos(const Vector3D& center) const
149 {
152  return T_c * R_tq;
153 }
154 
156 {
157  mDefaultCenter = c;
158  this->centerChangedSlot();
159 }
160 
162 {
163  mAlwaysUseDefaultCenter = on;
164  this->centerChangedSlot();
165 }
166 
167 void SliceProxy::centerChangedSlot()
168 {
169  if (mAlwaysUseDefaultCenter)
170  {
171  mCutplane->setFixedCenter(mDefaultCenter);
172  }
173  else if (mTool)
174  {
175  Vector3D c = mDataManager->getCenter();
176  mCutplane->setFixedCenter(c);
177  //std::cout << "center changed: " + string_cast(c) << std::endl;
178  }
179 
180  changed();
181 }
182 
183 void SliceProxy::clinicalApplicationChangedSlot()
184 {
185  mCutplane->setClinicalApplication(mDataManager->getClinicalApplication());
186  changed();
187 }
188 
191 void SliceProxy::initializeFromPlane(PLANE_TYPE plane, bool useGravity, bool useViewOffset, double viewportHeight, double toolViewOffset)
192 {
193  Vector3D gravityDir = -mDataManager->getOperatingTable().getVectorUp();
194 
195  if (plane==ptTOOLSIDEPLANE)
196  {
197  useGravity = true;
198  }
199 
200  mCutplane->initializeFromPlane(plane,
201  useGravity, gravityDir,
202  useViewOffset, viewportHeight, toolViewOffset,
203  mDataManager->getClinicalApplication());
204 
205  changed();
206 }
207 
209 {
210  return *mCutplane;
211 }
212 
214 {
215  mCutplane.reset(new SliceComputer(val));
216  changed();
217 }
218 
219 void SliceProxy::setOrientation(ORIENTATION_TYPE orientation)
220 {
221  mCutplane->setOrientationType(orientation);
222  changed();
223 }
224 
225 void SliceProxy::setPlane(PLANE_TYPE plane)
226 {
227  mCutplane->setPlaneType(plane);
228  changed();
229 }
230 
231 void SliceProxy::setFollowType(FOLLOW_TYPE followType)
232 {
233  mCutplane->setFollowType(followType);
234  changed();
235 }
236 
237 void SliceProxy::setGravity(bool use, const Vector3D& dir)
238 {
239  mCutplane->setGravity(use, dir);
240  this->changed();
241 }
242 void SliceProxy::setToolViewOffset(bool use, double viewportHeight, double toolViewOffset)
243 {
244  mCutplane->setToolViewOffset(use, viewportHeight, toolViewOffset);
245  this->changed();
246 }
247 
248 void SliceProxy::setToolViewportHeight(double viewportHeight)
249 {
250  mCutplane->setToolViewportHeight(viewportHeight);
251  this->changed();
252 }
253 
255 {
256  return mTool;
257 }
258 
260 {
261  SlicePlane plane = mCutplane->getPlane();
262  //std::cout << "---" << " proxy get transform.c : " << plane.c << std::endl;
263  //std::cout << "proxy get transform -" << getName() <<":\n" << plane << std::endl;
264  return createTransformIJC(plane.i, plane.j, plane.c).inv();
265 }
266 
267 void SliceProxy::changed()
268 {
269  SlicePlane plane = mCutplane->getPlane();
270  if (similar(plane, mLastEmittedSlicePlane))
271  return;
272  mLastEmittedSlicePlane = plane;
273  emit transformChanged(get_sMr());
274 }
275 
276 void SliceProxy::printSelf(std::ostream & os, Indent indent)
277 {
278  os << indent << "sliceproxy" << std::endl;
279  os << indent << "sMr: " << std::endl;
280  get_sMr().put(os, indent.getIndent()+3);
281  os << std::endl;
282 }
283 
284 } // 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:103
Transform3D createTransformRotateY(const double angle)
static SliceProxyPtr create(PatientModelServicePtr dataManager)
void setToolViewOffset(bool use, double viewportHeight, double toolViewOffset)
int getIndent() const
Definition: cxIndent.cpp:44
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:56
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:49
Transform3D createTransformTranslate(const Vector3D &translation)
virtual ~SliceProxy()
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:63
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