Medical Imaging Interaction Toolkit  2018.4.99-e1268d66
Medical Imaging Interaction Toolkit
mitkMapper.cpp
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 #include "mitkMapper.h"
14 #include "mitkBaseRenderer.h"
15 #include "mitkDataNode.h"
16 #include "mitkProperties.h"
17 
18 mitk::Mapper::Mapper() : m_DataNode(nullptr), m_TimeStep(0)
19 {
20 }
21 
23 {
24 }
25 
27 {
28  return m_DataNode == nullptr ? nullptr : m_DataNode->GetData();
29 }
30 
32 {
33  return this->m_DataNode;
34 }
35 
36 bool mitk::Mapper::GetColor(float rgb[3], mitk::BaseRenderer *renderer, const char *name) const
37 {
38  const mitk::DataNode *node = GetDataNode();
39  if (node == nullptr)
40  return false;
41 
42  return node->GetColor(rgb, renderer, name);
43 }
44 
45 bool mitk::Mapper::GetVisibility(bool &visible, mitk::BaseRenderer *renderer, const char *name) const
46 {
47  const mitk::DataNode *node = GetDataNode();
48  if (node == nullptr)
49  return false;
50 
51  return node->GetVisibility(visible, renderer, name);
52 }
53 
54 bool mitk::Mapper::GetOpacity(float &opacity, mitk::BaseRenderer *renderer, const char *name) const
55 {
56  const mitk::DataNode *node = GetDataNode();
57  if (node == nullptr)
58  return false;
59 
60  return node->GetOpacity(opacity, renderer, name);
61 }
62 
63 bool mitk::Mapper::GetLevelWindow(mitk::LevelWindow &levelWindow, mitk::BaseRenderer *renderer, const char *name) const
64 {
65  const mitk::DataNode *node = GetDataNode();
66  if (node == nullptr)
67  return false;
68 
69  return node->GetLevelWindow(levelWindow, renderer, name);
70 }
71 
72 bool mitk::Mapper::IsVisible(mitk::BaseRenderer *renderer, const char *name) const
73 {
74  bool visible = true;
75  GetDataNode()->GetVisibility(visible, renderer, name);
76  return visible;
77 }
78 
80 {
81  if ((renderer != nullptr) && (m_DataNode != nullptr))
82  {
83  m_TimeStep = renderer->GetTimeStep(m_DataNode->GetData());
84  }
85  else
86  {
87  m_TimeStep = 0;
88  }
89 }
90 
92 {
93  const DataNode *node = GetDataNode();
94 
95  assert(node != nullptr);
96 
97  auto *data = static_cast<mitk::BaseData *>(node->GetData());
98 
99  if (!data)
100  return;
101 
102  // Calculate time step of the input data for the specified renderer (integer value)
103  this->CalculateTimeStep(renderer);
104 
105  // Check if time step is valid
106  const TimeGeometry *dataTimeGeometry = data->GetTimeGeometry();
107  if ((dataTimeGeometry == nullptr) || (dataTimeGeometry->CountTimeSteps() == 0) ||
108  (!dataTimeGeometry->IsValidTimeStep(m_TimeStep)))
109  {
110  // TimeGeometry or time step is not valid for this data:
111  // reset mapper so that nothing is displayed
112  this->ResetMapper(renderer);
113  return;
114  }
115 
116  this->GenerateDataForRenderer(renderer);
117 }
118 
120  mitk::Mapper *mapper,
121  mitk::DataNode *dataNode) const
122 {
123  if (mapper && m_LastGenerateDataTime < mapper->GetMTime())
124  return true;
125 
126  if (dataNode)
127  {
128  if (m_LastGenerateDataTime < dataNode->GetDataReferenceChangedTime())
129  return true;
130 
131  mitk::BaseData *data = dataNode->GetData();
132 
133  if (data && m_LastGenerateDataTime < data->GetMTime())
134  return true;
135  }
136 
137  if (renderer && m_LastGenerateDataTime < renderer->GetTimeStepUpdateTime())
138  return true;
139 
140  return false;
141 }
142 
144 {
145  node->AddProperty("visible", mitk::BoolProperty::New(true), renderer, overwrite);
146  node->AddProperty("layer", mitk::IntProperty::New(0), renderer, overwrite);
147  node->AddProperty("name", mitk::StringProperty::New(DataNode::NO_NAME_VALUE()), renderer, overwrite);
148 }
Base of all data objects.
Definition: mitkBaseData.h:37
Mapper()
explicit constructor which disallows implicit conversions
Definition: mitkMapper.cpp:18
bool IsGenerateDataRequired(mitk::BaseRenderer *renderer, mitk::Mapper *mapper, mitk::DataNode *dataNode) const
Definition: mitkMapper.cpp:119
virtual DataNode * GetDataNode() const
Get the DataNode containing the data to map. Method only returns valid DataNode Pointer if the mapper...
Definition: mitkMapper.cpp:31
virtual bool GetLevelWindow(LevelWindow &levelWindow, BaseRenderer *renderer, const char *name="levelwindow") const
Convenience access method for color properties (instances of LevelWindoProperty)
Definition: mitkMapper.cpp:63
Organizes the rendering process.
bool GetOpacity(float &opacity, const mitk::BaseRenderer *renderer, const char *propertyKey="opacity") const
Convenience access method for opacity properties (instances of FloatProperty)
Base class of all mappers, Vtk as well as OpenGL mappers.
Definition: mitkMapper.h:49
virtual bool IsVisible(BaseRenderer *renderer, const char *name="visible") const
Convenience access method for visibility properties (instances of BoolProperty). Return value is the ...
Definition: mitkMapper.cpp:72
static std::string NO_NAME_VALUE()
Definition: mitkDataNode.h:401
The LevelWindow class Class to store level/window values.
static Pointer New()
BaseData * GetData() const
Get the data object (instance of BaseData, e.g., an Image) managed by this DataNode.
void AddProperty(const char *propertyKey, BaseProperty *property, const mitk::BaseRenderer *renderer=nullptr, bool overwrite=false)
Add the property (instance of BaseProperty) if it does not exist (or always ifoverwrite istrue) with ...
bool GetColor(float rgb[3], const mitk::BaseRenderer *renderer=nullptr, const char *propertyKey="color") const
Convenience access method for color properties (instances of ColorProperty)
virtual bool GetVisibility(bool &visible, BaseRenderer *renderer, const char *name="visible") const
Convenience access method for visibility properties (instances of BoolProperty)
Definition: mitkMapper.cpp:45
virtual bool GetOpacity(float &opacity, BaseRenderer *renderer, const char *name="opacity") const
Convenience access method for opacity properties (instances of FloatProperty)
Definition: mitkMapper.cpp:54
virtual unsigned int GetTimeStep() const
mitk::DataNode * m_DataNode
Definition: mitkMapper.h:175
virtual bool GetColor(float rgb[3], BaseRenderer *renderer, const char *name="color") const
Convenience access method for color properties (instances of ColorProperty)
Definition: mitkMapper.cpp:36
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
virtual void Update(BaseRenderer *renderer)
Calls the time step of the input data for the specified renderer and checks whether the time step is ...
Definition: mitkMapper.cpp:91
virtual void ResetMapper(BaseRenderer *)
Reset the mapper (i.e., make sure that nothing is displayed) if no valid data is present. In most cases the reimplemented function disables the according actors (toggling visibility off)
Definition: mitkMapper.h:174
virtual void GenerateDataForRenderer(BaseRenderer *)
Generate the data needed for rendering into renderer.
Definition: mitkMapper.h:164
~Mapper() override
virtual destructor in order to derive from this class
Definition: mitkMapper.cpp:22
virtual void CalculateTimeStep(BaseRenderer *renderer)
Updates the time step, which is sometimes needed in subclasses.
Definition: mitkMapper.cpp:79
static Pointer New()
BaseData * GetData() const
Get the data to map.
Definition: mitkMapper.cpp:26
bool GetLevelWindow(mitk::LevelWindow &levelWindow, const mitk::BaseRenderer *renderer=nullptr, const char *propertyKey="levelwindow") const
Convenience access method for level-window properties (instances of LevelWindowProperty) ...
static Pointer New()
virtual bool IsValidTimeStep(TimeStepType timeStep) const =0
Test for the given time step if a geometry is availible.
Class for nodes of the DataTree.
Definition: mitkDataNode.h:64
static void SetDefaultProperties(DataNode *node, BaseRenderer *renderer=nullptr, bool overwrite=false)
Set default values of properties used by this mapper to node.
Definition: mitkMapper.cpp:143