00001 /*========================================================================= 00002 00003 Program: Medical Imaging & Interaction Toolkit 00004 Language: C++ 00005 Date: $Date$ 00006 Version: $Revision$ 00007 00008 Copyright (c) German Cancer Research Center, Division of Medical and 00009 Biological Informatics. All rights reserved. 00010 See MITKCopyright.txt or https://www.mitk.org/copyright.html for details. 00011 00012 This software is distributed WITHOUT ANY WARRANTY; without even 00013 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00014 PURPOSE. See the above copyright notices for more information. 00015 00016 =========================================================================*/ 00017 00018 00019 #ifndef MITKSTANDALONEDATASTORAGE_H_HEADER_INCLUDED_ 00020 #define MITKSTANDALONEDATASTORAGE_H_HEADER_INCLUDED_ 00021 00022 #include "mitkDataStorage.h" 00023 #include "mitkMessage.h" 00024 #include "itkVectorContainer.h" 00025 #include <map> 00026 00027 namespace mitk { 00028 00029 class NodePredicateBase; 00030 class DataNode; 00031 00032 //##Documentation 00033 //## @brief Data management class that handles 'was created by' relations 00034 //## 00035 //## The StandaloneDataStorage provides data storage and management functionality. 00036 //## It handles a 'was created by' relation by associating each data object with a 00037 //## set of source objects that were used to create the new object was created from. 00038 //## Thus, nodes are stored in a noncyclical directed graph data structure. 00039 //## It is derived from mitk::DataStorage and implements its interface, 00040 //## including AddNodeEvent and RemoveNodeEvent. 00041 //## @ingroup StandaloneDataStorage 00042 class MITK_CORE_EXPORT StandaloneDataStorage : public mitk::DataStorage 00043 { 00044 public: 00045 mitkClassMacro(StandaloneDataStorage, mitk::DataStorage); 00046 itkNewMacro(Self); 00047 00048 //##Documentation 00049 //## @brief Adds a DataNode containing a data object to its internal storage 00050 //## 00051 //## This Method adds a new data object to the StandaloneDataStorage. The new object is 00052 //## passed in the first parameter. The second parameter is a set 00053 //## of source objects, that were used to create this object. The new object will have 00054 //## a 'was created from' relation to its source objects. 00055 //## the addition of a new object will fire the notification mechanism. 00056 //## If the node parameter is NULL or if the DataNode has already been added, 00057 //## an exception will be thrown. 00058 void Add(mitk::DataNode* node, const mitk::DataStorage::SetOfObjects* parents = NULL); 00059 00060 //##Documentation 00061 //## @brief Removes node from the StandaloneDataStorage 00062 //## 00063 void Remove(const mitk::DataNode* node); 00064 00065 //##Documentation 00066 //## @brief Checks if a node exists in the StandaloneDataStorage 00067 //## 00068 virtual bool Exists(const mitk::DataNode* node) const; 00069 00070 //##Documentation 00071 //## @brief returns a set of source objects for a given node that meet the given condition(s). 00072 //## 00073 SetOfObjects::ConstPointer GetSources(const mitk::DataNode* node, const NodePredicateBase* condition = NULL, bool onlyDirectSources = true) const; 00074 00075 //##Documentation 00076 //## @brief returns a set of derived objects for a given node. 00077 //## 00078 //## GetDerivations() returns a set of objects that are derived from the DataNode node. 00079 //## This means, that node was used to create the returned objects. If the parameter 00080 //## onlyDirectDerivations is set to true (default value), only objects that directly have 00081 //## node as one of their source objects will be returned. Otherwise, objects that are 00082 //## derived from derivations of node are returned too. 00083 //## The derived objects can be filtered with a predicate object as described in the GetSubset() 00084 //## method by providing a predicate as the condition parameter. 00085 SetOfObjects::ConstPointer GetDerivations(const mitk::DataNode* node, const NodePredicateBase* condition = NULL, bool onlyDirectDerivations = true) const; 00086 00087 //##Documentation 00088 //## @brief returns a set of all data objects that are stored in the data storage 00089 //## 00090 SetOfObjects::ConstPointer GetAll() const; 00091 00092 /*ITK Mutex */ 00093 mutable itk::SimpleFastMutexLock m_Mutex; 00094 00095 protected: 00096 00097 //##Documentation 00098 //## @brief noncyclical directed graph data structure to store the nodes with their relation 00099 typedef std::map<mitk::DataNode::ConstPointer, SetOfObjects::ConstPointer> AdjacencyList; 00100 00101 //##Documentation 00102 //## @brief Standard Constructor for ::New() instantiation 00103 StandaloneDataStorage(); 00104 //##Documentation 00105 //## @brief Standard Destructor 00106 virtual ~StandaloneDataStorage(); 00107 00108 //##Documentation 00109 //## @brief convenience method to check if the object has been initialized (i.e. a data tree has been set) 00110 bool IsInitialized() const; 00111 00112 //##Documentation 00113 //## @brief Traverses the Relation graph and extracts a list of related elements (e.g. Sources or Derivations) 00114 SetOfObjects::ConstPointer GetRelations(const mitk::DataNode* node, const AdjacencyList& relation, const NodePredicateBase* condition = NULL, bool onlyDirectlyRelated = true) const; 00115 00116 //##Documentation 00117 //## @brief deletes all references to a node in a given relation (used in Remove() and TreeListener) 00118 void RemoveFromRelation(const mitk::DataNode* node, AdjacencyList& relation); 00119 00120 //##Documentation 00121 //## @brief Prints the contents of the StandaloneDataStorage to os. Do not call directly, call ->Print() instead 00122 virtual void PrintSelf(std::ostream& os, itk::Indent indent) const; 00123 00124 //##Documentation 00125 //## @brief Nodes and their relation are stored in m_SourceNodes 00126 AdjacencyList m_SourceNodes; 00127 //##Documentation 00128 //## @brief Nodes are stored in reverse relation for easier traversal in the opposite direction of the relation 00129 AdjacencyList m_DerivedNodes; 00130 }; 00131 } // namespace mitk 00132 #endif /* MITKSTANDALONEDATASTORAGE_H_HEADER_INCLUDED_ */