37 #include <QDomDocument>
40 #include <QTextStream>
78 mActiveData(activeData)
84 connect(
settings(), SIGNAL(valueChangedFor(QString)),
this, SLOT(settingsChangedSlot(QString)));
150 mStreams[stream->getUid()] = stream;
169 for (
unsigned i = 0; i < names.size(); ++i)
180 std::map<QString, LandmarkProperty>::iterator iter;
212 if (
mData.count(uid))
217 reportError(
"DataManagerImpl::loadData() Got no DataFactory");
222 reportError(
"Failed to find loaded for: [" + path +
"]");
226 bool loaded = data->load(path);
230 reportError(
"Failed to load file: [" + path +
"]");
240 if (data->getUid().contains(
'%'))
242 QString uid = data->getUid();
243 QString name = data->getName();
251 if (
mData.count(data->getUid()) &&
mData[data->getUid()]!=data)
252 reportError(QString(
"Overwriting Data with uid=%1 with new object into PasM").arg(data->getUid()));
254 mData[data->getUid()] = data;
261 DataMap::const_iterator iter =
mData.find(uid);
262 if (iter ==
mData.end())
274 std::map<QString, ImagePtr> retval;
275 for (DataMap::const_iterator iter =
mData.begin(); iter !=
mData.end(); ++iter)
280 retval[iter->first] = image;
287 std::map<QString, MeshPtr> retval;
288 for (DataMap::const_iterator iter =
mData.begin(); iter !=
mData.end(); ++iter)
293 retval[iter->first] = mesh;
300 QDomDocument doc = parentNode.ownerDocument();
301 QDomElement dataManagerNode = doc.createElement(
"datamanager");
302 parentNode.appendChild(dataManagerNode);
306 QDomElement landmarkPropsNode = doc.createElement(
"landmarkprops");
310 QDomElement landmarkPropNode = doc.createElement(
"landmarkprop");
311 it->second.addXml(landmarkPropNode);
312 landmarkPropsNode.appendChild(landmarkPropNode);
314 dataManagerNode.appendChild(landmarkPropsNode);
316 QDomElement landmarksNode = doc.createElement(
"landmarks");
318 dataManagerNode.appendChild(landmarksNode);
320 QDomElement centerNode = doc.createElement(
"center");
322 dataManagerNode.appendChild(centerNode);
324 for (DataMap::const_iterator iter =
mData.begin(); iter !=
mData.end(); ++iter)
326 QDomElement dataNode = doc.createElement(
"data");
327 dataManagerNode.appendChild(dataNode);
328 iter->second->addXml(dataNode);
335 QDomNode toolManagerNode = dataManagerNode.parentNode().namedItem(
"toolManager");
337 QDomNode registrationHistory = dataManagerNode.namedItem(
"registrationHistory");
338 if (registrationHistory.isNull())
339 registrationHistory = toolManagerNode.namedItem(
"registrationHistory");
342 QDomNode landmarksNode = dataManagerNode.namedItem(
"landmarkprops");
343 QDomElement landmarkNode = landmarksNode.firstChildElement(
"landmarkprop");
344 for (; !landmarkNode.isNull(); landmarkNode = landmarkNode.nextSiblingElement(
"landmarkprop"))
347 landmarkProp.
parseXml(landmarkNode);
353 QDomNode patientLandmarksNode = dataManagerNode.namedItem(
"landmarks");
354 if (patientLandmarksNode.isNull())
355 patientLandmarksNode = toolManagerNode.namedItem(
"landmarks");
359 std::map<DataPtr, QDomNode> datanodes;
361 QDomNode child = dataManagerNode.firstChild();
362 for (; !child.isNull(); child = child.nextSibling())
364 if (child.nodeName() ==
"data")
368 datanodes[data] = child.toElement();
374 for (std::map<DataPtr, QDomNode>::iterator iter = datanodes.begin(); iter != datanodes.end(); ++iter)
376 iter->first->parseXml(iter->second);
382 child = dataManagerNode.firstChild();
383 while (!child.isNull())
385 if (child.toElement().tagName() ==
"center")
387 const QString centerString = child.toElement().text();
388 if (!centerString.isEmpty())
390 Vector3D center = Vector3D::fromString(centerString);
394 child = child.nextSibling();
400 QString uid = node.toElement().attribute(
"uid");
401 QString name = node.toElement().attribute(
"name");
402 QString type = node.toElement().attribute(
"type");
404 QDir relativePath = this->findRelativePath(node, rootPath);
405 QString absolutePath = this->findAbsolutePath(relativePath, rootPath);
407 if (
mData.count(uid))
413 reportWarning(QString(
"Unknown type: %1 for file %2").arg(type).arg(absolutePath));
416 bool loaded = data->load(absolutePath);
426 data->setFilename(relativePath.path());
431 QString newPath = rootPath+
"/"+data->getFilename();
432 if (QDir::cleanPath(absolutePath) != QDir::cleanPath(newPath))
434 reportWarning(QString(
"Detected old data format, converting from %1 to %2").arg(absolutePath).arg(newPath));
435 data->save(rootPath);
441 QDir DataManagerImpl::findRelativePath(QDomElement node, QString rootPath)
443 QString path = this->findPath(node);
444 QDir relativePath = QDir(QString(path));
446 QDir patientDataDir(rootPath);
447 relativePath.setPath(patientDataDir.relativeFilePath(relativePath.path()));
452 QString DataManagerImpl::findPath(QDomElement node)
454 QDomElement filePathNode = node.namedItem(
"filePath").toElement();
456 if (filePathNode.isNull())
459 QString path = filePathNode.text();
465 QString DataManagerImpl::findAbsolutePath(QDir relativePath, QString rootPath)
467 QString absolutePath = relativePath.path();
468 if (!rootPath.isEmpty())
469 absolutePath = rootPath +
"/" + relativePath.path();
490 void DataManagerImpl::settingsChangedSlot(QString key)
492 if (key ==
"View/clinicalView")
501 QString val =
settings()->
value(
"View/clinicalView", defVal).toString();
502 CLINICAL_VIEW view = string2enum<CLINICAL_VIEW>(val);
510 if (!uidBase.contains(
"%"))
513 size_t numMatches = 1;
518 while (numMatches != 0)
533 QString& uid = *_uid;
534 QString& name = *_name;
538 if (uid.contains(
"%"))
540 uid = uid.arg(recNumber);
543 if (name.contains(
"%"))
548 name = name.arg(recNumber);
562 report(
"Removed data [" + uid +
"].");
571 if (!data->getFilename().isEmpty())
573 files << QDir(basePath).absoluteFilePath(data->getFilename());
578 for (
int i=0; i<files.size(); ++i)
580 if (!QFileInfo(files[i]).exists())
582 report(QString(
"Removing %1 from disk").arg(files[i]));
583 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)
std::map< QString, VideoSourcePtr > mStreams
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
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
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()
LandmarksPtr mPatientLandmarks
in space patient reference.
cxLogicManager_EXPORT SpaceProviderPtr spaceProvider()
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)
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
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()
std::map< QString, VideoSourcePtr > StreamMap