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