16 #include <QDomDocument> 19 #include <QTextStream> 63 connect(
settings(), SIGNAL(valueChangedFor(QString)),
this, SLOT(settingsChangedSlot(QString)));
129 mStreams[stream->getUid()] = stream;
162 for (
unsigned i = 0; i < names.size(); ++i)
173 std::map<QString, LandmarkProperty>::iterator iter;
211 if (
mData.count(uid))
216 reportError(
"DataManagerImpl::loadData() Got no DataFactory");
221 reportError(
"Failed to find loaded for: [" + path +
"]");
225 bool loaded = data->load(path);
229 reportError(
"Failed to load file: [" + path +
"]");
239 if (data->getUid().contains(
'%'))
241 QString uid = data->getUid();
242 QString name = data->getName();
250 if (
mData.count(data->getUid()) &&
mData[data->getUid()]!=data)
251 reportError(QString(
"Overwriting Data with uid=%1 with new object into PasM").arg(data->getUid()));
253 mData[data->getUid()] = data;
260 DataMap::const_iterator iter =
mData.find(uid);
261 if (iter ==
mData.end())
273 std::map<QString, ImagePtr> retval;
274 for (DataMap::const_iterator iter =
mData.begin(); iter !=
mData.end(); ++iter)
279 retval[iter->first] = image;
286 std::map<QString, MeshPtr> retval;
287 for (DataMap::const_iterator iter =
mData.begin(); iter !=
mData.end(); ++iter)
292 retval[iter->first] = mesh;
299 QDomDocument doc = parentNode.ownerDocument();
300 QDomElement dataManagerNode = doc.createElement(
"datamanager");
301 parentNode.appendChild(dataManagerNode);
305 QDomElement landmarkPropsNode = doc.createElement(
"landmarkprops");
309 QDomElement landmarkPropNode = doc.createElement(
"landmarkprop");
310 it->second.addXml(landmarkPropNode);
311 landmarkPropsNode.appendChild(landmarkPropNode);
313 dataManagerNode.appendChild(landmarkPropsNode);
315 QDomElement landmarksNode = doc.createElement(
"landmarks");
317 dataManagerNode.appendChild(landmarksNode);
319 QDomElement centerNode = doc.createElement(
"center");
321 dataManagerNode.appendChild(centerNode);
323 QDomElement otNode = doc.createElement(
"operatingTable");
325 dataManagerNode.appendChild(otNode);
327 for (DataMap::const_iterator iter =
mData.begin(); iter !=
mData.end(); ++iter)
329 QDomElement dataNode = doc.createElement(
"data");
330 dataManagerNode.appendChild(dataNode);
331 iter->second->addXml(dataNode);
338 QDomNode toolManagerNode = dataManagerNode.parentNode().namedItem(
"toolManager");
340 QDomNode registrationHistory = dataManagerNode.namedItem(
"registrationHistory");
341 if (registrationHistory.isNull())
342 registrationHistory = toolManagerNode.namedItem(
"registrationHistory");
345 QDomNode landmarksNode = dataManagerNode.namedItem(
"landmarkprops");
346 QDomElement landmarkNode = landmarksNode.firstChildElement(
"landmarkprop");
347 for (; !landmarkNode.isNull(); landmarkNode = landmarkNode.nextSiblingElement(
"landmarkprop"))
350 landmarkProp.
parseXml(landmarkNode);
356 QDomNode patientLandmarksNode = dataManagerNode.namedItem(
"landmarks");
357 if (patientLandmarksNode.isNull())
358 patientLandmarksNode = toolManagerNode.namedItem(
"landmarks");
362 std::map<DataPtr, QDomNode> datanodes;
364 QDomNode child = dataManagerNode.firstChild();
365 for (; !child.isNull(); child = child.nextSibling())
367 if (child.nodeName() ==
"data")
371 datanodes[data] = child.toElement();
377 for (std::map<DataPtr, QDomNode>::iterator iter = datanodes.begin(); iter != datanodes.end(); ++iter)
379 iter->first->parseXml(iter->second);
385 child = dataManagerNode.firstChild();
386 while (!child.isNull())
388 if (child.toElement().tagName() ==
"center")
390 const QString centerString = child.toElement().text();
391 if (!centerString.isEmpty())
393 Vector3D center = Vector3D::fromString(centerString);
397 if (child.toElement().tagName() ==
"operatingTable")
399 const QString ot = child.toElement().text();
407 child = child.nextSibling();
413 QString uid = node.toElement().attribute(
"uid");
414 QString name = node.toElement().attribute(
"name");
415 QString type = node.toElement().attribute(
"type");
417 QDir relativePath = this->findRelativePath(node, rootPath);
418 QString absolutePath = this->findAbsolutePath(relativePath, rootPath);
420 if (
mData.count(uid))
426 reportWarning(QString(
"Unknown type: %1 for file %2").arg(type).arg(absolutePath));
429 bool loaded = data->load(absolutePath);
439 data->setFilename(relativePath.path());
444 QString newPath = rootPath+
"/"+data->getFilename();
445 if (QDir::cleanPath(absolutePath) != QDir::cleanPath(newPath))
447 reportWarning(QString(
"Detected old data format, converting from %1 to %2").arg(absolutePath).arg(newPath));
448 data->save(rootPath);
454 QDir DataManagerImpl::findRelativePath(QDomElement node, QString rootPath)
456 QString path = this->findPath(node);
457 QDir relativePath = QDir(QString(path));
459 QDir patientDataDir(rootPath);
460 relativePath.setPath(patientDataDir.relativeFilePath(relativePath.path()));
465 QString DataManagerImpl::findPath(QDomElement node)
467 QDomElement filePathNode = node.namedItem(
"filePath").toElement();
469 if (filePathNode.isNull())
472 QString path = filePathNode.text();
478 QString DataManagerImpl::findAbsolutePath(QDir relativePath, QString rootPath)
480 QString absolutePath = relativePath.path();
481 if (!rootPath.isEmpty())
482 absolutePath = rootPath +
"/" + relativePath.path();
503 void DataManagerImpl::settingsChangedSlot(QString key)
505 if (key ==
"View/clinicalView")
514 QString val =
settings()->
value(
"View/clinicalView", defVal).toString();
515 CLINICAL_VIEW view = string2enum<CLINICAL_VIEW>(val);
523 if (!uidBase.contains(
"%"))
526 size_t numMatches = 1;
531 while (numMatches != 0)
546 QString& uid = *_uid;
547 QString& name = *_name;
551 if (uid.contains(
"%"))
553 uid = uid.arg(recNumber);
556 if (name.contains(
"%"))
561 name = name.arg(recNumber);
575 report(
"Removed data [" + uid +
"].");
584 if (!data->getFilename().isEmpty())
586 files << QDir(basePath).absoluteFilePath(data->getFilename());
591 for (
int i=0; i<files.size(); ++i)
593 if (!QFileInfo(files[i]).exists())
595 report(QString(
"Removing %1 from disk").arg(files[i]));
596 QFile(files[i]).remove();
boost::shared_ptr< class SpaceProvider > SpaceProviderPtr
QString qstring_cast(const T &val)
DataFactoryPtr mDataFactory
cxResource_EXPORT ProfilePtr profile()
void rMprChanged()
emitted when the transformation between patient reference and (data) reference is set ...
int findUniqueUidNumber(QString uidBase) const
virtual void removeData(const QString &uid, QString basePath)
remove data from datamanger, emit signal
void reportError(QString msg)
virtual CLINICAL_VIEW getClinicalApplication() const
boost::shared_ptr< class RegistrationHistory > RegistrationHistoryPtr
std::map< QString, VideoSourcePtr > mStreams
QString findDataTypeFromFile(QString filename)
void operatingTableChanged()
OperatingTable getOperatingTable() const
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
OperatingTable mOperatingTable
virtual std::map< QString, LandmarkProperty > getLandmarkProperties() const
boost::shared_ptr< class TransferFunctions3DPresets > PresetTransferFunctions3DPtr
virtual void setLandmarkName(QString uid, QString name)
boost::shared_ptr< class Image > ImagePtr
virtual VideoSourcePtr getStream(const QString &uid) const
boost::shared_ptr< class DataManagerImpl > DataManagerImplPtr
void deleteFiles(DataPtr data, QString basePath)
virtual void generateUidAndName(QString *_uid, QString *_name)
virtual MeshPtr getMesh(const QString &uid) const
boost::shared_ptr< class ActiveData > ActiveDataPtr
void landmarkPropertiesChanged()
emitted when global info about a landmark changed
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
void centerChanged()
emitted when center is changed.
ActiveDataPtr mActiveData
virtual LandmarksPtr getPatientLandmarks()
virtual void addXml(QDomNode &parentNode)
adds xml information about the datamanger and its variabels
boost::shared_ptr< class Landmarks > LandmarksPtr
PresetTransferFunctions3DPtr mPresetTransferFunctions3D
void setValue(const QString &key, const QVariant &value)
boost::shared_ptr< class Data > DataPtr
DataManagerImpl(ActiveDataPtr activeData)
virtual void parseXml(QDomNode &datamangerNode, QString absolutePath=QString())
Use a XML node to load data.
virtual StreamMap getStreams() const
static DataManagerImplPtr create(ActiveDataPtr activeData)
virtual std::map< QString, ImagePtr > getImages() const
virtual void setLandmarkNames(std::vector< QString > names)
void reportWarning(QString msg)
virtual void setClinicalApplication(CLINICAL_VIEW application)
std::map< QString, DataPtr > getData() const
void dataAddedOrRemoved()
void parseXml(QDomNode &dataNode)
virtual PresetTransferFunctions3DPtr getPresetTransferFunctions3D() const
boost::shared_ptr< class VideoSource > VideoSourcePtr
virtual Transform3D get_rMpr() const
get the patient registration transform
Read or write vtk or ssc data objects from/to file.
static QString findConfigFilePath(QString fileName, QString pathRelativeToConfigRoot, QString alternativeAbsolutePath="")
RegistrationHistoryPtr m_rMpr_History
transform from the patient reference to the reference, along with historical data.
Settings * settings()
Shortcut for accessing the settings instance.
virtual void setLandmarkActive(QString uid, bool active)
static LandmarksPtr create()
Transform3D rMot
Transform from OT to reference space.
void setOperatingTable(const OperatingTable &ot)
virtual void deleteLandmarks()
LandmarksPtr mPatientLandmarks
in space patient reference.
virtual Vector3D getCenter() const
current common center point for user viewing.
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
virtual void setCenter(const Vector3D ¢er)
virtual ImagePtr getImage(const QString &uid) const
QString changeExtension(QString name, QString ext)
bool similar(const CameraInfo &lhs, const CameraInfo &rhs, double tol)
void setDataFactory(DataFactoryPtr dataFactory)
virtual SpaceProviderPtr getSpaceProvider()
virtual void set_rMpr(const Transform3D &val)
set the transform from patient to reference space
virtual std::map< QString, MeshPtr > getMeshes() const
virtual QString addLandmark()
CLINICAL_VIEW mClinicalApplication
The OperatingTable class.
LandmarkPropertyMap mLandmarkProperties
uid and name
SpaceProviderPtr mSpaceProvider
boost::shared_ptr< class DataFactory > DataFactoryPtr
boost::shared_ptr< class Mesh > MeshPtr
void loadData(DataPtr data)
void clinicalApplicationChanged()
virtual void loadStream(VideoSourcePtr stream)
A history of registration events.
void setSpaceProvider(SpaceProviderPtr spaceProvider)
Helper class for xml files used to store ssc/cx data.
Handles transfer function presets.
virtual void clear()
remove all stuff from manager
virtual DataFactoryPtr getDataFactory()
virtual RegistrationHistoryPtr get_rMpr_History() const
virtual ~DataManagerImpl()
Namespace for all CustusX production code.
std::map< QString, VideoSourcePtr > StreamMap