Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
mitkDataStorage.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 mitkDataStorage_h
14 #define mitkDataStorage_h
15 
16 #include <itkObject.h>
17 #include <itkVectorContainer.h>
18 #include <mitkDataNode.h>
19 #include <mitkGeometry3D.h>
20 #include <mitkMessage.h>
21 #include <MitkCoreExports.h>
22 #include <map>
23 #include <mutex>
24 
25 namespace mitk
26 {
27  class NodePredicateBase;
28  class DataNode;
29  class BaseRenderer;
30 
49  class MITKCORE_EXPORT DataStorage : public itk::Object
50  {
51  public:
53 
59  typedef itk::VectorContainer<unsigned int, DataNode::Pointer> SetOfObjects;
60 
68  typedef itk::VectorContainer<unsigned int, DataNode::ConstPointer> ConstSetOfObjects;
69 
82  virtual void Add(DataNode *node, const DataStorage::SetOfObjects *parents = nullptr) = 0;
83 
92  void Add(DataNode *node, DataNode *parent);
93 
105  void Add(DataNode *node, const ConstSetOfObjects *parents);
106 
115  virtual void Remove(const DataNode *node) = 0;
116 
123  virtual bool Exists(const DataNode *node) const = 0;
124 
133  void Remove(const DataStorage::SetOfObjects *nodes);
134 
143  void Remove(const ConstSetOfObjects *nodes);
144 
157  SetOfObjects::ConstPointer GetSubset(const NodePredicateBase *condition) const;
158 
170  virtual SetOfObjects::ConstPointer GetSources(const DataNode *node,
171  const NodePredicateBase *condition = nullptr,
172  bool onlyDirectSources = true) const = 0;
173 
187  virtual SetOfObjects::ConstPointer GetDerivations(const DataNode *node,
188  const NodePredicateBase *condition = nullptr,
189  bool onlyDirectDerivations = true) const = 0;
190 
197  virtual SetOfObjects::ConstPointer GetAll() const = 0;
198 
206  DataNode *GetNode(const NodePredicateBase *condition = nullptr) const;
207 
217  DataNode *GetNamedNode(const char *name) const;
218 
226  DataNode *GetNamedNode(const std::string& name) const { return this->GetNamedNode(name.c_str()); }
227 
237  DataNode *GetNamedDerivedNode(const char *name,
238  const DataNode *sourceNode,
239  bool onlyDirectDerivations = true) const;
240 
251  template <class DataType>
252  DataType *GetNamedObject(const char *name) const
253  {
254  if (name == nullptr)
255  return nullptr;
256  DataNode *n = this->GetNamedNode(name);
257  if (n == nullptr)
258  return nullptr;
259  else
260  return dynamic_cast<DataType *>(n->GetData());
261  }
262 
271  template <class DataType>
272  DataType *GetNamedObject(const std::string& name) const
273  {
274  return this->GetNamedObject<DataType>(name.c_str());
275  }
276 
287  template <class DataType>
288  DataType *GetNamedDerivedObject(const char *name,
289  const DataNode *sourceNode,
290  bool onlyDirectDerivations = true) const
291  {
292  if (name == nullptr)
293  return nullptr;
294  DataNode *n = this->GetNamedDerivedNode(name, sourceNode, onlyDirectDerivations);
295  if (n == nullptr)
296  return nullptr;
297  else
298  return dynamic_cast<DataType *>(n->GetData());
299  }
300 
314  std::string GetUniqueName(const std::string& name, const DataNode* sourceNode = nullptr, bool onlyDirectDerivations = true) const;
315 
325 
327  mutable std::mutex m_MutexOne;
328 
331 
340 
349 
361 
373 
381 
394  TimeGeometry::ConstPointer ComputeBoundingGeometry3D(const SetOfObjects *input,
395  const char *boolPropertyKey = nullptr,
396  const BaseRenderer *renderer = nullptr,
397  const char *boolPropertyKey2 = nullptr) const;
398 
412  TimeGeometry::ConstPointer ComputeBoundingGeometry3D(const ConstSetOfObjects *input,
413  const char *boolPropertyKey = nullptr,
414  const BaseRenderer *renderer = nullptr,
415  const char *boolPropertyKey2 = nullptr) const;
416 
427  TimeGeometry::ConstPointer ComputeBoundingGeometry3D(const char *boolPropertyKey = nullptr,
428  const BaseRenderer *renderer = nullptr,
429  const char *boolPropertyKey2 = nullptr) const;
430 
440  TimeGeometry::ConstPointer ComputeVisibleBoundingGeometry3D(const BaseRenderer *renderer = nullptr,
441  const char *boolPropertyKey = nullptr);
442 
451  BoundingBox::Pointer ComputeBoundingBox(const char *boolPropertyKey = nullptr,
452  const BaseRenderer *renderer = nullptr,
453  const char *boolPropertyKey2 = nullptr);
454 
464  BoundingBox::Pointer ComputeVisibleBoundingBox(const BaseRenderer *renderer = nullptr,
465  const char *boolPropertyKey = nullptr)
466  {
467  return ComputeBoundingBox("visible", renderer, boolPropertyKey);
468  }
469 
482  TimeBounds ComputeTimeBounds(const char *boolPropertyKey,
483  const BaseRenderer *renderer,
484  const char *boolPropertyKey2);
485 
495  TimeBounds ComputeTimeBounds(const BaseRenderer *renderer, const char *boolPropertyKey)
496  {
497  return ComputeTimeBounds("visible", renderer, boolPropertyKey);
498  }
499 
510  void BlockNodeModifiedEvents(bool block);
511 
512  protected:
513  //##Documentation
514  //## @brief EmitAddNodeEvent emits the AddNodeEvent
515  //##
516  //## This method should be called by subclasses to emit the AddNodeEvent
517  void EmitAddNodeEvent(const DataNode *node);
518 
519  //##Documentation
520  //## @brief EmitRemoveNodeEvent emits the RemoveNodeEvent
521  //##
522  //## This method should be called by subclasses to emit the RemoveNodeEvent
523  void EmitRemoveNodeEvent(const DataNode *node);
524 
525  void OnNodeInteractorChanged(itk::Object *caller, const itk::EventObject &event);
526 
527  //##Documentation
528  //## @brief OnNodeModified listens to modified events of DataNodes.
529  //##
530  //## The node is hidden behind the caller parameter, which has to be casted first.
531  //## If the cast succeeds the ChangedNodeEvent is emitted with this node.
532  void OnNodeModifiedOrDeleted(const itk::Object *caller, const itk::EventObject &event);
533 
534  //##Documentation
535  //## @brief Adds a Modified-Listener to the given Node.
536  void AddListeners(const DataNode *_Node);
537 
538  //##Documentation
539  //## @brief Removes a Modified-Listener from the given Node.
540  void RemoveListeners(const DataNode *_Node);
541 
542  //##Documentation
543  //## @brief Saves Modified-Observer Tags for each node in order to remove the event listeners again.
544  std::map<const DataNode *, unsigned long> m_NodeModifiedObserverTags;
545 
546  std::map<const DataNode *, unsigned long> m_NodeInteractorChangedObserverTags;
547 
548  //##Documentation
549  //## @brief Saves Delete-Observer Tags for each node in order to remove the event listeners again.
550  std::map<const DataNode *, unsigned long> m_NodeDeleteObserverTags;
551 
552  //##Documentation
553  //## @brief If this class changes nodes itself, set this to TRUE in order
554  //## to suppress NodeChangedEvent to be emitted.
556 
558  ~DataStorage() override;
559 
560  //##Documentation
561  //## @brief Filters a SetOfObjects by the condition. If no condition is provided, the original set is returned
562  SetOfObjects::ConstPointer FilterSetOfObjects(const SetOfObjects *set, const NodePredicateBase *condition) const;
563 
564  //##Documentation
565  //## @brief Prints the contents of the DataStorage to os. Do not call directly, call ->Print() instead
566  void PrintSelf(std::ostream &os, itk::Indent indent) const override;
567  };
568 
582  MITKCORE_EXPORT DataNode::Pointer FindTopmostVisibleNode(const DataStorage::SetOfObjects::ConstPointer nodes,
583  const Point3D worldPosition,
584  const TimePointType timePoint,
585  const BaseRenderer* baseRender);
586 } // namespace mitk
587 
588 #endif
#define MITKCORE_EXPORT
Organizes the rendering process.
Central node class of the MITK data tree, associating a data object with properties and mappers.
Definition: mitkDataNode.h:72
BaseData * GetData() const
Get the data object (instance of BaseData, e.g., an Image) managed by this DataNode.
std::set< std::string > GroupTagList
Set of group tag name strings (keys of GroupTagProperty entries).
Definition: mitkDataNode.h:83
Abstract data management class that organizes DataNode objects in a directed acyclic graph.
TimeGeometry::ConstPointer ComputeBoundingGeometry3D(const char *boolPropertyKey=nullptr, const BaseRenderer *renderer=nullptr, const char *boolPropertyKey2=nullptr) const
Compute the axis-parallel bounding geometry of all nodes in the DataStorage.
DataStorageEvent RemoveNodeEvent
Event emitted directly before a node is removed from the DataStorage.
TimeBounds ComputeTimeBounds(const BaseRenderer *renderer, const char *boolPropertyKey)
Compute the time bounds of all visible nodes.
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().
void Add(DataNode *node, DataNode *parent)
Convenience method to add a node with a single parent.
const DataNode::GroupTagList GetGroupTags() const
Return all group tags used across all nodes in the DataStorage.
DataType * GetNamedDerivedObject(const char *name, const DataNode *sourceNode, bool onlyDirectDerivations=true) const
Convenience method to get the first data object of a given type with a given name,...
Message1< const DataNode * > DataStorageEvent
Event type used for all DataStorage notifications, carrying a const DataNode pointer.
DataNode * GetNode(const NodePredicateBase *condition=nullptr) const
Convenience method to get the first node that matches the predicate condition.
SetOfObjects::ConstPointer FilterSetOfObjects(const SetOfObjects *set, const NodePredicateBase *condition) const
Filters a SetOfObjects by the condition. If no condition is provided, the original set is returned.
std::string GetUniqueName(const std::string &name, const DataNode *sourceNode=nullptr, bool onlyDirectDerivations=true) const
Generate a unique node name by appending an incrementing number if necessary.
~DataStorage() override
DataNode * GetNamedNode(const char *name) const
Convenience method to get the first node with a given name.
void BlockNodeModifiedEvents(bool block)
Enable or disable suppression of ChangedNodeEvent emission.
void EmitRemoveNodeEvent(const DataNode *node)
EmitRemoveNodeEvent emits the RemoveNodeEvent.
std::mutex m_MutexOne
Mutex for thread-safe operations on the DataStorage.
DataType * GetNamedObject(const std::string &name) const
Convenience method to get the first data object of a given type with a given name (std::string overlo...
BoundingBox::Pointer ComputeBoundingBox(const char *boolPropertyKey=nullptr, const BaseRenderer *renderer=nullptr, const char *boolPropertyKey2=nullptr)
Compute the axis-parallel bounding box of all nodes in the DataStorage.
void Add(DataNode *node, const ConstSetOfObjects *parents)
Convenience overload for callers that hold only const node pointers for the parents.
void OnNodeModifiedOrDeleted(const itk::Object *caller, const itk::EventObject &event)
OnNodeModified listens to modified events of DataNodes.
DataStorageEvent ChangedNodeEvent
Event emitted after a managed node has been modified.
void AddListeners(const DataNode *_Node)
Adds a Modified-Listener to the given Node.
DataStorageEvent AddNodeEvent
Event emitted after a new node has been added to the DataStorage.
bool m_BlockNodeModifiedEvents
If this class changes nodes itself, set this to TRUE in order to suppress NodeChangedEvent to be emit...
DataStorageEvent DeleteNodeEvent
Event emitted directly before a managed node is deleted.
DataStorageEvent InteractorChangedNodeEvent
Event emitted when the DataInteractor of a managed node changes.
TimeGeometry::ConstPointer ComputeVisibleBoundingGeometry3D(const BaseRenderer *renderer=nullptr, const char *boolPropertyKey=nullptr)
Compute the axis-parallel bounding geometry of all visible nodes.
std::map< const DataNode *, unsigned long > m_NodeModifiedObserverTags
Saves Modified-Observer Tags for each node in order to remove the event listeners again.
DataNode * GetNamedDerivedNode(const char *name, const DataNode *sourceNode, bool onlyDirectDerivations=true) const
Convenience method to get the first node with a given name that is derived from a source node.
itk::VectorContainer< unsigned int, DataNode::ConstPointer > ConstSetOfObjects
Container type for const node pointers, used for input parameters where nodes are read-only.
virtual SetOfObjects::ConstPointer GetAll() const =0
Return all nodes managed by this DataStorage.
void OnNodeInteractorChanged(itk::Object *caller, const itk::EventObject &event)
virtual SetOfObjects::ConstPointer GetSources(const DataNode *node, const NodePredicateBase *condition=nullptr, bool onlyDirectSources=true) const =0
Return the source (parent) nodes of a given node.
TimeGeometry::ConstPointer ComputeBoundingGeometry3D(const SetOfObjects *input, const char *boolPropertyKey=nullptr, const BaseRenderer *renderer=nullptr, const char *boolPropertyKey2=nullptr) const
Compute the axis-parallel bounding geometry encompassing the given set of nodes.
void Remove(const DataStorage::SetOfObjects *nodes)
Remove a set of nodes from the DataStorage.
mitkClassMacroItkParent(DataStorage, itk::Object)
std::map< const DataNode *, unsigned long > m_NodeInteractorChangedObserverTags
TimeGeometry::ConstPointer ComputeBoundingGeometry3D(const ConstSetOfObjects *input, const char *boolPropertyKey=nullptr, const BaseRenderer *renderer=nullptr, const char *boolPropertyKey2=nullptr) const
Compute the axis-parallel bounding geometry for a set of const node pointers.
TimeBounds ComputeTimeBounds(const char *boolPropertyKey, const BaseRenderer *renderer, const char *boolPropertyKey2)
Compute the time bounds of all nodes in the DataStorage.
void Remove(const ConstSetOfObjects *nodes)
Remove a set of const-pointer nodes from the DataStorage.
std::map< const DataNode *, unsigned long > m_NodeDeleteObserverTags
Saves Delete-Observer Tags for each node in order to remove the event listeners again.
SetOfObjects::ConstPointer GetSubset(const NodePredicateBase *condition) const
Return all nodes that satisfy the given predicate condition.
virtual void Remove(const DataNode *node)=0
Remove a single node from the DataStorage.
BoundingBox::Pointer ComputeVisibleBoundingBox(const BaseRenderer *renderer=nullptr, const char *boolPropertyKey=nullptr)
Compute the bounding box of all visible nodes.
virtual bool Exists(const DataNode *node) const =0
Check whether a node exists in the DataStorage.
void RemoveListeners(const DataNode *_Node)
Removes a Modified-Listener from the given Node.
virtual SetOfObjects::ConstPointer GetDerivations(const DataNode *node, const NodePredicateBase *condition=nullptr, bool onlyDirectDerivations=true) const =0
Return the derived (child) nodes of a given node.
void PrintSelf(std::ostream &os, itk::Indent indent) const override
Prints the contents of the DataStorage to os. Do not call directly, call ->Print() instead.
DataType * GetNamedObject(const char *name) const
Convenience method to get the first data object of a given type with a given name.
void EmitAddNodeEvent(const DataNode *node)
EmitAddNodeEvent emits the AddNodeEvent.
DataNode * GetNamedNode(const std::string &name) const
Convenience method to get the first node with a given name (std::string overload).
Abstract base class for predicates used to filter DataNode objects in DataStorage queries.
Find image slices visible on a given plane.
itk::FixedArray< ScalarType, 2 > TimeBounds
Fixed-size array holding a pair of time bound values [min, max] in milliseconds.
MITKCORE_EXPORT DataNode::Pointer FindTopmostVisibleNode(const DataStorage::SetOfObjects::ConstPointer nodes, const Point3D worldPosition, const TimePointType timePoint, const BaseRenderer *baseRender)
Find the topmost visible node at a given world position and time point.
mitk::ScalarType TimePointType
Type for time point values in milliseconds (ms).