Medical Imaging Interaction Toolkit  2025.12.02
Medical Imaging Interaction Toolkit
mitkAnnotation.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 mitkAnnotation_h
14 #define mitkAnnotation_h
15 
16 #include "mitkServiceInterface.h"
17 #include "usServiceRegistration.h"
18 #include <MitkCoreExports.h>
19 #include <mitkBaseRenderer.h>
20 #include <mitkCommon.h>
21 
22 namespace mitk
23 {
27  class MITKCORE_EXPORT Annotation : public itk::Object
28  {
29  public:
31  struct Bounds
32  {
33  itk::Point<double, 2> Position;
34  itk::Point<double, 2> Size;
35  };
36 
40  {
41  public:
43 
44  inline void UpdateGenerateDataTime() { m_LastGenerateDataTime.Modified(); }
45  inline itk::TimeStamp &GetLastGenerateDataTime() { return m_LastGenerateDataTime; }
46  protected:
48  itk::TimeStamp m_LastGenerateDataTime;
49  };
50 
62  void SetProperty(const std::string &propertyKey, const BaseProperty::Pointer &property);
63 
74  void ReplaceProperty(const std::string &propertyKey, const BaseProperty::Pointer &property);
75 
92  void AddProperty(const std::string &propertyKey, const BaseProperty::Pointer &property, bool overwrite = false);
93 
110  void ConcatenatePropertyList(PropertyList *pList, bool replace = false);
111 
123  mitk::BaseProperty *GetProperty(const std::string &propertyKey) const;
124 
136  template <typename T>
137  bool GetProperty(itk::SmartPointer<T> &property, const std::string &propertyKey) const
138  {
139  property = dynamic_cast<T *>(GetProperty(propertyKey));
140  return property.IsNotNull();
141  }
142 
154  template <typename T>
155  bool GetProperty(T *&property, const std::string &propertyKey) const
156  {
157  property = dynamic_cast<T *>(GetProperty(propertyKey));
158  return property != nullptr;
159  }
160 
166  template <typename T>
167  bool GetPropertyValue(const std::string &propertyKey, T &value) const
168  {
169  GenericProperty<T> *gp = dynamic_cast<GenericProperty<T> *>(GetProperty(propertyKey));
170  if (gp != nullptr)
171  {
172  value = gp->GetValue();
173  return true;
174  }
175  return false;
176  }
177 
183  bool GetBoolProperty(const std::string &propertyKey, bool &boolValue) const;
184 
190  bool GetIntProperty(const std::string &propertyKey, int &intValue) const;
191 
197  bool GetFloatProperty(const std::string &propertyKey, float &floatValue) const;
198 
204  bool GetDoubleProperty(const std::string &propertyKey, double &doubleValue) const;
205 
211  bool GetStringProperty(const std::string &propertyKey, std::string &string) const;
212 
217  void SetIntProperty(const std::string &propertyKey, int intValue);
218 
223  void SetBoolProperty(const std::string &propertyKey, bool boolValue);
224 
229  void SetFloatProperty(const std::string &propertyKey, float floatValue);
230 
235  void SetDoubleProperty(const std::string &propertyKey, double doubleValue);
236 
241  void SetStringProperty(const std::string &propertyKey, const std::string &string);
242 
252  bool IsOn(const std::string &propertyKey, bool defaultIsOn = true) const
253  {
254  GetBoolProperty(propertyKey, defaultIsOn);
255  return defaultIsOn;
256  }
257 
263  bool GetName(std::string &nodeName, const std::string &propertyKey = "name") const;
264 
274  virtual std::string GetName() const;
275 
281  virtual void SetName(const std::string &name);
282 
288  bool GetColor(float rgb[], const std::string &propertyKey = "color") const;
293  void SetColor(const mitk::Color &color, const std::string &propertyKey = "color");
298  void SetColor(float red, float green, float blue, const std::string &propertyKey = "color");
303  void SetColor(const float rgb[], const std::string &propertyKey = "color");
309  bool GetOpacity(float &opacity, const std::string &propertyKey = "opacity") const;
314  void SetOpacity(float opacity, const std::string &propertyKey = "opacity");
315 
316  void SetText(std::string text);
317 
318  std::string GetText() const;
319 
320  void SetFontSize(int fontSize);
321 
322  int GetFontSize() const;
323 
330  bool GetVisibility(bool &visible, const std::string &propertyKey = "visible") const;
331 
343  bool IsVisible(const std::string &propertyKey = "visible", bool defaultIsOn = true) const;
344 
351  void SetVisibility(bool visible, const std::string &propertyKey = "visible");
352 
356  virtual void AddToBaseRenderer(BaseRenderer *renderer) = 0;
357 
361  virtual void AddToRenderer(BaseRenderer *renderer, vtkRenderer *vtkrenderer) = 0;
362 
364  virtual void RemoveFromBaseRenderer(BaseRenderer *renderer) = 0;
365 
367  virtual void RemoveFromRenderer(BaseRenderer *renderer, vtkRenderer *vtkrenderer) = 0;
368 
370  virtual void Update(BaseRenderer *renderer) = 0;
371 
373  virtual Bounds GetBoundsOnDisplay(BaseRenderer *renderer) const;
374 
376  virtual void SetBoundsOnDisplay(BaseRenderer *renderer, const Bounds &);
377 
378  void SetForceInForeground(bool forceForeground);
379 
380  bool IsForceInForeground() const;
381 
383 
388  std::string GetMicroserviceID();
389 
393  static const std::string US_INTERFACE_NAME;
394  static const std::string US_PROPKEY_AnnotationNAME;
395  static const std::string US_PROPKEY_ID;
396  static const std::string US_PROPKEY_MODIFIED;
397  static const std::string US_PROPKEY_RENDERER_ID;
398  static const std::string US_PROPKEY_AR_ID;
399 
405 
409  virtual void UnRegisterMicroservice();
410 
412 
414 
415  protected:
418 
420  ~Annotation() override;
421 
428  PropertyList::Pointer m_PropertyList;
429 
434 
435  void SetUSProperty(const std::string &propertyKey, us::Any value);
436 
437  private:
439  bool m_ForceInForeground;
440 
442  Annotation(const Annotation &);
443 
445  Annotation &operator=(const Annotation &);
446 
447  private:
448  us::ServiceRegistration<Self> m_ServiceRegistration;
449 
450  unsigned long m_PropertyListModifiedObserverTag;
451  void PropertyListModified(const itk::Object *, const itk::EventObject &);
452  };
453 
454 } // namespace mitk
455 
456 MITK_DECLARE_SERVICE_INTERFACE(mitk::Annotation, "org.mitk.services.Annotation")
457 
458 #endif
#define MITKCORE_EXPORT
Base class for mapper specific rendering resources.
itk::TimeStamp & GetLastGenerateDataTime()
itk::TimeStamp m_LastGenerateDataTime
timestamp of last update of stored data
bool IsGenerateDataRequired(mitk::BaseRenderer *renderer, mitk::Annotation *Annotation)
Base class for all Annotation This class is to be implemented in order to create Annotation which are...
virtual void SetName(const std::string &name)
Extra convenience access method to set the name of an object.
bool GetName(std::string &nodeName, const std::string &propertyKey="name") const
Convenience access method for accessing the name of an object (instance of StringProperty with proper...
virtual void AddToBaseRenderer(BaseRenderer *renderer)=0
Adds the Annotation to the specified renderer. Update Annotation should be called soon in order to ap...
void SetFontSize(int fontSize)
static const std::string US_PROPKEY_AnnotationNAME
bool GetStringProperty(const std::string &propertyKey, std::string &string) const
Convenience access method for string properties (instances of StringProperty)
mitk::BaseProperty * GetProperty(const std::string &propertyKey) const
Get the property (instance of BaseProperty) with key propertyKey from the PropertyList of the rendere...
bool GetPropertyValue(const std::string &propertyKey, T &value) const
Convenience access method for GenericProperty<T> properties (T being the type of the second parameter...
static const std::string US_INTERFACE_NAME
These Constants are used in conjunction with Microservices.
mitkClassMacroItkParent(Annotation, itk::Object)
void SetText(std::string text)
virtual Bounds GetBoundsOnDisplay(BaseRenderer *renderer) const
Returns position and size of the Annotation on the display.
void SetStringProperty(const std::string &propertyKey, const std::string &string)
Convenience method for setting int properties (instances of IntProperty)
bool GetFloatProperty(const std::string &propertyKey, float &floatValue) const
Convenience access method for float properties (instances of FloatProperty)
void SetColor(const mitk::Color &color, const std::string &propertyKey="color")
Convenience method for setting color properties (instances of ColorProperty)
virtual void SetBoundsOnDisplay(BaseRenderer *renderer, const Bounds &)
Sets position and size of the Annotation on the display.
bool GetColor(float rgb[], const std::string &propertyKey="color") const
Convenience access method for color properties (instances of ColorProperty)
bool IsOn(const std::string &propertyKey, bool defaultIsOn=true) const
Convenience access method for boolean properties (instances of BoolProperty). Return value is the val...
void ConcatenatePropertyList(PropertyList *pList, bool replace=false)
Add values from another PropertyList.
static const std::string US_PROPKEY_AR_ID
bool GetProperty(itk::SmartPointer< T > &property, const std::string &propertyKey) const
Get the property of type T with key propertyKey from the PropertyList of the renderer,...
void SetDoubleProperty(const std::string &propertyKey, double doubleValue)
Convenience method for setting int properties (instances of IntProperty)
virtual std::string GetName() const
Extra convenience access method for accessing the name of an object (instance of StringProperty with ...
void ReplaceProperty(const std::string &propertyKey, const BaseProperty::Pointer &property)
Replace the property (instance of BaseProperty) with key propertyKey in the PropertyList of the rende...
static const std::string US_PROPKEY_RENDERER_ID
bool GetProperty(T *&property, const std::string &propertyKey) const
Get the property of type T with key propertyKey from the PropertyList of the renderer,...
bool GetIntProperty(const std::string &propertyKey, int &intValue) const
Convenience access method for int properties (instances of IntProperty)
PropertyList * GetPropertyList() const
void SetBoolProperty(const std::string &propertyKey, bool boolValue)
Convenience method for setting int properties (instances of IntProperty)
itk::TimeStamp m_DataReferenceChangedTime
Timestamp of the last change of m_Data.
void AddProperty(const std::string &propertyKey, const BaseProperty::Pointer &property, bool overwrite=false)
Add the property (instance of BaseProperty) if it does not exist (or always if overwrite is true) wit...
void AnnotationModified()
virtual void UnRegisterMicroservice()
Registers this object as a Microservice, making it available to every module and/or plugin.
virtual void RemoveFromRenderer(BaseRenderer *renderer, vtkRenderer *vtkrenderer)=0
Removes the Annotation from the specified renderer. It is not visible anymore then.
void SetFloatProperty(const std::string &propertyKey, float floatValue)
Convenience method for setting int properties (instances of IntProperty)
bool GetDoubleProperty(const std::string &propertyKey, double &doubleValue) const
Convenience access method for double properties (instances of DoubleProperty)
void SetColor(float red, float green, float blue, const std::string &propertyKey="color")
Convenience method for setting color properties (instances of ColorProperty)
virtual void RegisterAsMicroservice(us::ServiceProperties props)
Registers this object as a Microservice, making it available to every module and/or plugin....
Annotation()
explicit constructor which disallows implicit conversions
void SetProperty(const std::string &propertyKey, const BaseProperty::Pointer &property)
Set the property (instance of BaseProperty) with key propertyKey in the PropertyList of the renderer ...
static const std::string US_PROPKEY_MODIFIED
void SetUSProperty(const std::string &propertyKey, us::Any value)
void SetVisibility(bool visible, const std::string &propertyKey="visible")
Convenience method for setting visibility properties (instances of BoolProperty)
void SetOpacity(float opacity, const std::string &propertyKey="opacity")
Convenience method for setting opacity properties (instances of FloatProperty)
bool IsVisible(const std::string &propertyKey="visible", bool defaultIsOn=true) const
Convenience access method for visibility properties (instances of BoolProperty). Return value is the ...
bool IsForceInForeground() const
int GetFontSize() const
std::string GetMicroserviceID()
Returns the id that this device is registered with. The id will only be valid, if the Annotation has ...
~Annotation() override
virtual destructor in order to derive from this class
bool GetOpacity(float &opacity, const std::string &propertyKey="opacity") const
Convenience access method for opacity properties (instances of FloatProperty)
virtual void AddToRenderer(BaseRenderer *renderer, vtkRenderer *vtkrenderer)=0
Adds the Annotation to the specified renderer. Update Annotation should be called soon in order to ap...
static const std::string US_PROPKEY_ID
void SetColor(const float rgb[], const std::string &propertyKey="color")
Convenience method for setting color properties (instances of ColorProperty)
bool GetBoolProperty(const std::string &propertyKey, bool &boolValue) const
Convenience access method for bool properties (instances of BoolProperty)
virtual void RemoveFromBaseRenderer(BaseRenderer *renderer)=0
Removes the Annotation from the specified renderer. It is not visible anymore then.
PropertyList::Pointer m_PropertyList
BaseRenderer-independent PropertyList.
bool GetVisibility(bool &visible, const std::string &propertyKey="visible") const
Convenience access method for visibility properties (instances of BoolProperty with property-key "vis...
virtual void Update(BaseRenderer *renderer)=0
Applies all properties and should be called before the rendering procedure.
void SetForceInForeground(bool forceForeground)
std::string GetText() const
void SetIntProperty(const std::string &propertyKey, int intValue)
Convenience method for setting int properties (instances of IntProperty)
Abstract base class for properties.
virtual T GetValue() const
Key-value list holding instances of BaseProperty.
Definition: usAny.h:164
US_UNORDERED_MAP_TYPE< std::string, Any > ServiceProperties
#define MITK_DECLARE_SERVICE_INTERFACE(IFace, IId)
Find image slices visible on a given plane.
static const char * replace[]
This is a dictionary to replace long names of classes, modules, etc. to shorter versions in the conso...
itk::RGBPixel< float > Color
Color Standard RGB color typedef (float)
Container for position and size on the display.
itk::Point< double, 2 > Size
itk::Point< double, 2 > Position