Medical Imaging Interaction Toolkit  2016.11.0
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,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #ifndef DATATREENODE_H_HEADER_INCLUDED_C1E14338
18 #define DATATREENODE_H_HEADER_INCLUDED_C1E14338
19 
20 #include "mitkBaseData.h"
21 //#include "mitkMapper.h"
22 #include "mitkDataInteractor.h"
23 
24 #ifdef MBI_NO_STD_NAMESPACE
25 #define MBI_STD
26 #include <fstream.h>
27 #include <iostream.h>
28 #else
29 #define MBI_STD std
30 #include <fstream>
31 #include <iostream>
32 #endif
33 
34 #include "mitkColorProperty.h"
35 #include "mitkPropertyList.h"
36 #include "mitkStringProperty.h"
37 //#include "mitkMapper.h"
38 
39 #include "mitkGeometry3D.h"
40 #include "mitkLevelWindow.h"
41 #include <map>
42 #include <set>
43 
44 class vtkLinearTransform;
45 
46 namespace mitk
47 {
48  class BaseRenderer;
49  class Mapper;
50 
66  class MITKCORE_EXPORT DataNode : public itk::DataObject
67  {
68  public:
70  typedef std::vector<itk::SmartPointer<Mapper>> MapperVector;
71  typedef std::map<std::string, mitk::PropertyList::Pointer> MapOfPropertyLists;
72  typedef std::vector<MapOfPropertyLists::key_type> PropertyListKeyNames;
73  typedef std::set<std::string> GroupTagList;
74 
79  itkEventMacro(InteractorChangedEvent, itk::AnyEvent);
80 
81  mitkClassMacroItkParent(DataNode, itk::DataObject);
82 
83  itkFactorylessNewMacro(Self) itkCloneMacro(Self)
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  virtual void UpdateOutputInformation() override;
125 
126  virtual void SetRequestedRegionToLargestPossibleRegion() override;
127 
128  virtual bool RequestedRegionIsOutsideOfTheBufferedRegion() override;
129 
130  virtual bool VerifyRequestedRegion() override;
131 
132  virtual void SetRequestedRegion(const itk::DataObject *data) override;
133 
134  virtual 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 
229  mitk::BaseProperty *GetProperty(const char *propertyKey, const mitk::BaseRenderer *renderer = nullptr) const;
230 
242  template <typename T>
243  bool GetProperty(itk::SmartPointer<T> &property,
244  const char *propertyKey,
245  const mitk::BaseRenderer *renderer = nullptr) const
246  {
247  property = dynamic_cast<T *>(GetProperty(propertyKey, renderer));
248  return property.IsNotNull();
249  }
250 
262  template <typename T>
263  bool GetProperty(T *&property, const char *propertyKey, const mitk::BaseRenderer *renderer = nullptr) const
264  {
265  property = dynamic_cast<T *>(GetProperty(propertyKey, renderer));
266  return property != nullptr;
267  }
268 
274  template <typename T>
275  bool GetPropertyValue(const char *propertyKey, T &value, const mitk::BaseRenderer *renderer = nullptr) const
276  {
277  GenericProperty<T> *gp = dynamic_cast<GenericProperty<T> *>(GetProperty(propertyKey, renderer));
278  if (gp != NULL)
279  {
280  value = gp->GetValue();
281  return true;
282  }
283  return false;
284  }
285 
287  GroupTagList GetGroupTags() const;
288 
294  bool GetBoolProperty(const char *propertyKey, bool &boolValue, const mitk::BaseRenderer *renderer = nullptr) const;
295 
301  bool GetIntProperty(const char *propertyKey, int &intValue, const mitk::BaseRenderer *renderer = nullptr) const;
302 
308  bool GetFloatProperty(const char *propertyKey,
309  float &floatValue,
310  const mitk::BaseRenderer *renderer = nullptr) const;
311 
321  bool GetDoubleProperty(const char *propertyKey,
322  double &doubleValue,
323  const mitk::BaseRenderer *renderer = nullptr) const;
324 
330  bool GetStringProperty(const char *propertyKey,
331  std::string &string,
332  const mitk::BaseRenderer *renderer = nullptr) const;
333 
339  bool GetColor(float rgb[3], const mitk::BaseRenderer *renderer = nullptr, const char *propertyKey = "color") const;
340 
346  bool GetLevelWindow(mitk::LevelWindow &levelWindow,
347  const mitk::BaseRenderer *renderer = nullptr,
348  const char *propertyKey = "levelwindow") const;
349 
353  void SetSelected(bool selected, const mitk::BaseRenderer *renderer = nullptr);
354 
359  bool IsSelected(const mitk::BaseRenderer *renderer = nullptr);
360 
366  bool GetName(std::string &nodeName,
367  const mitk::BaseRenderer *renderer = nullptr,
368  const char *propertyKey = "name") const
369  {
370  return GetStringProperty(propertyKey, nodeName, renderer);
371  }
372 
382  virtual std::string GetName() const
383  {
384  mitk::StringProperty *sp = dynamic_cast<mitk::StringProperty *>(this->GetProperty("name"));
385  if (sp == nullptr)
386  return "";
387  return sp->GetValue();
388  }
389 
395  virtual void SetName(const char *name)
396  {
397  if (name == nullptr)
398  return;
399  this->SetProperty("name", StringProperty::New(name));
400  }
406  virtual void SetName(const std::string name) { this->SetName(name.c_str()); }
413  bool GetVisibility(bool &visible, const mitk::BaseRenderer *renderer, const char *propertyKey = "visible") const
414  {
415  return GetBoolProperty(propertyKey, visible, renderer);
416  }
417 
423  bool GetOpacity(float &opacity, const mitk::BaseRenderer *renderer, const char *propertyKey = "opacity") const;
424 
434  bool IsOn(const char *propertyKey, const mitk::BaseRenderer *renderer, bool defaultIsOn = true) const
435  {
436  if (propertyKey == nullptr)
437  return defaultIsOn;
438  GetBoolProperty(propertyKey, defaultIsOn, renderer);
439  return defaultIsOn;
440  }
441 
453  bool IsVisible(const mitk::BaseRenderer *renderer,
454  const char *propertyKey = "visible",
455  bool defaultIsOn = true) const
456  {
457  return IsOn(propertyKey, renderer, defaultIsOn);
458  }
459 
464  void SetColor(const mitk::Color &color,
465  const mitk::BaseRenderer *renderer = nullptr,
466  const char *propertyKey = "color");
467 
472  void SetColor(float red,
473  float green,
474  float blue,
475  const mitk::BaseRenderer *renderer = nullptr,
476  const char *propertyKey = "color");
477 
482  void SetColor(const float rgb[3], const mitk::BaseRenderer *renderer = nullptr, const char *propertyKey = "color");
483 
491  void SetVisibility(bool visible, const mitk::BaseRenderer *renderer = nullptr, const char *propertyKey = "visible");
492 
497  void SetOpacity(float opacity, const mitk::BaseRenderer *renderer = nullptr, const char *propertyKey = "opacity");
498 
503  void SetLevelWindow(mitk::LevelWindow levelWindow,
504  const mitk::BaseRenderer *renderer = nullptr,
505  const char *propertyKey = "levelwindow");
506 
511  void SetIntProperty(const char *propertyKey, int intValue, const mitk::BaseRenderer *renderer = nullptr);
512 
517  void SetBoolProperty(const char *propertyKey, bool boolValue, const mitk::BaseRenderer *renderer = nullptr);
518 
523  void SetFloatProperty(const char *propertyKey, float floatValue, const mitk::BaseRenderer *renderer = nullptr);
524 
529  void SetDoubleProperty(const char *propertyKey, double doubleValue, const mitk::BaseRenderer *renderer = nullptr);
530 
535  void SetStringProperty(const char *propertyKey, const char *string, const mitk::BaseRenderer *renderer = nullptr);
536 
541  virtual unsigned long GetMTime() const override;
542 
547  unsigned long GetDataReferenceChangedTime() const { return m_DataReferenceChangedTime.GetMTime(); }
548  protected:
549  DataNode();
550 
551  virtual ~DataNode();
552 
554  virtual void PropertyListModified(const itk::Object *caller, const itk::EventObject &event);
555 
557  mutable MapperVector m_Mappers;
558 
564 
572 
574  mutable MapOfPropertyLists m_MapOfPropertyLists;
575 
577 
580 
582  };
583 
584 #if (_MSC_VER > 1200) || !defined(_MSC_VER)
585  MITKCORE_EXPORT MBI_STD::istream &operator>>(MBI_STD::istream &i, DataNode::Pointer &dtn);
586 
587  MITKCORE_EXPORT MBI_STD::ostream &operator<<(MBI_STD::ostream &o, DataNode::Pointer &dtn);
588 #endif
589 } // namespace mitk
590 
591 #if ((defined(_MSC_VER)) && (_MSC_VER <= 1200))
592 MITKCORE_EXPORT MBI_STD::istream &operator>>(MBI_STD::istream &i, mitk::DataNode::Pointer &dtn);
593 
594 MITKCORE_EXPORT MBI_STD::ostream &operator<<(MBI_STD::ostream &o, mitk::DataNode::Pointer &dtn);
595 #endif
596 
597 #endif /* DATATREENODE_H_HEADER_INCLUDED_C1E14338 */
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:263
virtual void SetName(const std::string name)
Extra convenience access method to set the name of an object.
Definition: mitkDataNode.h:406
mitk::Geometry3D::Pointer Geometry3DPointer
Definition: mitkDataNode.h:69
MapperVector m_Mappers
Mapper-slots.
Definition: mitkDataNode.h:557
#define MITKCORE_EXPORT
std::set< std::string > GroupTagList
Definition: mitkDataNode.h:73
MITKCORE_EXPORT std::ostream & operator<<(std::ostream &o, DataNode::Pointer &dtn)
std::vector< MapOfPropertyLists::key_type > PropertyListKeyNames
Definition: mitkDataNode.h:72
signed integer value
Definition: jsoncpp.h:348
Base of all data objects.
Definition: mitkBaseData.h:39
itk::TimeStamp m_DataReferenceChangedTime
Timestamp of the last change of m_Data.
Definition: mitkDataNode.h:579
PropertyList::Pointer m_PropertyList
BaseRenderer-independent PropertyList.
Definition: mitkDataNode.h:571
Organizes the rendering process.
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:366
STL namespace.
DataCollection - Class to facilitate loading/accessing structured data.
MapOfPropertyLists m_MapOfPropertyLists
Map associating each BaseRenderer with its own PropertyList.
Definition: mitkDataNode.h:574
Key-value list holding instances of BaseProperty.
Base class of all mappers, Vtk as well as OpenGL mappers.
Definition: mitkMapper.h:54
BaseData::Pointer m_Data
The data object (instance of BaseData, e.g., an Image) managed by this DataNode.
Definition: mitkDataNode.h:563
virtual const char * GetValue() const
MITKCORE_EXPORT std::istream & operator>>(std::istream &i, DataNode::Pointer &dtn)
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:453
virtual std::string GetName() const
Extra convenience access method for accessing the name of an object (instance of StringProperty with ...
Definition: mitkDataNode.h:382
T::Pointer GetData(const std::string &name)
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.
unsigned long m_PropertyListModifiedObserverTag
Definition: mitkDataNode.h:581
#define mitkClassMacroItkParent(className, SuperClassName)
Definition: mitkCommon.h:53
virtual void SetName(const char *name)
Extra convenience access method to set the name of an object.
Definition: mitkDataNode.h:395
bool GetPropertyValue(const char *propertyKey, T &value, const mitk::BaseRenderer *renderer=nullptr) const
Convenience access method for GenericProperty properties (T being the type of the second parameter...
Definition: mitkDataNode.h:275
itk::RGBPixel< float > Color
Color Standard RGB color typedef (float)
itkEventMacro(ContourModelEvent, itk::AnyEvent)
std::map< std::string, mitk::PropertyList::Pointer > MapOfPropertyLists
Definition: mitkDataNode.h:71
DataInteractor::Pointer m_DataInteractor
Definition: mitkDataNode.h:576
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:434
unsigned long GetDataReferenceChangedTime() const
Get the timestamp of the last change of the reference to the BaseData.
Definition: mitkDataNode.h:547
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:70
Property for strings.
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:413
unsigned int MapperSlotId
Definition: mitkCommon.h:37
static Pointer New()
Class for nodes of the DataTree.
Definition: mitkDataNode.h:66
virtual T GetValue() const