Medical Imaging Interaction Toolkit  2016.11.0
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,
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 #include "mitkMapper.h"
18 #include "mitkBaseRenderer.h"
19 #include "mitkDataNode.h"
20 #include "mitkOverlayManager.h"
21 #include "mitkProperties.h"
22 
23 mitk::Mapper::Mapper() : m_DataNode(NULL), m_TimeStep(0)
24 {
25 }
26 
28 {
29 }
30 
32 {
33  return m_DataNode == NULL ? NULL : m_DataNode->GetData();
34 }
35 
37 {
38  return this->m_DataNode;
39 }
40 
41 bool mitk::Mapper::GetColor(float rgb[3], mitk::BaseRenderer *renderer, const char *name) const
42 {
43  const mitk::DataNode *node = GetDataNode();
44  if (node == NULL)
45  return false;
46 
47  return node->GetColor(rgb, renderer, name);
48 }
49 
50 bool mitk::Mapper::GetVisibility(bool &visible, mitk::BaseRenderer *renderer, const char *name) const
51 {
52  const mitk::DataNode *node = GetDataNode();
53  if (node == NULL)
54  return false;
55 
56  return node->GetVisibility(visible, renderer, name);
57 }
58 
59 bool mitk::Mapper::GetOpacity(float &opacity, mitk::BaseRenderer *renderer, const char *name) const
60 {
61  const mitk::DataNode *node = GetDataNode();
62  if (node == NULL)
63  return false;
64 
65  return node->GetOpacity(opacity, renderer, name);
66 }
67 
68 bool mitk::Mapper::GetLevelWindow(mitk::LevelWindow &levelWindow, mitk::BaseRenderer *renderer, const char *name) const
69 {
70  const mitk::DataNode *node = GetDataNode();
71  if (node == NULL)
72  return false;
73 
74  return node->GetLevelWindow(levelWindow, renderer, name);
75 }
76 
77 bool mitk::Mapper::IsVisible(mitk::BaseRenderer *renderer, const char *name) const
78 {
79  bool visible = true;
80  GetDataNode()->GetVisibility(visible, renderer, name);
81  return visible;
82 }
83 
85 {
86  if ((renderer != NULL) && (m_DataNode != NULL))
87  {
88  m_TimeStep = renderer->GetTimeStep(m_DataNode->GetData());
89  }
90  else
91  {
92  m_TimeStep = 0;
93  }
94 }
95 
97 {
98  if (GetOverlayManager())
99  GetOverlayManager()->AddBaseRenderer(renderer);
100 
101  const DataNode *node = GetDataNode();
102 
103  assert(node != NULL);
104 
105  mitk::BaseData *data = static_cast<mitk::BaseData *>(node->GetData());
106 
107  if (!data)
108  return;
109 
110  // Calculate time step of the input data for the specified renderer (integer value)
111  this->CalculateTimeStep(renderer);
112 
113  // Check if time step is valid
114  const TimeGeometry *dataTimeGeometry = data->GetTimeGeometry();
115  if ((dataTimeGeometry == NULL) || (dataTimeGeometry->CountTimeSteps() == 0) ||
116  (!dataTimeGeometry->IsValidTimeStep(m_TimeStep)))
117  {
118  // TimeGeometry or time step is not valid for this data:
119  // reset mapper so that nothing is displayed
120  this->ResetMapper(renderer);
121  return;
122  }
123 
124  this->GenerateDataForRenderer(renderer);
125  if (GetOverlayManager())
126  GetOverlayManager()->UpdateOverlays(renderer);
127 }
128 
130  mitk::Mapper *mapper,
131  mitk::DataNode *dataNode) const
132 {
133  if (mapper && m_LastGenerateDataTime < mapper->GetMTime())
134  return true;
135 
136  if (dataNode)
137  {
138  if (m_LastGenerateDataTime < dataNode->GetDataReferenceChangedTime())
139  return true;
140 
141  mitk::BaseData *data = dataNode->GetData();
142 
143  if (data && m_LastGenerateDataTime < data->GetMTime())
144  return true;
145  }
146 
147  if (renderer && m_LastGenerateDataTime < renderer->GetTimeStepUpdateTime())
148  return true;
149 
150  return false;
151 }
152 
154 {
155  node->AddProperty("visible", mitk::BoolProperty::New(true), renderer, overwrite);
156  node->AddProperty("layer", mitk::IntProperty::New(0), renderer, overwrite);
157  node->AddProperty("name", mitk::StringProperty::New("No Name!"), renderer, overwrite);
158 }
159 
161 {
162  return NULL;
163 }
virtual ~Mapper()
virtual destructor in order to derive from this class
Definition: mitkMapper.cpp:27
Base of all data objects.
Definition: mitkBaseData.h:39
Mapper()
explicit constructor which disallows implicit conversions
Definition: mitkMapper.cpp:23
Organizes the rendering process.
const mitk::TimeGeometry * GetTimeGeometry() const
Return the TimeGeometry of the data as const pointer.
Definition: mitkBaseData.h:52
BaseData * GetData() const
Get the data object (instance of BaseData, e.g., an Image) managed by this DataNode.
Base class of all mappers, Vtk as well as OpenGL mappers.
Definition: mitkMapper.h:54
The LevelWindow class Class to store level/window values.
static Pointer New()
virtual bool GetVisibility(bool &visible, BaseRenderer *renderer, const char *name="visible") const
Convenience access method for visibility properties (instances of BoolProperty)
Definition: mitkMapper.cpp:50
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 IsGenerateDataRequired(mitk::BaseRenderer *renderer, mitk::Mapper *mapper, mitk::DataNode *dataNode) const
Definition: mitkMapper.cpp:129
bool GetOpacity(float &opacity, const mitk::BaseRenderer *renderer, const char *propertyKey="opacity") const
Convenience access method for opacity properties (instances of FloatProperty)
virtual bool GetLevelWindow(LevelWindow &levelWindow, BaseRenderer *renderer, const char *name="levelwindow") const
Convenience access method for color properties (instances of LevelWindoProperty)
Definition: mitkMapper.cpp:68
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:96
virtual OverlayManager * GetOverlayManager() const
Definition: mitkMapper.cpp:160
virtual void CalculateTimeStep(BaseRenderer *renderer)
Updates the time step, which is sometimes needed in subclasses.
Definition: mitkMapper.cpp:84
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:41
virtual unsigned int GetTimeStep() const
BaseData * GetData() const
Get the data to map.
Definition: mitkMapper.cpp:31
static Pointer New()
virtual bool GetOpacity(float &opacity, BaseRenderer *renderer, const char *name="opacity") const
Convenience access method for opacity properties (instances of FloatProperty)
Definition: mitkMapper.cpp:59
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:77
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) ...
virtual DataNode * GetDataNode() const
Get the DataNode containing the data to map. Method only returns valid DataNode Pointer if the mapper...
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:413
bool GetColor(float rgb[3], const mitk::BaseRenderer *renderer=nullptr, const char *propertyKey="color") const
Convenience access method for color properties (instances of ColorProperty)
static Pointer New()
virtual bool IsValidTimeStep(TimeStepType timeStep) const =0
Test for the given time step if a geometry is availible.
The OverlayManager updates and manages Overlays and the respective Layouters.
Class for nodes of the DataTree.
Definition: mitkDataNode.h:66
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:153