Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
mitkStandaloneDataStorage.h
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #ifndef mitkStandaloneDataStorage_h
14 #define mitkStandaloneDataStorage_h
15 
16 #include <itkVectorContainer.h>
17 #include <mitkDataStorage.h>
18 #include <mitkMessage.h>
19 #include <map>
20 #include <mutex>
21 
22 namespace mitk
23 {
24  class NodePredicateBase;
25  class DataNode;
26 
42  {
43  public:
45  itkFactorylessNewMacro(Self);
46  itkCloneMacro(Self);
47 
60  void Add(mitk::DataNode *node, const mitk::DataStorage::SetOfObjects *parents = nullptr) override;
61  using DataStorage::Add; //ensure that also "void Add(DataNode *node, DataNode *parent);" is visible
62 
73  void Remove(const mitk::DataNode *node) override;
74 
81  bool Exists(const mitk::DataNode *node) const override;
82 
94  SetOfObjects::ConstPointer GetSources(const mitk::DataNode *node,
95  const NodePredicateBase *condition = nullptr,
96  bool onlyDirectSources = true) const override;
97 
111  SetOfObjects::ConstPointer GetDerivations(const mitk::DataNode *node,
112  const NodePredicateBase *condition = nullptr,
113  bool onlyDirectDerivations = true) const override;
114 
121  SetOfObjects::ConstPointer GetAll() const override;
122 
124  mutable std::mutex m_Mutex;
125 
126  protected:
127  //##Documentation
128  //## @brief noncyclical directed graph data structure to store the nodes with their relation
129  typedef std::map<mitk::DataNode::ConstPointer, SetOfObjects::ConstPointer> AdjacencyList;
130 
133 
134  //##Documentation
135  //## @brief convenience method to check if the object has been initialized (i.e. a data tree has been set)
136  bool IsInitialized() const;
137 
138  //##Documentation
139  //## @brief Traverses the Relation graph and extracts a list of related elements (e.g. Sources or Derivations)
140  SetOfObjects::ConstPointer GetRelations(const mitk::DataNode *node,
141  const AdjacencyList &relation,
142  const NodePredicateBase *condition = nullptr,
143  bool onlyDirectlyRelated = true) const;
144 
145  //##Documentation
146  //## @brief deletes all references to a node in a given relation (used in Remove() and TreeListener)
147  void RemoveFromRelation(const mitk::DataNode *node, AdjacencyList &relation);
148 
149  //##Documentation
150  //## @brief Prints the contents of the StandaloneDataStorage to os. Do not call directly, call ->Print() instead
151  void PrintSelf(std::ostream &os, itk::Indent indent) const override;
152 
153  //##Documentation
154  //## @brief Nodes and their relation are stored in m_SourceNodes
156  //##Documentation
157  //## @brief Nodes are stored in reverse relation for easier traversal in the opposite direction of the relation
159  };
160 } // namespace mitk
161 #endif
#define MITKCORE_EXPORT
Central node class of the MITK data tree, associating a data object with properties and mappers.
Definition: mitkDataNode.h:72
Abstract data management class that organizes DataNode objects in a directed acyclic graph.
virtual void Add(DataNode *node, const DataStorage::SetOfObjects *parents=nullptr)=0
Add a DataNode to the storage, optionally with parent (source) nodes.
itk::VectorContainer< unsigned int, DataNode::Pointer > SetOfObjects
Container type used as a result set of query operations such as GetSubset().
Abstract base class for predicates used to filter DataNode objects in DataStorage queries.
Concrete DataStorage implementation that stores nodes in an in-memory adjacency list graph.
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.
AdjacencyList m_SourceNodes
Nodes and their relation are stored in m_SourceNodes.
SetOfObjects::ConstPointer GetDerivations(const mitk::DataNode *node, const NodePredicateBase *condition=nullptr, bool onlyDirectDerivations=true) const override
Return the derived (child) nodes of a given node, optionally filtered.
SetOfObjects::ConstPointer GetSources(const mitk::DataNode *node, const NodePredicateBase *condition=nullptr, bool onlyDirectSources=true) const override
Return the source (parent) nodes of a given node, optionally filtered.
void RemoveFromRelation(const mitk::DataNode *node, AdjacencyList &relation)
deletes all references to a node in a given relation (used in Remove() and TreeListener)
void Remove(const mitk::DataNode *node) override
Remove a node from the StandaloneDataStorage.
bool IsInitialized() const
convenience method to check if the object has been initialized (i.e. a data tree has been set)
mitkClassMacro(StandaloneDataStorage, mitk::DataStorage)
AdjacencyList m_DerivedNodes
Nodes are stored in reverse relation for easier traversal in the opposite direction of the relation.
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::mutex m_Mutex
Mutex protecting the internal adjacency lists for thread-safe access.
bool Exists(const mitk::DataNode *node) const override
Check whether a node exists in this StandaloneDataStorage.
void Add(mitk::DataNode *node, const mitk::DataStorage::SetOfObjects *parents=nullptr) override
Add a DataNode to the storage, optionally with parent (source) nodes.
SetOfObjects::ConstPointer GetAll() const override
Return all nodes managed by this StandaloneDataStorage.
std::map< mitk::DataNode::ConstPointer, SetOfObjects::ConstPointer > AdjacencyList
noncyclical directed graph data structure to store the nodes with their relation
Find image slices visible on a given plane.