Medical Imaging Interaction Toolkit  2018.4.99-c0f884b2
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  itkCloneMacro(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>
246  bool GetProperty(itk::SmartPointer<T> &property,
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 
404  virtual void SetName(const char *name)
405  {
406  if (name == nullptr)
407  return;
408  this->SetProperty("name", StringProperty::New(name));
409  }
415  virtual void SetName(const std::string name) { this->SetName(name.c_str()); }
422  bool GetVisibility(bool &visible, const mitk::BaseRenderer *renderer, const char *propertyKey = "visible") const
423  {
424  return GetBoolProperty(propertyKey, visible, renderer);
425  }
426 
432  bool GetOpacity(float &opacity, const mitk::BaseRenderer *renderer, const char *propertyKey = "opacity") const;
433 
443  bool IsOn(const char *propertyKey, const mitk::BaseRenderer *renderer, bool defaultIsOn = true) const
444  {
445  if (propertyKey == nullptr)
446  return defaultIsOn;
447  GetBoolProperty(propertyKey, defaultIsOn, renderer);
448  return defaultIsOn;
449  }
450 
462  bool IsVisible(const mitk::BaseRenderer *renderer,
463  const char *propertyKey = "visible",
464  bool defaultIsOn = true) const
465  {
466  return IsOn(propertyKey, renderer, defaultIsOn);
467  }
468 
473  void SetColor(const mitk::Color &color,
474  const mitk::BaseRenderer *renderer = nullptr,
475  const char *propertyKey = "color");
476 
481  void SetColor(float red,
482  float green,
483  float blue,
484  const mitk::BaseRenderer *renderer = nullptr,
485  const char *propertyKey = "color");
486 
491  void SetColor(const float rgb[3], const mitk::BaseRenderer *renderer = nullptr, const char *propertyKey = "color");
492 
500  void SetVisibility(bool visible, const mitk::BaseRenderer *renderer = nullptr, const char *propertyKey = "visible");
501 
506  void SetOpacity(float opacity, const mitk::BaseRenderer *renderer = nullptr, const char *propertyKey = "opacity");
507 
512  void SetLevelWindow(mitk::LevelWindow levelWindow,
513  const mitk::BaseRenderer *renderer = nullptr,
514  const char *propertyKey = "levelwindow");
515 
520  void SetIntProperty(const char *propertyKey, int intValue, const mitk::BaseRenderer *renderer = nullptr);
521 
526  void SetBoolProperty(const char *propertyKey, bool boolValue, const mitk::BaseRenderer *renderer = nullptr);
527 
532  void SetFloatProperty(const char *propertyKey, float floatValue, const mitk::BaseRenderer *renderer = nullptr);
533 
538  void SetDoubleProperty(const char *propertyKey, double doubleValue, const mitk::BaseRenderer *renderer = nullptr);
539 
544  void SetStringProperty(const char *propertyKey, const char *string, const mitk::BaseRenderer *renderer = nullptr);
545 
550  unsigned long GetMTime() const override;
551 
556  unsigned long GetDataReferenceChangedTime() const { return m_DataReferenceChangedTime.GetMTime(); }
557 
558  protected:
559  DataNode();
560 
561  ~DataNode() override;
562 
564  virtual void PropertyListModified(const itk::Object *caller, const itk::EventObject &event);
565 
567  mutable MapperVector m_Mappers;
568 
574 
582 
584  mutable MapOfPropertyLists m_MapOfPropertyLists;
585 
587 
590 
592  };
593 
594  MITKCORE_EXPORT std::istream &operator>>(std::istream &i, DataNode::Pointer &dtn);
595  MITKCORE_EXPORT std::ostream &operator<<(std::ostream &o, DataNode::Pointer &dtn);
596 } // namespace mitk
597 
598 #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:385
virtual void SetName(const std::string name)
Extra convenience access method to set the name of an object.
Definition: mitkDataNode.h:415
mitk::Geometry3D::Pointer Geometry3DPointer
Definition: mitkDataNode.h:60
MapperVector m_Mappers
Mapper-slots.
Definition: mitkDataNode.h:567
#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:37
itk::TimeStamp m_DataReferenceChangedTime
Timestamp of the last change of m_Data.
Definition: mitkDataNode.h:589
PropertyList::Pointer m_PropertyList
BaseRenderer-independent PropertyList.
Definition: mitkDataNode.h:581
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:584
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
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:266
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:573
static std::string NO_NAME_VALUE()
Definition: mitkDataNode.h:394
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:462
MITKCORE_EXPORT std::istream & operator>>(std::istream &i, DataNode::Pointer &dtn)
unsigned long m_PropertyListModifiedObserverTag
Definition: mitkDataNode.h:591
unsigned long GetDataReferenceChangedTime() const
Get the timestamp of the last change of the reference to the BaseData.
Definition: mitkDataNode.h:556
#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:404
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:422
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:443
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:586
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:369