Medical Imaging Interaction Toolkit  2018.4.99-6a3ea89d
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 
109  void ConcatenatePropertyList(PropertyList *pList, bool replace = false);
110 
122  mitk::BaseProperty *GetProperty(const std::string &propertyKey) const;
123 
135  template <typename T>
136  bool GetProperty(itk::SmartPointer<T> &property, const std::string &propertyKey) const
137  {
138  property = dynamic_cast<T *>(GetProperty(propertyKey));
139  return property.IsNotNull();
140  }
141 
153  template <typename T>
154  bool GetProperty(T *&property, const std::string &propertyKey) const
155  {
156  property = dynamic_cast<T *>(GetProperty(propertyKey));
157  return property != nullptr;
158  }
159 
165  template <typename T>
166  bool GetPropertyValue(const std::string &propertyKey, T &value) const
167  {
168  GenericProperty<T> *gp = dynamic_cast<GenericProperty<T> *>(GetProperty(propertyKey));
169  if (gp != nullptr)
170  {
171  value = gp->GetValue();
172  return true;
173  }
174  return false;
175  }
176 
182  bool GetBoolProperty(const std::string &propertyKey, bool &boolValue) const;
183 
189  bool GetIntProperty(const std::string &propertyKey, int &intValue) const;
190 
196  bool GetFloatProperty(const std::string &propertyKey, float &floatValue) const;
197 
203  bool GetDoubleProperty(const std::string &propertyKey, double &doubleValue) const;
204 
210  bool GetStringProperty(const std::string &propertyKey, std::string &string) const;
211 
216  void SetIntProperty(const std::string &propertyKey, int intValue);
217 
222  void SetBoolProperty(const std::string &propertyKey, bool boolValue);
223 
228  void SetFloatProperty(const std::string &propertyKey, float floatValue);
229 
234  void SetDoubleProperty(const std::string &propertyKey, double doubleValue);
235 
240  void SetStringProperty(const std::string &propertyKey, const std::string &string);
241 
251  bool IsOn(const std::string &propertyKey, bool defaultIsOn = true) const
252  {
253  GetBoolProperty(propertyKey, defaultIsOn);
254  return defaultIsOn;
255  }
256 
262  bool GetName(std::string &nodeName, const std::string &propertyKey = "name") const;
263 
273  virtual std::string GetName() const;
274 
280  virtual void SetName(const std::string &name);
281 
287  bool GetColor(float rgb[], const std::string &propertyKey = "color") const;
292  void SetColor(const mitk::Color &color, const std::string &propertyKey = "color");
297  void SetColor(float red, float green, float blue, const std::string &propertyKey = "color");
302  void SetColor(const float rgb[], const std::string &propertyKey = "color");
308  bool GetOpacity(float &opacity, const std::string &propertyKey = "opacity") const;
313  void SetOpacity(float opacity, const std::string &propertyKey = "opacity");
314 
315  void SetText(std::string text);
316 
317  std::string GetText() const;
318 
319  void SetFontSize(int fontSize);
320 
321  int GetFontSize() const;
322 
329  bool GetVisibility(bool &visible, const std::string &propertyKey = "visible") const;
330 
342  bool IsVisible(const std::string &propertyKey = "visible", bool defaultIsOn = true) const;
343 
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
signed integer value
Definition: jsoncpp.h:348
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.
static void Update(vtkPolyData *)
Definition: mitkSurface.cpp:31
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:49
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 std::string GetName(std::string fileName, std::string suffix)
static const std::string US_PROPKEY_MODIFIED