Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkOverlay.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 "mitkOverlay.h"
18 
19 mitk::Overlay::Overlay() : m_LayoutedBy(NULL)
20 {
22  this->SetName(this->GetNameOfClass());
23  this->SetVisibility(true);
24  this->SetOpacity(1.0);
25 }
26 
28 {
29 }
30 
31 void mitk::Overlay::SetProperty(const std::string &propertyKey,
32  const BaseProperty::Pointer &propertyValue,
33  const mitk::BaseRenderer *renderer)
34 {
35  GetPropertyList(renderer)->SetProperty(propertyKey, propertyValue);
36  GetPropertyList(renderer)->Modified();
37 }
38 
39 void mitk::Overlay::ReplaceProperty(const std::string &propertyKey,
40  const BaseProperty::Pointer &propertyValue,
41  const mitk::BaseRenderer *renderer)
42 {
43  GetPropertyList(renderer)->ReplaceProperty(propertyKey, propertyValue);
44  GetPropertyList(renderer)->Modified();
45 }
46 
47 void mitk::Overlay::AddProperty(const std::string &propertyKey,
48  const BaseProperty::Pointer &propertyValue,
49  const mitk::BaseRenderer *renderer,
50  bool overwrite)
51 {
52  if ((overwrite) || (GetProperty(propertyKey, renderer) == NULL))
53  {
54  SetProperty(propertyKey, propertyValue, renderer);
55  }
56 }
57 
59 {
60  m_PropertyList->ConcatenatePropertyList(pList, replace);
61 }
62 
63 mitk::BaseProperty *mitk::Overlay::GetProperty(const std::string &propertyKey, const mitk::BaseRenderer *renderer) const
64 {
65  // renderer specified?
66  if (renderer)
67  {
68  std::map<const mitk::BaseRenderer *, mitk::PropertyList::Pointer>::const_iterator it;
69  // check for the renderer specific property
70  it = m_MapOfPropertyLists.find(renderer);
71  if (it != m_MapOfPropertyLists.cend()) // found
72  {
73  mitk::BaseProperty::Pointer property = it->second->GetProperty(propertyKey);
74  if (property.IsNotNull()) // found an enabled property in the render specific list
75  return property;
76  else // found a renderer specific list, but not the desired property
77  return m_PropertyList->GetProperty(propertyKey); // return renderer unspecific property
78  }
79  else // didn't find the property list of the given renderer
80  {
81  // return the renderer unspecific property if there is one
82  return m_PropertyList->GetProperty(propertyKey);
83  }
84  }
85  else // no specific renderer given; use the renderer independent one
86  {
87  mitk::BaseProperty::Pointer property = m_PropertyList->GetProperty(propertyKey);
88  if (property.IsNotNull())
89  return property;
90  }
91 
92  // only to satisfy compiler!
93  return NULL;
94 }
95 
96 bool mitk::Overlay::GetBoolProperty(const std::string &propertyKey, bool &boolValue, mitk::BaseRenderer *renderer) const
97 {
98  mitk::BoolProperty::Pointer boolprop = dynamic_cast<mitk::BoolProperty *>(GetProperty(propertyKey, renderer));
99  if (boolprop.IsNull())
100  return false;
101 
102  boolValue = boolprop->GetValue();
103  return true;
104 }
105 
106 bool mitk::Overlay::GetIntProperty(const std::string &propertyKey, int &intValue, mitk::BaseRenderer *renderer) const
107 {
108  mitk::IntProperty::Pointer intprop = dynamic_cast<mitk::IntProperty *>(GetProperty(propertyKey, renderer));
109  if (intprop.IsNull())
110  return false;
111 
112  intValue = intprop->GetValue();
113  return true;
114 }
115 
116 bool mitk::Overlay::GetFloatProperty(const std::string &propertyKey,
117  float &floatValue,
118  mitk::BaseRenderer *renderer) const
119 {
120  mitk::FloatProperty::Pointer floatprop = dynamic_cast<mitk::FloatProperty *>(GetProperty(propertyKey, renderer));
121  if (floatprop.IsNull())
122  return false;
123 
124  floatValue = floatprop->GetValue();
125  return true;
126 }
127 
128 bool mitk::Overlay::GetStringProperty(const std::string &propertyKey,
129  std::string &string,
130  mitk::BaseRenderer *renderer) const
131 {
132  mitk::StringProperty::Pointer stringProp = dynamic_cast<mitk::StringProperty *>(GetProperty(propertyKey, renderer));
133  if (stringProp.IsNull())
134  {
135  return false;
136  }
137  else
138  {
139  // memcpy((void*)string, stringProp->GetValue(), strlen(stringProp->GetValue()) + 1 ); // looks dangerous
140  string = stringProp->GetValue();
141  return true;
142  }
143 }
144 
145 void mitk::Overlay::SetIntProperty(const std::string &propertyKey, int intValue, mitk::BaseRenderer *renderer)
146 {
147  GetPropertyList(renderer)->SetProperty(propertyKey, mitk::IntProperty::New(intValue));
148  Modified();
149 }
150 void mitk::Overlay::SetBoolProperty(const std::string &propertyKey,
151  bool boolValue,
152  mitk::BaseRenderer *renderer /*=NULL*/)
153 {
154  GetPropertyList(renderer)->SetProperty(propertyKey, mitk::BoolProperty::New(boolValue));
155  Modified();
156 }
157 
158 void mitk::Overlay::SetFloatProperty(const std::string &propertyKey,
159  float floatValue,
160  mitk::BaseRenderer *renderer /*=NULL*/)
161 {
162  GetPropertyList(renderer)->SetProperty(propertyKey, mitk::FloatProperty::New(floatValue));
163  Modified();
164 }
165 
166 void mitk::Overlay::SetStringProperty(const std::string &propertyKey,
167  const std::string &stringValue,
168  mitk::BaseRenderer *renderer /*=NULL*/)
169 {
170  GetPropertyList(renderer)->SetProperty(propertyKey, mitk::StringProperty::New(stringValue));
171  Modified();
172 }
173 
174 std::string mitk::Overlay::GetName() const
175 {
176  mitk::StringProperty *sp = dynamic_cast<mitk::StringProperty *>(this->GetProperty("name"));
177  if (sp == NULL)
178  return "";
179  return sp->GetValue();
180 }
181 
182 void mitk::Overlay::SetName(const std::string &name)
183 {
184  this->SetStringProperty("name", name);
185 }
186 
187 bool mitk::Overlay::GetName(std::string &nodeName, mitk::BaseRenderer *renderer, const std::string &propertyKey) const
188 {
189  return GetStringProperty(propertyKey, nodeName, renderer);
190 }
191 
192 void mitk::Overlay::SetText(std::string text, mitk::BaseRenderer *renderer)
193 {
194  SetStringProperty("Text", text.c_str(), renderer);
195 }
196 
197 std::string mitk::Overlay::GetText(mitk::BaseRenderer *renderer) const
198 {
199  std::string text;
200  GetStringProperty("Text", text, renderer);
201  return text;
202 }
203 
204 void mitk::Overlay::SetFontSize(int fontSize, mitk::BaseRenderer *renderer)
205 {
206  SetIntProperty("FontSize", fontSize, renderer);
207 }
208 
210 {
211  int fontSize = 1;
212  GetIntProperty("FontSize", fontSize, renderer);
213  return fontSize;
214 }
215 
216 bool mitk::Overlay::GetVisibility(bool &visible, mitk::BaseRenderer *renderer, const std::string &propertyKey) const
217 {
218  return GetBoolProperty(propertyKey, visible, renderer);
219 }
220 
221 bool mitk::Overlay::IsVisible(mitk::BaseRenderer *renderer, const std::string &propertyKey, bool defaultIsOn) const
222 {
223  return IsOn(propertyKey, renderer, defaultIsOn);
224 }
225 
226 bool mitk::Overlay::GetColor(float rgb[], mitk::BaseRenderer *renderer, const std::string &propertyKey) const
227 {
228  mitk::ColorProperty::Pointer colorprop = dynamic_cast<mitk::ColorProperty *>(GetProperty(propertyKey, renderer));
229  if (colorprop.IsNull())
230  return false;
231 
232  memcpy(rgb, colorprop->GetColor().GetDataPointer(), 3 * sizeof(float));
233  return true;
234 }
235 
236 void mitk::Overlay::SetColor(const mitk::Color &color, mitk::BaseRenderer *renderer, const std::string &propertyKey)
237 {
239  prop = mitk::ColorProperty::New(color);
240  GetPropertyList(renderer)->SetProperty(propertyKey, prop);
241 }
242 
244  float red, float green, float blue, mitk::BaseRenderer *renderer, const std::string &propertyKey)
245 {
246  float color[3];
247  color[0] = red;
248  color[1] = green;
249  color[2] = blue;
250  SetColor(color, renderer, propertyKey);
251 }
252 
253 void mitk::Overlay::SetColor(const float rgb[], mitk::BaseRenderer *renderer, const std::string &propertyKey)
254 {
256  prop = mitk::ColorProperty::New(rgb);
257  GetPropertyList(renderer)->SetProperty(propertyKey, prop);
258 }
259 
260 bool mitk::Overlay::GetOpacity(float &opacity, mitk::BaseRenderer *renderer, const std::string &propertyKey) const
261 {
262  mitk::FloatProperty::Pointer opacityprop = dynamic_cast<mitk::FloatProperty *>(GetProperty(propertyKey, renderer));
263  if (opacityprop.IsNull())
264  return false;
265 
266  opacity = opacityprop->GetValue();
267  return true;
268 }
269 
270 void mitk::Overlay::SetOpacity(float opacity, mitk::BaseRenderer *renderer, const std::string &propertyKey)
271 {
273  prop = mitk::FloatProperty::New(opacity);
274  GetPropertyList(renderer)->SetProperty(propertyKey, prop);
275 }
276 
277 void mitk::Overlay::SetVisibility(bool visible, mitk::BaseRenderer *renderer, const std::string &propertyKey)
278 {
280  prop = mitk::BoolProperty::New(visible);
281  GetPropertyList(renderer)->SetProperty(propertyKey, prop);
282 }
283 
285 {
286  if (renderer == NULL)
287  return m_PropertyList;
288 
289  mitk::PropertyList::Pointer &propertyList = m_MapOfPropertyLists[renderer];
290 
291  if (propertyList.IsNull())
292  propertyList = mitk::PropertyList::New();
293 
294  assert(m_MapOfPropertyLists[renderer].IsNotNull());
295 
296  return propertyList;
297 }
298 
300 {
301  if (m_LastGenerateDataTime < overlay->GetMTime())
302  return true;
303 
304  if (m_LastGenerateDataTime < overlay->GetPropertyList()->GetMTime())
305  return true;
306 
307  if (m_LastGenerateDataTime < overlay->GetPropertyList(renderer)->GetMTime())
308  return true;
309 
310  if (renderer && m_LastGenerateDataTime < renderer->GetTimeStepUpdateTime())
311  return true;
312 
313  return false;
314 }
315 
317 {
318  mitk::Overlay::Bounds bounds;
319  bounds.Position[0] = bounds.Position[1] = bounds.Size[0] = bounds.Size[1] = 0;
320  return bounds;
321 }
322 
324 {
325 }
326 
327 void mitk::Overlay::SetForceInForeground(bool forceForeground)
328 {
329  m_ForceInForeground = forceForeground;
330 }
331 
333 {
334  return m_ForceInForeground;
335 }
void SetVisibility(bool visible, mitk::BaseRenderer *renderer=nullptr, const std::string &propertyKey="visible")
Convenience method for setting visibility properties (instances of BoolProperty)
void AddProperty(const std::string &propertyKey, const BaseProperty::Pointer &property, const mitk::BaseRenderer *renderer=nullptr, bool overwrite=false)
Add the property (instance of BaseProperty) if it does not exist (or always if overwrite is true) wit...
Definition: mitkOverlay.cpp:47
virtual std::string GetName() const
Extra convenience access method for accessing the name of an object (instance of StringProperty with ...
virtual void SetBoundsOnDisplay(BaseRenderer *renderer, const Bounds &)
Sets position and size of the overlay on the display.
void ConcatenatePropertyList(PropertyList *pList, bool replace=false)
Add values from another PropertyList.
Definition: mitkOverlay.cpp:58
static Pointer New()
virtual Bounds GetBoundsOnDisplay(BaseRenderer *renderer) const
Returns position and size of the overlay on the display.
signed integer value
Definition: jsoncpp.h:348
mitk::BaseProperty * GetProperty(const std::string &propertyKey, const mitk::BaseRenderer *renderer=nullptr) const
Get the property (instance of BaseProperty) with key propertyKey from the PropertyList of the rendere...
Definition: mitkOverlay.cpp:63
int GetFontSize(mitk::BaseRenderer *renderer=nullptr) const
bool GetVisibility(bool &visible, mitk::BaseRenderer *renderer, const std::string &propertyKey="visible") const
Convenience access method for visibility properties (instances of BoolProperty with property-key "vis...
itk::Point< double, 2 > Size
Definition: mitkOverlay.h:43
static Pointer New()
void SetFloatProperty(const std::string &propertyKey, float floatValue, mitk::BaseRenderer *renderer=nullptr)
Convenience method for setting int properties (instances of IntProperty)
Organizes the rendering process.
bool IsForceInForeground() const
itk::Point< double, 2 > Position
Definition: mitkOverlay.h:42
Key-value list holding instances of BaseProperty.
void ReplaceProperty(const std::string &propertyKey, const BaseProperty::Pointer &property, const mitk::BaseRenderer *renderer=nullptr)
Replace the property (instance of BaseProperty) with key propertyKey in the PropertyList of the rende...
Definition: mitkOverlay.cpp:39
void SetColor(const mitk::Color &color, mitk::BaseRenderer *renderer=nullptr, const std::string &propertyKey="color")
Convenience method for setting color properties (instances of ColorProperty)
PropertyList::Pointer m_PropertyList
BaseRenderer-independent PropertyList.
Definition: mitkOverlay.h:431
bool GetStringProperty(const std::string &propertyKey, std::string &string, mitk::BaseRenderer *renderer=nullptr) const
Convenience access method for string properties (instances of StringProperty)
void SetIntProperty(const std::string &propertyKey, int intValue, mitk::BaseRenderer *renderer=nullptr)
Convenience method for setting int properties (instances of IntProperty)
virtual const char * GetValue() const
void SetForceInForeground(bool forceForeground)
static Pointer New()
The ColorProperty class RGB color property.
bool GetColor(float rgb[], mitk::BaseRenderer *renderer=nullptr, const std::string &propertyKey="color") const
Convenience access method for color properties (instances of ColorProperty)
Abstract base class for properties.
bool GetOpacity(float &opacity, mitk::BaseRenderer *renderer, const std::string &propertyKey="opacity") const
Convenience access method for opacity properties (instances of FloatProperty)
bool GetFloatProperty(const std::string &propertyKey, float &floatValue, mitk::BaseRenderer *renderer=nullptr) const
Convenience access method for float properties (instances of FloatProperty)
virtual ~Overlay()
virtual destructor in order to derive from this class
Definition: mitkOverlay.cpp:27
bool GetIntProperty(const std::string &propertyKey, int &intValue, mitk::BaseRenderer *renderer=nullptr) const
Convenience access method for int properties (instances of IntProperty)
void SetProperty(const std::string &propertyKey, const BaseProperty::Pointer &property, const mitk::BaseRenderer *renderer=nullptr)
Set the property (instance of BaseProperty) with key propertyKey in the PropertyList of the renderer ...
Definition: mitkOverlay.cpp:31
bool IsVisible(mitk::BaseRenderer *renderer, const std::string &propertyKey="visible", bool defaultIsOn=true) const
Convenience access method for visibility properties (instances of BoolProperty). Return value is the ...
itk::RGBPixel< float > Color
Color Standard RGB color typedef (float)
bool GetBoolProperty(const std::string &propertyKey, bool &boolValue, mitk::BaseRenderer *renderer=nullptr) const
Convenience access method for bool properties (instances of BoolProperty)
Definition: mitkOverlay.cpp:96
static Pointer New()
void SetOpacity(float opacity, mitk::BaseRenderer *renderer=nullptr, const std::string &propertyKey="opacity")
Convenience method for setting opacity properties (instances of FloatProperty)
void SetFontSize(int fontSize, mitk::BaseRenderer *renderer=nullptr)
virtual void SetName(const std::string &name)
Extra convenience access method to set the name of an object.
static Pointer New()
void SetBoolProperty(const std::string &propertyKey, bool boolValue, mitk::BaseRenderer *renderer=nullptr)
Convenience method for setting int properties (instances of IntProperty)
Overlay()
explicit constructor which disallows implicit conversions
Definition: mitkOverlay.cpp:19
UTF-8 string value.
Definition: jsoncpp.h:351
Base class for all overlays.
Definition: mitkOverlay.h:34
static const char * replace[]
This is a dictionary to replace long names of classes, modules, etc. to shorter versions in the conso...
bool IsGenerateDataRequired(mitk::BaseRenderer *renderer, mitk::Overlay *overlay)
void SetText(std::string text, mitk::BaseRenderer *renderer=nullptr)
Property for strings.
std::string GetText(mitk::BaseRenderer *renderer=nullptr) const
static Pointer New()
void SetStringProperty(const std::string &propertyKey, const std::string &string, mitk::BaseRenderer *renderer=nullptr)
Convenience method for setting int properties (instances of IntProperty)
Container for position and size on the display.
Definition: mitkOverlay.h:40
mitk::PropertyList * GetPropertyList(const mitk::BaseRenderer *renderer=nullptr) const
Get the PropertyList of the renderer. If renderer is NULL, the BaseRenderer-independent PropertyList ...