Medical Imaging Interaction Toolkit  2023.12.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 "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 
98  vtkLinearTransform *GetVtkTransform(int t = 0) const;
99 
112  virtual void SetData(mitk::BaseData *baseData);
113 
117  virtual void SetDataInteractor(const DataInteractor::Pointer interactor);
118  virtual DataInteractor::Pointer GetDataInteractor() const;
119 
120  mitk::DataNode &operator=(const DataNode &right);
121 
122  mitk::DataNode &operator=(BaseData *right);
123  virtual void SetMapper(MapperSlotId id, mitk::Mapper *mapper);
124  void UpdateOutputInformation() override;
125 
126  void SetRequestedRegionToLargestPossibleRegion() override;
127 
128  bool RequestedRegionIsOutsideOfTheBufferedRegion() override;
129 
130  bool VerifyRequestedRegion() override;
131 
132  void SetRequestedRegion(const itk::DataObject *data) override;
133 
134  void CopyInformation(const itk::DataObject *data) override;
135 
142  PropertyListKeyNames GetPropertyListNames() const;
143 
155  void SetProperty(const char *propertyKey, BaseProperty *property, const mitk::BaseRenderer *renderer = nullptr);
156 
167  void ReplaceProperty(const char *propertyKey, BaseProperty *property, const mitk::BaseRenderer *renderer = nullptr);
168 
185  void AddProperty(const char *propertyKey,
186  BaseProperty *property,
187  const mitk::BaseRenderer *renderer = nullptr,
188  bool overwrite = false);
189 
198  mitk::PropertyList *GetPropertyList(const mitk::BaseRenderer *renderer = nullptr) const;
199  mitk::PropertyList *GetPropertyList(const std::string &rendererName) const;
200 
216  void ConcatenatePropertyList(PropertyList *pList, bool replace = false);
217 
232  mitk::BaseProperty *GetProperty(const char *propertyKey, const mitk::BaseRenderer *renderer = nullptr, bool fallBackOnDataProperties = true) const;
233 
245  template <typename T>
247  const char *propertyKey,
248  const mitk::BaseRenderer *renderer = nullptr) const
249  {
250  property = dynamic_cast<T *>(GetProperty(propertyKey, renderer));
251  return property.IsNotNull();
252  }
253 
265  template <typename T>
266  bool GetProperty(T *&property, const char *propertyKey, const mitk::BaseRenderer *renderer = nullptr) const
267  {
268  property = dynamic_cast<T *>(GetProperty(propertyKey, renderer));
269  return property != nullptr;
270  }
271 
277  template <typename T>
278  bool GetPropertyValue(const char *propertyKey, T &value, const mitk::BaseRenderer *renderer = nullptr) const
279  {
280  GenericProperty<T> *gp = dynamic_cast<GenericProperty<T> *>(GetProperty(propertyKey, renderer));
281  if (gp != nullptr)
282  {
283  value = gp->GetValue();
284  return true;
285  }
286  return false;
287  }
288 
290  GroupTagList GetGroupTags() const;
291 
297  bool GetBoolProperty(const char *propertyKey, bool &boolValue, const mitk::BaseRenderer *renderer = nullptr) const;
298 
304  bool GetIntProperty(const char *propertyKey, int &intValue, const mitk::BaseRenderer *renderer = nullptr) const;
305 
311  bool GetFloatProperty(const char *propertyKey,
312  float &floatValue,
313  const mitk::BaseRenderer *renderer = nullptr) const;
314 
324  bool GetDoubleProperty(const char *propertyKey,
325  double &doubleValue,
326  const mitk::BaseRenderer *renderer = nullptr) const;
327 
333  bool GetStringProperty(const char *propertyKey,
334  std::string &string,
335  const mitk::BaseRenderer *renderer = nullptr) const;
336 
342  bool GetColor(float rgb[3], const mitk::BaseRenderer *renderer = nullptr, const char *propertyKey = "color") const;
343 
349  bool GetLevelWindow(mitk::LevelWindow &levelWindow,
350  const mitk::BaseRenderer *renderer = nullptr,
351  const char *propertyKey = "levelwindow") const;
352 
356  void SetSelected(bool selected, const mitk::BaseRenderer *renderer = nullptr);
357 
362  bool IsSelected(const mitk::BaseRenderer *renderer = nullptr);
363 
369  bool GetName(std::string &nodeName,
370  const mitk::BaseRenderer *renderer = nullptr,
371  const char *propertyKey = "name") const
372  {
373  return GetStringProperty(propertyKey, nodeName, renderer);
374  }
375 
385  virtual std::string GetName() const
386  {
387  mitk::StringProperty *sp = dynamic_cast<mitk::StringProperty *>(this->GetProperty("name"));
388  if (sp == nullptr)
389  return "";
390  return sp->GetValue();
391  }
392 
394  static std::string NO_NAME_VALUE()
395  {
396  return "No Name!";
397  }
398 
405  virtual void SetName(const char *name)
406  {
407  if (name == nullptr)
408  return;
409 
410  auto* data = this->GetData();
411 
412  if (nullptr != data)
413  {
414  auto property = data->GetProperty("name");
415 
416  if (property.IsNotNull())
417  {
418  auto* stringProperty = dynamic_cast<StringProperty*>(property.GetPointer());
419 
420  if (nullptr != stringProperty)
421  {
422  stringProperty->SetValue(name);
423  return;
424  }
425  }
426  }
427 
428  this->SetStringProperty("name", name);
429  }
435  virtual void SetName(const std::string& name) { this->SetName(name.c_str()); }
442  bool GetVisibility(bool &visible, const mitk::BaseRenderer *renderer, const char *propertyKey = "visible") const
443  {
444  return GetBoolProperty(propertyKey, visible, renderer);
445  }
446 
452  bool GetOpacity(float &opacity, const mitk::BaseRenderer *renderer, const char *propertyKey = "opacity") const;
453 
463  bool IsOn(const char *propertyKey, const mitk::BaseRenderer *renderer, bool defaultIsOn = true) const
464  {
465  if (propertyKey == nullptr)
466  return defaultIsOn;
467  GetBoolProperty(propertyKey, defaultIsOn, renderer);
468  return defaultIsOn;
469  }
470 
482  bool IsVisible(const mitk::BaseRenderer *renderer,
483  const char *propertyKey = "visible",
484  bool defaultIsOn = true) const
485  {
486  return IsOn(propertyKey, renderer, defaultIsOn);
487  }
488 
493  void SetColor(const mitk::Color &color,
494  const mitk::BaseRenderer *renderer = nullptr,
495  const char *propertyKey = "color");
496 
501  void SetColor(float red,
502  float green,
503  float blue,
504  const mitk::BaseRenderer *renderer = nullptr,
505  const char *propertyKey = "color");
506 
511  void SetColor(const float rgb[3], const mitk::BaseRenderer *renderer = nullptr, const char *propertyKey = "color");
512 
520  void SetVisibility(bool visible, const mitk::BaseRenderer *renderer = nullptr, const char *propertyKey = "visible");
521 
526  void SetOpacity(float opacity, const mitk::BaseRenderer *renderer = nullptr, const char *propertyKey = "opacity");
527 
532  void SetLevelWindow(mitk::LevelWindow levelWindow,
533  const mitk::BaseRenderer *renderer = nullptr,
534  const char *propertyKey = "levelwindow");
535 
540  void SetIntProperty(const char *propertyKey, int intValue, const mitk::BaseRenderer *renderer = nullptr);
541 
546  void SetBoolProperty(const char *propertyKey, bool boolValue, const mitk::BaseRenderer *renderer = nullptr);
547 
552  void SetFloatProperty(const char *propertyKey, float floatValue, const mitk::BaseRenderer *renderer = nullptr);
553 
558  void SetDoubleProperty(const char *propertyKey, double doubleValue, const mitk::BaseRenderer *renderer = nullptr);
559 
564  void SetStringProperty(const char *propertyKey, const char *string, const mitk::BaseRenderer *renderer = nullptr);
565 
570  itk::ModifiedTimeType GetMTime() const override;
571 
576  unsigned long GetDataReferenceChangedTime() const { return m_DataReferenceChangedTime.GetMTime(); }
577 
578  protected:
579  DataNode();
580 
581  ~DataNode() override;
582 
584  virtual void PropertyListModified(const itk::Object *caller, const itk::EventObject &event);
585 
588 
594 
602 
605 
607 
610 
612  };
613 
614  MITKCORE_EXPORT std::istream &operator>>(std::istream &i, DataNode::Pointer &dtn);
615  MITKCORE_EXPORT std::ostream &operator<<(std::ostream &o, DataNode::Pointer &dtn);
616 } // namespace mitk
617 
618 #endif
mitk::DataNode::m_PropertyListModifiedObserverTag
unsigned long m_PropertyListModifiedObserverTag
Definition: mitkDataNode.h:611
mitk::DataNode::m_DataInteractor
DataInteractor::Pointer m_DataInteractor
Definition: mitkDataNode.h:606
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:463
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:369
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:435
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:609
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:246
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:266
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:385
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::DataNode::Geometry3DPointer
mitk::Geometry3D::Pointer Geometry3DPointer
Definition: mitkDataNode.h:66
mitk::DataNode::NO_NAME_VALUE
static std::string NO_NAME_VALUE()
Definition: mitkDataNode.h:394
mitk::DataNode::m_Mappers
MapperVector m_Mappers
Mapper-slots.
Definition: mitkDataNode.h:587
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:593
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:601
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:482
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:278
mitk::DataNode::m_MapOfPropertyLists
MapOfPropertyLists m_MapOfPropertyLists
Map associating each BaseRenderer with its own PropertyList.
Definition: mitkDataNode.h:604
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:576
mitk::DataNode::SetName
virtual void SetName(const char *name)
Extra convenience access method to set the name of an object.
Definition: mitkDataNode.h:405
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:442