CustusX  15.8
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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) 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 "cxData.h"
35 
36 #include <QDomDocument>
37 #include <QDateTime>
38 #include <QRegExp>
40 #include "cxTime.h"
41 #include "cxLandmark.h"
43 
44 namespace cx
45 {
46 
47 Data::Data(const QString& uid, const QString& name) :
48  mUid(uid), mFilename(""), mRegistrationStatus(rsNOT_REGISTRATED)//, mParentFrame("")
49 {
50  mAcquisitionTime = QDateTime::currentDateTime();
51 
52  if (name == "")
53  mName = mUid;
54  else
55  mName = name;
57  connect(m_rMd_History.get(), SIGNAL(currentChanged()), this, SIGNAL(transformChanged()));
58  connect(m_rMd_History.get(), SIGNAL(currentChanged()), this, SLOT(transformChangedSlot()));
59 
61 }
62 
64 {
65 }
66 void Data::setUid(const QString& uid)
67 {
68  mUid = uid;
69  emit propertiesChanged();
70 }
71 
72 void Data::setName(const QString& name)
73 {
74  mName = name;
75  emit propertiesChanged();
76 }
77 
78 QString Data::getUid() const
79 {
80  return mUid;
81 }
82 
83 QString Data::getName() const
84 {
85  return mName;
86 }
87 
88 QString Data::getFilename() const
89 {
90  return mFilename;
91 }
92 void Data::setFilename(QString val)
93 {
94  mFilename = val;
95 }
96 
101 {
102  return m_rMd_History->getCurrentRegistration().mValue;
103 }
104 
106 {
107  return m_rMd_History;
108 }
109 
110 QString Data::getSpace()
111 {
112  return mUid;
113 }
114 
116 {
117  return m_rMd_History->getCurrentParentSpace().mValue;
118 }
119 
120 void Data::addXml(QDomNode& dataNode)
121 {
122  QDomDocument doc = dataNode.ownerDocument();
123 
124  m_rMd_History->addXml(dataNode);
125 
126  dataNode.toElement().setAttribute("uid", mUid);
127  dataNode.toElement().setAttribute("name", mName);
128  dataNode.toElement().setAttribute("type", this->getType());
129 
130  QDomElement filePathNode = doc.createElement("filePath");
131  filePathNode.appendChild(doc.createTextNode(this->getFilename()));
132  dataNode.appendChild(filePathNode);
133 
134  QDomElement acqTimeNode = doc.createElement("acqusitionTime");
135  acqTimeNode.appendChild(doc.createTextNode(mAcquisitionTime.toString(timestampMilliSecondsFormat())));
136  dataNode.appendChild(acqTimeNode);
137 
138  if (!mLandmarks->getLandmarks().empty())
139  {
140  QDomElement landmarksNode = doc.createElement("landmarks");
141  mLandmarks->addXml(landmarksNode);
142  dataNode.appendChild(landmarksNode);
143  }
144 }
145 
146 void Data::parseXml(QDomNode& dataNode)
147 {
148  if (dataNode.isNull())
149  return;
150 
151  QDomNode registrationHistory = dataNode.namedItem("registrationHistory");
152  m_rMd_History->parseXml(registrationHistory);
153 
154  if (!dataNode.namedItem("acqusitionTime").toElement().isNull())
155  mAcquisitionTime = QDateTime::fromString(dataNode.namedItem("acqusitionTime").toElement().text(),
157 
158  if (mLandmarks)
159  mLandmarks->parseXml(dataNode.namedItem("landmarks"));
160 }
161 
165 QDateTime Data::getAcquisitionTime() const
166 {
167  if (!mAcquisitionTime.isNull())
168  return mAcquisitionTime;
169  // quickie implementation: Assume uid contains time on format timestampSecondsFormat():
170 
171  // retrieve timestamp as
172  QRegExp tsReg("[0-9]{8}T[0-9]{6}");
173  if (tsReg.indexIn(mUid) > 0)
174  {
175  QDateTime datetime = QDateTime::fromString(tsReg.cap(0), timestampSecondsFormat());
176  return datetime;
177  }
178  return QDateTime();
179 }
180 
181 void Data::setAcquisitionTime(QDateTime time)
182 {
183  mAcquisitionTime = time;
184 }
185 
187 {
188  return mLandmarks;
189 }
190 
191 
193 {
194  return CoordinateSystem(csDATA, this->getUid());
195 }
196 
197 } // namespace cx
virtual Transform3D get_rMd() const
Definition: cxData.cpp:100
boost::shared_ptr< class RegistrationHistory > RegistrationHistoryPtr
Definition: cxDataManager.h:57
QString mUid
Definition: cxData.h:118
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:88
LandmarksPtr getLandmarks()
Definition: cxData.cpp:186
QString timestampMilliSecondsFormat()
Definition: cxTime.cpp:43
QString mName
Definition: cxData.h:119
void transformChanged()
emitted when transform is changed
void setName(const QString &name)
Definition: cxData.cpp:72
virtual void addXml(QDomNode &dataNode)
adds xml information about the data and its variabels
Definition: cxData.cpp:120
QString timestampSecondsFormat()
Definition: cxTime.cpp:39
csDATA
a datas space (d)
boost::shared_ptr< class Landmarks > LandmarksPtr
Definition: cxData.h:60
virtual QString getUid() const
Definition: cxData.cpp:78
QString mFilename
Definition: cxData.h:120
virtual RegistrationHistoryPtr get_rMd_History()
Definition: cxData.cpp:105
virtual QString getType() const
Definition: cxData.h:86
void setUid(const QString &uid)
Definition: cxData.cpp:66
virtual QString getName() const
Definition: cxData.cpp:83
virtual void parseXml(QDomNode &dataNode)
Use a XML node to load data.
Definition: cxData.cpp:146
virtual ~Data()
Definition: cxData.cpp:63
virtual QString getSpace()
Definition: cxData.cpp:110
void setAcquisitionTime(QDateTime time)
Definition: cxData.cpp:181
Identification of a Coordinate system.
virtual QDateTime getAcquisitionTime() const
Definition: cxData.cpp:165
QDateTime mAcquisitionTime
Definition: cxData.h:121
rsNOT_REGISTRATED
static LandmarksPtr create()
Definition: cxLandmark.cpp:116
Data(const QString &uid, const QString &name="")
Definition: cxData.cpp:47
virtual QString getParentSpace()
Definition: cxData.cpp:115
RegistrationHistoryPtr m_rMd_History
Definition: cxData.h:125
virtual CoordinateSystem getCoordinateSystem()
Definition: cxData.cpp:192
virtual void transformChangedSlot()
Definition: cxData.h:113
LandmarksPtr mLandmarks
Definition: cxData.h:122
A history of registration events.
virtual void setFilename(QString val)
Definition: cxData.cpp:92