37 #include <QDomDocument> 40 #include <QTextStream> 84 connect(
settings(), SIGNAL(valueChangedFor(QString)),
this, SLOT(settingsChangedSlot(QString)));
150 mStreams[stream->getUid()] = stream;
183 for (
unsigned i = 0; i < names.size(); ++i)
194 std::map<QString, LandmarkProperty>::iterator iter;
232 if (
mData.count(uid))
237 reportError(
"DataManagerImpl::loadData() Got no DataFactory");
242 reportError(
"Failed to find loaded for: [" + path +
"]");
246 bool loaded = data->load(path);
250 reportError(
"Failed to load file: [" + path +
"]");
260 if (data->getUid().contains(
'%'))
262 QString uid = data->getUid();
263 QString name = data->getName();
271 if (
mData.count(data->getUid()) &&
mData[data->getUid()]!=data)
272 reportError(QString(
"Overwriting Data with uid=%1 with new object into PasM").arg(data->getUid()));
274 mData[data->getUid()] = data;
281 DataMap::const_iterator iter =
mData.find(uid);
282 if (iter ==
mData.end())
294 std::map<QString, ImagePtr> retval;
295 for (DataMap::const_iterator iter =
mData.begin(); iter !=
mData.end(); ++iter)
300 retval[iter->first] = image;
307 std::map<QString, MeshPtr> retval;
308 for (DataMap::const_iterator iter =
mData.begin(); iter !=
mData.end(); ++iter)
313 retval[iter->first] = mesh;
320 QDomDocument doc = parentNode.ownerDocument();
321 QDomElement dataManagerNode = doc.createElement(
"datamanager");
322 parentNode.appendChild(dataManagerNode);
326 QDomElement landmarkPropsNode = doc.createElement(
"landmarkprops");
330 QDomElement landmarkPropNode = doc.createElement(
"landmarkprop");
331 it->second.addXml(landmarkPropNode);
332 landmarkPropsNode.appendChild(landmarkPropNode);
334 dataManagerNode.appendChild(landmarkPropsNode);
336 QDomElement landmarksNode = doc.createElement(
"landmarks");
338 dataManagerNode.appendChild(landmarksNode);
340 QDomElement centerNode = doc.createElement(
"center");
342 dataManagerNode.appendChild(centerNode);
344 QDomElement otNode = doc.createElement(
"operatingTable");
346 dataManagerNode.appendChild(otNode);
348 for (DataMap::const_iterator iter =
mData.begin(); iter !=
mData.end(); ++iter)
350 QDomElement dataNode = doc.createElement(
"data");
351 dataManagerNode.appendChild(dataNode);
352 iter->second->addXml(dataNode);
359 QDomNode toolManagerNode = dataManagerNode.parentNode().namedItem(
"toolManager");
361 QDomNode registrationHistory = dataManagerNode.namedItem(
"registrationHistory");
362 if (registrationHistory.isNull())
363 registrationHistory = toolManagerNode.namedItem(
"registrationHistory");
366 QDomNode landmarksNode = dataManagerNode.namedItem(
"landmarkprops");
367 QDomElement landmarkNode = landmarksNode.firstChildElement(
"landmarkprop");
368 for (; !landmarkNode.isNull(); landmarkNode = landmarkNode.nextSiblingElement(
"landmarkprop"))
371 landmarkProp.
parseXml(landmarkNode);
377 QDomNode patientLandmarksNode = dataManagerNode.namedItem(
"landmarks");
378 if (patientLandmarksNode.isNull())
379 patientLandmarksNode = toolManagerNode.namedItem(
"landmarks");
383 std::map<DataPtr, QDomNode> datanodes;
385 QDomNode child = dataManagerNode.firstChild();
386 for (; !child.isNull(); child = child.nextSibling())
388 if (child.nodeName() ==
"data")
392 datanodes[data] = child.toElement();
398 for (std::map<DataPtr, QDomNode>::iterator iter = datanodes.begin(); iter != datanodes.end(); ++iter)
400 iter->first->parseXml(iter->second);
406 child = dataManagerNode.firstChild();
407 while (!child.isNull())
409 if (child.toElement().tagName() ==
"center")
411 const QString centerString = child.toElement().text();
412 if (!centerString.isEmpty())
414 Vector3D center = Vector3D::fromString(centerString);
418 if (child.toElement().tagName() ==
"operatingTable")
420 const QString ot = child.toElement().text();
428 child = child.nextSibling();
434 QString uid = node.toElement().attribute(
"uid");
435 QString name = node.toElement().attribute(
"name");
436 QString type = node.toElement().attribute(
"type");
438 QDir relativePath = this->findRelativePath(node, rootPath);
439 QString absolutePath = this->findAbsolutePath(relativePath, rootPath);
441 if (
mData.count(uid))
447 reportWarning(QString(
"Unknown type: %1 for file %2").arg(type).arg(absolutePath));
450 bool loaded = data->load(absolutePath);
460 data->setFilename(relativePath.path());
465 QString newPath = rootPath+
"/"+data->getFilename();
466 if (QDir::cleanPath(absolutePath) != QDir::cleanPath(newPath))
468 reportWarning(QString(
"Detected old data format, converting from %1 to %2").arg(absolutePath).arg(newPath));
469 data->save(rootPath);
475 QDir DataManagerImpl::findRelativePath(QDomElement node, QString rootPath)
477 QString path = this->findPath(node);
478 QDir relativePath = QDir(QString(path));
480 QDir patientDataDir(rootPath);
481 relativePath.setPath(patientDataDir.relativeFilePath(relativePath.path()));
486 QString DataManagerImpl::findPath(QDomElement node)
488 QDomElement filePathNode = node.namedItem(
"filePath").toElement();
490 if (filePathNode.isNull())
493 QString path = filePathNode.text();
499 QString DataManagerImpl::findAbsolutePath(QDir relativePath, QString rootPath)
501 QString absolutePath = relativePath.path();
502 if (!rootPath.isEmpty())
503 absolutePath = rootPath +
"/" + relativePath.path();
524 void DataManagerImpl::settingsChangedSlot(QString key)
526 if (key ==
"View/clinicalView")
535 QString val =
settings()->
value(
"View/clinicalView", defVal).toString();
536 CLINICAL_VIEW view = string2enum<CLINICAL_VIEW>(val);
544 if (!uidBase.contains(
"%"))
547 size_t numMatches = 1;
552 while (numMatches != 0)
567 QString& uid = *_uid;
568 QString& name = *_name;
572 if (uid.contains(
"%"))
574 uid = uid.arg(recNumber);
577 if (name.contains(
"%"))
582 name = name.arg(recNumber);
596 report(
"Removed data [" + uid +
"].");
605 if (!data->getFilename().isEmpty())
607 files << QDir(basePath).absoluteFilePath(data->getFilename());
612 for (
int i=0; i<files.size(); ++i)
614 if (!QFileInfo(files[i]).exists())
616 report(QString(
"Removing %1 from disk").arg(files[i]));
617 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