Medical Imaging Interaction Toolkit  2025.08.99-f7084adb
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 "mitkMapper.h"
18 #include "mitkDataInteractor.h"
19 #include "mitkIdentifiable.h"
20 #include "mitkIPropertyOwner.h"
21 
22 #include <fstream>
23 #include <iostream>
24 
25 #include "mitkColorProperty.h"
26 #include "mitkPropertyList.h"
27 #include "mitkStringProperty.h"
28 //#include "mitkMapper.h"
29 
30 #include "mitkGeometry3D.h"
31 #include "mitkLevelWindow.h"
32 #include <map>
33 #include <set>
34 
35 class vtkLinearTransform;
36 
37 namespace mitk
38 {
39  class BaseRenderer;
40  class Mapper;
41 
46  itkEventMacroDeclaration(InteractorChangedEvent, itk::AnyEvent);
47 
63  class MITKCORE_EXPORT DataNode : public itk::DataObject, public IPropertyOwner
64  {
65  public:
67  typedef std::vector<itk::SmartPointer<Mapper>> MapperVector;
68  typedef std::map<std::string, mitk::PropertyList::Pointer> MapOfPropertyLists;
69  typedef std::vector<MapOfPropertyLists::key_type> PropertyListKeyNames;
70  typedef std::set<std::string> GroupTagList;
71 
72  mitkClassMacroItkParent(DataNode, itk::DataObject);
73  itkFactorylessNewMacro(Self);
74 
75  // IPropertyProvider
76  BaseProperty::ConstPointer GetConstProperty(const std::string &propertyKey, const std::string &contextName = "", bool fallBackOnDefaultContext = true) const override;
77  std::vector<std::string> GetPropertyKeys(const std::string &contextName = "", bool includeDefaultContext = false) const override;
78  std::vector<std::string> GetPropertyContextNames() const override;
79 
80  // IPropertyOwner
81  BaseProperty * GetNonConstProperty(const std::string &propertyKey, const std::string &contextName = "", bool fallBackOnDefaultContext = true) override;
82  void SetProperty(const std::string &propertyKey, BaseProperty *property, const std::string &contextName = "", bool fallBackOnDefaultContext = false) override;
83  void RemoveProperty(const std::string &propertyKey, const std::string &contextName = "", bool fallBackOnDefaultContext = false) override;
84 
85  mitk::Mapper *GetMapper(MapperSlotId id) const;
86 
91  BaseData *GetData() const;
92 
93  template <typename T>
94  T* GetDataAs() const
95  {
96  return dynamic_cast<T*>(this->GetData());
97  }
98 
104  vtkLinearTransform *GetVtkTransform(int t = 0) const;
105 
118  virtual void SetData(mitk::BaseData *baseData);
119 
123  virtual void SetDataInteractor(const DataInteractor::Pointer interactor);
124  virtual DataInteractor::Pointer GetDataInteractor() const;
125 
126  mitk::DataNode &operator=(const DataNode &right);
127 
128  mitk::DataNode &operator=(BaseData *right);
129  virtual void SetMapper(MapperSlotId id, mitk::Mapper *mapper);
130  void UpdateOutputInformation() override;
131 
132  void SetRequestedRegionToLargestPossibleRegion() override;
133 
134  bool RequestedRegionIsOutsideOfTheBufferedRegion() override;
135 
136  bool VerifyRequestedRegion() override;
137 
138  void SetRequestedRegion(const itk::DataObject *data) override;
139 
140  void CopyInformation(const itk::DataObject *data) override;
141 
148  PropertyListKeyNames GetPropertyListNames() const;
149 
161  void SetProperty(const char *propertyKey, BaseProperty *property, const mitk::BaseRenderer *renderer = nullptr);
162 
173  void ReplaceProperty(const char *propertyKey, BaseProperty *property, const mitk::BaseRenderer *renderer = nullptr);
174 
191  void AddProperty(const char *propertyKey,
192  BaseProperty *property,
193  const mitk::BaseRenderer *renderer = nullptr,
194  bool overwrite = false);
195 
204  mitk::PropertyList *GetPropertyList(const mitk::BaseRenderer *renderer = nullptr) const;
205  mitk::PropertyList *GetPropertyList(const std::string &rendererName) const;
206 
222  void ConcatenatePropertyList(PropertyList *pList, bool replace = false);
223 
238  mitk::BaseProperty *GetProperty(const char *propertyKey, const mitk::BaseRenderer *renderer = nullptr, bool fallBackOnDataProperties = true) const;
239 
251  template <typename T>
253  const char *propertyKey,
254  const mitk::BaseRenderer *renderer = nullptr) const
255  {
256  property = dynamic_cast<T *>(GetProperty(propertyKey, renderer));
257  return property.IsNotNull();
258  }
259 
271  template <typename T>
272  bool GetProperty(T *&property, const char *propertyKey, const mitk::BaseRenderer *renderer = nullptr) const
273  {
274  property = dynamic_cast<T *>(GetProperty(propertyKey, renderer));
275  return property != nullptr;
276  }
277 
283  template <typename T>
284  bool GetPropertyValue(const char *propertyKey, T &value, const mitk::BaseRenderer *renderer = nullptr) const
285  {
286  GenericProperty<T> *gp = dynamic_cast<GenericProperty<T> *>(GetProperty(propertyKey, renderer));
287  if (gp != nullptr)
288  {
289  value = gp->GetValue();
290  return true;
291  }
292  return false;
293  }
294 
296  GroupTagList GetGroupTags() const;
297 
303  bool GetBoolProperty(const char *propertyKey, bool &boolValue, const mitk::BaseRenderer *renderer = nullptr) const;
304 
310  bool GetIntProperty(const char *propertyKey, int &intValue, const mitk::BaseRenderer *renderer = nullptr) const;
311 
317  bool GetFloatProperty(const char *propertyKey,
318  float &floatValue,
319  const mitk::BaseRenderer *renderer = nullptr) const;
320 
330  bool GetDoubleProperty(const char *propertyKey,
331  double &doubleValue,
332  const mitk::BaseRenderer *renderer = nullptr) const;
333 
339  bool GetStringProperty(const char *propertyKey,
340  std::string &string,
341  const mitk::BaseRenderer *renderer = nullptr) const;
342 
348  bool GetColor(float rgb[3], const mitk::BaseRenderer *renderer = nullptr, const char *propertyKey = "color") const;
349 
355  bool GetLevelWindow(mitk::LevelWindow &levelWindow,
356  const mitk::BaseRenderer *renderer = nullptr,
357  const char *propertyKey = "levelwindow") const;
358 
362  void SetSelected(bool selected, const mitk::BaseRenderer *renderer = nullptr);
363 
368  bool IsSelected(const mitk::BaseRenderer *renderer = nullptr);
369 
375  bool GetName(std::string &nodeName,
376  const mitk::BaseRenderer *renderer = nullptr,
377  const char *propertyKey = "name") const
378  {
379  return GetStringProperty(propertyKey, nodeName, renderer);
380  }
381 
391  virtual std::string GetName() const
392  {
393  mitk::StringProperty *sp = dynamic_cast<mitk::StringProperty *>(this->GetProperty("name"));
394  if (sp == nullptr)
395  return "";
396  return sp->GetValue();
397  }
398 
400  static std::string NO_NAME_VALUE()
401  {
402  return "No Name!";
403  }
404 
411  virtual void SetName(const char *name)
412  {
413  if (name == nullptr)
414  return;
415 
416  auto* data = this->GetData();
417 
418  if (nullptr != data)
419  {
420  auto property = data->GetProperty("name");
421 
422  if (property.IsNotNull())
423  {
424  auto* stringProperty = dynamic_cast<StringProperty*>(property.GetPointer());
425 
426  if (nullptr != stringProperty)
427  {
428  stringProperty->SetValue(name);
429  return;
430  }
431  }
432  }
433 
434  this->SetStringProperty("name", name);
435  }
441  virtual void SetName(const std::string& name) { this->SetName(name.c_str()); }
448  bool GetVisibility(bool &visible, const mitk::BaseRenderer *renderer, const char *propertyKey = "visible") const
449  {
450  return GetBoolProperty(propertyKey, visible, renderer);
451  }
452 
458  bool GetOpacity(float &opacity, const mitk::BaseRenderer *renderer, const char *propertyKey = "opacity") const;
459 
469  bool IsOn(const char *propertyKey, const mitk::BaseRenderer *renderer, bool defaultIsOn = true) const
470  {
471  if (propertyKey == nullptr)
472  return defaultIsOn;
473  GetBoolProperty(propertyKey, defaultIsOn, renderer);
474  return defaultIsOn;
475  }
476 
488  bool IsVisible(const mitk::BaseRenderer *renderer,
489  const char *propertyKey = "visible",
490  bool defaultIsOn = true) const
491  {
492  return IsOn(propertyKey, renderer, defaultIsOn);
493  }
494 
499  void SetColor(const mitk::Color &color,
500  const mitk::BaseRenderer *renderer = nullptr,
501  const char *propertyKey = "color");
502 
507  void SetColor(float red,
508  float green,
509  float blue,
510  const mitk::BaseRenderer *renderer = nullptr,
511  const char *propertyKey = "color");
512 
517  void SetColor(const float rgb[3], const mitk::BaseRenderer *renderer = nullptr, const char *propertyKey = "color");
518 
526  void SetVisibility(bool visible, const mitk::BaseRenderer *renderer = nullptr, const char *propertyKey = "visible");
527 
532  void SetOpacity(float opacity, const mitk::BaseRenderer *renderer = nullptr, const char *propertyKey = "opacity");
533 
538  void SetLevelWindow(mitk::LevelWindow levelWindow,
539  const mitk::BaseRenderer *renderer = nullptr,
540  const char *propertyKey = "levelwindow");
541 
546  void SetIntProperty(const char *propertyKey, int intValue, const mitk::BaseRenderer *renderer = nullptr);
547 
552  void SetBoolProperty(const char *propertyKey, bool boolValue, const mitk::BaseRenderer *renderer = nullptr);
553 
558  void SetFloatProperty(const char *propertyKey, float floatValue, const mitk::BaseRenderer *renderer = nullptr);
559 
564  void SetDoubleProperty(const char *propertyKey, double doubleValue, const mitk::BaseRenderer *renderer = nullptr);
565 
570  void SetStringProperty(const char *propertyKey, const char *string, const mitk::BaseRenderer *renderer = nullptr);
571 
576  itk::ModifiedTimeType GetMTime() const override;
577 
582  unsigned long GetDataReferenceChangedTime() const { return m_DataReferenceChangedTime.GetMTime(); }
583 
584  protected:
585  DataNode();
586 
587  ~DataNode() override;
588 
590  virtual void PropertyListModified(const itk::Object *caller, const itk::EventObject &event);
591 
594 
600 
608 
611 
613 
616 
618  };
619 
620  MITKCORE_EXPORT std::istream &operator>>(std::istream &i, DataNode::Pointer &dtn);
621  MITKCORE_EXPORT std::ostream &operator<<(std::ostream &o, DataNode::Pointer &dtn);
622 } // namespace mitk
623 
624 #endif
mitk::DataNode::m_PropertyListModifiedObserverTag
unsigned long m_PropertyListModifiedObserverTag
Definition: mitkDataNode.h:617
mitk::DataNode::GetDataAs
T * GetDataAs() const
Definition: mitkDataNode.h:94
mitk::DataNode::m_DataInteractor
DataInteractor::Pointer m_DataInteractor
Definition: mitkDataNode.h:612
mitk::BaseProperty
Abstract base class for properties.
Definition: mitkBaseProperty.h:36
mitkIdentifiable.h
mitk::StringProperty
Property for strings.
Definition: mitkStringProperty.h:34
mitk::GenericProperty::GetValue
virtual T GetValue() const
mitk::DataNode::MapperVector
std::vector< itk::SmartPointer< Mapper > > MapperVector
Definition: mitkDataNode.h:67
mitk::Color
itk::RGBPixel< float > Color
Color Standard RGB color typedef (float)
Definition: mitkColorProperty.h:38
mitk::DataNode::IsOn
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:469
mitk::operator<<
MITKCORE_EXPORT std::ostream & operator<<(std::ostream &o, DataNode::Pointer &dtn)
mitk::DataNode::GetName
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:375
itk::SmartPointer< Self >
mitk::StringProperty::SetValue
virtual void SetValue(const char *_arg)
mitk::GenericProperty
Definition: mitkGenericProperty.h:46
mitk::DataNode::SetName
virtual void SetName(const std::string &name)
Extra convenience access method to set the name of an object.
Definition: mitkDataNode.h:441
mitk::DataNode::MapOfPropertyLists
std::map< std::string, mitk::PropertyList::Pointer > MapOfPropertyLists
Definition: mitkDataNode.h:68
mitkGeometry3D.h
mitkClassMacroItkParent
#define mitkClassMacroItkParent(className, SuperClassName)
Definition: mitkCommon.h:45
mitk
Find image slices visible on a given plane.
Definition: RenderingTests.dox:1
mitk::LevelWindow
The LevelWindow class Class to store level/window values.
Definition: mitkLevelWindow.h:45
mitk::DataNode::GroupTagList
std::set< std::string > GroupTagList
Definition: mitkDataNode.h:70
mitk::operator>>
MITKCORE_EXPORT std::istream & operator>>(std::istream &i, DataNode::Pointer &dtn)
mitkIPropertyOwner.h
mitk::StringProperty::GetValue
virtual const char * GetValue() const
mitkStringProperty.h
mitk::Mapper
Base class of all mappers, Vtk as well as OpenGL mappers.
Definition: mitkMapper.h:46
mitkPropertyList.h
mitk::DataNode::m_DataReferenceChangedTime
itk::TimeStamp m_DataReferenceChangedTime
Timestamp of the last change of m_Data.
Definition: mitkDataNode.h:615
mitk::DataNode::GetProperty
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:252
mitk::DataNode::GetProperty
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:272
mitk::DataNode::GetName
virtual std::string GetName() const
Extra convenience access method for accessing the name of an object (instance of StringProperty with ...
Definition: mitkDataNode.h:391
mitk::PropertyList
Key-value list holding instances of BaseProperty.
Definition: mitkPropertyList.h:56
mitk::BaseData
Base of all data objects.
Definition: mitkBaseData.h:42
mitkDataInteractor.h
mitk::nnInteractive::GetColor
const MITKPYTHONSEGMENTATION_EXPORT Color & GetColor(PromptType promptType, ColorIntensity colorIntensity)
Returns the color associated with a specific prompt type and color intensity.
mitk::DataNode::Geometry3DPointer
mitk::Geometry3D::Pointer Geometry3DPointer
Definition: mitkDataNode.h:66
mitk::DataNode::NO_NAME_VALUE
static std::string NO_NAME_VALUE()
Definition: mitkDataNode.h:400
mitk::DataNode::m_Mappers
MapperVector m_Mappers
Mapper-slots.
Definition: mitkDataNode.h:593
mitk::DataNode::m_Data
BaseData::Pointer m_Data
The data object (instance of BaseData, e.g., an Image) managed by this DataNode.
Definition: mitkDataNode.h:599
mitk::ROIMapperHelper::GetConstProperty
const T * GetConstProperty(const std::string &propertyKey, const ROI::Element &roi, TimeStepType t)
Syntactic sugar for getting ROI properties.
Definition: mitkROIMapperHelper.h:48
mitk::DataNode::PropertyListKeyNames
std::vector< MapOfPropertyLists::key_type > PropertyListKeyNames
Definition: mitkDataNode.h:69
mitkBaseData.h
mitkLevelWindow.h
mitkColorProperty.h
mitk::DataNode::m_PropertyList
PropertyList::Pointer m_PropertyList
BaseRenderer-independent PropertyList.
Definition: mitkDataNode.h:607
mitk::BaseRenderer
Definition: mitkBaseRenderer.h:56
mitk::DataNode::IsVisible
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:488
MapperSlotId
unsigned int MapperSlotId
Definition: mitkCommon.h:29
mitk::DataNode::GetPropertyValue
bool GetPropertyValue(const char *propertyKey, T &value, const mitk::BaseRenderer *renderer=nullptr) const
Convenience access method for GenericProperty<T> properties (T being the type of the second parameter...
Definition: mitkDataNode.h:284
mitk::DataNode::m_MapOfPropertyLists
MapOfPropertyLists m_MapOfPropertyLists
Map associating each BaseRenderer with its own PropertyList.
Definition: mitkDataNode.h:610
mitk::IPropertyOwner
Definition: mitkIPropertyOwner.h:22
MITKCORE_EXPORT
#define MITKCORE_EXPORT
Definition: MitkCoreExports.h:15
mitk::DataNode::GetDataReferenceChangedTime
unsigned long GetDataReferenceChangedTime() const
Get the timestamp of the last change of the reference to the BaseData.
Definition: mitkDataNode.h:582
mitk::DataNode::SetName
virtual void SetName(const char *name)
Extra convenience access method to set the name of an object.
Definition: mitkDataNode.h:411
mitk::DataNode
Class for nodes of the DataTree.
Definition: mitkDataNode.h:63
mitk::itkEventMacroDeclaration
itkEventMacroDeclaration(BoundingShapeInteractionEvent, itk::AnyEvent)
mitk::replace
static const char * replace[]
This is a dictionary to replace long names of classes, modules, etc. to shorter versions in the conso...
Definition: mitkLogDictionary.h:20
mitk::DataNode::GetVisibility
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:448