Medical Imaging Interaction Toolkit  2018.4.99-12ad79a3
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 #ifdef MBI_NO_STD_NAMESPACE
23 #define MBI_STD
24 #include <fstream.h>
25 #include <iostream.h>
26 #else
27 #define MBI_STD std
28 #include <fstream>
29 #include <iostream>
30 #endif
31 
32 #include "mitkColorProperty.h"
33 #include "mitkPropertyList.h"
34 #include "mitkStringProperty.h"
35 //#include "mitkMapper.h"
36 
37 #include "mitkGeometry3D.h"
38 #include "mitkLevelWindow.h"
39 #include <map>
40 #include <set>
41 
42 class vtkLinearTransform;
43 
44 namespace mitk
45 {
46  class BaseRenderer;
47  class Mapper;
48 
64  class MITKCORE_EXPORT DataNode : public itk::DataObject, public IPropertyOwner
65  {
66  public:
68  typedef std::vector<itk::SmartPointer<Mapper>> MapperVector;
69  typedef std::map<std::string, mitk::PropertyList::Pointer> MapOfPropertyLists;
70  typedef std::vector<MapOfPropertyLists::key_type> PropertyListKeyNames;
71  typedef std::set<std::string> GroupTagList;
72 
77  itkEventMacro(InteractorChangedEvent, itk::AnyEvent)
79  itkFactorylessNewMacro(Self)
80  itkCloneMacro(Self)
81 
82  // IPropertyProvider
83  BaseProperty::ConstPointer GetConstProperty(const std::string &propertyKey, const std::string &contextName = "", bool fallBackOnDefaultContext = true) const override;
84  std::vector<std::string> GetPropertyKeys(const std::string &contextName = "", bool includeDefaultContext = false) const override;
85  std::vector<std::string> GetPropertyContextNames() const override;
86 
87  // IPropertyOwner
88  BaseProperty * GetNonConstProperty(const std::string &propertyKey, const std::string &contextName = "", bool fallBackOnDefaultContext = true) override;
89  void SetProperty(const std::string &propertyKey, BaseProperty *property, const std::string &contextName = "", bool fallBackOnDefaultContext = false) override;
90  void RemoveProperty(const std::string &propertyKey, const std::string &contextName = "", bool fallBackOnDefaultContext = false) override;
91 
92  mitk::Mapper *GetMapper(MapperSlotId id) const;
93 
98  BaseData *GetData() const;
99 
105  vtkLinearTransform *GetVtkTransform(int t = 0) const;
106 
119  virtual void SetData(mitk::BaseData *baseData);
120 
124  virtual void SetDataInteractor(const DataInteractor::Pointer interactor);
125  virtual DataInteractor::Pointer GetDataInteractor() const;
126 
127  mitk::DataNode &operator=(const DataNode &right);
128 
129  mitk::DataNode &operator=(BaseData *right);
130  virtual void SetMapper(MapperSlotId id, mitk::Mapper *mapper);
131  void UpdateOutputInformation() override;
132 
133  void SetRequestedRegionToLargestPossibleRegion() override;
134 
135  bool RequestedRegionIsOutsideOfTheBufferedRegion() override;
136 
137  bool VerifyRequestedRegion() override;
138 
139  void SetRequestedRegion(const itk::DataObject *data) override;
140 
141  void CopyInformation(const itk::DataObject *data) override;
142 
149  PropertyListKeyNames GetPropertyListNames() const;
150 
162  void SetProperty(const char *propertyKey, BaseProperty *property, const mitk::BaseRenderer *renderer = nullptr);
163 
174  void ReplaceProperty(const char *propertyKey, BaseProperty *property, const mitk::BaseRenderer *renderer = nullptr);
175 
192  void AddProperty(const char *propertyKey,
193  BaseProperty *property,
194  const mitk::BaseRenderer *renderer = nullptr,
195  bool overwrite = false);
196 
205  mitk::PropertyList *GetPropertyList(const mitk::BaseRenderer *renderer = nullptr) const;
206  mitk::PropertyList *GetPropertyList(const std::string &rendererName) const;
207 
223  void ConcatenatePropertyList(PropertyList *pList, bool replace = false);
224 
239  mitk::BaseProperty *GetProperty(const char *propertyKey, const mitk::BaseRenderer *renderer = nullptr, bool fallBackOnDataProperties = true) const;
240 
252  template <typename T>
253  bool GetProperty(itk::SmartPointer<T> &property,
254  const char *propertyKey,
255  const mitk::BaseRenderer *renderer = nullptr) const
256  {
257  property = dynamic_cast<T *>(GetProperty(propertyKey, renderer));
258  return property.IsNotNull();
259  }
260 
272  template <typename T>
273  bool GetProperty(T *&property, const char *propertyKey, const mitk::BaseRenderer *renderer = nullptr) const
274  {
275  property = dynamic_cast<T *>(GetProperty(propertyKey, renderer));
276  return property != nullptr;
277  }
278 
284  template <typename T>
285  bool GetPropertyValue(const char *propertyKey, T &value, const mitk::BaseRenderer *renderer = nullptr) const
286  {
287  GenericProperty<T> *gp = dynamic_cast<GenericProperty<T> *>(GetProperty(propertyKey, renderer));
288  if (gp != nullptr)
289  {
290  value = gp->GetValue();
291  return true;
292  }
293  return false;
294  }
295 
297  GroupTagList GetGroupTags() const;
298 
304  bool GetBoolProperty(const char *propertyKey, bool &boolValue, const mitk::BaseRenderer *renderer = nullptr) const;
305 
311  bool GetIntProperty(const char *propertyKey, int &intValue, const mitk::BaseRenderer *renderer = nullptr) const;
312 
318  bool GetFloatProperty(const char *propertyKey,
319  float &floatValue,
320  const mitk::BaseRenderer *renderer = nullptr) const;
321 
331  bool GetDoubleProperty(const char *propertyKey,
332  double &doubleValue,
333  const mitk::BaseRenderer *renderer = nullptr) const;
334 
340  bool GetStringProperty(const char *propertyKey,
341  std::string &string,
342  const mitk::BaseRenderer *renderer = nullptr) const;
343 
349  bool GetColor(float rgb[3], const mitk::BaseRenderer *renderer = nullptr, const char *propertyKey = "color") const;
350 
356  bool GetLevelWindow(mitk::LevelWindow &levelWindow,
357  const mitk::BaseRenderer *renderer = nullptr,
358  const char *propertyKey = "levelwindow") const;
359 
363  void SetSelected(bool selected, const mitk::BaseRenderer *renderer = nullptr);
364 
369  bool IsSelected(const mitk::BaseRenderer *renderer = nullptr);
370 
376  bool GetName(std::string &nodeName,
377  const mitk::BaseRenderer *renderer = nullptr,
378  const char *propertyKey = "name") const
379  {
380  return GetStringProperty(propertyKey, nodeName, renderer);
381  }
382 
392  virtual std::string GetName() const
393  {
394  mitk::StringProperty *sp = dynamic_cast<mitk::StringProperty *>(this->GetProperty("name"));
395  if (sp == nullptr)
396  return "";
397  return sp->GetValue();
398  }
399 
401  static std::string NO_NAME_VALUE()
402  {
403  return "No Name!";
404  }
405 
411  virtual void SetName(const char *name)
412  {
413  if (name == nullptr)
414  return;
415  this->SetProperty("name", StringProperty::New(name));
416  }
422  virtual void SetName(const std::string name) { this->SetName(name.c_str()); }
429  bool GetVisibility(bool &visible, const mitk::BaseRenderer *renderer, const char *propertyKey = "visible") const
430  {
431  return GetBoolProperty(propertyKey, visible, renderer);
432  }
433 
439  bool GetOpacity(float &opacity, const mitk::BaseRenderer *renderer, const char *propertyKey = "opacity") const;
440 
450  bool IsOn(const char *propertyKey, const mitk::BaseRenderer *renderer, bool defaultIsOn = true) const
451  {
452  if (propertyKey == nullptr)
453  return defaultIsOn;
454  GetBoolProperty(propertyKey, defaultIsOn, renderer);
455  return defaultIsOn;
456  }
457 
469  bool IsVisible(const mitk::BaseRenderer *renderer,
470  const char *propertyKey = "visible",
471  bool defaultIsOn = true) const
472  {
473  return IsOn(propertyKey, renderer, defaultIsOn);
474  }
475 
480  void SetColor(const mitk::Color &color,
481  const mitk::BaseRenderer *renderer = nullptr,
482  const char *propertyKey = "color");
483 
488  void SetColor(float red,
489  float green,
490  float blue,
491  const mitk::BaseRenderer *renderer = nullptr,
492  const char *propertyKey = "color");
493 
498  void SetColor(const float rgb[3], const mitk::BaseRenderer *renderer = nullptr, const char *propertyKey = "color");
499 
507  void SetVisibility(bool visible, const mitk::BaseRenderer *renderer = nullptr, const char *propertyKey = "visible");
508 
513  void SetOpacity(float opacity, const mitk::BaseRenderer *renderer = nullptr, const char *propertyKey = "opacity");
514 
519  void SetLevelWindow(mitk::LevelWindow levelWindow,
520  const mitk::BaseRenderer *renderer = nullptr,
521  const char *propertyKey = "levelwindow");
522 
527  void SetIntProperty(const char *propertyKey, int intValue, const mitk::BaseRenderer *renderer = nullptr);
528 
533  void SetBoolProperty(const char *propertyKey, bool boolValue, const mitk::BaseRenderer *renderer = nullptr);
534 
539  void SetFloatProperty(const char *propertyKey, float floatValue, const mitk::BaseRenderer *renderer = nullptr);
540 
545  void SetDoubleProperty(const char *propertyKey, double doubleValue, const mitk::BaseRenderer *renderer = nullptr);
546 
551  void SetStringProperty(const char *propertyKey, const char *string, const mitk::BaseRenderer *renderer = nullptr);
552 
557  unsigned long GetMTime() const override;
558 
563  unsigned long GetDataReferenceChangedTime() const { return m_DataReferenceChangedTime.GetMTime(); }
564 
565  protected:
566  DataNode();
567 
568  ~DataNode() override;
569 
571  virtual void PropertyListModified(const itk::Object *caller, const itk::EventObject &event);
572 
574  mutable MapperVector m_Mappers;
575 
581 
589 
591  mutable MapOfPropertyLists m_MapOfPropertyLists;
592 
594 
597 
599  };
600 
601 #if (_MSC_VER > 1200) || !defined(_MSC_VER)
602  MITKCORE_EXPORT MBI_STD::istream &operator>>(MBI_STD::istream &i, DataNode::Pointer &dtn);
603 
604  MITKCORE_EXPORT MBI_STD::ostream &operator<<(MBI_STD::ostream &o, DataNode::Pointer &dtn);
605 #endif
606 } // namespace mitk
607 
608 #if ((defined(_MSC_VER)) && (_MSC_VER <= 1200))
609 MITKCORE_EXPORT MBI_STD::istream &operator>>(MBI_STD::istream &i, mitk::DataNode::Pointer &dtn);
610 
611 MITKCORE_EXPORT MBI_STD::ostream &operator<<(MBI_STD::ostream &o, mitk::DataNode::Pointer &dtn);
612 #endif
613 
614 #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:392
virtual void SetName(const std::string name)
Extra convenience access method to set the name of an object.
Definition: mitkDataNode.h:422
mitk::Geometry3D::Pointer Geometry3DPointer
Definition: mitkDataNode.h:67
MapperVector m_Mappers
Mapper-slots.
Definition: mitkDataNode.h:574
#define MITKCORE_EXPORT
std::set< std::string > GroupTagList
Definition: mitkDataNode.h:71
virtual const char * GetValue() const
std::vector< MapOfPropertyLists::key_type > PropertyListKeyNames
Definition: mitkDataNode.h:70
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:596
PropertyList::Pointer m_PropertyList
BaseRenderer-independent PropertyList.
Definition: mitkDataNode.h:588
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:591
MITKCORE_EXPORT std ::istream & operator>>(std ::istream &i, DataNode::Pointer &dtn)
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:285
MITKCORE_EXPORT std ::ostream & operator<<(std ::ostream &o, DataNode::Pointer &dtn)
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:273
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:580
static std::string NO_NAME_VALUE()
Definition: mitkDataNode.h:401
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:469
unsigned long m_PropertyListModifiedObserverTag
Definition: mitkDataNode.h:598
unsigned long GetDataReferenceChangedTime() const
Get the timestamp of the last change of the reference to the BaseData.
Definition: mitkDataNode.h:563
#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:411
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:429
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:450
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:69
DataInteractor::Pointer m_DataInteractor
Definition: mitkDataNode.h:593
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:68
Property for strings.
unsigned int MapperSlotId
Definition: mitkCommon.h:33
static Pointer New()
Class for nodes of the DataTree.
Definition: mitkDataNode.h:64
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:376