Medical Imaging Interaction Toolkit  2018.4.99-b20efe7f
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 DATATREENODE_H_HEADER_INCLUDED_C1E14338
14 #define DATATREENODE_H_HEADER_INCLUDED_C1E14338
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 
57  class MITKCORE_EXPORT DataNode : public itk::DataObject, public IPropertyOwner
58  {
59  public:
61  typedef std::vector<itk::SmartPointer<Mapper>> MapperVector;
62  typedef std::map<std::string, mitk::PropertyList::Pointer> MapOfPropertyLists;
63  typedef std::vector<MapOfPropertyLists::key_type> PropertyListKeyNames;
64  typedef std::set<std::string> GroupTagList;
65 
70  itkEventMacro(InteractorChangedEvent, itk::AnyEvent)
72  itkFactorylessNewMacro(Self);
73 
74  // IPropertyProvider
75  BaseProperty::ConstPointer GetConstProperty(const std::string &propertyKey, const std::string &contextName = "", bool fallBackOnDefaultContext = true) const override;
76  std::vector<std::string> GetPropertyKeys(const std::string &contextName = "", bool includeDefaultContext = false) const override;
77  std::vector<std::string> GetPropertyContextNames() const override;
78 
79  // IPropertyOwner
80  BaseProperty * GetNonConstProperty(const std::string &propertyKey, const std::string &contextName = "", bool fallBackOnDefaultContext = true) override;
81  void SetProperty(const std::string &propertyKey, BaseProperty *property, const std::string &contextName = "", bool fallBackOnDefaultContext = false) override;
82  void RemoveProperty(const std::string &propertyKey, const std::string &contextName = "", bool fallBackOnDefaultContext = false) override;
83 
84  mitk::Mapper *GetMapper(MapperSlotId id) const;
85 
90  BaseData *GetData() const;
91 
97  vtkLinearTransform *GetVtkTransform(int t = 0) const;
98 
111  virtual void SetData(mitk::BaseData *baseData);
112 
116  virtual void SetDataInteractor(const DataInteractor::Pointer interactor);
117  virtual DataInteractor::Pointer GetDataInteractor() const;
118 
119  mitk::DataNode &operator=(const DataNode &right);
120 
121  mitk::DataNode &operator=(BaseData *right);
122  virtual void SetMapper(MapperSlotId id, mitk::Mapper *mapper);
123  void UpdateOutputInformation() override;
124 
125  void SetRequestedRegionToLargestPossibleRegion() override;
126 
127  bool RequestedRegionIsOutsideOfTheBufferedRegion() override;
128 
129  bool VerifyRequestedRegion() override;
130 
131  void SetRequestedRegion(const itk::DataObject *data) override;
132 
133  void CopyInformation(const itk::DataObject *data) override;
134 
141  PropertyListKeyNames GetPropertyListNames() const;
142 
154  void SetProperty(const char *propertyKey, BaseProperty *property, const mitk::BaseRenderer *renderer = nullptr);
155 
166  void ReplaceProperty(const char *propertyKey, BaseProperty *property, const mitk::BaseRenderer *renderer = nullptr);
167 
184  void AddProperty(const char *propertyKey,
185  BaseProperty *property,
186  const mitk::BaseRenderer *renderer = nullptr,
187  bool overwrite = false);
188 
197  mitk::PropertyList *GetPropertyList(const mitk::BaseRenderer *renderer = nullptr) const;
198  mitk::PropertyList *GetPropertyList(const std::string &rendererName) const;
199 
215  void ConcatenatePropertyList(PropertyList *pList, bool replace = false);
216 
231  mitk::BaseProperty *GetProperty(const char *propertyKey, const mitk::BaseRenderer *renderer = nullptr, bool fallBackOnDataProperties = true) const;
232 
244  template <typename T>
245  bool GetProperty(itk::SmartPointer<T> &property,
246  const char *propertyKey,
247  const mitk::BaseRenderer *renderer = nullptr) const
248  {
249  property = dynamic_cast<T *>(GetProperty(propertyKey, renderer));
250  return property.IsNotNull();
251  }
252 
264  template <typename T>
265  bool GetProperty(T *&property, const char *propertyKey, const mitk::BaseRenderer *renderer = nullptr) const
266  {
267  property = dynamic_cast<T *>(GetProperty(propertyKey, renderer));
268  return property != nullptr;
269  }
270 
276  template <typename T>
277  bool GetPropertyValue(const char *propertyKey, T &value, const mitk::BaseRenderer *renderer = nullptr) const
278  {
279  GenericProperty<T> *gp = dynamic_cast<GenericProperty<T> *>(GetProperty(propertyKey, renderer));
280  if (gp != nullptr)
281  {
282  value = gp->GetValue();
283  return true;
284  }
285  return false;
286  }
287 
289  GroupTagList GetGroupTags() const;
290 
296  bool GetBoolProperty(const char *propertyKey, bool &boolValue, const mitk::BaseRenderer *renderer = nullptr) const;
297 
303  bool GetIntProperty(const char *propertyKey, int &intValue, const mitk::BaseRenderer *renderer = nullptr) const;
304 
310  bool GetFloatProperty(const char *propertyKey,
311  float &floatValue,
312  const mitk::BaseRenderer *renderer = nullptr) const;
313 
323  bool GetDoubleProperty(const char *propertyKey,
324  double &doubleValue,
325  const mitk::BaseRenderer *renderer = nullptr) const;
326 
332  bool GetStringProperty(const char *propertyKey,
333  std::string &string,
334  const mitk::BaseRenderer *renderer = nullptr) const;
335 
341  bool GetColor(float rgb[3], const mitk::BaseRenderer *renderer = nullptr, const char *propertyKey = "color") const;
342 
348  bool GetLevelWindow(mitk::LevelWindow &levelWindow,
349  const mitk::BaseRenderer *renderer = nullptr,
350  const char *propertyKey = "levelwindow") const;
351 
355  void SetSelected(bool selected, const mitk::BaseRenderer *renderer = nullptr);
356 
361  bool IsSelected(const mitk::BaseRenderer *renderer = nullptr);
362 
368  bool GetName(std::string &nodeName,
369  const mitk::BaseRenderer *renderer = nullptr,
370  const char *propertyKey = "name") const
371  {
372  return GetStringProperty(propertyKey, nodeName, renderer);
373  }
374 
384  virtual std::string GetName() const
385  {
386  mitk::StringProperty *sp = dynamic_cast<mitk::StringProperty *>(this->GetProperty("name"));
387  if (sp == nullptr)
388  return "";
389  return sp->GetValue();
390  }
391 
393  static std::string NO_NAME_VALUE()
394  {
395  return "No Name!";
396  }
397 
403  virtual void SetName(const char *name)
404  {
405  if (name == nullptr)
406  return;
407  this->SetProperty("name", StringProperty::New(name));
408  }
414  virtual void SetName(const std::string name) { this->SetName(name.c_str()); }
421  bool GetVisibility(bool &visible, const mitk::BaseRenderer *renderer, const char *propertyKey = "visible") const
422  {
423  return GetBoolProperty(propertyKey, visible, renderer);
424  }
425 
431  bool GetOpacity(float &opacity, const mitk::BaseRenderer *renderer, const char *propertyKey = "opacity") const;
432 
442  bool IsOn(const char *propertyKey, const mitk::BaseRenderer *renderer, bool defaultIsOn = true) const
443  {
444  if (propertyKey == nullptr)
445  return defaultIsOn;
446  GetBoolProperty(propertyKey, defaultIsOn, renderer);
447  return defaultIsOn;
448  }
449 
461  bool IsVisible(const mitk::BaseRenderer *renderer,
462  const char *propertyKey = "visible",
463  bool defaultIsOn = true) const
464  {
465  return IsOn(propertyKey, renderer, defaultIsOn);
466  }
467 
472  void SetColor(const mitk::Color &color,
473  const mitk::BaseRenderer *renderer = nullptr,
474  const char *propertyKey = "color");
475 
480  void SetColor(float red,
481  float green,
482  float blue,
483  const mitk::BaseRenderer *renderer = nullptr,
484  const char *propertyKey = "color");
485 
490  void SetColor(const float rgb[3], const mitk::BaseRenderer *renderer = nullptr, const char *propertyKey = "color");
491 
499  void SetVisibility(bool visible, const mitk::BaseRenderer *renderer = nullptr, const char *propertyKey = "visible");
500 
505  void SetOpacity(float opacity, const mitk::BaseRenderer *renderer = nullptr, const char *propertyKey = "opacity");
506 
511  void SetLevelWindow(mitk::LevelWindow levelWindow,
512  const mitk::BaseRenderer *renderer = nullptr,
513  const char *propertyKey = "levelwindow");
514 
519  void SetIntProperty(const char *propertyKey, int intValue, const mitk::BaseRenderer *renderer = nullptr);
520 
525  void SetBoolProperty(const char *propertyKey, bool boolValue, const mitk::BaseRenderer *renderer = nullptr);
526 
531  void SetFloatProperty(const char *propertyKey, float floatValue, const mitk::BaseRenderer *renderer = nullptr);
532 
537  void SetDoubleProperty(const char *propertyKey, double doubleValue, const mitk::BaseRenderer *renderer = nullptr);
538 
543  void SetStringProperty(const char *propertyKey, const char *string, const mitk::BaseRenderer *renderer = nullptr);
544 
549  unsigned long GetMTime() const override;
550 
555  unsigned long GetDataReferenceChangedTime() const { return m_DataReferenceChangedTime.GetMTime(); }
556 
557  protected:
558  DataNode();
559 
560  ~DataNode() override;
561 
563  virtual void PropertyListModified(const itk::Object *caller, const itk::EventObject &event);
564 
566  mutable MapperVector m_Mappers;
567 
573 
581 
583  mutable MapOfPropertyLists m_MapOfPropertyLists;
584 
586 
589 
591  };
592 
593  MITKCORE_EXPORT std::istream &operator>>(std::istream &i, DataNode::Pointer &dtn);
594  MITKCORE_EXPORT std::ostream &operator<<(std::ostream &o, DataNode::Pointer &dtn);
595 } // namespace mitk
596 
597 #endif /* DATATREENODE_H_HEADER_INCLUDED_C1E14338 */
virtual std::string GetName() const
Extra convenience access method for accessing the name of an object (instance of StringProperty with ...
Definition: mitkDataNode.h:384
virtual void SetName(const std::string name)
Extra convenience access method to set the name of an object.
Definition: mitkDataNode.h:414
mitk::Geometry3D::Pointer Geometry3DPointer
Definition: mitkDataNode.h:60
MapperVector m_Mappers
Mapper-slots.
Definition: mitkDataNode.h:566
#define MITKCORE_EXPORT
std::set< std::string > GroupTagList
Definition: mitkDataNode.h:64
itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent)
virtual const char * GetValue() const
std::vector< MapOfPropertyLists::key_type > PropertyListKeyNames
Definition: mitkDataNode.h:63
signed integer value
Definition: jsoncpp.h:348
Base of all data objects.
Definition: mitkBaseData.h:42
itk::TimeStamp m_DataReferenceChangedTime
Timestamp of the last change of m_Data.
Definition: mitkDataNode.h:588
PropertyList::Pointer m_PropertyList
BaseRenderer-independent PropertyList.
Definition: mitkDataNode.h:580
Organizes the rendering process.
STL namespace.
DataCollection - Class to facilitate loading/accessing structured data.
MapOfPropertyLists m_MapOfPropertyLists
Map associating each BaseRenderer with its own PropertyList.
Definition: mitkDataNode.h:583
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:277
Key-value list holding instances of BaseProperty.
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, if available there, otherwise use the BaseRenderer-independent PropertyList.
Definition: mitkDataNode.h:265
Base class of all mappers, Vtk as well as OpenGL mappers.
Definition: mitkMapper.h:49
BaseData::Pointer m_Data
The data object (instance of BaseData, e.g., an Image) managed by this DataNode.
Definition: mitkDataNode.h:572
static std::string NO_NAME_VALUE()
Definition: mitkDataNode.h:393
virtual T GetValue() const
The LevelWindow class Class to store level/window values.
Base class from with interactors that handle DataNodes are to be derived.
Abstract base class for properties.
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:461
MITKCORE_EXPORT std::istream & operator>>(std::istream &i, DataNode::Pointer &dtn)
unsigned long m_PropertyListModifiedObserverTag
Definition: mitkDataNode.h:590
unsigned long GetDataReferenceChangedTime() const
Get the timestamp of the last change of the reference to the BaseData.
Definition: mitkDataNode.h:555
#define mitkClassMacroItkParent(className, SuperClassName)
Definition: mitkCommon.h:49
virtual void SetName(const char *name)
Extra convenience access method to set the name of an object.
Definition: mitkDataNode.h:403
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:421
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:442
itk::RGBPixel< float > Color
Color Standard RGB color typedef (float)
std::map< std::string, mitk::PropertyList::Pointer > MapOfPropertyLists
Definition: mitkDataNode.h:62
DataInteractor::Pointer m_DataInteractor
Definition: mitkDataNode.h:585
static const char * replace[]
This is a dictionary to replace long names of classes, modules, etc. to shorter versions in the conso...
std::vector< itk::SmartPointer< Mapper > > MapperVector
Definition: mitkDataNode.h:61
Property for strings.
unsigned int MapperSlotId
Definition: mitkCommon.h:33
static Pointer New()
MITKCORE_EXPORT std::ostream & operator<<(std::ostream &o, DataNode::Pointer &dtn)
Class for nodes of the DataTree.
Definition: mitkDataNode.h:57
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:368