Medical Imaging Interaction Toolkit  2022.04.99-b2814023
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 Annotation_H
14 #define Annotation_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 
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 // Annotation_H
#define MITK_DECLARE_SERVICE_INTERFACE(IFace, IId)
#define MITKCORE_EXPORT
Container for position and size on the display.
PropertyList::Pointer m_PropertyList
BaseRenderer-independent PropertyList.
bool IsOn(const std::string &propertyKey, bool defaultIsOn=true) const
Convenience access method for boolean properties (instances of BoolProperty). Return value is the val...
itk::Point< double, 2 > Size
static const std::string US_PROPKEY_ID
Organizes the rendering process.
DataCollection - Class to facilitate loading/accessing structured data.
itk::TimeStamp m_LastGenerateDataTime
timestamp of last update of stored data
itk::TimeStamp & GetLastGenerateDataTime()
Key-value list holding instances of BaseProperty.
Base class for mapper specific rendering ressources.
static const std::string US_INTERFACE_NAME
These Constants are used in conjunction with Microservices.
virtual T GetValue() const
itk::TimeStamp m_DataReferenceChangedTime
Timestamp of the last change of m_Data.
static const std::string US_PROPKEY_AnnotationNAME
Abstract base class for properties.
itk::Point< double, 2 > Position
bool GetProperty(T *&property, const std::string &propertyKey) const
Get the property of type T with key propertyKey from the PropertyList of the renderer, if available there, otherwise use the BaseRenderer-independent PropertyList.
#define mitkClassMacroItkParent(className, SuperClassName)
Definition: mitkCommon.h:45
Definition: usAny.h:163
bool GetPropertyValue(const std::string &propertyKey, T &value) const
Convenience access method for GenericProperty<T> properties (T being the type of the second parameter...
itk::RGBPixel< float > Color
Color Standard RGB color typedef (float)
US_UNORDERED_MAP_TYPE< std::string, Any > ServiceProperties
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, if available there, otherwise use the BaseRenderer-independent PropertyList.
Base class for all Annotation This class is to be implemented in order to create Annotation which are...
static const std::string US_PROPKEY_RENDERER_ID
static const std::string US_PROPKEY_AR_ID
static const char * replace[]
This is a dictionary to replace long names of classes, modules, etc. to shorter versions in the conso...
static const std::string US_PROPKEY_MODIFIED