Fraxinus  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
std::vector< vtkPlanePtr > mInteractiveClipPlanes
Definition: cxData.h:162
virtual void clearPersistentClipPlanes()
Definition: cxData.cpp:247
virtual Transform3D get_rMd() const
Definition: cxData.cpp:86
boost::shared_ptr< class RegistrationHistory > RegistrationHistoryPtr
Definition: cxDataManager.h:37
void removeInteractiveClipPlane(vtkPlanePtr plane)
Definition: cxData.cpp:264
Vector3D corner(int x, int y, int z) const
QDateTime mOriginalAcquisitionTime
Original aquisition time (from hardware if possible)
Definition: cxData.h:47
void setSoftwareAcquisitionTime(QDateTime time)
Definition: cxData.cpp:199
QString mUid
Definition: cxData.h:153
virtual bool isEqual(DataPtr metric)
Definition: cxData.cpp:189
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
void propertiesChanged()
emitted when one of the metadata properties (uid, name etc) changes
virtual QString getFilename() const
Definition: cxData.cpp:74
LandmarksPtr getLandmarks()
Definition: cxData.cpp:209
QString timestampMilliSecondsFormat()
Definition: cxTime.cpp:22
QString mName
Definition: cxData.h:154
void transformChanged()
emitted when transform is changed
TimeInfo mTimeInfo
Definition: cxData.h:156
void setName(const QString &name)
Definition: cxData.cpp:58
virtual void addXml(QDomNode &dataNode)
adds xml information about the data and its variabels
Definition: cxData.cpp:123
QString timestampSecondsFormat()
Definition: cxTime.cpp:18
csDATA
a datas space (d)
Definition: cxDefinitions.h:90
boost::shared_ptr< class Landmarks > LandmarksPtr
Definition: cxData.h:41
virtual QString getUid() const
Definition: cxData.cpp:64
void clipPlanesChanged()
boost::shared_ptr< class Data > DataPtr
QString mFilename
Definition: cxData.h:155
virtual RegistrationHistoryPtr get_rMd_History()
Definition: cxData.cpp:91
virtual QString getType() const
Definition: cxData.h:109
void setUid(const QString &uid)
Definition: cxData.cpp:52
virtual QString getName() const
Definition: cxData.cpp:69
virtual void parseXml(QDomNode &dataNode)
Use a XML node to load data.
Definition: cxData.cpp:149
virtual ~Data()
Definition: cxData.cpp:49
virtual TimeInfo getAdvancedTimeInfo() const
Definition: cxData.cpp:184
virtual QString getSpace()
Definition: cxData.cpp:96
void setAcquisitionTime(QDateTime time)
Definition: cxData.cpp:194
Identification of a Coordinate system.
virtual void setInteractiveClipPlane(vtkPlanePtr plane)
set a plane that is not saved
Definition: cxData.cpp:253
virtual std::vector< vtkPlanePtr > getAllClipPlanes()
Definition: cxData.cpp:234
void addInteractiveClipPlane(vtkPlanePtr plane)
Definition: cxData.cpp:259
virtual QDateTime getAcquisitionTime() const
Definition: cxData.cpp:168
rsNOT_REGISTRATED
Representation of a floating-point bounding box in 3D. The data are stored as {xmin,xmax,ymin,ymax,zmin,zmax}, in order to simplify communication with vtk.
static LandmarksPtr create()
Definition: cxLandmark.cpp:95
QDateTime mSoftwareAcquisitionTime
Time stamp created in at arrival in CX or CX related software.
Definition: cxData.h:46
Data(const QString &uid, const QString &name="")
Definition: cxData.cpp:31
virtual std::vector< Vector3D > getPointCloud() const
Definition: cxData.cpp:106
virtual DoubleBoundingBox3D boundingBox() const =0
virtual QString getParentSpace()
Definition: cxData.cpp:101
vtkPlanePtr mInteractiveClipPlane
Definition: cxData.h:163
QDateTime mAcquisitionTime
Possibly modified time stamp.
Definition: cxData.h:45
RegistrationHistoryPtr m_rMd_History
Definition: cxData.h:160
virtual CoordinateSystem getCoordinateSystem()
Definition: cxData.cpp:215
void setOriginalAcquisitionTime(QDateTime time)
Definition: cxData.cpp:204
virtual void transformChangedSlot()
Definition: cxData.h:148
QString streamXml2String(T &val)
LandmarksPtr mLandmarks
Definition: cxData.h:157
virtual void addPersistentClipPlane(vtkPlanePtr plane)
Definition: cxData.cpp:222
vtkSmartPointer< class vtkPlane > vtkPlanePtr
A history of registration events.
virtual void setFilename(QString val)
Definition: cxData.cpp:78
Namespace for all CustusX production code.
std::vector< vtkPlanePtr > mPersistentClipPlanes
Definition: cxData.h:161