NorMIT-nav  22.09
An IGT application
cxProbeDefinition.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 "cxProbeDefinition.h"
14 #include <QDomNode>
15 #include "cxTypeConversions.h"
16 #include <iostream>
17 #include "cxLogger.h"
18 #include "cxImage.h"
19 
20 namespace cx
21 {
22 
23 namespace
24 {
25  double loadAttribute(QDomNode dataNode, QString name, double defVal)
26  {
27  QString text = dataNode.toElement().attribute(name);
28  bool ok;
29  double val = text.toDouble(&ok);
30  if (ok)
31  return val;
32  return defVal;
33  }
34 }
35 
36 // --------------------------------------------------------
37 // --------------------------------------------------------
38 // --------------------------------------------------------
39 
40 
42  mType(type), mDepthStart(0), mDepthEnd(0), mWidth(0),
43  mTemporalCalibration(0), mCenterOffset(0), mSoundSpeedCompensationFactor(1.0),
44  mUid("default"),
45  mOrigin_p(0, 0, 0), mSpacing(-1, -1, -1), mClipRect_p(0, 0, 0, 0), mSize(0, 0),
46  mDigital(false)
47 {}
48 
49 void ProbeDefinition::addXml(QDomNode dataNode) const
50 {
51  QDomElement elem = dataNode.toElement();
52  elem.setAttribute("type", qstring_cast(mType));
53  elem.setAttribute("depthStart", qstring_cast(mDepthStart));
54  elem.setAttribute("depthEnd", qstring_cast(mDepthEnd));
55  elem.setAttribute("width", qstring_cast(mWidth));
56 
57  elem.setAttribute("temporalCalibration", qstring_cast(mTemporalCalibration));
58  elem.setAttribute("centerOffset", qstring_cast(mCenterOffset));
59 
60  elem.setAttribute("uid", qstring_cast(mUid));
61 
62  QDomElement imageNode = dataNode.ownerDocument().createElement(Image::getTypeName());
63  this->addImageXml(imageNode);
64  dataNode.appendChild(imageNode);
65 }
66 
67 void ProbeDefinition::parseXml(QDomNode dataNode)
68 {
69  QDomElement elem = dataNode.toElement();
70 
71  mType = static_cast<TYPE>(elem.attribute("type").toInt());
72  mDepthStart = loadAttribute(elem, "depthStart", 0);
73  mDepthEnd = loadAttribute(elem, "depthEnd", 0);
74  mWidth = loadAttribute(elem, "width", 0);
75 
76  mTemporalCalibration = loadAttribute(elem, "temporalCalibration", 0);
77  mCenterOffset = loadAttribute(elem, "centerOffset", 0);
78  mUid = elem.attribute("uid");
79 
80  QDomNode imageNode = dataNode.namedItem(Image::getTypeName());
81  this->parseImageXml(imageNode);
82 }
83 
84 void ProbeDefinition::addImageXml(QDomNode dataNode) const
85 {
86  QDomElement elem = dataNode.toElement();
87 
88  elem.setAttribute("origin_p", qstring_cast(mOrigin_p));
89  elem.setAttribute("spacing", qstring_cast(mSpacing));
90  elem.setAttribute("clipRect_p", qstring_cast(mClipRect_p));
91  elem.setAttribute("width", qstring_cast(mSize.width()));
92  elem.setAttribute("height", qstring_cast(mSize.height()));
93 }
94 
95 void ProbeDefinition::parseImageXml(QDomNode dataNode)
96 {
97  QDomElement elem = dataNode.toElement();
98 
99  mOrigin_p = Vector3D::fromString(elem.attribute("origin_p"));
100  mSpacing = Vector3D::fromString(elem.attribute("spacing"));
101  mClipRect_p = DoubleBoundingBox3D::fromString(elem.attribute("clipRect_p"));
102  mSize.setWidth(loadAttribute(elem, "width", 0));
103  mSize.setHeight(loadAttribute(elem, "height", 0));
104 }
105 
107 {
108  mTemporalCalibration = value;
109 }
110 
112 {
113  mType = type;
114 }
115 
116 void ProbeDefinition::setSector(double depthStart, double depthEnd, double width, double centerOffset)
117 {
118  mDepthStart=depthStart;
119  mDepthEnd=depthEnd;
120  mWidth=width;
121  mCenterOffset=centerOffset;
122 }
123 
125 {
126  return mType;
127 }
128 
130 {
131  return mDepthStart;
132 }
133 
135 {
136  return mDepthEnd;
137 }
138 
140 {
141  return mWidth;
142 }
143 
145 {
146  return mTemporalCalibration;
147 }
148 
150 {
151  return mCenterOffset;
152 }
153 
154 void ProbeDefinition::resample(QSize newSize)
155 {
156  if (newSize==mSize)
157  return;
158 
159  Vector3D factor(double(newSize.width())/mSize.width(), double(newSize.height())/mSize.height(), 1);
160 
161  mOrigin_p = multiply_elems(mOrigin_p, factor);
162  mSpacing = divide_elems(mSpacing, factor);
163 
164  Vector3D cr0 = multiply_elems(mClipRect_p.corner(0,0,0), factor);
165  Vector3D cr1 = multiply_elems(mClipRect_p.corner(1,1,1), factor);
166  mClipRect_p = DoubleBoundingBox3D(cr0, cr1);
167 
168  mSize = newSize;
169 }
170 
171 QString ProbeDefinition::getUid() const
172 {
173  return mUid;
174 }
175 
176 void ProbeDefinition::setUid(QString uid)
177 {
178  mUid = uid;
179 }
180 
182 {
183  // cliprect and sector data are connected to linear probes:
184  if (mType==tLINEAR)
185  {
186  mClipRect_p[0] = mOrigin_p[0] - mWidth/2/mSpacing[0];
187  mClipRect_p[1] = mOrigin_p[0] + mWidth/2/mSpacing[0];
188 
189  mClipRect_p[2] = mOrigin_p[1] + mDepthStart/mSpacing[1];
190  mClipRect_p[3] = mOrigin_p[1] + mDepthEnd/mSpacing[1];
191  }
192 }
193 
195 {
196  // cliprect and sector data are connected to linear probes:
197  if (mType==tLINEAR)
198  {
199  mWidth = 2*std::max(fabs(mClipRect_p[0] - mOrigin_p[0]), fabs(mClipRect_p[1] - mOrigin_p[0])) * mSpacing[0];
200  mDepthStart = (mClipRect_p[2] - mOrigin_p[1]) * mSpacing[1];
201  mDepthEnd = (mClipRect_p[3] - mOrigin_p[1]) * mSpacing[1];
202  }
203 }
204 
206 {
207  if(similar(factor, 1.0))
208  return;
209  mSpacing[1] = mSpacing[1] * factor / mSoundSpeedCompensationFactor;
210  mSoundSpeedCompensationFactor = factor;
211 
212  if (this->getType() != ProbeDefinition::tLINEAR)
213  reportWarning("Sound speed compensation is applied to spacing[1], i.e. it is correct for linear probes and approxomate for other probes. Factor: " + qstring_cast(factor));
214 }
215 
217 {
218  return mSoundSpeedCompensationFactor;
219 }
220 
221 //Should be transform_uMv(p) (input in pixels, output in mm)
222 Vector3D ProbeDefinition::transform_p_to_u(const Vector3D& q_p) const
223 {
224  Vector3D c(q_p[0], double(mSize.height()) - q_p[1] - 1, -q_p[2]);
225  c = multiply_elems(c, mSpacing);
226  return c;
227 }
228 
230 {
231  return this->transform_p_to_u(mOrigin_p);
232 }
233 
235 {
236  Vector3D p0 = transform_p_to_u(mClipRect_p.corner(0,0,0));
237  Vector3D p1 = transform_p_to_u(mClipRect_p.corner(1,1,1));
238  return DoubleBoundingBox3D(p0,p1);
239 }
240 
242 {
243  return mOrigin_p;
244 }
245 
247 {
248  return mSpacing;
249 }
250 
252 {
253  return mClipRect_p;
254 }
255 
257 {
258  return mSize;
259 }
260 
262 {
263  mOrigin_p = origin_p;
264 }
265 
267 {
268  mSpacing = spacing;
269 }
270 
272 {
273  mClipRect_p = clipRect_p;
274 }
275 
276 void ProbeDefinition::setSize(QSize size)
277 {
278  mSize = size;
279 }
280 
282 {
283  mDigital = val;
284 }
285 
287 {
288  return mDigital;
289 }
290 
291 void ProbeDefinition::setVariable(QString variableName, QVariant value)
292 {
293  mAdditionalVariables[variableName] = value;
294 }
295 
296 QVariant ProbeDefinition::getVariable(QString variableName)
297 {
298  if(!mAdditionalVariables.contains(variableName))
299  CX_LOG_ERROR(QString("Variable %1 don't exist in ProbeDefinition with uid %2").arg(variableName).arg(this->mUid));
300  return mAdditionalVariables[variableName];
301 }
302 
303 } //cx
cx::ProbeDefinition::getOrigin_p
Vector3D getOrigin_p() const
Definition: cxProbeDefinition.cpp:241
cx::ProbeDefinition::getSoundSpeedCompensationFactor
double getSoundSpeedCompensationFactor() const
Definition: cxProbeDefinition.cpp:216
cxLogger.h
cxProbeDefinition.h
qstring_cast
QString qstring_cast(const T &val)
Definition: cxTypeConversions.h:46
cx::DoubleBoundingBox3D
Representation of a floating-point bounding box in 3D. The data are stored as {xmin,...
Definition: cxBoundingBox3D.h:63
cx::ProbeDefinition::tLINEAR
@ tLINEAR
US beam is emitted straight forward.
Definition: cxProbeDefinition.h:106
cx::ProbeDefinition::getWidth
double getWidth() const
Definition: cxProbeDefinition.cpp:139
cx::ProbeDefinition::getClipRect_u
DoubleBoundingBox3D getClipRect_u() const
sector clipping rect in image space u. (lower-left corner origin)
Definition: cxProbeDefinition.cpp:234
cx::ProbeDefinition::getUseDigitalVideo
bool getUseDigitalVideo() const
Definition: cxProbeDefinition.cpp:286
cx::ProbeDefinition::getDepthEnd
double getDepthEnd() const
Definition: cxProbeDefinition.cpp:134
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::ProbeDefinition::getVariable
QVariant getVariable(QString variableName)
Definition: cxProbeDefinition.cpp:296
cx::DoubleBoundingBox3D::corner
Vector3D corner(int x, int y, int z) const
Definition: cxBoundingBox3D.cpp:208
cxImage.h
cx::ProbeDefinition::TYPE
TYPE
Definition: cxProbeDefinition.h:104
cx::ProbeDefinition::getSize
QSize getSize() const
Definition: cxProbeDefinition.cpp:256
cx::ProbeDefinition::setType
void setType(TYPE type)
Definition: cxProbeDefinition.cpp:111
cx::ProbeDefinition::setSector
void setSector(double depthStart, double depthEnd, double width, double centerOffset=0)
Definition: cxProbeDefinition.cpp:116
cx::ProbeDefinition::updateSectorFromClipRect
void updateSectorFromClipRect()
Definition: cxProbeDefinition.cpp:194
cx::ProbeDefinition::setSpacing
void setSpacing(Vector3D spacing)
Definition: cxProbeDefinition.cpp:266
cx::ProbeDefinition::parseXml
void parseXml(QDomNode dataNode)
Definition: cxProbeDefinition.cpp:67
cx::ProbeDefinition::addXml
void addXml(QDomNode dataNode) const
Definition: cxProbeDefinition.cpp:49
cx::multiply_elems
Vector3D multiply_elems(const Vector3D &a, const Vector3D &b)
perform element-wise multiplication of a and b.
Definition: cxVector3D.cpp:31
cx::divide_elems
Vector3D divide_elems(const Vector3D &a, const Vector3D &b)
perform element-wise division of a and b.
Definition: cxVector3D.cpp:36
cx::ProbeDefinition::getCenterOffset
double getCenterOffset() const
Definition: cxProbeDefinition.cpp:149
cx::ProbeDefinition::setUseDigitalVideo
void setUseDigitalVideo(bool val)
RTSource is digital (eg. US sector is set digitally, not read from .xml file)
Definition: cxProbeDefinition.cpp:281
cx::ProbeDefinition::getDepthStart
double getDepthStart() const
Definition: cxProbeDefinition.cpp:129
cx::ProbeDefinition::setOrigin_p
void setOrigin_p(Vector3D origin_p)
Definition: cxProbeDefinition.cpp:261
cx::ProbeDefinition::resample
void resample(QSize mSize)
Set a new image size. Resample all other parameters to match this new image size, keeping sizes in mi...
Definition: cxProbeDefinition.cpp:154
cx::ProbeDefinition::getUid
QString getUid() const
Definition: cxProbeDefinition.cpp:171
cx::ProbeDefinition::ProbeDefinition
ProbeDefinition(TYPE type=tNONE)
Definition: cxProbeDefinition.cpp:41
cx::ProbeDefinition::updateClipRectFromSector
void updateClipRectFromSector()
Definition: cxProbeDefinition.cpp:181
cx::Image::getTypeName
static QString getTypeName()
Definition: cxImage.h:126
cxTypeConversions.h
CX_LOG_ERROR
#define CX_LOG_ERROR
Definition: cxLogger.h:99
cx::ProbeDefinition::setClipRect_p
void setClipRect_p(DoubleBoundingBox3D clipRect_p)
Definition: cxProbeDefinition.cpp:271
cx::DoubleBoundingBox3D::fromString
static DoubleBoundingBox3D fromString(const QString &text)
construct a bb from a string containing 6 whitespace-separated numbers
Definition: cxBoundingBox3D.cpp:258
cx::ProbeDefinition::getType
TYPE getType() const
Definition: cxProbeDefinition.cpp:124
cx::ProbeDefinition::setTemporalCalibration
void setTemporalCalibration(double value)
Definition: cxProbeDefinition.cpp:106
cx::ProbeDefinition::setUid
void setUid(QString uid)
Definition: cxProbeDefinition.cpp:176
cx::ProbeDefinition::getOrigin_u
Vector3D getOrigin_u() const
probe origin in image space u. (lower-left corner origin)
Definition: cxProbeDefinition.cpp:229
cx::ProbeDefinition::getSpacing
Vector3D getSpacing() const
Definition: cxProbeDefinition.cpp:246
cx::ProbeDefinition::getClipRect_p
DoubleBoundingBox3D getClipRect_p() const
Definition: cxProbeDefinition.cpp:251
cx::ProbeDefinition::applySoundSpeedCompensationFactor
void applySoundSpeedCompensationFactor(double factor)
Compensate for soundspeed for linear probes.
Definition: cxProbeDefinition.cpp:205
cx::ProbeDefinition::getTemporalCalibration
double getTemporalCalibration() const
Definition: cxProbeDefinition.cpp:144
cx::similar
bool similar(const CameraInfo &lhs, const CameraInfo &rhs, double tol)
Definition: cxCameraStyleForView.cpp:506
cx::Vector3D
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:42
cx::ProbeDefinition::setVariable
void setVariable(QString variableName, QVariant value)
Definition: cxProbeDefinition.cpp:291
cx::reportWarning
void reportWarning(QString msg)
Definition: cxLogger.cpp:70
cx::ProbeDefinition::setSize
void setSize(QSize size)
Definition: cxProbeDefinition.cpp:276