Fraxinus  16.5.0-fx-rc9
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>
39 
40 #include <vtkPlane.h>
41 
43 #include "cxTime.h"
44 #include "cxLandmark.h"
46 #include "cxLogger.h"
47 
48 namespace cx
49 {
50 
51 Data::Data(const QString& uid, const QString& name) :
52  mUid(uid), mFilename(""), mRegistrationStatus(rsNOT_REGISTRATED)//, mParentFrame("")
53 {
54  mTimeInfo.mAcquisitionTime = QDateTime::currentDateTime();
55  mTimeInfo.mSoftwareAcquisitionTime = QDateTime();
56  mTimeInfo.mOriginalAcquisitionTime = QDateTime();
57 
58  if (name == "")
59  mName = mUid;
60  else
61  mName = name;
65 
67 }
68 
70 {
71 }
72 void Data::setUid(const QString& uid)
73 {
74  mUid = uid;
75  emit propertiesChanged();
76 }
77 
78 void Data::setName(const QString& name)
79 {
80  mName = name;
81  emit propertiesChanged();
82 }
83 
84 QString Data::getUid() const
85 {
86  return mUid;
87 }
88 
89 QString Data::getName() const
90 {
91  return mName;
92 }
93 
94 QString Data::getFilename() const
95 {
96  return mFilename;
97 }
98 void Data::setFilename(QString val)
99 {
100  mFilename = val;
101 }
102 
107 {
108  return m_rMd_History->getCurrentRegistration().mValue;
109 }
110 
112 {
113  return m_rMd_History;
114 }
115 
116 QString Data::getSpace()
117 {
118  return mUid;
119 }
120 
122 {
123  return m_rMd_History->getCurrentParentSpace().mValue;
124 }
125 
126 void Data::addXml(QDomNode& dataNode)
127 {
128  QDomDocument doc = dataNode.ownerDocument();
129 
130  m_rMd_History->addXml(dataNode);
131 
132  dataNode.toElement().setAttribute("uid", mUid);
133  dataNode.toElement().setAttribute("name", mName);
134  dataNode.toElement().setAttribute("type", this->getType());
135 
136  QDomElement filePathNode = doc.createElement("filePath");
137  filePathNode.appendChild(doc.createTextNode(this->getFilename()));
138  dataNode.appendChild(filePathNode);
139 
140  QDomElement acqTimeNode = doc.createElement("acqusitionTime");
141  acqTimeNode.appendChild(doc.createTextNode(mTimeInfo.mAcquisitionTime.toString(timestampMilliSecondsFormat())));
142  dataNode.appendChild(acqTimeNode);
143 
144  if (!mLandmarks->getLandmarks().empty())
145  {
146  QDomElement landmarksNode = doc.createElement("landmarks");
147  mLandmarks->addXml(landmarksNode);
148  dataNode.appendChild(landmarksNode);
149  }
150 }
151 
152 void Data::parseXml(QDomNode& dataNode)
153 {
154  if (dataNode.isNull())
155  return;
156 
157  QDomNode registrationHistory = dataNode.namedItem("registrationHistory");
158  m_rMd_History->parseXml(registrationHistory);
159 
160  if (!dataNode.namedItem("acqusitionTime").toElement().isNull())
161  mTimeInfo.mAcquisitionTime = QDateTime::fromString(dataNode.namedItem("acqusitionTime").toElement().text(),
163 
164  if (mLandmarks)
165  mLandmarks->parseXml(dataNode.namedItem("landmarks"));
166 }
167 
171 QDateTime Data::getAcquisitionTime() const
172 {
173  if (!mTimeInfo.mAcquisitionTime.isNull())
175  // quickie implementation: Assume uid contains time on format timestampSecondsFormat():
176 
177  // retrieve timestamp as
178  QRegExp tsReg("[0-9]{8}T[0-9]{6}");
179  if (tsReg.indexIn(mUid) > 0)
180  {
181  QDateTime datetime = QDateTime::fromString(tsReg.cap(0), timestampSecondsFormat());
182  return datetime;
183  }
184  return QDateTime();
185 }
186 
188 {
189  return mTimeInfo;
190 }
191 
192 void Data::setAcquisitionTime(QDateTime time)
193 {
195 }
196 
198 {
200 }
201 
203 {
205 }
206 
208 {
209  return mLandmarks;
210 }
211 
212 
214 {
215  return CoordinateSystem(csDATA, this->getUid());
216 }
217 
218 //Moved from Image
219 // methods for defining and storing clip planes. Data does not use these data, this is up to the mapper
221 {
222  this->addPlane(plane, mPersistentClipPlanes);
223 }
224 
225 void Data::addPlane(vtkPlanePtr plane, std::vector<vtkPlanePtr> &planes)
226 {
227  if (std::count(planes.begin(), planes.end(), plane))
228  return;
229  planes.push_back(plane);
230  emit clipPlanesChanged();
231 }
232 std::vector<vtkPlanePtr> Data::getAllClipPlanes()
233 {
234  std::vector<vtkPlanePtr> retval = mPersistentClipPlanes;
235 
236  for(int i = 0; i < mInteractiveClipPlanes.size(); ++i)
237  retval.push_back(mInteractiveClipPlanes[i]);
238 
240  retval.push_back(mInteractiveClipPlane);
241 
242  return retval;
243 }
244 
246 {
247  mPersistentClipPlanes.clear();
248  emit clipPlanesChanged();
249 }
250 
252 {
253  mInteractiveClipPlane = plane;
254  emit clipPlanesChanged();
255 }
256 
258 {
259  this->addPlane(plane, mInteractiveClipPlanes);
260 }
261 
263 {
264  for(int i = 0; i < mInteractiveClipPlanes.size(); ++i)
265  {
266  if(mInteractiveClipPlanes[i] == plane)
268  }
269 
270  emit clipPlanesChanged();
271 }
272 } // namespace cx
std::vector< vtkPlanePtr > mInteractiveClipPlanes
Definition: cxData.h:180
virtual void clearPersistentClipPlanes()
Definition: cxData.cpp:245
virtual Transform3D get_rMd() const
Definition: cxData.cpp:106
boost::shared_ptr< class RegistrationHistory > RegistrationHistoryPtr
Definition: cxDataManager.h:57
void removeInteractiveClipPlane(vtkPlanePtr plane)
Definition: cxData.cpp:262
QDateTime mOriginalAcquisitionTime
Original aquisition time (from hardware if possible)
Definition: cxData.h:67
void setSoftwareAcquisitionTime(QDateTime time)
Definition: cxData.cpp:197
QString mUid
Definition: cxData.h:171
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:94
LandmarksPtr getLandmarks()
Definition: cxData.cpp:207
QString timestampMilliSecondsFormat()
Definition: cxTime.cpp:43
QString mName
Definition: cxData.h:172
void transformChanged()
emitted when transform is changed
TimeInfo mTimeInfo
Definition: cxData.h:174
void setName(const QString &name)
Definition: cxData.cpp:78
virtual void addXml(QDomNode &dataNode)
adds xml information about the data and its variabels
Definition: cxData.cpp:126
QString timestampSecondsFormat()
Definition: cxTime.cpp:39
csDATA
a datas space (d)
boost::shared_ptr< class Landmarks > LandmarksPtr
Definition: cxData.h:61
virtual QString getUid() const
Definition: cxData.cpp:84
void clipPlanesChanged()
QString mFilename
Definition: cxData.h:173
virtual RegistrationHistoryPtr get_rMd_History()
Definition: cxData.cpp:111
virtual QString getType() const
Definition: cxData.h:129
void setUid(const QString &uid)
Definition: cxData.cpp:72
virtual QString getName() const
Definition: cxData.cpp:89
virtual void parseXml(QDomNode &dataNode)
Use a XML node to load data.
Definition: cxData.cpp:152
virtual ~Data()
Definition: cxData.cpp:69
virtual TimeInfo getAdvancedTimeInfo() const
Definition: cxData.cpp:187
virtual QString getSpace()
Definition: cxData.cpp:116
void setAcquisitionTime(QDateTime time)
Definition: cxData.cpp:192
Identification of a Coordinate system.
virtual void setInteractiveClipPlane(vtkPlanePtr plane)
set a plane that is not saved
Definition: cxData.cpp:251
virtual std::vector< vtkPlanePtr > getAllClipPlanes()
Definition: cxData.cpp:232
void addInteractiveClipPlane(vtkPlanePtr plane)
Definition: cxData.cpp:257
virtual QDateTime getAcquisitionTime() const
Definition: cxData.cpp:171
rsNOT_REGISTRATED
static LandmarksPtr create()
Definition: cxLandmark.cpp:116
QDateTime mSoftwareAcquisitionTime
Time stamp created in at arrival in CX or CX related software.
Definition: cxData.h:66
Data(const QString &uid, const QString &name="")
Definition: cxData.cpp:51
virtual QString getParentSpace()
Definition: cxData.cpp:121
vtkPlanePtr mInteractiveClipPlane
Definition: cxData.h:181
QDateTime mAcquisitionTime
Possibly modified time stamp.
Definition: cxData.h:65
RegistrationHistoryPtr m_rMd_History
Definition: cxData.h:178
virtual CoordinateSystem getCoordinateSystem()
Definition: cxData.cpp:213
void setOriginalAcquisitionTime(QDateTime time)
Definition: cxData.cpp:202
virtual void transformChangedSlot()
Definition: cxData.h:166
LandmarksPtr mLandmarks
Definition: cxData.h:175
virtual void addPersistentClipPlane(vtkPlanePtr plane)
Definition: cxData.cpp:220
vtkSmartPointer< class vtkPlane > vtkPlanePtr
A history of registration events.
virtual void setFilename(QString val)
Definition: cxData.cpp:98
std::vector< vtkPlanePtr > mPersistentClipPlanes
Definition: cxData.h:179