Medical Imaging Interaction Toolkit  2024.12.00
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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:
42  bool IsGenerateDataRequired(mitk::BaseRenderer *renderer, mitk::Annotation *Annotation);
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 
382  PropertyList *GetPropertyList() const;
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 
404  virtual void RegisterAsMicroservice(us::ServiceProperties props);
405 
409  virtual void UnRegisterMicroservice();
410 
411  void AnnotationModified();
412 
413  mitkClassMacroItkParent(Annotation, itk::Object);
414 
415  protected:
417  Annotation();
418 
420  ~Annotation() override;
421 
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
mitk::Annotation
Base class for all Annotation This class is to be implemented in order to create Annotation which are...
Definition: mitkAnnotation.h:27
us::ServiceProperties
US_UNORDERED_MAP_TYPE< std::string, Any > ServiceProperties
Definition: usServiceProperties.h:42
mitk::BaseProperty
Abstract base class for properties.
Definition: mitkBaseProperty.h:36
mitk::Annotation::Bounds
Container for position and size on the display.
Definition: mitkAnnotation.h:31
mitk::Annotation::BaseLocalStorage::UpdateGenerateDataTime
void UpdateGenerateDataTime()
Definition: mitkAnnotation.h:44
mitkServiceInterface.h
mitk::Annotation::GetProperty
bool GetProperty(T *&property, const std::string &propertyKey) const
Get the property of type T with key propertyKey from the PropertyList of the renderer,...
Definition: mitkAnnotation.h:155
mitk::Annotation::GetProperty
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,...
Definition: mitkAnnotation.h:137
mitk::GenericProperty::GetValue
virtual T GetValue() const
mitk::Annotation::Bounds::Position
itk::Point< double, 2 > Position
Definition: mitkAnnotation.h:33
mitk::Annotation::BaseLocalStorage::GetLastGenerateDataTime
itk::TimeStamp & GetLastGenerateDataTime()
Definition: mitkAnnotation.h:45
mitk::Color
itk::RGBPixel< float > Color
Color Standard RGB color typedef (float)
Definition: mitkColorProperty.h:38
itk::SmartPointer< Self >
mitk::Annotation::GetPropertyValue
bool GetPropertyValue(const std::string &propertyKey, T &value) const
Convenience access method for GenericProperty<T> properties (T being the type of the second parameter...
Definition: mitkAnnotation.h:167
mitk::GenericProperty
Definition: mitkGenericProperty.h:46
mitk::Annotation::US_PROPKEY_AnnotationNAME
static const std::string US_PROPKEY_AnnotationNAME
Definition: mitkAnnotation.h:394
mitk::Annotation::m_PropertyList
PropertyList::Pointer m_PropertyList
BaseRenderer-independent PropertyList.
Definition: mitkAnnotation.h:428
mitkClassMacroItkParent
#define mitkClassMacroItkParent(className, SuperClassName)
Definition: mitkCommon.h:45
mitk
Find image slices visible on a given plane.
Definition: RenderingTests.dox:1
mitk::Annotation::Bounds::Size
itk::Point< double, 2 > Size
Definition: mitkAnnotation.h:34
mitk::Annotation::m_DataReferenceChangedTime
itk::TimeStamp m_DataReferenceChangedTime
Timestamp of the last change of m_Data.
Definition: mitkAnnotation.h:433
mitk::Annotation::US_PROPKEY_AR_ID
static const std::string US_PROPKEY_AR_ID
Definition: mitkAnnotation.h:398
us::Any
Definition: usAny.h:163
MitkCoreExports.h
mitk::Annotation::US_PROPKEY_ID
static const std::string US_PROPKEY_ID
Definition: mitkAnnotation.h:395
mitkCommon.h
mitk::PropertyList
Key-value list holding instances of BaseProperty.
Definition: mitkPropertyList.h:56
usServiceRegistration.h
mitk::Annotation::BaseLocalStorage::m_LastGenerateDataTime
itk::TimeStamp m_LastGenerateDataTime
timestamp of last update of stored data
Definition: mitkAnnotation.h:48
mitk::Annotation::US_PROPKEY_MODIFIED
static const std::string US_PROPKEY_MODIFIED
Definition: mitkAnnotation.h:396
mitk::Annotation::IsOn
bool IsOn(const std::string &propertyKey, bool defaultIsOn=true) const
Convenience access method for boolean properties (instances of BoolProperty). Return value is the val...
Definition: mitkAnnotation.h:252
mitk::BaseRenderer
Definition: mitkBaseRenderer.h:56
mitk::Annotation::US_INTERFACE_NAME
static const std::string US_INTERFACE_NAME
These Constants are used in conjunction with Microservices.
Definition: mitkAnnotation.h:393
us::ServiceRegistration< Self >
MITK_DECLARE_SERVICE_INTERFACE
#define MITK_DECLARE_SERVICE_INTERFACE(IFace, IId)
Definition: mitkServiceInterface.h:26
mitk::Annotation::US_PROPKEY_RENDERER_ID
static const std::string US_PROPKEY_RENDERER_ID
Definition: mitkAnnotation.h:397
mitkBaseRenderer.h
MITKCORE_EXPORT
#define MITKCORE_EXPORT
Definition: MitkCoreExports.h:15
mitk::replace
static const char * replace[]
This is a dictionary to replace long names of classes, modules, etc. to shorter versions in the conso...
Definition: mitkLogDictionary.h:20
mitk::Annotation::BaseLocalStorage
Base class for mapper specific rendering resources.
Definition: mitkAnnotation.h:39