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