Fraxinus  16.5.0-fx-rc6
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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, const Vector3D& gravityDir, bool useViewOffset, double viewportHeight, double toolViewOffset, bool useConstrainedViewOffset)
192 {
193  mCutplane->initializeFromPlane(plane,
194  useGravity, gravityDir,
195  useViewOffset, viewportHeight, toolViewOffset,
196  mDataManager->getClinicalApplication(),
197  useConstrainedViewOffset);
198  changed();
199 // setPlane(plane);
200 // //Logger::log("vm.log"," set plane to proxy ");
201 // if (plane == ptSAGITTAL || plane == ptCORONAL || plane == ptAXIAL )
202 // {
203 // setOrientation(otORTHOGONAL);
204 // setFollowType(ftFIXED_CENTER);
205 // }
206 // else if (plane == ptANYPLANE || plane==ptRADIALPLANE || plane==ptSIDEPLANE)
207 // {
208 // setOrientation(otOBLIQUE);
209 // setFollowType(ftFOLLOW_TOOL);
210 //
211 // setGravity(useGravity, gravityDir);
212 // setToolViewOffset(useViewOffset, viewportHeight, toolViewOffset); // TODO finish this one
213 // }
214 }
215 
217 {
218  return *mCutplane;
219 }
220 
222 {
223  mCutplane.reset(new SliceComputer(val));
224  changed();
225 }
226 
227 void SliceProxy::setOrientation(ORIENTATION_TYPE orientation)
228 {
229  mCutplane->setOrientationType(orientation);
230  changed();
231 }
232 
233 void SliceProxy::setPlane(PLANE_TYPE plane)
234 {
235  mCutplane->setPlaneType(plane);
236  changed();
237 }
238 
239 void SliceProxy::setFollowType(FOLLOW_TYPE followType)
240 {
241  mCutplane->setFollowType(followType);
242  changed();
243 }
244 
245 void SliceProxy::setGravity(bool use, const Vector3D& dir)
246 {
247  mCutplane->setGravity(use, dir);
248  this->changed();
249 }
250 void SliceProxy::setToolViewOffset(bool use, double viewportHeight, double toolViewOffset, bool useConstrainedViewOffset)
251 {
252  mCutplane->setToolViewOffset(use, viewportHeight, toolViewOffset, useConstrainedViewOffset);
253  this->changed();
254 }
255 
256 void SliceProxy::setToolViewportHeight(double viewportHeight)
257 {
258  mCutplane->setToolViewportHeight(viewportHeight);
259  this->changed();
260 }
261 
263 {
264  return mTool;
265 }
266 
268 {
269  SlicePlane plane = mCutplane->getPlane();
270  //std::cout << "---" << " proxy get transform.c : " << plane.c << std::endl;
271  //std::cout << "proxy get transform -" << getName() <<":\n" << plane << std::endl;
272  return createTransformIJC(plane.i, plane.j, plane.c).inv();
273 }
274 
275 void SliceProxy::changed()
276 {
277  emit transformChanged(get_sMr());
278 }
279 
280 void SliceProxy::printSelf(std::ostream & os, Indent indent)
281 {
282  os << indent << "sliceproxy" << std::endl;
283  os << indent << "sMr: " << std::endl;
284  get_sMr().put(os, indent.getIndent()+3);
285  os << std::endl;
286 }
287 
288 } // 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:102
Transform3D createTransformRotateY(const double angle)
static SliceProxyPtr create(PatientModelServicePtr dataManager)
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)
void initializeFromPlane(PLANE_TYPE plane, bool useGravity, const Vector3D &gravityDir, bool useViewOffset, double viewportHeight, double toolViewOffset, bool useConstrainedViewOffset=false)
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 transformChanged(Transform3D sMr)
emitted when transform is changed.
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()
void setToolViewOffset(bool use, double viewportHeight, double toolViewOffset, bool useConstrainedViewOffset=false)
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)
Transform3D createTransformRotateZ(const double angle)
void setDefaultCenter(const Vector3D &c)
void toolTransformAndTimestamp(Transform3D prMt, double timestamp)
forwarded from tool
#define M_PI
boost::shared_ptr< class Tool > ToolPtr