Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkTextOverlay2D.cpp
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #include "mitkTextOverlay2D.h"
18 #include "vtkUnicodeString.h"
19 #include <vtkPropAssembly.h>
20 #include <vtkTextActor.h>
21 #include <vtkTextProperty.h>
22 
24 {
25  mitk::Point2D position;
26  position[0] = position[1] = 0;
27  this->SetPosition2D(position);
28  this->SetOffsetVector(position);
29  this->SetText("");
30  this->SetFontSize(20);
31  this->SetColor(1.0, 1.0, 1.0);
32  this->SetStringProperty("font.family", "Arial");
33  this->SetBoolProperty("font.bold", false);
34  this->SetBoolProperty("font.italic", false);
35  this->SetBoolProperty("drawShadow", false);
36 }
37 
39 {
40 }
41 
43 {
44  LocalStorage *ls = this->m_LSH.GetLocalStorage(renderer);
45  mitk::Overlay::Bounds bounds;
46  bounds.Position = ls->m_TextActor->GetPosition();
47 
48  double size[2];
49  ls->m_TextActor->GetSize(renderer->GetVtkRenderer(), size);
50  bounds.Size[0] = size[0];
51  bounds.Size[1] = size[1];
52  return bounds;
53 }
54 
56 {
57  LocalStorage *ls = this->m_LSH.GetLocalStorage(renderer);
58 
59  mitk::Point2D posT, posS;
60  posT[0] = bounds.Position[0];
61  posT[1] = bounds.Position[1];
62  posS[0] = posT[0] + 1;
63  posS[1] = posT[1] - 1;
64 
65  ls->m_TextActor->SetDisplayPosition(posT[0], posT[1]);
66  ls->m_STextActor->SetDisplayPosition(posS[0], posS[1]);
67 }
68 
70 {
71 }
72 
74 {
75  m_TextActor = vtkSmartPointer<vtkTextActor>::New();
77  m_STextActor = vtkSmartPointer<vtkTextActor>::New();
79  m_TextActor->SetTextProperty(m_TextProp);
80  m_STextActor->SetTextProperty(m_STextProp);
82  m_Assembly->AddPart(m_STextActor);
83  m_Assembly->AddPart(m_TextActor);
84 }
85 
87 {
88  LocalStorage *ls = this->m_LSH.GetLocalStorage(renderer);
89 
90  if (ls->IsGenerateDataRequired(renderer, this))
91  {
92  float color[3] = {0.0, 1.0, 0.0};
93  float opacity = 1.0;
94  GetColor(color, renderer);
95  GetOpacity(opacity, renderer);
96  ls->m_TextProp->SetColor(color[0], color[1], color[2]);
97  ls->m_STextProp->SetColor(0, 0, 0);
98  ls->m_TextProp->SetFontSize(GetFontSize());
99  ls->m_TextProp->SetOpacity(opacity);
100  ls->m_STextProp->SetFontSize(GetFontSize());
101  ls->m_STextProp->SetOpacity(opacity);
102 
103  std::string fontFamilyAsString;
104  if (GetStringProperty("font.family", fontFamilyAsString) == false)
105  {
106  fontFamilyAsString = "Arial";
107  }
108  ls->m_TextProp->SetFontFamilyAsString(fontFamilyAsString.c_str());
109  ls->m_STextProp->SetFontFamilyAsString(fontFamilyAsString.c_str());
110 
111  bool boldFont(false);
112  GetBoolProperty("font.bold", boldFont);
113  ls->m_TextProp->SetBold(boldFont);
114  ls->m_STextProp->SetBold(boldFont);
115 
116  bool italicFont(false);
117  GetBoolProperty("font.italic", italicFont);
118  ls->m_TextProp->SetBold(italicFont);
119  ls->m_STextProp->SetBold(italicFont);
120 
121  bool drawShadow;
122  GetBoolProperty("drawShadow", drawShadow);
123  ls->m_TextProp->SetShadow(false);
124  ls->m_STextProp->SetShadow(false);
125  ls->m_STextActor->SetVisibility(drawShadow);
126 
127  ls->m_TextActor->SetInput(GetText().c_str());
128  ls->m_STextActor->SetInput(GetText().c_str());
129 
130  mitk::Point2D posT, posS;
131  posT[0] = GetPosition2D(renderer)[0] + GetOffsetVector(renderer)[0];
132  posT[1] = GetPosition2D(renderer)[1] + GetOffsetVector(renderer)[1];
133  posS[0] = posT[0] + 1;
134  posS[1] = posT[1] - 1;
135 
136  ls->m_TextActor->SetDisplayPosition(posT[0], posT[1]);
137  ls->m_STextActor->SetDisplayPosition(posS[0], posS[1]);
139  }
140 }
141 
143 {
144  LocalStorage *ls = this->m_LSH.GetLocalStorage(renderer);
145  return ls->m_Assembly;
146 }
147 
149 {
150  LocalStorage *ls = this->m_LSH.GetLocalStorage(renderer);
151  return ls->m_TextActor;
152 }
TextOverlay2D()
explicit constructor which disallows implicit conversions
LocalStorage()
Default constructor of the local storage.
itk::Point< double, 2 > Size
Definition: mitkOverlay.h:43
Organizes the rendering process.
vtkSmartPointer< vtkTextProperty > m_TextProp
itk::Point< double, 2 > Position
Definition: mitkOverlay.h:42
void SetColor(const mitk::Color &color, mitk::BaseRenderer *renderer=nullptr, const std::string &propertyKey="color")
Convenience method for setting color properties (instances of ColorProperty)
void SetOffsetVector(const Point2D &OffsetVector, BaseRenderer *renderer=NULL)
virtual vtkActor2D * GetVtkActor2D(BaseRenderer *renderer) const override
virtual ~TextOverlay2D()
virtual destructor in order to derive from this class
vtkSmartPointer< vtkTextActor > m_STextActor
vtkSmartPointer< vtkPropAssembly > m_Assembly
void SetFontSize(int fontSize, mitk::BaseRenderer *renderer=nullptr)
vtkSmartPointer< vtkTextProperty > m_STextProp
virtual void SetBoundsOnDisplay(BaseRenderer *renderer, const Bounds &bounds) override
Sets position and size of the overlay on the display.
void SetBoolProperty(const std::string &propertyKey, bool boolValue, mitk::BaseRenderer *renderer=nullptr)
Convenience method for setting int properties (instances of IntProperty)
~LocalStorage()
Default deconstructor of the local storage.
virtual Overlay::Bounds GetBoundsOnDisplay(BaseRenderer *renderer) const override
Returns position and size of the overlay on the display.
void SetPosition2D(const Point2D &position2D, mitk::BaseRenderer *renderer=NULL)
bool IsGenerateDataRequired(mitk::BaseRenderer *renderer, mitk::Overlay *overlay)
void SetText(std::string text, mitk::BaseRenderer *renderer=nullptr)
vtkRenderer * GetVtkRenderer() const
vtkProp * GetVtkProp(BaseRenderer *renderer) const override
This method is implemented by the specific VTKOverlays in order to create the element as a vtkProp...
void UpdateVtkOverlay2D(mitk::BaseRenderer *renderer) override
void SetStringProperty(const std::string &propertyKey, const std::string &string, mitk::BaseRenderer *renderer=nullptr)
Convenience method for setting int properties (instances of IntProperty)
Container for position and size on the display.
Definition: mitkOverlay.h:40
vtkSmartPointer< vtkTextActor > m_TextActor
Actor of a 2D render window.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.