15 #include "itkMutexLockHolder.h" 16 #include "itkSimpleFastMutexLock.h" 45 throw std::logic_error(
"DataStorage not initialized");
47 if ((parents !=
nullptr) && (std::find(parents->begin(), parents->end(), node) != parents->end()))
48 throw std::invalid_argument(
"Node is it's own parent");
51 throw std::invalid_argument(
"Node is already in DataStorage");
54 mitk::DataStorage::SetOfObjects::ConstPointer sp;
55 if (parents !=
nullptr)
58 sp = mitk::DataStorage::SetOfObjects::New();
63 mitk::DataStorage::SetOfObjects::Pointer childrenPointer = mitk::DataStorage::SetOfObjects::New();
64 mitk::DataStorage::SetOfObjects::ConstPointer children = childrenPointer.GetPointer();
68 for (SetOfObjects::ConstIterator it = sp->Begin(); it != sp->End(); it++)
71 mitk::DataStorage::SetOfObjects::ConstPointer derivedObjects =
73 if (derivedObjects.IsNull())
75 mitk::DataStorage::SetOfObjects::New();
78 deob->InsertElement(deob->Size(),
93 throw std::logic_error(
"DataStorage not initialized");
126 for (
auto mapIter = relation.cbegin(); mapIter != relation.cend();
128 if (mapIter->second.IsNotNull())
130 SetOfObjects::Pointer s =
131 const_cast<SetOfObjects *
>(mapIter->second.GetPointer());
132 auto relationListIter = std::find(
136 if (relationListIter != s->end())
137 s->erase(relationListIter);
140 AdjacencyList::iterator adIt;
141 adIt = relation.find(node);
142 if (adIt != relation.end())
143 relation.erase(adIt);
150 throw std::logic_error(
"DataStorage not initialized");
152 mitk::DataStorage::SetOfObjects::Pointer resultset = mitk::DataStorage::SetOfObjects::New();
154 unsigned int index = 0;
156 if (it->first.IsNull())
159 resultset->InsertElement(index++, const_cast<mitk::DataNode *>(it->first.GetPointer()));
161 return SetOfObjects::ConstPointer(resultset);
168 bool onlyDirectlyRelated)
const 171 throw std::invalid_argument(
"invalid node");
174 if (onlyDirectlyRelated)
176 auto it = relation.find(node);
177 if ((it == relation.cend()) || (it->second.IsNull()))
178 return SetOfObjects::ConstPointer(mitk::DataStorage::SetOfObjects::New());
184 std::vector<mitk::DataNode::ConstPointer> resultset;
185 std::vector<mitk::DataNode::ConstPointer> openlist;
189 openlist.push_back(node);
191 while (openlist.size() > 0)
195 resultset.push_back(current);
196 auto it = relation.find(current);
197 if ((it == relation.cend())
199 (it->second.IsNull())
201 (it->second->Size() == 0))
204 for (SetOfObjects::ConstIterator parentIt = it->second->Begin(); parentIt != it->second->End();
208 if (!(std::find(resultset.cbegin(), resultset.cend(), p) !=
211 !(std::find(openlist.cbegin(), openlist.cend(), p) != openlist.cend()))
212 openlist.push_back(p);
218 mitk::DataStorage::SetOfObjects::Pointer realResultset = mitk::DataStorage::SetOfObjects::New();
219 if (condition !=
nullptr)
221 for (
auto resultIt = resultset.cbegin();
222 resultIt != resultset.cend();
224 if ((*resultIt != node) && (condition->
CheckNode(*resultIt) ==
true))
225 realResultset->InsertElement(realResultset->Size(),
230 for (
auto resultIt = resultset.cbegin();
231 resultIt != resultset.cend();
233 if (*resultIt != node)
234 realResultset->InsertElement(realResultset->Size(),
237 return SetOfObjects::ConstPointer(realResultset);
256 os << indent <<
"StandaloneDataStorage:\n";
void RemoveListeners(const DataNode *_Node)
Removes a Modified-Listener from the given Node.
Data management class that handles 'was created by' relations.
void PrintSelf(std::ostream &os, itk::Indent indent) const override
Prints the contents of the StandaloneDataStorage to os. Do not call directly, call ->Print() instead...
SetOfObjects::ConstPointer GetSources(const mitk::DataNode *node, const NodePredicateBase *condition=nullptr, bool onlyDirectSources=true) const override
returns a set of source objects for a given node that meet the given condition(s).
void PrintSelf(std::ostream &os, itk::Indent indent) const override
Prints the contents of the DataStorage to os. Do not call directly, call ->Print() instead...
DataCollection - Class to facilitate loading/accessing structured data.
SetOfObjects::ConstPointer FilterSetOfObjects(const SetOfObjects *set, const NodePredicateBase *condition) const
Filters a SetOfObjects by the condition. If no condition is provided, the original set is returned...
bool Exists(const mitk::DataNode *node) const override
Checks if a node exists in the StandaloneDataStorage.
void EmitAddNodeEvent(const DataNode *node)
EmitAddNodeEvent emits the AddNodeEvent.
AdjacencyList m_SourceNodes
Nodes and their relation are stored in m_SourceNodes.
bool IsInitialized() const
convenience method to check if the object has been initialized (i.e. a data tree has been set) ...
~StandaloneDataStorage() override
Standard Destructor.
virtual bool CheckNode(const mitk::DataNode *node) const =0
This method will be used to evaluate the node. Has to be overwritten in subclasses.
itk::SmartPointer< Self > Pointer
void EmitRemoveNodeEvent(const DataNode *node)
EmitRemoveNodeEvent emits the RemoveNodeEvent.
void AddListeners(const DataNode *_Node)
Adds a Modified-Listener to the given Node.
SetOfObjects::ConstPointer GetDerivations(const mitk::DataNode *node, const NodePredicateBase *condition=nullptr, bool onlyDirectDerivations=true) const override
returns a set of derived objects for a given node.
itk::SimpleFastMutexLock m_Mutex
void Add(mitk::DataNode *node, const mitk::DataStorage::SetOfObjects *parents=nullptr) override
Adds a DataNode containing a data object to its internal storage.
void Remove(const mitk::DataNode *node) override
Removes node from the StandaloneDataStorage.
itk::VectorContainer< unsigned int, DataNode::Pointer > SetOfObjects
A Container of objects that is used as a result set of GetSubset() query operations (Set of...
AdjacencyList m_DerivedNodes
Nodes are stored in reverse relation for easier traversal in the opposite direction of the relation...
SetOfObjects::ConstPointer GetAll() const override
returns a set of all data objects that are stored in the data storage
Interface for evaluation conditions used in the DataStorage class GetSubset() method.
StandaloneDataStorage()
Standard Constructor for ::New() instantiation.
void RemoveFromRelation(const mitk::DataNode *node, AdjacencyList &relation)
deletes all references to a node in a given relation (used in Remove() and TreeListener) ...
SetOfObjects::ConstPointer GetRelations(const mitk::DataNode *node, const AdjacencyList &relation, const NodePredicateBase *condition=nullptr, bool onlyDirectlyRelated=true) const
Traverses the Relation graph and extracts a list of related elements (e.g. Sources or Derivations) ...
std::map< mitk::DataNode::ConstPointer, SetOfObjects::ConstPointer > AdjacencyList
noncyclical directed graph data structure to store the nodes with their relation
Class for nodes of the DataTree.