Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkVtkLogoRepresentation.cxx
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 
14 #include "vtkActor2D.h"
15 #include "vtkCallbackCommand.h"
16 #include "vtkCellArray.h"
17 #include "vtkFloatArray.h"
18 #include "vtkImageData.h"
19 #include "vtkObjectFactory.h"
20 #include "vtkPointData.h"
21 #include "vtkPoints.h"
22 #include "vtkPolyData.h"
23 #include "vtkPolyData.h"
24 #include "vtkPolyDataMapper2D.h"
25 #include "vtkPolyDataMapper2D.h"
26 #include "vtkPropCollection.h"
27 #include "vtkProperty2D.h"
28 #include "vtkRenderer.h"
29 #include "vtkTexture.h"
30 #include "vtkWindow.h"
31 
33 
34 //----------------------------------------------------------------------
35 inline void mitkVtkLogoRepresentation::AdjustImageSize(double /*o*/[2], double borderSize[2], double imageSize[2])
36 {
37  // Scale the image to fit with in the border.
38  // Also update the origin so the image is centered.
39  double r0 = borderSize[0] / imageSize[0];
40  double r1 = borderSize[1] / imageSize[1];
41  if (r0 > r1)
42  {
43  imageSize[0] *= r1;
44  imageSize[1] *= r1;
45  }
46  else
47  {
48  imageSize[0] *= r0;
49  imageSize[1] *= r0;
50  }
51 }
52 
53 //-------------------------------------------------------------------------
55 {
56  if (this->GetMTime() > this->BuildTime || (this->Renderer && this->Renderer->GetVTKWindow() &&
57  this->Renderer->GetVTKWindow()->GetMTime() > this->BuildTime))
58  {
59  // Determine and adjust the size of the image
60  if (this->Image)
61  {
62  double imageSize[2], borderSize[2], o[2];
63  imageSize[0] = 0.0;
64  imageSize[1] = 0.0;
65  // this->Image->Update();
66  if (this->Image->GetDataDimension() == 2)
67  {
68  int dims[3];
69  this->Image->GetDimensions(dims);
70  imageSize[0] = static_cast<double>(dims[0]);
71  imageSize[1] = static_cast<double>(dims[1]);
72  }
73  int *p1 = this->PositionCoordinate->GetComputedDisplayValue(this->Renderer);
74  int *p2 = this->Position2Coordinate->GetComputedDisplayValue(this->Renderer);
75  borderSize[0] = p2[0];
76  borderSize[1] = p2[1];
77  o[0] = static_cast<double>(p1[0]);
78  o[1] = static_cast<double>(p1[1]);
79 
80  // this preserves the image aspect ratio. The image is
81  // centered around the center of the bordered ragion.
82  this->AdjustImageSize(o, borderSize, imageSize);
83 
84  // Update the points
85  this->Texture->SetInputData(this->Image);
86  int *size = this->Renderer->GetSize();
87 
88  switch (this->cornerPosition)
89  {
90  case 0:
91  {
92  this->TexturePoints->SetPoint(0, o[0], o[1], 0.0);
93  this->TexturePoints->SetPoint(1, o[0] + imageSize[0], o[1], 0.0);
94  this->TexturePoints->SetPoint(2, o[0] + imageSize[0], o[1] + imageSize[1], 0.0);
95  this->TexturePoints->SetPoint(3, o[0], o[1] + imageSize[1], 0.0);
96  break;
97  }
98  case 1:
99  {
100  o[0] = size[0] - o[0];
101  this->TexturePoints->SetPoint(0, o[0] - imageSize[0], o[1], 0.0);
102  this->TexturePoints->SetPoint(1, o[0], o[1], 0.0);
103  this->TexturePoints->SetPoint(2, o[0], o[1] + imageSize[1], 0.0);
104  this->TexturePoints->SetPoint(3, o[0] - imageSize[0], o[1] + imageSize[1], 0.0);
105  break;
106  }
107  case 2:
108  {
109  o[0] = size[0] - o[0];
110  o[1] = size[1] - o[1];
111  this->TexturePoints->SetPoint(0, o[0] - imageSize[0], o[1] - imageSize[1], 0.0);
112  this->TexturePoints->SetPoint(1, o[0], o[1] - imageSize[1], 0.0);
113  this->TexturePoints->SetPoint(2, o[0], o[1], 0.0);
114  this->TexturePoints->SetPoint(3, o[0] - imageSize[0], o[1], 0.0);
115  break;
116  }
117  case 3:
118  {
119  o[1] = size[1] - o[1];
120  this->TexturePoints->SetPoint(0, o[0], o[1] - imageSize[1], 0.0);
121  this->TexturePoints->SetPoint(1, o[0] + imageSize[0], o[1] - imageSize[1], 0.0);
122  this->TexturePoints->SetPoint(2, o[0] + imageSize[0], o[1], 0.0);
123  this->TexturePoints->SetPoint(3, o[0], o[1], 0.0);
124  break;
125  }
126  case 4:
127  {
128  double ish[2];
129  // ish = middle of the image
130  ish[0] = imageSize[0] / 2.0;
131  ish[1] = imageSize[1] / 2.0;
132  // o = middle of the window
133  o[0] = (size[0]) / 2.0;
134  o[1] = (size[1]) / 2.0;
135  this->TexturePoints->SetPoint(0, o[0] - ish[0], o[1] - ish[1], 0.0);
136  this->TexturePoints->SetPoint(1, o[0] + ish[0], o[1] - ish[1], 0.0);
137  this->TexturePoints->SetPoint(2, o[0] + ish[0], o[1] + ish[1], 0.0);
138  this->TexturePoints->SetPoint(3, o[0] - ish[0], o[1] + ish[1], 0.0);
139  break;
140  }
141  default:
142  {
143  this->TexturePoints->SetPoint(0, o[0], o[1], 0.0);
144  this->TexturePoints->SetPoint(1, o[0] + imageSize[0], o[1], 0.0);
145  this->TexturePoints->SetPoint(2, o[0] + imageSize[0], o[1] + imageSize[1], 0.0);
146  this->TexturePoints->SetPoint(3, o[0], o[1] + imageSize[1], 0.0);
147  }
148  }
149  }
150  }
151  this->TexturePoints->Modified();
152 }
153 
155 {
156 }
157 
159 {
160 }
161 
162 //-------------------------------------------------------------------------
163 void mitkVtkLogoRepresentation::PrintSelf(ostream &os, vtkIndent indent)
164 {
165  this->Superclass::PrintSelf(os, indent);
166 
167  if (this->Image)
168  {
169  os << indent << "Image:\n";
170  this->Image->PrintSelf(os, indent.GetNextIndent());
171  }
172  else
173  {
174  os << indent << "Image: (none)\n";
175  }
176 
177  if (this->ImageProperty)
178  {
179  os << indent << "Image Property:\n";
180  this->ImageProperty->PrintSelf(os, indent.GetNextIndent());
181  }
182  else
183  {
184  os << indent << "Image Property: (none)\n";
185  }
186 }
void PrintSelf(ostream &os, vtkIndent indent) override
class ITK_EXPORT Image
void AdjustImageSize(double o[2], double borderSize[2], double imageSize[2]) override
vtkStandardNewMacro(mitkVtkLogoRepresentation)