NorMIT-nav  22.09
An IGT application
cxData.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 "cxData.h"
14 
15 #include <QDomDocument>
16 #include <QDateTime>
17 #include <QRegExp>
18 
19 #include <vtkPlane.h>
20 
22 #include "cxTime.h"
23 #include "cxLandmark.h"
25 #include "cxLogger.h"
26 #include "cxBoundingBox3D.h"
27 
28 namespace cx
29 {
30 
31 Data::Data(const QString& uid, const QString& name) :
32  mUid(uid), mFilename(""), mRegistrationStatus(rsNOT_REGISTRATED)//, mParentFrame("")
33 {
34  mTimeInfo.mAcquisitionTime = QDateTime::currentDateTime();
35  mTimeInfo.mSoftwareAcquisitionTime = QDateTime();
36  mTimeInfo.mOriginalAcquisitionTime = QDateTime();
37 
38  if (name == "")
39  mName = mUid;
40  else
41  mName = name;
45 
47 }
48 
50 {
51 }
52 void Data::setUid(const QString& uid)
53 {
54  mUid = uid;
55  emit propertiesChanged();
56 }
57 
58 void Data::setName(const QString& name)
59 {
60  mName = name;
61  emit propertiesChanged();
62 }
63 
64 QString Data::getUid() const
65 {
66  return mUid;
67 }
68 
69 QString Data::getName() const
70 {
71  return mName;
72 }
73 
74 QString Data::getFilename() const
75 {
76  return mFilename;
77 }
78 void Data::setFilename(QString val)
79 {
80  mFilename = val;
81 }
82 
87 {
88  return m_rMd_History->getCurrentRegistration().mValue;
89 }
90 
92 {
93  return m_rMd_History;
94 }
95 
96 QString Data::getSpace()
97 {
98  return mUid;
99 }
100 
102 {
103  return m_rMd_History->getCurrentParentSpace().mUid;
104 }
105 
106 std::vector<Vector3D> Data::getPointCloud() const
107 {
108  DoubleBoundingBox3D bb = this->boundingBox();
109  std::vector<Vector3D> retval;
110 
111  for (unsigned x=0; x<2; ++x)
112  for (unsigned y=0; y<2; ++y)
113  for (unsigned z=0; z<2; ++z)
114  retval.push_back(bb.corner(x,y,z));
115 
116 // Transform3D rMd = this->get_rMd();
117 // for (unsigned i=0; i<retval.size(); ++i)
118 // retval[i] = rMd.coord(retval[i]);
119 
120  return retval;
121 }
122 
123 void Data::addXml(QDomNode& dataNode)
124 {
125  QDomDocument doc = dataNode.ownerDocument();
126 
127  m_rMd_History->addXml(dataNode);
128 
129  dataNode.toElement().setAttribute("uid", mUid);
130  dataNode.toElement().setAttribute("name", mName);
131  dataNode.toElement().setAttribute("type", this->getType());
132 
133  QDomElement filePathNode = doc.createElement("filePath");
134  filePathNode.appendChild(doc.createTextNode(this->getFilename()));
135  dataNode.appendChild(filePathNode);
136 
137  QDomElement acqTimeNode = doc.createElement("acqusitionTime");
138  acqTimeNode.appendChild(doc.createTextNode(mTimeInfo.mAcquisitionTime.toString(timestampMilliSecondsFormat())));
139  dataNode.appendChild(acqTimeNode);
140 
141  if (!mLandmarks->getLandmarks().empty())
142  {
143  QDomElement landmarksNode = doc.createElement("landmarks");
144  mLandmarks->addXml(landmarksNode);
145  dataNode.appendChild(landmarksNode);
146  }
147 }
148 
149 void Data::parseXml(QDomNode& dataNode)
150 {
151  if (dataNode.isNull())
152  return;
153 
154  QDomNode registrationHistory = dataNode.namedItem("registrationHistory");
155  m_rMd_History->parseXml(registrationHistory);
156 
157  if (!dataNode.namedItem("acqusitionTime").toElement().isNull())
158  mTimeInfo.mAcquisitionTime = QDateTime::fromString(dataNode.namedItem("acqusitionTime").toElement().text(),
160 
161  if (mLandmarks)
162  mLandmarks->parseXml(dataNode.namedItem("landmarks"));
163 }
164 
168 QDateTime Data::getAcquisitionTime() const
169 {
170  if (!mTimeInfo.mAcquisitionTime.isNull())
172  // quickie implementation: Assume uid contains time on format timestampSecondsFormat():
173 
174  // retrieve timestamp as
175  QRegExp tsReg("[0-9]{8}T[0-9]{6}");
176  if (tsReg.indexIn(mUid) > 0)
177  {
178  QDateTime datetime = QDateTime::fromString(tsReg.cap(0), timestampSecondsFormat());
179  return datetime;
180  }
181  return QDateTime();
182 }
183 
185 {
186  return mTimeInfo;
187 }
188 
189 bool Data::isEqual(DataPtr metric)
190 {
191  return streamXml2String(*this) == streamXml2String(*(metric.get()));
192 }
193 
194 void Data::setAcquisitionTime(QDateTime time)
195 {
197 }
198 
200 {
202 }
203 
205 {
207 }
208 
210 {
211  return mLandmarks;
212 }
213 
214 
216 {
217  return CoordinateSystem(csDATA, this->getUid());
218 }
219 
220 //Moved from Image
221 // methods for defining and storing clip planes. Data does not use these data, this is up to the mapper
223 {
224  this->addPlane(plane, mPersistentClipPlanes);
225 }
226 
227 void Data::addPlane(vtkPlanePtr plane, std::vector<vtkPlanePtr> &planes)
228 {
229  if (std::count(planes.begin(), planes.end(), plane))
230  return;
231  planes.push_back(plane);
232  emit clipPlanesChanged();
233 }
234 std::vector<vtkPlanePtr> Data::getAllClipPlanes()
235 {
236  std::vector<vtkPlanePtr> retval = mPersistentClipPlanes;
237 
238  for(int i = 0; i < mInteractiveClipPlanes.size(); ++i)
239  retval.push_back(mInteractiveClipPlanes[i]);
240 
242  retval.push_back(mInteractiveClipPlane);
243 
244  return retval;
245 }
246 
248 {
249  mPersistentClipPlanes.clear();
250  emit clipPlanesChanged();
251 }
252 
254 {
255  mInteractiveClipPlane = plane;
256  emit clipPlanesChanged();
257 }
258 
260 {
261  this->addPlane(plane, mInteractiveClipPlanes);
262 }
263 
265 {
266  for(int i = 0; i < mInteractiveClipPlanes.size(); ++i)
267  {
268  if(mInteractiveClipPlanes[i] == plane)
270  }
271 
272  emit clipPlanesChanged();
273 }
274 } // namespace cx
cx::Data::getType
virtual QString getType() const
Definition: cxData.h:109
cx::Data::getAllClipPlanes
virtual std::vector< vtkPlanePtr > getAllClipPlanes()
Definition: cxData.cpp:234
cxLogger.h
cx::Data::removeInteractiveClipPlane
void removeInteractiveClipPlane(vtkPlanePtr plane)
Definition: cxData.cpp:264
cx::DoubleBoundingBox3D
Representation of a floating-point bounding box in 3D. The data are stored as {xmin,...
Definition: cxBoundingBox3D.h:63
cx::RegistrationHistory
A history of registration events.
Definition: cxRegistrationTransform.h:96
cx::Data::addXml
virtual void addXml(QDomNode &dataNode)
adds xml information about the data and its variabels
Definition: cxData.cpp:123
rsNOT_REGISTRATED
rsNOT_REGISTRATED
Definition: cxDefinitions.h:128
cx::timestampMilliSecondsFormat
QString timestampMilliSecondsFormat()
Definition: cxTime.cpp:22
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::DoubleBoundingBox3D::corner
Vector3D corner(int x, int y, int z) const
Definition: cxBoundingBox3D.cpp:208
cx::Data::get_rMd
virtual Transform3D get_rMd() const
Definition: cxData.cpp:86
cx::Data::getAdvancedTimeInfo
virtual TimeInfo getAdvancedTimeInfo() const
Definition: cxData.cpp:184
cx::Data::getParentSpace
virtual QString getParentSpace()
Definition: cxData.cpp:101
csDATA
csDATA
a datas space (d)
Definition: cxDefinitions.h:91
cx::Data::getFilename
virtual QString getFilename() const
Definition: cxData.cpp:74
cxBoundingBox3D.h
cxData.h
cx::Data::mPersistentClipPlanes
std::vector< vtkPlanePtr > mPersistentClipPlanes
Definition: cxData.h:161
cx::Data::transformChanged
void transformChanged()
emitted when transform is changed
cx::Data::clearPersistentClipPlanes
virtual void clearPersistentClipPlanes()
Definition: cxData.cpp:247
cx::RegistrationHistory::currentChanged
void currentChanged()
cx::Data::mInteractiveClipPlanes
std::vector< vtkPlanePtr > mInteractiveClipPlanes
Definition: cxData.h:162
cx::Data::isEqual
virtual bool isEqual(DataPtr metric)
Definition: cxData.cpp:189
cx::Data::setSoftwareAcquisitionTime
void setSoftwareAcquisitionTime(QDateTime time)
Definition: cxData.cpp:199
cx::Data::setOriginalAcquisitionTime
void setOriginalAcquisitionTime(QDateTime time)
Definition: cxData.cpp:204
cx::Transform3D
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
Definition: cxLandmarkPatientRegistrationWidget.h:33
cx::TimeInfo
Definition: cxData.h:43
cx::Data::mUid
QString mUid
Definition: cxData.h:153
cx::Data::mFilename
QString mFilename
Definition: cxData.h:155
cx::Data::m_rMd_History
RegistrationHistoryPtr m_rMd_History
Definition: cxData.h:160
cx::Data::mInteractiveClipPlane
vtkPlanePtr mInteractiveClipPlane
Definition: cxData.h:163
cx::RegistrationHistoryPtr
boost::shared_ptr< class RegistrationHistory > RegistrationHistoryPtr
Definition: cxDataManager.h:37
cx::DataPtr
boost::shared_ptr< class Data > DataPtr
Definition: cxRegistrationApplicator.h:22
cxCoordinateSystemHelpers.h
cx::Data::setAcquisitionTime
void setAcquisitionTime(QDateTime time)
Definition: cxData.cpp:194
cx::TimeInfo::mAcquisitionTime
QDateTime mAcquisitionTime
Possibly modified time stamp.
Definition: cxData.h:45
cx::timestampSecondsFormat
QString timestampSecondsFormat()
Definition: cxTime.cpp:18
vtkPlanePtr
vtkSmartPointer< class vtkPlane > vtkPlanePtr
Definition: cxProbeSector.cpp:33
cx::Data::getSpace
virtual QString getSpace()
Definition: cxData.cpp:96
cx::Data::clipPlanesChanged
void clipPlanesChanged()
cxRegistrationTransform.h
cx::Data::getUid
virtual QString getUid() const
Definition: cxData.cpp:64
cx::LandmarksPtr
boost::shared_ptr< class Landmarks > LandmarksPtr
Definition: cxData.h:41
cx::Data::addPersistentClipPlane
virtual void addPersistentClipPlane(vtkPlanePtr plane)
Definition: cxData.cpp:222
cx::TimeInfo::mSoftwareAcquisitionTime
QDateTime mSoftwareAcquisitionTime
Time stamp created in at arrival in CX or CX related software.
Definition: cxData.h:46
cx::Data::~Data
virtual ~Data()
Definition: cxData.cpp:49
cxTime.h
cx::Data::setUid
void setUid(const QString &uid)
Definition: cxData.cpp:52
cx::Data::addInteractiveClipPlane
void addInteractiveClipPlane(vtkPlanePtr plane)
Definition: cxData.cpp:259
cx::Data::mTimeInfo
TimeInfo mTimeInfo
Definition: cxData.h:156
cx::Data::getLandmarks
LandmarksPtr getLandmarks()
Definition: cxData.cpp:209
cx::Data::propertiesChanged
void propertiesChanged()
emitted when one of the metadata properties (uid, name etc) changes
cx::Data::parseXml
virtual void parseXml(QDomNode &dataNode)
Use a XML node to load data.
Definition: cxData.cpp:149
cx::Data::getCoordinateSystem
virtual CoordinateSystem getCoordinateSystem()
Definition: cxData.cpp:215
cx::Landmarks::create
static LandmarksPtr create()
Definition: cxLandmark.cpp:95
cx::Data::get_rMd_History
virtual RegistrationHistoryPtr get_rMd_History()
Definition: cxData.cpp:91
cx::Data::boundingBox
virtual DoubleBoundingBox3D boundingBox() const =0
cx::Data::getName
virtual QString getName() const
Definition: cxData.cpp:69
cx::Data::mName
QString mName
Definition: cxData.h:154
cx::Data::mLandmarks
LandmarksPtr mLandmarks
Definition: cxData.h:157
cx::Data::transformChangedSlot
virtual void transformChangedSlot()
Definition: cxData.h:148
streamXml2String
QString streamXml2String(T &val)
Definition: cxTypeConversions.h:89
cx::Data::getAcquisitionTime
virtual QDateTime getAcquisitionTime() const
Definition: cxData.cpp:168
cx::Data::setName
void setName(const QString &name)
Definition: cxData.cpp:58
cx::Data::getPointCloud
virtual std::vector< Vector3D > getPointCloud() const
Definition: cxData.cpp:106
cxLandmark.h
cx::CoordinateSystem
Identification of a Coordinate system.
Definition: cxCoordinateSystemHelpers.h:31
cx::Data::Data
Data(const QString &uid, const QString &name="")
Definition: cxData.cpp:31
cx::Data::setInteractiveClipPlane
virtual void setInteractiveClipPlane(vtkPlanePtr plane)
set a plane that is not saved
Definition: cxData.cpp:253
cx::TimeInfo::mOriginalAcquisitionTime
QDateTime mOriginalAcquisitionTime
Original aquisition time (from hardware if possible)
Definition: cxData.h:47
cx::Data::setFilename
virtual void setFilename(QString val)
Definition: cxData.cpp:78