Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkOverlay2DLayouter.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 "mitkOverlay2DLayouter.h"
18 
20 {
21  static const std::string s = "STANDARD_2D_TOPLEFT";
22  return s;
23 }
25 {
26  static const std::string s = "STANDARD_2D_TOP";
27  return s;
28 }
30 {
31  static const std::string s = "STANDARD_2D_TOPRIGHT";
32  return s;
33 }
35 {
36  static const std::string s = "STANDARD_2D_BOTTOMLEFT";
37  return s;
38 }
40 {
41  static const std::string s = "STANDARD_2D_BOTTOM";
42  return s;
43 }
45 {
46  static const std::string s = "STANDARD_2D_BOTTOMRIGHT";
47  return s;
48 }
49 
51 {
52  m_Margin = 5;
53 }
54 
56 {
57 }
58 
60  mitk::BaseRenderer *renderer)
61 {
62  if (renderer == NULL)
63  return NULL;
64  Alignment alignment;
65  if (identifier.compare(0, 11, "STANDARD_2D") != 0)
66  return NULL;
67  if (identifier.compare(STANDARD_2D_TOPLEFT()) == 0)
68  alignment = TopLeft;
69  else if (identifier.compare(STANDARD_2D_TOP()) == 0)
70  alignment = Top;
71  else if (identifier.compare(STANDARD_2D_TOPRIGHT()) == 0)
72  alignment = TopRight;
73  else if (identifier.compare(STANDARD_2D_BOTTOMLEFT()) == 0)
74  alignment = BottomLeft;
75  else if (identifier.compare(STANDARD_2D_BOTTOM()) == 0)
76  alignment = Bottom;
77  else if (identifier.compare(STANDARD_2D_BOTTOMRIGHT()) == 0)
78  alignment = BottomRight;
79  else
80  return NULL;
81 
83  layouter->m_Alignment = alignment;
84  layouter->m_Identifier = identifier;
85  layouter->SetBaseRenderer(renderer);
86  return layouter;
87 }
88 
90  mitk::BaseRenderer *renderer)
91 {
92  if (renderer == NULL)
93  return NULL;
94  std::string identifier;
95  switch (alignment)
96  {
97  case TopLeft:
98  identifier = STANDARD_2D_TOPLEFT();
99  break;
100  case Top:
101  identifier = STANDARD_2D_TOP();
102  break;
103  case TopRight:
104  identifier = STANDARD_2D_TOPRIGHT();
105  break;
106  case BottomLeft:
107  identifier = STANDARD_2D_BOTTOMLEFT();
108  break;
109  case Bottom:
110  identifier = STANDARD_2D_BOTTOM();
111  break;
112  case BottomRight:
113  identifier = STANDARD_2D_BOTTOMRIGHT();
114  break;
115  default:
116  return NULL;
117  }
118 
120  layouter->m_Alignment = alignment;
121  layouter->m_Identifier = identifier;
122  layouter->SetBaseRenderer(renderer);
123  return layouter;
124 }
125 
127 {
128  std::list<mitk::Overlay *> managedOverlays = GetManagedOverlays();
129  std::list<mitk::Overlay *>::iterator it;
130  mitk::Overlay::Bounds bounds;
131  double posX, posY;
132  int *size = GetBaseRenderer()->GetVtkRenderer()->GetSize();
133 
134  // The alignment enum defines the type of this layouter
135  switch (m_Alignment)
136  {
137  case TopLeft:
138  posX = m_Margin;
139  posY = size[1] - m_Margin;
140  for (it = managedOverlays.begin(); it != managedOverlays.end(); it++)
141  {
142  mitk::Overlay *overlay = *it;
143  bounds = overlay->GetBoundsOnDisplay(this->GetBaseRenderer());
144  posY -= bounds.Size[1];
145  bounds.Position[0] = posX;
146  bounds.Position[1] = posY;
147  overlay->SetBoundsOnDisplay(this->GetBaseRenderer(), bounds);
148  posY -= m_Margin;
149  }
150  break;
151  default:
152  break;
153  case Top:
154  posX = 0;
155  posY = size[1] - m_Margin;
156  for (it = managedOverlays.begin(); it != managedOverlays.end(); it++)
157  {
158  mitk::Overlay *overlay = *it;
159  bounds = overlay->GetBoundsOnDisplay(this->GetBaseRenderer());
160  posX = size[0] / 2 - bounds.Size[0] / 2;
161  posY -= bounds.Size[1];
162  bounds.Position[0] = posX;
163  bounds.Position[1] = posY;
164  overlay->SetBoundsOnDisplay(this->GetBaseRenderer(), bounds);
165  posY -= m_Margin;
166  }
167  break;
168  case TopRight:
169  posX = 0;
170  posY = size[1] - m_Margin;
171  for (it = managedOverlays.begin(); it != managedOverlays.end(); it++)
172  {
173  mitk::Overlay *overlay = *it;
174  bounds = overlay->GetBoundsOnDisplay(this->GetBaseRenderer());
175  posX = size[0] - (bounds.Size[0] + m_Margin);
176  posY -= bounds.Size[1];
177  bounds.Position[0] = posX;
178  bounds.Position[1] = posY;
179  overlay->SetBoundsOnDisplay(this->GetBaseRenderer(), bounds);
180  posY -= m_Margin;
181  }
182  break;
183  case BottomLeft:
184  posX = m_Margin;
185  posY = m_Margin;
186  for (it = managedOverlays.begin(); it != managedOverlays.end(); it++)
187  {
188  mitk::Overlay *overlay = *it;
189  bounds = overlay->GetBoundsOnDisplay(this->GetBaseRenderer());
190  bounds.Position[0] = posX;
191  bounds.Position[1] = posY;
192  overlay->SetBoundsOnDisplay(this->GetBaseRenderer(), bounds);
193  posY += bounds.Size[1];
194  posY += m_Margin;
195  }
196  break;
197  case Bottom:
198  posX = 0;
199  posY = m_Margin;
200  for (it = managedOverlays.begin(); it != managedOverlays.end(); it++)
201  {
202  mitk::Overlay *overlay = *it;
203  bounds = overlay->GetBoundsOnDisplay(this->GetBaseRenderer());
204  posX = size[0] / 2 - bounds.Size[0] / 2;
205  bounds.Position[0] = posX;
206  bounds.Position[1] = posY;
207  overlay->SetBoundsOnDisplay(this->GetBaseRenderer(), bounds);
208  posY += bounds.Size[1];
209  posY += m_Margin;
210  }
211  break;
212  case BottomRight:
213  posX = 0;
214  posY = m_Margin;
215  for (it = managedOverlays.begin(); it != managedOverlays.end(); it++)
216  {
217  mitk::Overlay *overlay = *it;
218  bounds = overlay->GetBoundsOnDisplay(this->GetBaseRenderer());
219  posX = size[0] - (bounds.Size[0] + m_Margin);
220  bounds.Position[0] = posX;
221  bounds.Position[1] = posY;
222  overlay->SetBoundsOnDisplay(this->GetBaseRenderer(), bounds);
223  posY += bounds.Size[1];
224  posY += m_Margin;
225  }
226  break;
227  }
228 }
void PrepareLayout() override
Sets the positions of each managed overlay according to the layouter role.
virtual void SetBoundsOnDisplay(BaseRenderer *renderer, const Bounds &)
Sets position and size of the overlay on the display.
itk::SmartPointer< Self > Pointer
virtual Bounds GetBoundsOnDisplay(BaseRenderer *renderer) const
Returns position and size of the overlay on the display.
static Pointer New()
itk::Point< double, 2 > Size
Definition: mitkOverlay.h:43
Organizes the rendering process.
static std::string STANDARD_2D_TOPLEFT()
Overlay2DLayouter()
explicit constructor which disallows implicit conversions
static std::string STANDARD_2D_BOTTOM()
itk::Point< double, 2 > Position
Definition: mitkOverlay.h:42
virtual ~Overlay2DLayouter()
virtual destructor in order to derive from this class
static std::string STANDARD_2D_TOP()
static std::string STANDARD_2D_BOTTOMLEFT()
static std::string STANDARD_2D_BOTTOMRIGHT()
Base class for all overlays.
Definition: mitkOverlay.h:34
static Overlay2DLayouter::Pointer CreateLayouter(Alignment alignment, BaseRenderer *renderer)
Factory method for the different kinds of Layouters.
static std::string STANDARD_2D_TOPRIGHT()
Container for position and size on the display.
Definition: mitkOverlay.h:40