Medical Imaging Interaction Toolkit  2026.06.00
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 #include <vector>
23 
24 namespace mitk
25 {
38  class MITKCORE_EXPORT Annotation : public itk::Object
39  {
40  public:
42  struct Bounds
43  {
44  itk::Point<double, 2> Position;
45  itk::Point<double, 2> Size;
46  };
47 
51  {
52  public:
54 
55  inline void UpdateGenerateDataTime() { m_LastGenerateDataTime.Modified(); }
56  inline itk::TimeStamp &GetLastGenerateDataTime() { return m_LastGenerateDataTime; }
57  protected:
59  itk::TimeStamp m_LastGenerateDataTime;
60  };
61 
73  void SetProperty(const std::string &propertyKey, const BaseProperty::Pointer &property);
74 
85  void ReplaceProperty(const std::string &propertyKey, const BaseProperty::Pointer &property);
86 
103  void AddProperty(const std::string &propertyKey, const BaseProperty::Pointer &property, bool overwrite = false);
104 
121  void ConcatenatePropertyList(PropertyList *pList, bool replace = false);
122 
134  mitk::BaseProperty *GetProperty(const std::string &propertyKey) const;
135 
147  template <typename T>
148  bool GetProperty(itk::SmartPointer<T> &property, const std::string &propertyKey) const
149  {
150  property = dynamic_cast<T *>(GetProperty(propertyKey));
151  return property.IsNotNull();
152  }
153 
165  template <typename T>
166  bool GetProperty(T *&property, const std::string &propertyKey) const
167  {
168  property = dynamic_cast<T *>(GetProperty(propertyKey));
169  return property != nullptr;
170  }
171 
177  template <typename T>
178  bool GetPropertyValue(const std::string &propertyKey, T &value) const
179  {
180  GenericProperty<T> *gp = dynamic_cast<GenericProperty<T> *>(GetProperty(propertyKey));
181  if (gp != nullptr)
182  {
183  value = gp->GetValue();
184  return true;
185  }
186  return false;
187  }
188 
194  bool GetBoolProperty(const std::string &propertyKey, bool &boolValue) const;
195 
201  bool GetIntProperty(const std::string &propertyKey, int &intValue) const;
202 
208  bool GetFloatProperty(const std::string &propertyKey, float &floatValue) const;
209 
215  bool GetDoubleProperty(const std::string &propertyKey, double &doubleValue) const;
216 
222  bool GetStringProperty(const std::string &propertyKey, std::string &string) const;
223 
227  void SetIntProperty(const std::string &propertyKey, int intValue);
228 
232  void SetBoolProperty(const std::string &propertyKey, bool boolValue);
233 
237  void SetFloatProperty(const std::string &propertyKey, float floatValue);
238 
242  void SetDoubleProperty(const std::string &propertyKey, double doubleValue);
243 
247  void SetStringProperty(const std::string &propertyKey, const std::string &string);
248 
258  bool IsOn(const std::string &propertyKey, bool defaultIsOn = true) const
259  {
260  GetBoolProperty(propertyKey, defaultIsOn);
261  return defaultIsOn;
262  }
263 
269  bool GetName(std::string &nodeName, const std::string &propertyKey = "name") const;
270 
280  virtual std::string GetName() const;
281 
287  virtual void SetName(const std::string &name);
288 
294  bool GetColor(float rgb[], const std::string &propertyKey = "color") const;
299  void SetColor(const mitk::Color &color, const std::string &propertyKey = "color");
304  void SetColor(float red, float green, float blue, const std::string &propertyKey = "color");
309  void SetColor(const float rgb[], const std::string &propertyKey = "color");
315  bool GetOpacity(float &opacity, const std::string &propertyKey = "opacity") const;
320  void SetOpacity(float opacity, const std::string &propertyKey = "opacity");
321 
322  void SetText(std::string text);
323 
324  std::string GetText() const;
325 
326  void SetFontSize(int fontSize);
327 
328  int GetFontSize() const;
329 
336  bool GetVisibility(bool &visible, const std::string &propertyKey = "visible") const;
337 
349  bool IsVisible(const std::string &propertyKey = "visible", bool defaultIsOn = true) const;
350 
357  void SetVisibility(bool visible, const std::string &propertyKey = "visible");
358 
362  virtual void AddToBaseRenderer(BaseRenderer *renderer) = 0;
363 
367  virtual void AddToRenderer(BaseRenderer *renderer, vtkRenderer *vtkrenderer) = 0;
368 
370  virtual void RemoveFromBaseRenderer(BaseRenderer *renderer) = 0;
371 
373  virtual void RemoveFromRenderer(BaseRenderer *renderer, vtkRenderer *vtkrenderer) = 0;
374 
376  virtual void Update(BaseRenderer *renderer) = 0;
377 
379  virtual Bounds GetBoundsOnDisplay(BaseRenderer *renderer) const;
380 
382  virtual void SetBoundsOnDisplay(BaseRenderer *renderer, const Bounds &);
383 
384  void SetForceInForeground(bool forceForeground);
385 
386  bool IsForceInForeground() const;
387 
389 
394  std::string GetMicroserviceID();
395 
399  static const std::string US_INTERFACE_NAME;
400  static const std::string US_PROPKEY_AnnotationNAME;
401  static const std::string US_PROPKEY_ID;
402  static const std::string US_PROPKEY_MODIFIED;
403  static const std::string US_PROPKEY_RENDERER_ID;
404  static const std::string US_PROPKEY_AR_ID;
405 
411 
415  virtual void UnRegisterMicroservice();
416 
418 
420 
421  protected:
424 
426  ~Annotation() override;
427 
434  PropertyList::Pointer m_PropertyList;
435 
440 
441  void SetUSProperty(const std::string &propertyKey, us::Any value);
442 
452  void RemoveFromAllRegisteredBaseRenderers(const std::vector<BaseRenderer *> &renderers) noexcept;
453 
454  private:
456  bool m_ForceInForeground;
457 
459  Annotation(const Annotation &);
460 
462  Annotation &operator=(const Annotation &);
463 
464  private:
465  us::ServiceRegistration<Self> m_ServiceRegistration;
466 
467  unsigned long m_PropertyListModifiedObserverTag;
468  void PropertyListModified(const itk::Object *, const itk::EventObject &);
469  };
470 
471 } // namespace mitk
472 
473 MITK_DECLARE_SERVICE_INTERFACE(mitk::Annotation, "org.mitk.services.Annotation")
474 
475 #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 objects.
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 string properties (instances of StringProperty).
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 double properties (instances of DoubleProperty).
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 bool properties (instances of BoolProperty).
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 float properties (instances of FloatProperty).
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 RemoveFromAllRegisteredBaseRenderers(const std::vector< BaseRenderer * > &renderers) noexcept
Calls RemoveFromBaseRenderer on every non-null entry, swallowing any exception.
void SetIntProperty(const std::string &propertyKey, int intValue)
Convenience method for setting int properties (instances of IntProperty).
Abstract base class for properties.
Organizes the rendering process.
Template class for generating properties for simple value types (int, float, bool,...
virtual T GetValue() const
Get the property value.
Key-value list holding instances of BaseProperty.
An Any class represents a general type and is capable of storing any type, supporting type-safe extra...
Definition: usAny.h:145
std::unordered_map< std::string, Any > ServiceProperties
Provides the MITK_DECLARE_SERVICE_INTERFACE macro for registering C++ interfaces with both the CppMic...
#define MITK_DECLARE_SERVICE_INTERFACE(IFace, IId)
Declare a C++ interface for use with CppMicroServices (Qt not available).
Find image slices visible on a given plane.
static const char * replace[]
Dictionary for abbreviating class, module, and namespace names in log output.
itk::RGBPixel< float > Color
Standard RGB color typedef using float components.
Container for position and size on the display.
itk::Point< double, 2 > Size
itk::Point< double, 2 > Position