19 #include "itkMutexLockHolder.h"
20 #include "itkSimpleFastMutexLock.h"
33 for (AdjacencyList::iterator it = m_SourceNodes.begin(); it != m_SourceNodes.end(); ++it)
35 this->RemoveListeners(it->first);
49 throw std::logic_error(
"DataStorage not initialized");
51 if ((parents != NULL) && (std::find(parents->begin(), parents->end(), node) != parents->end()))
52 throw std::invalid_argument(
"Node is it's own parent");
54 if (m_SourceNodes.find(node) != m_SourceNodes.end())
55 throw std::invalid_argument(
"Node is already in DataStorage");
64 m_SourceNodes.insert(std::make_pair(node, sp));
69 m_DerivedNodes.insert(std::make_pair(node, children));
72 for (SetOfObjects::ConstIterator it = sp->Begin(); it != sp->End(); it++)
76 m_DerivedNodes[parent];
77 if (derivedObjects.IsNull())
78 m_DerivedNodes[parent] =
81 m_DerivedNodes[parent].GetPointer());
82 deob->InsertElement(deob->Size(),
87 this->AddListeners(node);
91 EmitAddNodeEvent(node);
97 throw std::logic_error(
"DataStorage not initialized");
102 this->RemoveListeners(node);
113 EmitRemoveNodeEvent(node);
117 this->RemoveFromRelation(node, m_SourceNodes);
118 this->RemoveFromRelation(node, m_DerivedNodes);
125 return (m_SourceNodes.find(node) != m_SourceNodes.end());
130 for (AdjacencyList::const_iterator mapIter = relation.cbegin(); mapIter != relation.cend();
132 if (mapIter->second.IsNotNull())
135 const_cast<SetOfObjects *
>(mapIter->second.GetPointer());
136 SetOfObjects::STLContainerType::iterator relationListIter = std::find(
140 if (relationListIter != s->end())
141 s->erase(relationListIter);
144 AdjacencyList::iterator adIt;
145 adIt = relation.find(node);
146 if (adIt != relation.end())
147 relation.erase(adIt);
153 if (!IsInitialized())
154 throw std::logic_error(
"DataStorage not initialized");
158 unsigned int index = 0;
159 for (AdjacencyList::const_iterator it = m_SourceNodes.cbegin(); it != m_SourceNodes.cend(); ++it)
160 if (it->first.IsNull())
163 resultset->InsertElement(index++, const_cast<mitk::DataNode *>(it->first.GetPointer()));
172 bool onlyDirectlyRelated)
const
175 throw std::invalid_argument(
"invalid node");
178 if (onlyDirectlyRelated)
180 AdjacencyList::const_iterator it = relation.find(node);
181 if ((it == relation.cend()) || (it->second.IsNull()))
184 return this->FilterSetOfObjects(it->second, condition);
188 std::vector<mitk::DataNode::ConstPointer> resultset;
189 std::vector<mitk::DataNode::ConstPointer> openlist;
193 openlist.push_back(node);
195 while (openlist.size() > 0)
199 resultset.push_back(current);
200 AdjacencyList::const_iterator it = relation.find(current);
201 if ((it == relation.cend())
203 (it->second.IsNull())
205 (it->second->Size() == 0))
208 for (SetOfObjects::ConstIterator parentIt = it->second->Begin(); parentIt != it->second->End();
212 if (!(std::find(resultset.cbegin(), resultset.cend(), p) !=
215 !(std::find(openlist.cbegin(), openlist.cend(), p) != openlist.cend()))
216 openlist.push_back(p);
223 if (condition != NULL)
225 for (std::vector<mitk::DataNode::ConstPointer>::const_iterator resultIt = resultset.cbegin();
226 resultIt != resultset.cend();
228 if ((*resultIt != node) && (condition->
CheckNode(*resultIt) ==
true))
229 realResultset->InsertElement(realResultset->Size(),
234 for (std::vector<mitk::DataNode::ConstPointer>::const_iterator resultIt = resultset.cbegin();
235 resultIt != resultset.cend();
237 if (*resultIt != node)
238 realResultset->InsertElement(realResultset->Size(),
248 return this->GetRelations(node, m_SourceNodes, condition, onlyDirectSources);
255 return this->GetRelations(node, m_DerivedNodes, condition, onlyDirectDerivations);
260 os << indent <<
"StandaloneDataStorage:\n";
261 Superclass::PrintSelf(os, indent);
Data management class that handles 'was created by' relations.
itk::SmartPointer< Self > Pointer
itk::VectorContainer< unsigned int, mitk::DataNode::Pointer > SetOfObjects
A Container of objects that is used as a result set of GetSubset() query operations (Set of...
virtual 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).
DataCollection - Class to facilitate loading/accessing structured data.
virtual bool Exists(const mitk::DataNode *node) const override
Checks if a node exists in the StandaloneDataStorage.
itk::SmartPointer< const Self > ConstPointer
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
virtual ~StandaloneDataStorage()
Standard Destructor.
bool IsInitialized() const
convenience method to check if the object has been initialized (i.e. a data tree has been set) ...
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.
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.
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.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.