Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkLogoOverlay.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 "mitkLogoOverlay.h"
18 #include "vtkUnicodeString.h"
19 #include <vtkImageData.h>
20 #include <vtkImageData.h>
21 #include <vtkImageMapper.h>
22 #include <vtkImageMapper.h>
23 #include <vtkImageReader2.h>
24 #include <vtkImageReader2Factory.h>
25 #include <vtkTextActor.h>
26 #include <vtkTextProperty.h>
27 #include <vtkTextRenderer.h>
28 #include <vtkTextRendererStringToImage.h>
29 
30 #include <mbilogo.h>
32 #include <vtkImageImport.h>
33 #include <vtkProperty2D.h>
34 
36 {
39  offset.Fill(0.03);
40  SetOffsetVector(offset);
41  SetRelativeSize(0.2);
43  m_VtkImageImport = vtkSmartPointer<vtkImageImport>::New();
44 }
45 
47 {
48 }
49 
51 {
52 }
53 
55 {
57 }
58 
60 {
61  LocalStorage *ls = this->m_LSH.GetLocalStorage(renderer);
62  if (ls->IsGenerateDataRequired(renderer, this))
63  {
64  if (GetLogoImagePath().empty())
65  {
66  ls->m_LogoRep->SetVisibility(0);
67  return;
68  }
69  vtkImageReader2 *imageReader = m_readerFactory->CreateImageReader2(GetLogoImagePath().c_str());
70  if (imageReader)
71  {
72  imageReader->SetFileName(GetLogoImagePath().c_str());
73  imageReader->Update();
74  ls->m_LogoImage = imageReader->GetOutput();
75  imageReader->Delete();
76  }
77  else
78  {
79  ls->m_LogoImage = CreateMbiLogo();
80  }
81 
82  ls->m_LogoRep->SetImage(ls->m_LogoImage);
83  ls->m_LogoRep->SetDragable(false);
84  ls->m_LogoRep->SetMoving(false);
85  ls->m_LogoRep->SetPickable(false);
86  ls->m_LogoRep->SetShowBorder(true);
87  ls->m_LogoRep->SetRenderer(renderer->GetVtkRenderer());
88  float size = GetRelativeSize(renderer);
89  ls->m_LogoRep->SetPosition2(size, size);
90  int corner = GetCornerPosition(renderer);
91  ls->m_LogoRep->SetCornerPosition(corner);
92  mitk::Point2D offset = GetOffsetVector(renderer);
93  ls->m_LogoRep->SetPosition(offset[0], offset[1]);
94  float opacity = 1.0;
95  GetOpacity(opacity, renderer);
96  ls->m_LogoRep->GetImageProperty()->SetOpacity(opacity);
97  ls->m_LogoRep->BuildRepresentation();
99  }
100 }
101 
103 {
104  m_VtkImageImport->SetDataScalarTypeToUnsignedChar();
105  m_VtkImageImport->SetNumberOfScalarComponents(mbiLogo_NumberOfScalars);
106  m_VtkImageImport->SetWholeExtent(0, mbiLogo_Width - 1, 0, mbiLogo_Height - 1, 0, 1 - 1);
107  m_VtkImageImport->SetDataExtentToWholeExtent();
108 
109  char *ImageData;
110  // flip mbi logo around y axis and change color order
111  ImageData = new char[mbiLogo_Height * mbiLogo_Width * mbiLogo_NumberOfScalars];
112 
113  unsigned int column, row;
114  char *dest = ImageData;
115  char *source = (char *)&mbiLogo_Data[0];
116  ;
117  char r, g, b, a;
118  for (column = 0; column < mbiLogo_Height; column++)
119  for (row = 0; row < mbiLogo_Width; row++)
120  { // change r with b
121  b = *source++;
122  g = *source++;
123  r = *source++;
124  a = *source++;
125 
126  *dest++ = r;
127  *dest++ = g;
128  *dest++ = b;
129  *dest++ = a;
130  }
131 
132  m_VtkImageImport->SetImportVoidPointer(ImageData);
133  m_VtkImageImport->Modified();
134  m_VtkImageImport->Update();
135  return m_VtkImageImport->GetOutput();
136 }
137 
139 {
140  SetStringProperty("Overlay.LogoImagePath", path.c_str());
141  Modified();
142 }
143 
145 {
146  std::string path;
147  GetPropertyList()->GetStringProperty("Overlay.LogoImagePath", path);
148  return path;
149 }
150 
152 {
153  mitk::Point2dProperty::Pointer OffsetVectorProperty = mitk::Point2dProperty::New(OffsetVector);
154  SetProperty("Overlay.OffsetVector", OffsetVectorProperty.GetPointer(), renderer);
155  Modified();
156 }
157 
159 {
160  mitk::Point2D OffsetVector;
161  OffsetVector.Fill(0);
162  GetPropertyValue<mitk::Point2D>("Overlay.OffsetVector", OffsetVector, renderer);
163  return OffsetVector;
164 }
165 
167 {
168  SetIntProperty("Overlay.CornerPosition", corner, renderer);
169  Modified();
170 }
171 
173 {
174  int corner = 0;
175  GetIntProperty("Overlay.CornerPosition", corner, renderer);
176  return corner;
177 }
178 
179 void mitk::LogoOverlay::SetRelativeSize(const float &size, mitk::BaseRenderer *renderer)
180 {
181  SetFloatProperty("Overlay.RelativeSize", size, renderer);
182  Modified();
183 }
184 
186 {
187  float size = 0;
188  GetFloatProperty("Overlay.RelativeSize", size, renderer);
189  return size;
190 }
191 
193 {
194  LocalStorage *ls = this->m_LSH.GetLocalStorage(renderer);
195  return ls->m_LogoRep;
196 }
void SetLogoImagePath(std::string text)
LocalStorage()
Default constructor of the local storage.
void SetCornerPosition(const int &corner, BaseRenderer *renderer=NULL)
The corner where the logo is displayed. 0 = Bottom left 1 = Bottom right 2 = Top right 3 = Top left 4...
vtkSmartPointer< mitkVtkLogoRepresentation > m_LogoRep
virtual vtkProp * GetVtkProp(BaseRenderer *renderer) const override
This method is implemented by the specific VTKOverlays in order to create the element as a vtkProp...
LogoOverlay()
explicit constructor which disallows implicit conversions
void UpdateVtkOverlay(mitk::BaseRenderer *renderer) override
static const unsigned int mbiLogo_Data[]
Definition: mbilogo.h:32
Point2D GetOffsetVector(mitk::BaseRenderer *renderer=NULL) const
Organizes the rendering process.
virtual ~LogoOverlay()
virtual destructor in order to derive from this class
vtkImageData * CreateMbiLogo()
std::string GetLogoImagePath() const
static Pointer New()
void SetRelativeSize(const float &size, BaseRenderer *renderer=NULL)
static const unsigned int mbiLogo_Height
Definition: mbilogo.h:31
static Vector3D offset
vtkSmartPointer< vtkImageData > m_LogoImage
Actor of a 2D render window.
static const unsigned int mbiLogo_Width
Definition: mbilogo.h:30
void SetOffsetVector(const Point2D &OffsetVector, BaseRenderer *renderer=NULL)
The relative offset to the corner position.
vtkSmartPointer< vtkImageReader2Factory > m_readerFactory
~LocalStorage()
Default deconstructor of the local storage.
float GetRelativeSize(mitk::BaseRenderer *renderer=NULL) const
bool IsGenerateDataRequired(mitk::BaseRenderer *renderer, mitk::Overlay *overlay)
vtkRenderer * GetVtkRenderer() const
static const unsigned int mbiLogo_NumberOfScalars
Definition: mbilogo.h:29
int GetCornerPosition(mitk::BaseRenderer *renderer=NULL) const
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.