Medical Imaging Interaction Toolkit  2018.4.99-a3d2e8fb
Medical Imaging Interaction Toolkit
mitkLogoAnnotation.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 (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 #include "mitkLogoAnnotation.h"
14 #include <mitkIOUtil.h>
15 #include "vtkUnicodeString.h"
16 #include <vtkImageData.h>
17 #include <vtkImageData.h>
18 #include <vtkImageMapper.h>
19 #include <vtkImageMapper.h>
20 #include <vtkImageReader2.h>
21 #include <vtkImageReader2Factory.h>
22 #include <vtkTextActor.h>
23 #include <vtkTextProperty.h>
24 #include <vtkTextRenderer.h>
25 #include <vtkTextRendererStringToImage.h>
26 
28 #include <vtkImageImport.h>
29 #include <vtkProperty2D.h>
30 #include <vtkImageFlip.h>
31 #include <vtkNew.h>
32 
34 {
35  m_readerFactory = vtkSmartPointer<vtkImageReader2Factory>::New();
37  offset.Fill(0.03);
38  SetOffsetVector(offset);
39  SetRelativeSize(0.2);
40  SetLogoImagePath("mbiLogo");
42  m_VtkImageImport = vtkSmartPointer<vtkImageImport>::New();
43  m_UpdatedLogoImage = vtkSmartPointer<vtkImageData>::New();
44 }
45 
47 {
48  for (BaseRenderer *renderer : m_LSH.GetRegisteredBaseRenderer())
49  {
50  if (renderer)
51  {
52  this->RemoveFromBaseRenderer(renderer);
53  }
54  }
55 }
56 
58 {
59 }
60 
62 {
63  m_LogoRep = vtkSmartPointer<mitkVtkLogoRepresentation>::New();
64 }
65 
67 {
68  LocalStorage *ls = this->m_LSH.GetLocalStorage(renderer);
69  if (ls->IsGenerateDataRequired(renderer, this))
70  {
71  ls->m_LogoImage = m_UpdatedLogoImage;
72 
73  ls->m_LogoRep->SetImage(ls->m_LogoImage);
74  ls->m_LogoRep->SetDragable(false);
75  ls->m_LogoRep->SetMoving(false);
76  ls->m_LogoRep->SetPickable(false);
77  ls->m_LogoRep->SetShowBorder(true);
78  ls->m_LogoRep->SetRenderer(renderer->GetVtkRenderer());
79  float size = GetRelativeSize();
80  ls->m_LogoRep->SetPosition2(size, size);
81  int corner = GetCornerPosition();
82  ls->m_LogoRep->SetCornerPosition(corner);
84  ls->m_LogoRep->SetPosition(offset[0], offset[1]);
85  float opacity = 1.0;
86  GetOpacity(opacity);
87  ls->m_LogoRep->GetImageProperty()->SetOpacity(opacity);
88  ls->m_LogoRep->BuildRepresentation();
90  }
91 }
92 
94 {
95  SetStringProperty("Annotation.LogoImagePath", path.c_str());
96  Modified();
97 }
98 
100 {
101  auto imageNodeVector = mitk::IOUtil::Load(this->GetLogoImagePath());
102 
103  if (imageNodeVector.size() == 1)
104  {
105  mitk::Image::Pointer image = dynamic_cast<mitk::Image *>(imageNodeVector.front().GetPointer());
106 
107  if (image.IsNotNull())
108  {
109  vtkNew<vtkImageFlip> flip;
110  flip->SetInputData(image->GetVtkImageData());
111  flip->SetFilteredAxis(1);
112  flip->Update();
113  m_UpdatedLogoImage->DeepCopy(flip->GetOutput());
114  Modified();
115  }
116  }
117 }
118 
119 void mitk::LogoAnnotation::SetLogoImage(vtkSmartPointer<vtkImageData> logo)
120 {
121  m_UpdatedLogoImage = logo;
122  Modified();
123 }
124 
126 {
127  std::string path;
128  GetPropertyList()->GetStringProperty("Annotation.LogoImagePath", path);
129  return path;
130 }
131 
133 {
134  mitk::Point2dProperty::Pointer OffsetVectorProperty = mitk::Point2dProperty::New(OffsetVector);
135  SetProperty("Annotation.OffsetVector", OffsetVectorProperty.GetPointer());
136  Modified();
137 }
138 
140 {
141  mitk::Point2D OffsetVector;
142  OffsetVector.Fill(0);
143  GetPropertyValue<mitk::Point2D>("Annotation.OffsetVector", OffsetVector);
144  return OffsetVector;
145 }
146 
148 {
149  SetIntProperty("Annotation.CornerPosition", corner);
150  Modified();
151 }
152 
154 {
155  int corner = 0;
156  GetIntProperty("Annotation.CornerPosition", corner);
157  return corner;
158 }
159 
161 {
162  SetFloatProperty("Annotation.RelativeSize", size);
163  Modified();
164 }
165 
167 {
168  float size = 0;
169  GetFloatProperty("Annotation.RelativeSize", size);
170  return size;
171 }
172 
174 {
175  LocalStorage *ls = this->m_LSH.GetLocalStorage(renderer);
176  return ls->m_LogoRep;
177 }
#define ls
Definition: MitkMCxyz.cpp:57
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 ...
L * GetLocalStorage(mitk::BaseRenderer *forRenderer)
Retrieves a LocalStorage for a specific BaseRenderer.
LogoAnnotation()
explicit constructor which disallows implicit conversions
std::vector< mitk::BaseRenderer * > GetRegisteredBaseRenderer()
bool GetFloatProperty(const std::string &propertyKey, float &floatValue) const
Convenience access method for float properties (instances of FloatProperty)
vtkRenderer * GetVtkRenderer() const
LocalStorage()
Default constructor of the local storage.
Organizes the rendering process.
bool IsGenerateDataRequired(mitk::BaseRenderer *renderer, mitk::Annotation *Annotation)
mitk::LocalStorageHandler< LocalStorage > m_LSH
The LocalStorageHandler holds all LocalStorages for the render windows.
~LogoAnnotation() override
virtual destructor in order to derive from this class
void SetCornerPosition(const int &corner)
The corner where the logo is displayed. 0 = Bottom left 1 = Bottom right 2 = Top right 3 = Top left 4...
void SetLogoImage(vtkSmartPointer< vtkImageData > logo)
static Pointer New()
Point2D GetOffsetVector() const
static Vector3D offset
vtkSmartPointer< vtkImageData > m_LogoImage
Actor of a 2D render window.
bool GetStringProperty(const char *propertyKey, std::string &stringValue) const
Convenience method to access the value of a StringProperty.
void SetStringProperty(const std::string &propertyKey, const std::string &string)
Convenience method for setting int properties (instances of IntProperty)
Image class for storing images.
Definition: mitkImage.h:72
void SetFloatProperty(const std::string &propertyKey, float floatValue)
Convenience method for setting int properties (instances of IntProperty)
mitk::Image::Pointer image
vtkSmartPointer< mitkVtkLogoRepresentation > m_LogoRep
void RemoveFromBaseRenderer(BaseRenderer *renderer) override
Removes the Annotation from the specified renderer. It is not visible anymore then.
vtkProp * GetVtkProp(BaseRenderer *renderer) const override
This method is implemented by the specific VTKAnnotation in order to create the element as a vtkProp...
void UpdateVtkAnnotation(mitk::BaseRenderer *renderer) override
bool GetOpacity(float &opacity, const std::string &propertyKey="opacity") const
Convenience access method for opacity properties (instances of FloatProperty)
void SetOffsetVector(const Point2D &OffsetVector)
The relative offset to the corner position.
~LocalStorage()
Default deconstructor of the local storage.
void SetRelativeSize(const float &size)
PropertyList * GetPropertyList() const
void SetLogoImagePath(std::string text)
void SetIntProperty(const std::string &propertyKey, int intValue)
Convenience method for setting int properties (instances of IntProperty)
std::string GetLogoImagePath() const
bool GetIntProperty(const std::string &propertyKey, int &intValue) const
Convenience access method for int properties (instances of IntProperty)
static DataStorage::SetOfObjects::Pointer Load(const std::string &path, DataStorage &storage, const ReaderOptionsFunctorBase *optionsCallback=nullptr)
Load a file into the given DataStorage.
Definition: mitkIOUtil.cpp:489
vtkSmartPointer< vtkImageReader2Factory > m_readerFactory