CustusX  15.8
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 
65 {
66 }
67 
69 {
70  if (mTool)
71  {
72  disconnect(mTool.get(), SIGNAL(toolTransformAndTimestamp(Transform3D,double)), this, SLOT(toolTransformAndTimestampSlot(Transform3D,double)));
73  disconnect(mTool.get(), SIGNAL(toolVisible(bool)), this, SLOT(toolVisibleSlot(bool)));
74  disconnect(mTool.get(), SIGNAL(tooltipOffset(double)), this, SLOT(tooltipOffsetSlot(double)));
75  disconnect(mTool.get(), SIGNAL(toolProbeSector()), this, SLOT(changed()));
76  }
77 
78  mTool = tool;
79 
80  if (mTool)
81  {
82  connect(mTool.get(), SIGNAL(toolTransformAndTimestamp(Transform3D,double)), this, SLOT(toolTransformAndTimestampSlot(Transform3D,double)));
83  connect(mTool.get(), SIGNAL(toolVisible(bool)), this, SLOT(toolVisibleSlot(bool)));
84  connect(mTool.get(), SIGNAL(tooltipOffset(double)), this, SLOT(tooltipOffsetSlot(double)));
85  connect(mTool.get(), SIGNAL(toolProbeSector()), this, SLOT(changed()));
86 
87  emit toolVisible(mTool->getVisible());
88  toolTransformAndTimestampSlot(mTool->get_prMt(), 0); // initial values
89  tooltipOffsetSlot(mTool->getTooltipOffset());
90  }
91 
92  this->centerChangedSlot(); // force center update for tool==0
93  this->changed();
94 }
95 
96 void SliceProxy::toolTransformAndTimestampSlot(Transform3D prMt, double timestamp)
97 {
98  //std::cout << "proxy get transform" << std::endl;
99  Transform3D rMpr = mDataManager->get_rMpr();
100  Transform3D rMt = rMpr*prMt;
101 // if (similar(rMt, mCutplane->getToolPosition()))
102 // {
103 // return;
104 // }
105  mCutplane->setToolPosition(rMt);
106  this->changed();
107  emit toolTransformAndTimestamp(prMt, timestamp);
108 
109 }
110 
111 void SliceProxy::tooltipOffsetSlot(double val)
112 {
113  if (mUseTooltipOffset)
114  {
115  mCutplane->setToolOffset(val);
116  this->changed();
117  }
118 }
119 
121 {
122  if (!use)
123  {
124  tooltipOffsetSlot(0);
125  }
126  mUseTooltipOffset = use;
127  if (use)
128  {
129  tooltipOffsetSlot(mTool->getTooltipOffset());
130  }
131 }
132 
133 void SliceProxy::toolVisibleSlot(bool visible)
134 {
135 
136 }
137 
140 Transform3D SliceProxy::getSyntheticToolPos(const Vector3D& center) const
141 {
144  return T_c * R_tq;
145 }
146 
148 {
149  mDefaultCenter = c;
150  this->centerChangedSlot();
151 }
152 
154 {
155  mAlwaysUseDefaultCenter = on;
156  this->centerChangedSlot();
157 }
158 
159 void SliceProxy::centerChangedSlot()
160 {
161  if (mAlwaysUseDefaultCenter)
162  {
163  mCutplane->setFixedCenter(mDefaultCenter);
164  }
165  else if (mTool)
166  {
167  Vector3D c = mDataManager->getCenter();
168  mCutplane->setFixedCenter(c);
169  //std::cout << "center changed: " + string_cast(c) << std::endl;
170  }
171  else
172  {
173  // If no tool is available, ensure only dummy values are used.
174  // It is very important that this volume is completely frozen in order
175  // to avoid any confusion - the user must know it is nonnavigable.
176  mCutplane->setFixedCenter(mDefaultCenter);
177  mCutplane->setToolPosition(getSyntheticToolPos(mDefaultCenter));
178  //std::cout << "center changed: " + string_cast(mDefaultCenter) << std::endl;
179  }
180 
181  changed();
182 }
183 
184 void SliceProxy::clinicalApplicationChangedSlot()
185 {
186  mCutplane->setClinicalApplication(mDataManager->getClinicalApplication());
187  changed();
188 }
189 
192 void SliceProxy::initializeFromPlane(PLANE_TYPE plane, bool useGravity, const Vector3D& gravityDir, bool useViewOffset, double viewportHeight, double toolViewOffset, bool useConstrainedViewOffset)
193 {
194  mCutplane->initializeFromPlane(plane,
195  useGravity, gravityDir,
196  useViewOffset, viewportHeight, toolViewOffset,
197  mDataManager->getClinicalApplication(),
198  useConstrainedViewOffset);
199  changed();
200 // setPlane(plane);
201 // //Logger::log("vm.log"," set plane to proxy ");
202 // if (plane == ptSAGITTAL || plane == ptCORONAL || plane == ptAXIAL )
203 // {
204 // setOrientation(otORTHOGONAL);
205 // setFollowType(ftFIXED_CENTER);
206 // }
207 // else if (plane == ptANYPLANE || plane==ptRADIALPLANE || plane==ptSIDEPLANE)
208 // {
209 // setOrientation(otOBLIQUE);
210 // setFollowType(ftFOLLOW_TOOL);
211 //
212 // setGravity(useGravity, gravityDir);
213 // setToolViewOffset(useViewOffset, viewportHeight, toolViewOffset); // TODO finish this one
214 // }
215 }
216 
218 {
219  return *mCutplane;
220 }
221 
223 {
224  mCutplane.reset(new SliceComputer(val));
225  changed();
226 }
227 
228 void SliceProxy::setOrientation(ORIENTATION_TYPE orientation)
229 {
230  mCutplane->setOrientationType(orientation);
231  changed();
232 }
233 
234 void SliceProxy::setPlane(PLANE_TYPE plane)
235 {
236  mCutplane->setPlaneType(plane);
237  changed();
238 }
239 
240 void SliceProxy::setFollowType(FOLLOW_TYPE followType)
241 {
242  mCutplane->setFollowType(followType);
243  changed();
244 }
245 
246 void SliceProxy::setGravity(bool use, const Vector3D& dir)
247 {
248  mCutplane->setGravity(use, dir);
249  this->changed();
250 }
251 void SliceProxy::setToolViewOffset(bool use, double viewportHeight, double toolViewOffset, bool useConstrainedViewOffset)
252 {
253  mCutplane->setToolViewOffset(use, viewportHeight, toolViewOffset, useConstrainedViewOffset);
254  this->changed();
255 }
256 
257 void SliceProxy::setToolViewportHeight(double viewportHeight)
258 {
259  mCutplane->setToolViewportHeight(viewportHeight);
260  this->changed();
261 }
262 
264 {
265  return mTool;
266 }
267 
269 {
270  SlicePlane plane = mCutplane->getPlane();
271  //std::cout << "---" << " proxy get transform.c : " << plane.c << std::endl;
272  //std::cout << "proxy get transform -" << getName() <<":\n" << plane << std::endl;
273  return createTransformIJC(plane.i, plane.j, plane.c).inv();
274 }
275 
276 void SliceProxy::changed()
277 {
278  emit transformChanged(get_sMr());
279 }
280 
281 void SliceProxy::printSelf(std::ostream & os, Indent indent)
282 {
283  os << indent << "sliceproxy" << std::endl;
284  os << indent << "sMr: " << std::endl;
285  get_sMr().put(os, indent.getIndent()+3);
286  os << std::endl;
287 }
288 
289 } // 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