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