Medical Imaging Interaction Toolkit  2023.12.99-7a59bd54
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 
27  //##Documentation
28  //## @brief Data management class that handles 'was created by' relations
29  //##
30  //## The StandaloneDataStorage provides data storage and management functionality.
31  //## It handles a 'was created by' relation by associating each data object with a
32  //## set of source objects that were used to create the new object was created from.
33  //## Thus, nodes are stored in a noncyclical directed graph data structure.
34  //## It is derived from mitk::DataStorage and implements its interface,
35  //## including AddNodeEvent and RemoveNodeEvent.
36  //## @ingroup StandaloneDataStorage
38  {
39  public:
41  itkFactorylessNewMacro(Self);
42  itkCloneMacro(Self);
43 
44  //##Documentation
45  //## @brief Adds a DataNode containing a data object to its internal storage
46  //##
47  //## This Method adds a new data object to the StandaloneDataStorage. The new object is
48  //## passed in the first parameter. The second parameter is a set
49  //## of source objects, that were used to create this object. The new object will have
50  //## a 'was created from' relation to its source objects.
51  //## the addition of a new object will fire the notification mechanism.
52  //## If the node parameter is nullptr or if the DataNode has already been added,
53  //## an exception will be thrown.
54  void Add(mitk::DataNode *node, const mitk::DataStorage::SetOfObjects *parents = nullptr) override;
55 
56  //##Documentation
57  //## @brief Removes node from the StandaloneDataStorage
58  //##
59  void Remove(const mitk::DataNode *node) override;
60 
61  //##Documentation
62  //## @brief Checks if a node exists in the StandaloneDataStorage
63  //##
64  bool Exists(const mitk::DataNode *node) const override;
65 
66  //##Documentation
67  //## @brief returns a set of source objects for a given node that meet the given condition(s).
68  //##
69  SetOfObjects::ConstPointer GetSources(const mitk::DataNode *node,
70  const NodePredicateBase *condition = nullptr,
71  bool onlyDirectSources = true) const override;
72 
73  //##Documentation
74  //## @brief returns a set of derived objects for a given node.
75  //##
76  //## GetDerivations() returns a set of objects that are derived from the DataNode node.
77  //## This means, that node was used to create the returned objects. If the parameter
78  //## onlyDirectDerivations is set to true (default value), only objects that directly have
79  //## node as one of their source objects will be returned. Otherwise, objects that are
80  //## derived from derivations of node are returned too.
81  //## The derived objects can be filtered with a predicate object as described in the GetSubset()
82  //## method by providing a predicate as the condition parameter.
83  SetOfObjects::ConstPointer GetDerivations(const mitk::DataNode *node,
84  const NodePredicateBase *condition = nullptr,
85  bool onlyDirectDerivations = true) const override;
86 
87  //##Documentation
88  //## @brief returns a set of all data objects that are stored in the data storage
89  //##
90  SetOfObjects::ConstPointer GetAll() const override;
91 
92  mutable std::mutex m_Mutex;
93 
94  protected:
95  //##Documentation
96  //## @brief noncyclical directed graph data structure to store the nodes with their relation
97  typedef std::map<mitk::DataNode::ConstPointer, SetOfObjects::ConstPointer> AdjacencyList;
98 
100  ~StandaloneDataStorage() override;
101 
102  //##Documentation
103  //## @brief convenience method to check if the object has been initialized (i.e. a data tree has been set)
104  bool IsInitialized() const;
105 
106  //##Documentation
107  //## @brief Traverses the Relation graph and extracts a list of related elements (e.g. Sources or Derivations)
108  SetOfObjects::ConstPointer GetRelations(const mitk::DataNode *node,
109  const AdjacencyList &relation,
110  const NodePredicateBase *condition = nullptr,
111  bool onlyDirectlyRelated = true) const;
112 
113  //##Documentation
114  //## @brief deletes all references to a node in a given relation (used in Remove() and TreeListener)
115  void RemoveFromRelation(const mitk::DataNode *node, AdjacencyList &relation);
116 
117  //##Documentation
118  //## @brief Prints the contents of the StandaloneDataStorage to os. Do not call directly, call ->Print() instead
119  void PrintSelf(std::ostream &os, itk::Indent indent) const override;
120 
121  //##Documentation
122  //## @brief Nodes and their relation are stored in m_SourceNodes
124  //##Documentation
125  //## @brief Nodes are stored in reverse relation for easier traversal in the opposite direction of the relation
127  };
128 } // namespace mitk
129 #endif
mitk::StandaloneDataStorage
Data management class that handles 'was created by' relations.
Definition: mitkStandaloneDataStorage.h:37
mitk::DataStorage::SetOfObjects
itk::VectorContainer< unsigned int, DataNode::Pointer > SetOfObjects
A Container of objects that is used as a result set of GetSubset() query operations (Set of.
Definition: mitkDataStorage.h:46
mitk::StandaloneDataStorage::m_Mutex
std::mutex m_Mutex
Definition: mitkStandaloneDataStorage.h:92
mitkDataStorage.h
mitk::NodePredicateBase
Interface for evaluation conditions used in the DataStorage class GetSubset() method.
Definition: mitkNodePredicateBase.h:35
mitk::StandaloneDataStorage::m_SourceNodes
AdjacencyList m_SourceNodes
Nodes and their relation are stored in m_SourceNodes.
Definition: mitkStandaloneDataStorage.h:123
mitk::StandaloneDataStorage::AdjacencyList
std::map< mitk::DataNode::ConstPointer, SetOfObjects::ConstPointer > AdjacencyList
noncyclical directed graph data structure to store the nodes with their relation
Definition: mitkStandaloneDataStorage.h:97
mitk
Find image slices visible on a given plane.
Definition: RenderingTests.dox:1
mitkMessage.h
mitk::DataStorage
Data management class that handles 'was created by' relations.
Definition: mitkDataStorage.h:43
mitk::StandaloneDataStorage::m_DerivedNodes
AdjacencyList m_DerivedNodes
Nodes are stored in reverse relation for easier traversal in the opposite direction of the relation.
Definition: mitkStandaloneDataStorage.h:126
mitkClassMacro
#define mitkClassMacro(className, SuperClassName)
Definition: mitkCommon.h:36
MITKCORE_EXPORT
#define MITKCORE_EXPORT
Definition: MitkCoreExports.h:15
mitk::DataNode
Class for nodes of the DataTree.
Definition: mitkDataNode.h:63