14 #include "Poco/Path.h" 26 typedef std::pair<mitk::DataNode::Pointer, std::list<std::string>> NodesAndParentsPair;
28 bool NodeSortByLayerIsLessThan(
const NodesAndParentsPair &left,
const NodesAndParentsPair &right)
30 if (left.first.IsNotNull() && right.first.IsNotNull())
34 if (left.first->GetIntProperty(
"layer", leftLayer) && right.first->GetIntProperty(
"layer", rightLayer))
36 return leftLayer < rightLayer;
41 return left.first->GetName() < right.first->GetName();
48 return left.first.GetPointer() < right.first.GetPointer();
67 typedef std::vector<mitk::DataNode::Pointer> DataNodeVector;
68 DataNodeVector DataNodes;
69 unsigned int listSize = 0;
70 for (TiXmlElement *element = document.FirstChildElement(
"node"); element !=
nullptr;
71 element = element->NextSiblingElement(
"node"))
78 for (TiXmlElement *element = document.FirstChildElement(
"node"); element !=
nullptr;
79 element = element->NextSiblingElement(
"node"))
87 auto nit = DataNodes.begin();
88 for (TiXmlElement *element = document.FirstChildElement(
"node"); element !=
nullptr || nit != DataNodes.end();
89 element = element->NextSiblingElement(
"node"), ++nit)
94 TiXmlElement *dataXmlElement = element->FirstChildElement(
"data");
95 if (dataXmlElement && dataXmlElement->FirstChildElement(
"properties"))
97 TiXmlElement *baseDataElement = dataXmlElement->FirstChildElement(
"properties");
104 MITK_WARN <<
"BaseData properties stored in scene file, but BaseData could not be read" << std::endl;
109 const char *uida = element->Attribute(
"UID");
120 MITK_ERROR <<
"No UID found for current node. Node will have no parents.";
131 MITK_ERROR <<
"Could not load properties for node.";
139 for (TiXmlElement *source = element->FirstChildElement(
"source"); source !=
nullptr;
140 source = source->NextSiblingElement(
"source"))
142 const char *sourceUID = source->Attribute(
"UID");
160 for (
auto parentsIter = nodesIter->second.begin();
161 parentsIter != nodesIter->second.end();)
165 parentsIter = nodesIter->second.erase(parentsIter);
166 MITK_WARN <<
"Found a DataNode with unknown parents. Will add it to DataStorage without any parent objects.";
178 unsigned int lastMapSize(0);
179 while (lastMapSize !=
190 bool addThisNode(
true);
193 for (
auto parentsIter = nodesIter->second.begin();
194 parentsIter != nodesIter->second.end();
206 DataStorage::SetOfObjects::Pointer parents = DataStorage::SetOfObjects::New();
207 for (
auto parentsIter = nodesIter->second.begin();
208 parentsIter != nodesIter->second.end();
215 storage->
Add(nodesIter->first, parents);
231 storage->
Add(nodesIter->first);
232 MITK_WARN <<
"Encountered node that is not part of a directed graph structure. Will be added to DataStorage " 241 const std::string &workingDirectory,
248 const char *filename = dataElement->Attribute(
"file");
249 if (filename && strlen(filename) != 0)
253 std::vector<BaseData::Pointer> baseData =
IOUtil::Load(workingDirectory + Poco::Path::separator() + filename);
254 if (baseData.size() > 1)
256 MITK_WARN <<
"Discarding multiple base data results from " << filename <<
" except the first one.";
259 node->SetData(baseData.front());
261 catch (std::exception &e)
263 MITK_ERROR <<
"Error during attempt to read '" << filename <<
"'. Exception says: " << e.what();
269 MITK_ERROR <<
"Error during attempt to read '" << filename <<
"'. Factory returned nullptr object.";
291 if (dynamic_cast<Image *>(data))
308 propertiesToKeep->SetProperty(
"LookupTable", lutProperty);
322 if (compProperty.IsNotNull())
324 propertiesToKeep->SetProperty(
"Image.Displayed Component", compProperty);
328 propertyList.
Clear();
334 TiXmlElement *nodeElement,
335 const std::string &workingDirectory)
341 for (TiXmlElement *properties = nodeElement->FirstChildElement(
"properties"); properties !=
nullptr;
342 properties = properties->NextSiblingElement(
"properties"))
344 const char *propertiesfilea(properties->Attribute(
"file"));
345 std::string propertiesfile(propertiesfilea ? propertiesfilea :
"");
347 const char *renderwindowa(properties->Attribute(
"renderwindow"));
348 std::string renderwindow(renderwindowa ? renderwindowa :
"");
357 deserializer->SetFilename(workingDirectory + Poco::Path::separator() + propertiesfile);
358 bool success = deserializer->Deserialize();
362 if (readProperties.IsNotNull())
364 propertyList->ConcatenatePropertyList(readProperties,
true);
368 MITK_ERROR <<
"Property list reader did not return a property list. This is an implementation error. Please tell " 378 TiXmlElement *baseDataNodeElem,
379 const std::string &workingDir)
382 assert(baseDataNodeElem);
386 const char *baseDataPropertyFile(baseDataNodeElem->Attribute(
"file"));
388 if (baseDataPropertyFile)
395 propertyDeserializer->SetFilename(workingDir + Poco::Path::separator() + baseDataPropertyFile);
396 bool ioSuccess = propertyDeserializer->Deserialize();
403 if (inProperties.IsNotNull())
405 data->SetPropertyList(inProperties);
409 MITK_ERROR <<
"The property deserializer did not return a (valid) property list.";
415 MITK_ERROR <<
"Function DecorateBaseDataWithProperties(...) called with false TiXmlElement. \n \t ->Given element " 416 "does not contain a 'file' attribute. \n";
void Progress(unsigned int steps=1)
Sets the current amount of progress to current progress + steps.
#define MITK_REGISTER_SERIALIZER(classname)
Data management class that handles 'was created by' relations.
Base of all data objects.
void ConcatenatePropertyList(PropertyList *pList, bool replace=false)
Set a property object in the list/map by reference.
Key-value list holding instances of BaseProperty.
void ClearNodePropertyListWithExceptions(DataNode &node, PropertyList &propertyList)
Clear a default property list and handle some exceptions.
virtual void Add(DataNode *node, const DataStorage::SetOfObjects *parents=nullptr)=0
Adds a DataNode containing a data object to its internal storage.
static ProgressBar * GetInstance()
static method to get the GUI dependent ProgressBar-instance so the methods for steps to do and progre...
NodeToIDMappingType m_IDForNode
BaseData * GetData() const
Get the data object (instance of BaseData, e.g., an Image) managed by this DataNode.
bool DecorateBaseDataWithProperties(BaseData::Pointer data, TiXmlElement *baseDataNodeElem, const std::string &workingDir)
reads all properties assigned to a base data element and assigns the list to the base data object ...
IDToNodeMappingType m_NodeForID
mitk::PropertyList * GetPropertyList(const mitk::BaseRenderer *renderer=nullptr) const
Get the PropertyList of the renderer. If renderer is nullptr, the BaseRenderer-independent PropertyLi...
void AddStepsToDo(unsigned int steps)
Adds steps to totalSteps.
OrderedNodesList m_OrderedNodePairs
virtual bool Exists(const DataNode *node) const =0
Checks if a node exists in the DataStorage.
mitk::BaseProperty * GetProperty(const std::string &propertyKey) const
Get a property by its name.
bool DecorateNodeWithProperties(DataNode *node, TiXmlElement *nodeElement, const std::string &workingDirectory)
reads all the properties from the XML document and recreates them in node
static DataStorage::SetOfObjects::Pointer Load(const std::string &path, DataStorage &storage, const ReaderOptionsFunctorBase *optionsCallback=nullptr)
Load a file into the given DataStorage.
Class for nodes of the DataTree.
bool LoadScene(TiXmlDocument &document, const std::string &workingDirectory, DataStorage *storage) override
DataNode::Pointer LoadBaseDataFromDataTag(TiXmlElement *dataElement, const std::string &workingDirectory, bool &error)
tries to create one DataNode from a given XML <node> element