18 #include "Poco/Path.h"
30 typedef std::pair<mitk::DataNode::Pointer, std::list<std::string>> NodesAndParentsPair;
32 bool NodeSortByLayerIsLessThan(
const NodesAndParentsPair &left,
const NodesAndParentsPair &right)
34 if (left.first.IsNotNull() && right.first.IsNotNull())
38 if (left.first->GetIntProperty(
"layer", leftLayer) && right.first->GetIntProperty(
"layer", rightLayer))
40 return leftLayer < rightLayer;
45 return left.first->GetName() < right.first->GetName();
52 return left.first.GetPointer() < right.first.GetPointer();
71 typedef std::vector<mitk::DataNode::Pointer> DataNodeVector;
72 DataNodeVector DataNodes;
73 unsigned int listSize = 0;
74 for (TiXmlElement *element = document.FirstChildElement(
"node"); element != NULL;
75 element = element->NextSiblingElement(
"node"))
82 for (TiXmlElement *element = document.FirstChildElement(
"node"); element != NULL;
83 element = element->NextSiblingElement(
"node"))
91 DataNodeVector::iterator nit = DataNodes.begin();
92 for (TiXmlElement *element = document.FirstChildElement(
"node"); element != NULL || nit != DataNodes.end();
93 element = element->NextSiblingElement(
"node"), ++nit)
98 TiXmlElement *dataXmlElement = element->FirstChildElement(
"data");
99 if (dataXmlElement && dataXmlElement->FirstChildElement(
"properties"))
101 TiXmlElement *baseDataElement = dataXmlElement->FirstChildElement(
"properties");
108 MITK_WARN <<
"BaseData properties stored in scene file, but BaseData could not be read" << std::endl;
113 const char *uida = element->Attribute(
"UID");
124 MITK_ERROR <<
"No UID found for current node. Node will have no parents.";
135 MITK_ERROR <<
"Could not load properties for node.";
143 for (TiXmlElement *source = element->FirstChildElement(
"source"); source != NULL;
144 source = source->NextSiblingElement(
"source"))
146 const char *sourceUID = source->Attribute(
"UID");
164 for (std::list<std::string>::iterator parentsIter = nodesIter->second.begin();
165 parentsIter != nodesIter->second.end();)
169 parentsIter = nodesIter->second.erase(parentsIter);
170 MITK_WARN <<
"Found a DataNode with unknown parents. Will add it to DataStorage without any parent objects.";
182 unsigned int lastMapSize(0);
183 while (lastMapSize !=
194 bool addThisNode(
true);
197 for (std::list<std::string>::iterator parentsIter = nodesIter->second.begin();
198 parentsIter != nodesIter->second.end();
211 for (std::list<std::string>::iterator parentsIter = nodesIter->second.begin();
212 parentsIter != nodesIter->second.end();
219 storage->
Add(nodesIter->first, parents);
235 storage->
Add(nodesIter->first);
236 MITK_WARN <<
"Encountered node that is not part of a directed graph structure. Will be added to DataStorage "
245 const std::string &workingDirectory,
252 const char *
filename = dataElement->Attribute(
"file");
257 std::vector<BaseData::Pointer> baseData =
IOUtil::Load(workingDirectory + Poco::Path::separator() + filename);
258 if (baseData.size() > 1)
260 MITK_WARN <<
"Discarding multiple base data results from " << filename <<
" except the first one.";
263 node->SetData(baseData.front());
265 catch (std::exception &e)
267 MITK_ERROR <<
"Error during attempt to read '" << filename <<
"'. Exception says: " << e.what();
273 MITK_ERROR <<
"Error during attempt to read '" << filename <<
"'. Factory returned NULL object.";
295 if (dynamic_cast<Image *>(data))
312 propertiesToKeep->SetProperty(
"LookupTable", lutProperty);
330 if (compProperty.IsNotNull())
332 propertiesToKeep->SetProperty(
"Image.Displayed Component", compProperty);
336 propertyList.
Clear();
342 TiXmlElement *nodeElement,
343 const std::string &workingDirectory)
349 for (TiXmlElement *properties = nodeElement->FirstChildElement(
"properties"); properties != NULL;
350 properties = properties->NextSiblingElement(
"properties"))
352 const char *propertiesfilea(properties->Attribute(
"file"));
353 std::string propertiesfile(propertiesfilea ? propertiesfilea :
"");
355 const char *renderwindowa(properties->Attribute(
"renderwindow"));
356 std::string renderwindow(renderwindowa ? renderwindowa :
"");
360 ClearNodePropertyListWithExceptions(*node, *propertyList);
365 deserializer->SetFilename(workingDirectory + Poco::Path::separator() + propertiesfile);
366 bool success = deserializer->Deserialize();
370 if (readProperties.IsNotNull())
372 propertyList->ConcatenatePropertyList(readProperties,
true);
376 MITK_ERROR <<
"Property list reader did not return a property list. This is an implementation error. Please tell "
386 TiXmlElement *baseDataNodeElem,
387 const std::string &workingDir)
390 assert(baseDataNodeElem);
394 const char *baseDataPropertyFile(baseDataNodeElem->Attribute(
"file"));
396 if (baseDataPropertyFile)
403 propertyDeserializer->SetFilename(workingDir + Poco::Path::separator() + baseDataPropertyFile);
404 bool ioSuccess = propertyDeserializer->Deserialize();
411 if (inProperties.IsNotNull())
413 data->SetPropertyList(inProperties);
417 MITK_ERROR <<
"The property deserializer did not return a (valid) property list.";
423 MITK_ERROR <<
"Function DecorateBaseDataWithProperties(...) called with false TiXmlElement. \n \t ->Given element "
424 "does not contain a 'file' attribute. \n";
void Progress(unsigned int steps=1)
Sets the current amount of progress to current progress + steps.
virtual void Add(mitk::DataNode *node, const mitk::DataStorage::SetOfObjects *parents=nullptr)=0
Adds a DataNode containing a data object to its internal storage.
mitk::PropertyList * GetPropertyList(const mitk::BaseRenderer *renderer=nullptr) const
Get the PropertyList of the renderer. If renderer is NULL, the BaseRenderer-independent PropertyList ...
mitk::BaseProperty * GetProperty(const std::string &propertyKey) const
Get a property by its name.
#define MITK_REGISTER_SERIALIZER(classname)
Data management class that handles 'was created by' relations.
itk::SmartPointer< Self > Pointer
Base of all data objects.
void ConcatenatePropertyList(PropertyList *pList, bool replace=false)
Set a property object in the list/map by reference.
BaseData * GetData() const
Get the data object (instance of BaseData, e.g., an Image) managed by this DataNode.
Key-value list holding instances of BaseProperty.
void ClearNodePropertyListWithExceptions(DataNode &node, PropertyList &propertyList)
Clear a default property list and handle some exceptions.
static ProgressBar * GetInstance()
static method to get the GUI dependent ProgressBar-instance so the methods for steps to do and progre...
NodeToIDMappingType m_IDForNode
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 ...
static const std::string filename
IDToNodeMappingType m_NodeForID
void AddStepsToDo(unsigned int steps)
Adds steps to totalSteps.
OrderedNodesList m_OrderedNodePairs
bool DecorateNodeWithProperties(DataNode *node, TiXmlElement *nodeElement, const std::string &workingDirectory)
reads all the properties from the XML document and recreates them in node
virtual bool Exists(const mitk::DataNode *node) const =0
Checks if a node exists in the DataStorage.
static DataStorage::SetOfObjects::Pointer Load(const std::string &path, DataStorage &storage)
Load a file into the given DataStorage.
Class for nodes of the DataTree.
virtual 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 element
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.