Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
mitkDataNode.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 mitkDataNode_h
14 #define mitkDataNode_h
15 
16 #include <mitkBaseData.h>
17 #include <mitkDataInteractor.h>
18 #include <mitkIdentifiable.h>
19 #include <mitkIPropertyOwner.h>
20 
21 #include <fstream>
22 #include <iostream>
23 
24 #include <mitkColorProperty.h>
25 #include <mitkPropertyList.h>
26 #include <mitkStringProperty.h>
27 
28 #include <mitkGeometry3D.h>
29 #include <mitkLevelWindow.h>
30 #include <map>
31 #include <set>
32 
33 class vtkLinearTransform;
34 
35 namespace mitk
36 {
37  class BaseRenderer;
38  class Mapper;
39 
44  itkEventMacroDeclaration(InteractorChangedEvent, itk::AnyEvent);
45 
71  class MITKCORE_EXPORT DataNode : public itk::DataObject, public IPropertyOwner
72  {
73  public:
75  typedef mitk::Geometry3D::Pointer Geometry3DPointer;
77  typedef std::vector<itk::SmartPointer<Mapper>> MapperVector;
79  typedef std::map<std::string, mitk::PropertyList::Pointer> MapOfPropertyLists;
81  typedef std::vector<MapOfPropertyLists::key_type> PropertyListKeyNames;
83  typedef std::set<std::string> GroupTagList;
84 
85  mitkClassMacroItkParent(DataNode, itk::DataObject);
86  itkFactorylessNewMacro(Self);
87 
88  // IPropertyProvider
89 
105  BaseProperty::ConstPointer GetConstProperty(const std::string &propertyKey, const std::string &contextName = "", bool fallBackOnDefaultContext = true) const override;
106 
115  std::vector<std::string> GetPropertyKeys(const std::string &contextName = "", bool includeDefaultContext = false) const override;
116 
125  std::vector<std::string> GetPropertyContextNames() const override;
126 
127  // IPropertyOwner
128 
141  BaseProperty * GetNonConstProperty(const std::string &propertyKey, const std::string &contextName = "", bool fallBackOnDefaultContext = true) override;
142 
154  void SetProperty(const std::string &propertyKey, BaseProperty *property, const std::string &contextName = "", bool fallBackOnDefaultContext = false) override;
155 
166  void RemoveProperty(const std::string &propertyKey, const std::string &contextName = "", bool fallBackOnDefaultContext = false) override;
167 
179 
184  BaseData *GetData() const;
185 
195  template <typename T>
196  T* GetDataAs() const
197  {
198  return dynamic_cast<T*>(this->GetData());
199  }
200 
207  vtkLinearTransform *GetVtkTransform(int t = 0) const;
208 
221  virtual void SetData(mitk::BaseData *baseData);
222 
231  virtual void SetDataInteractor(const DataInteractor::Pointer interactor);
232 
239  virtual DataInteractor::Pointer GetDataInteractor() const;
240 
247 
254 
262  virtual void SetMapper(MapperSlotId id, mitk::Mapper *mapper);
263 
267  void UpdateOutputInformation() override;
268 
273 
279 
284  bool VerifyRequestedRegion() override;
285 
290  void SetRequestedRegion(const itk::DataObject *data) override;
291 
296  void CopyInformation(const itk::DataObject *data) override;
297 
305 
317  void SetProperty(const char *propertyKey, BaseProperty *property, const mitk::BaseRenderer *renderer = nullptr);
318 
329  void ReplaceProperty(const char *propertyKey, BaseProperty *property, const mitk::BaseRenderer *renderer = nullptr);
330 
347  void AddProperty(const char *propertyKey,
348  BaseProperty *property,
349  const mitk::BaseRenderer *renderer = nullptr,
350  bool overwrite = false);
351 
360  mitk::PropertyList *GetPropertyList(const mitk::BaseRenderer *renderer = nullptr) const;
371  mitk::PropertyList *GetPropertyList(const std::string &rendererName) const;
372 
388  void ConcatenatePropertyList(PropertyList *pList, bool replace = false);
389 
404  mitk::BaseProperty *GetProperty(const char *propertyKey, const mitk::BaseRenderer *renderer = nullptr, bool fallBackOnDataProperties = true) const;
405 
417  template <typename T>
419  const char *propertyKey,
420  const mitk::BaseRenderer *renderer = nullptr) const
421  {
422  property = dynamic_cast<T *>(GetProperty(propertyKey, renderer));
423  return property.IsNotNull();
424  }
425 
437  template <typename T>
438  bool GetProperty(T *&property, const char *propertyKey, const mitk::BaseRenderer *renderer = nullptr) const
439  {
440  property = dynamic_cast<T *>(GetProperty(propertyKey, renderer));
441  return property != nullptr;
442  }
443 
455  template <typename T>
456  bool GetPropertyValue(const char *propertyKey, T &value, const mitk::BaseRenderer *renderer = nullptr) const
457  {
458  GenericProperty<T> *gp = dynamic_cast<GenericProperty<T> *>(GetProperty(propertyKey, renderer));
459  if (gp != nullptr)
460  {
461  value = gp->GetValue();
462  return true;
463  }
464  return false;
465  }
466 
469 
479  bool GetBoolProperty(const char *propertyKey, bool &boolValue, const mitk::BaseRenderer *renderer = nullptr) const;
480 
490  bool GetIntProperty(const char *propertyKey, int &intValue, const mitk::BaseRenderer *renderer = nullptr) const;
491 
501  bool GetFloatProperty(const char *propertyKey,
502  float &floatValue,
503  const mitk::BaseRenderer *renderer = nullptr) const;
504 
518  bool GetDoubleProperty(const char *propertyKey,
519  double &doubleValue,
520  const mitk::BaseRenderer *renderer = nullptr) const;
521 
531  bool GetStringProperty(const char *propertyKey,
532  std::string &string,
533  const mitk::BaseRenderer *renderer = nullptr) const;
534 
544  bool GetColor(float rgb[3], const mitk::BaseRenderer *renderer = nullptr, const char *propertyKey = "color") const;
545 
556  const mitk::BaseRenderer *renderer = nullptr,
557  const char *propertyKey = "levelwindow") const;
558 
569  void SetSelected(bool selected, const mitk::BaseRenderer *renderer = nullptr);
570 
578  bool IsSelected(const mitk::BaseRenderer *renderer = nullptr);
579 
585  bool GetName(std::string &nodeName,
586  const mitk::BaseRenderer *renderer = nullptr,
587  const char *propertyKey = "name") const
588  {
589  return GetStringProperty(propertyKey, nodeName, renderer);
590  }
591 
601  virtual std::string GetName() const
602  {
603  mitk::StringProperty *sp = dynamic_cast<mitk::StringProperty *>(this->GetProperty("name"));
604  if (sp == nullptr)
605  return "";
606  return sp->GetValue();
607  }
608 
613  static std::string NO_NAME_VALUE()
614  {
615  return "No Name!";
616  }
617 
624  virtual void SetName(const char *name)
625  {
626  if (name == nullptr)
627  return;
628 
629  auto* data = this->GetData();
630 
631  if (nullptr != data)
632  {
633  auto property = data->GetProperty("name");
634 
635  if (property.IsNotNull())
636  {
637  auto* stringProperty = dynamic_cast<StringProperty*>(property.GetPointer());
638 
639  if (nullptr != stringProperty)
640  {
641  stringProperty->SetValue(name);
642  return;
643  }
644  }
645  }
646 
647  this->SetStringProperty("name", name);
648  }
654  virtual void SetName(const std::string& name) { this->SetName(name.c_str()); }
661  bool GetVisibility(bool &visible, const mitk::BaseRenderer *renderer, const char *propertyKey = "visible") const
662  {
663  return GetBoolProperty(propertyKey, visible, renderer);
664  }
665 
675  bool GetOpacity(float &opacity, const mitk::BaseRenderer *renderer, const char *propertyKey = "opacity") const;
676 
686  bool IsOn(const char *propertyKey, const mitk::BaseRenderer *renderer, bool defaultIsOn = true) const
687  {
688  if (propertyKey == nullptr)
689  return defaultIsOn;
690  GetBoolProperty(propertyKey, defaultIsOn, renderer);
691  return defaultIsOn;
692  }
693 
705  bool IsVisible(const mitk::BaseRenderer *renderer,
706  const char *propertyKey = "visible",
707  bool defaultIsOn = true) const
708  {
709  return IsOn(propertyKey, renderer, defaultIsOn);
710  }
711 
720  void SetColor(const mitk::Color &color,
721  const mitk::BaseRenderer *renderer = nullptr,
722  const char *propertyKey = "color");
723 
734  void SetColor(float red,
735  float green,
736  float blue,
737  const mitk::BaseRenderer *renderer = nullptr,
738  const char *propertyKey = "color");
739 
748  void SetColor(const float rgb[3], const mitk::BaseRenderer *renderer = nullptr, const char *propertyKey = "color");
749 
757  void SetVisibility(bool visible, const mitk::BaseRenderer *renderer = nullptr, const char *propertyKey = "visible");
758 
767  void SetOpacity(float opacity, const mitk::BaseRenderer *renderer = nullptr, const char *propertyKey = "opacity");
768 
778  const mitk::BaseRenderer *renderer = nullptr,
779  const char *propertyKey = "levelwindow");
780 
789  void SetIntProperty(const char *propertyKey, int intValue, const mitk::BaseRenderer *renderer = nullptr);
790 
799  void SetBoolProperty(const char *propertyKey, bool boolValue, const mitk::BaseRenderer *renderer = nullptr);
800 
811  void SetFloatProperty(const char *propertyKey, float floatValue, const mitk::BaseRenderer *renderer = nullptr);
812 
823  void SetDoubleProperty(const char *propertyKey, double doubleValue, const mitk::BaseRenderer *renderer = nullptr);
824 
833  void SetStringProperty(const char *propertyKey, const char *string, const mitk::BaseRenderer *renderer = nullptr);
834 
839  itk::ModifiedTimeType GetMTime() const override;
840 
845  unsigned long GetDataReferenceChangedTime() const { return m_DataReferenceChangedTime.GetMTime(); }
846 
847  protected:
849 
850  ~DataNode() override;
851 
853  virtual void PropertyListModified(const itk::Object *caller, const itk::EventObject &event);
854 
857 
862  BaseData::Pointer m_Data;
863 
870  PropertyList::Pointer m_PropertyList;
871 
874 
875  DataInteractor::Pointer m_DataInteractor;
876 
879 
881  };
882 
892  MITKCORE_EXPORT std::istream &operator>>(std::istream &i, DataNode::Pointer &dtn);
893 
903  MITKCORE_EXPORT std::ostream &operator<<(std::ostream &o, DataNode::Pointer &dtn);
904 } // namespace mitk
905 
906 #endif
#define MITKCORE_EXPORT
Base class of all data objects.
Definition: mitkBaseData.h:60
Abstract base class for properties.
Organizes the rendering process.
Central node class of the MITK data tree, associating a data object with properties and mappers.
Definition: mitkDataNode.h:72
void ReplaceProperty(const char *propertyKey, BaseProperty *property, const mitk::BaseRenderer *renderer=nullptr)
Replace the property (instance of BaseProperty) with key propertyKey in the PropertyList of the rende...
bool IsSelected(const mitk::BaseRenderer *renderer=nullptr)
Query whether this node is currently selected.
unsigned long m_PropertyListModifiedObserverTag
Definition: mitkDataNode.h:880
PropertyListKeyNames GetPropertyListNames() const
The "names" used for (renderer-specific) PropertyLists in GetPropertyList(string).
bool GetLevelWindow(mitk::LevelWindow &levelWindow, const mitk::BaseRenderer *renderer=nullptr, const char *propertyKey="levelwindow") const
Convenience access method for level-window properties (instances of LevelWindowProperty).
mitk::PropertyList * GetPropertyList(const mitk::BaseRenderer *renderer=nullptr) const
Get the PropertyList of the renderer. If renderer is nullptr, the BaseRenderer-independent PropertyLi...
bool GetDoubleProperty(const char *propertyKey, double &doubleValue, const mitk::BaseRenderer *renderer=nullptr) const
Convenience access method for double properties (instances of DoubleProperty).
virtual void SetDataInteractor(const DataInteractor::Pointer interactor)
Set the DataInteractor associated with this node.
unsigned long GetDataReferenceChangedTime() const
Get the timestamp of the last change of the reference to the BaseData.
Definition: mitkDataNode.h:845
bool VerifyRequestedRegion() override
Verify that the requested region is valid.
virtual void SetName(const std::string &name)
Extra convenience access method to set the name of an object.
Definition: mitkDataNode.h:654
std::map< std::string, mitk::PropertyList::Pointer > MapOfPropertyLists
Map from renderer name strings to renderer-specific PropertyList instances.
Definition: mitkDataNode.h:79
void SetLevelWindow(mitk::LevelWindow levelWindow, const mitk::BaseRenderer *renderer=nullptr, const char *propertyKey="levelwindow")
Convenience method for setting level-window properties (instances of LevelWindowProperty).
static std::string NO_NAME_VALUE()
Sentinel value indicating that a node name has not been set yet.
Definition: mitkDataNode.h:613
void SetRequestedRegionToLargestPossibleRegion() override
Set the requested region to the largest possible region (no-op for DataNode).
void SetProperty(const std::string &propertyKey, BaseProperty *property, const std::string &contextName="", bool fallBackOnDefaultContext=false) override
Set a property in the given context (IPropertyOwner interface).
void SetRequestedRegion(const itk::DataObject *data) override
Set the requested region from another data object (no-op for DataNode).
PropertyList::Pointer m_PropertyList
BaseRenderer-independent PropertyList.
Definition: mitkDataNode.h:870
virtual DataInteractor::Pointer GetDataInteractor() const
Get the DataInteractor associated with this node.
~DataNode() override
mitk::Mapper * GetMapper(MapperSlotId id) const
Get the Mapper for the given mapper slot, creating it on demand if necessary.
std::vector< MapOfPropertyLists::key_type > PropertyListKeyNames
Vector of renderer name keys used in the MapOfPropertyLists.
Definition: mitkDataNode.h:81
mitk::Geometry3D::Pointer Geometry3DPointer
Smart pointer type for Geometry3D.
Definition: mitkDataNode.h:75
itk::TimeStamp m_DataReferenceChangedTime
Timestamp of the last change of m_Data.
Definition: mitkDataNode.h:878
virtual void SetMapper(MapperSlotId id, mitk::Mapper *mapper)
Set a specific Mapper for the given mapper slot.
bool GetName(std::string &nodeName, const mitk::BaseRenderer *renderer=nullptr, const char *propertyKey="name") const
Convenience access method for accessing the name of an object (instance of StringProperty with proper...
Definition: mitkDataNode.h:585
std::vector< itk::SmartPointer< Mapper > > MapperVector
Vector of Mapper smart pointers, indexed by MapperSlotId.
Definition: mitkDataNode.h:77
bool IsVisible(const mitk::BaseRenderer *renderer, const char *propertyKey="visible", bool defaultIsOn=true) const
Convenience access method for visibility properties (instances of BoolProperty). Return value is the ...
Definition: mitkDataNode.h:705
bool GetBoolProperty(const char *propertyKey, bool &boolValue, const mitk::BaseRenderer *renderer=nullptr) const
Convenience access method for bool properties (instances of BoolProperty).
void SetColor(const float rgb[3], const mitk::BaseRenderer *renderer=nullptr, const char *propertyKey="color")
Convenience method for setting color properties from a float array.
bool GetProperty(itk::SmartPointer< T > &property, const char *propertyKey, const mitk::BaseRenderer *renderer=nullptr) const
Get the property of type T with key propertyKey from the PropertyList of the renderer,...
Definition: mitkDataNode.h:418
virtual void SetData(mitk::BaseData *baseData)
Set the data object (instance of BaseData, e.g., an Image) managed by this DataNode.
mitkClassMacroItkParent(DataNode, itk::DataObject)
bool GetColor(float rgb[3], const mitk::BaseRenderer *renderer=nullptr, const char *propertyKey="color") const
Convenience access method for color properties (instances of ColorProperty).
bool GetOpacity(float &opacity, const mitk::BaseRenderer *renderer, const char *propertyKey="opacity") const
Convenience access method for opacity properties (instances of FloatProperty).
void SetColor(float red, float green, float blue, const mitk::BaseRenderer *renderer=nullptr, const char *propertyKey="color")
Convenience method for setting color properties from individual RGB components.
mitk::DataNode & operator=(BaseData *right)
Assignment operator. Creates a new DataNode with the given BaseData.
T * GetDataAs() const
Convenience method to get the data object cast to a specific type.
Definition: mitkDataNode.h:196
BaseData * GetData() const
Get the data object (instance of BaseData, e.g., an Image) managed by this DataNode.
GroupTagList GetGroupTags() const
Get a set of all group tags from this node's property list.
void SetProperty(const char *propertyKey, BaseProperty *property, const mitk::BaseRenderer *renderer=nullptr)
Set the property (instance of BaseProperty) with key propertyKey in the PropertyList of the renderer ...
std::vector< std::string > GetPropertyContextNames() const override
Retrieve all available property context names (IPropertyProvider interface).
virtual void PropertyListModified(const itk::Object *caller, const itk::EventObject &event)
Invoked when the property list was modified. Calls Modified() of the DataNode.
bool GetVisibility(bool &visible, const mitk::BaseRenderer *renderer, const char *propertyKey="visible") const
Convenience access method for visibility properties (instances of BoolProperty with property-key "vis...
Definition: mitkDataNode.h:661
void SetVisibility(bool visible, const mitk::BaseRenderer *renderer=nullptr, const char *propertyKey="visible")
Convenience method for setting visibility properties (instances of BoolProperty)
virtual std::string GetName() const
Extra convenience access method for accessing the name of an object (instance of StringProperty with ...
Definition: mitkDataNode.h:601
itk::ModifiedTimeType GetMTime() const override
Get the timestamp of the last change of the contents of this node or the referenced BaseData.
bool RequestedRegionIsOutsideOfTheBufferedRegion() override
Check if the requested region is outside of the buffered region.
void SetDoubleProperty(const char *propertyKey, double doubleValue, const mitk::BaseRenderer *renderer=nullptr)
Convenience method for setting double properties (instances of DoubleProperty).
void SetOpacity(float opacity, const mitk::BaseRenderer *renderer=nullptr, const char *propertyKey="opacity")
Convenience method for setting opacity properties (instances of FloatProperty).
BaseData::Pointer m_Data
The data object (instance of BaseData, e.g., an Image) managed by this DataNode.
Definition: mitkDataNode.h:862
bool GetFloatProperty(const char *propertyKey, float &floatValue, const mitk::BaseRenderer *renderer=nullptr) const
Convenience access method for float properties (instances of FloatProperty).
DataInteractor::Pointer m_DataInteractor
Definition: mitkDataNode.h:875
void AddProperty(const char *propertyKey, BaseProperty *property, const mitk::BaseRenderer *renderer=nullptr, bool overwrite=false)
Add the property (instance of BaseProperty) if it does not exist (or always ifoverwrite istrue) with ...
void SetColor(const mitk::Color &color, const mitk::BaseRenderer *renderer=nullptr, const char *propertyKey="color")
Convenience method for setting color properties (instances of ColorProperty).
void UpdateOutputInformation() override
Update the output information by calling the source's UpdateOutputInformation().
void SetStringProperty(const char *propertyKey, const char *string, const mitk::BaseRenderer *renderer=nullptr)
Convenience method for setting string properties (instances of StringProperty).
mitk::PropertyList * GetPropertyList(const std::string &rendererName) const
Get the PropertyList for a renderer identified by name.
virtual void SetName(const char *name)
Extra convenience access method to set the name of an object.
Definition: mitkDataNode.h:624
BaseProperty::ConstPointer GetConstProperty(const std::string &propertyKey, const std::string &contextName="", bool fallBackOnDefaultContext=true) const override
Retrieve a property as a const pointer (IPropertyProvider interface).
bool GetIntProperty(const char *propertyKey, int &intValue, const mitk::BaseRenderer *renderer=nullptr) const
Convenience access method for int properties (instances of IntProperty).
bool IsOn(const char *propertyKey, const mitk::BaseRenderer *renderer, bool defaultIsOn=true) const
Convenience access method for boolean properties (instances of BoolProperty). Return value is the val...
Definition: mitkDataNode.h:686
std::set< std::string > GroupTagList
Set of group tag name strings (keys of GroupTagProperty entries).
Definition: mitkDataNode.h:83
void RemoveProperty(const std::string &propertyKey, const std::string &contextName="", bool fallBackOnDefaultContext=false) override
Remove a property from the given context (IPropertyOwner interface).
std::vector< std::string > GetPropertyKeys(const std::string &contextName="", bool includeDefaultContext=false) const override
Retrieve all property keys for a given context (IPropertyProvider interface).
void SetBoolProperty(const char *propertyKey, bool boolValue, const mitk::BaseRenderer *renderer=nullptr)
Convenience method for setting boolean properties (instances of BoolProperty).
MapOfPropertyLists m_MapOfPropertyLists
Map associating each BaseRenderer with its own PropertyList.
Definition: mitkDataNode.h:873
MapperVector m_Mappers
Mapper-slots.
Definition: mitkDataNode.h:856
void ConcatenatePropertyList(PropertyList *pList, bool replace=false)
Add values from another PropertyList.
bool GetStringProperty(const char *propertyKey, std::string &string, const mitk::BaseRenderer *renderer=nullptr) const
Convenience access method for string properties (instances of StringProperty).
vtkLinearTransform * GetVtkTransform(int t=0) const
Get the transformation applied prior to displaying the data as a vtkTransform.
bool GetPropertyValue(const char *propertyKey, T &value, const mitk::BaseRenderer *renderer=nullptr) const
Convenience access method for GenericProperty<T> properties.
Definition: mitkDataNode.h:456
void SetFloatProperty(const char *propertyKey, float floatValue, const mitk::BaseRenderer *renderer=nullptr)
Convenience method for setting float properties (instances of FloatProperty).
BaseProperty * GetNonConstProperty(const std::string &propertyKey, const std::string &contextName="", bool fallBackOnDefaultContext=true) override
Retrieve a mutable property pointer (IPropertyOwner interface).
void CopyInformation(const itk::DataObject *data) override
Copy information from another data object (no-op for DataNode).
mitk::BaseProperty * GetProperty(const char *propertyKey, const mitk::BaseRenderer *renderer=nullptr, bool fallBackOnDataProperties=true) const
Get the property (instance of BaseProperty) with key propertyKey from the PropertyList of the rendere...
mitk::DataNode & operator=(const DataNode &right)
Assignment operator. Creates a new DataNode with the data from right.
void SetSelected(bool selected, const mitk::BaseRenderer *renderer=nullptr)
Set the selection state of this node.
void SetIntProperty(const char *propertyKey, int intValue, const mitk::BaseRenderer *renderer=nullptr)
Convenience method for setting int properties (instances of IntProperty).
bool GetProperty(T *&property, const char *propertyKey, const mitk::BaseRenderer *renderer=nullptr) const
Get the property of type T with key propertyKey from the PropertyList of the renderer,...
Definition: mitkDataNode.h:438
Template class for generating properties for simple value types (int, float, bool,...
virtual T GetValue() const
Get the property value.
Interface implemented by classes that provide write/read access to property information.
The LevelWindow class Class to store level/window values.
Base class of all mappers, Vtk as well as OpenGL mappers.
Definition: mitkMapper.h:56
Key-value list holding instances of BaseProperty.
Property for storing string values.
virtual const char * GetValue() const
Get the string value.
virtual void SetValue(const char *_arg)
Set the string value.
unsigned int MapperSlotId
Definition: mitkCommon.h:23
Find image slices visible on a given plane.
MITKCORE_EXPORT std::istream & operator>>(std::istream &i, DataNode::Pointer &dtn)
Stream input operator for DataNode smart pointers.
static const char * replace[]
Dictionary for abbreviating class, module, and namespace names in log output.
itk::RGBPixel< float > Color
Standard RGB color typedef using float components.
MITKCORE_EXPORT std::ostream & operator<<(std::ostream &o, DataNode::Pointer &dtn)
Stream output operator for DataNode smart pointers.
itkEventMacroDeclaration(BoundingShapeInteractionEvent, itk::AnyEvent)