Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
QmitkMultiWidgetDecorationManager.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 
14 
15 // org mitk gui common plugin
16 #include <mitkIRenderWindowPart.h>
17 
18 // mitk annotation module
20 
21 // mitk qt widgets module
23 
24 // vtk
25 #include <vtkQImageToImageSource.h>
26 
27 // qt
28 #include <QColor>
29 
31  : m_MultiWidget(multiWidget)
32  , m_LogoAnnotation(mitk::LogoAnnotation::New())
33 {
34  // nothing here
35 }
36 
38 {
39  // Enable change of logo. If no DepartmentLogo was set explicitly, MBILogo is used.
40  // Set new department logo by prefs->Set("DepartmentLogo", "PathToImage");
41 
42  // If no logo was set for this plug-in specifically, walk the parent preference nodes
43  // and lookup a logo value there.
44 
45  // Disable the logo first, otherwise setting a new logo will have no effect due to how mitkManufacturerLogo works
46  ShowLogo(false);
47  SetupLogo(qPrintable(":/org.mitk.gui.qt.stdmultiwidgeteditor/defaultWatermark.png"));
48  ShowLogo(true);
49 
50  const berry::IPreferences* currentNode = preferences;
51  while (currentNode)
52  {
53  bool logoFound = false;
54  foreach(const QString& key, currentNode->Keys())
55  {
56  if (key == "DepartmentLogo")
57  {
58  ShowLogo(false);
59  QString departmentLogoLocation = currentNode->Get("DepartmentLogo", "");
60  if (!departmentLogoLocation.isEmpty())
61  {
62  SetupLogo(qPrintable(departmentLogoLocation));
63  ShowLogo(true);
64  }
65  logoFound = true;
66  break;
67  }
68  }
69 
70  if (logoFound)
71  {
72  break;
73  }
74  currentNode = currentNode->Parent().GetPointer();
75  }
76 
77  /*
78  QmitkMultiWidgetDecorationManager::Colormap colormap = static_cast<QmitkMultiWidgetDecorationManager::Colormap>(preferences->GetInt("Render window widget colormap", 0));
79  SetColormap(colormap);
80  */
81 
82  // show colored rectangle
84 
85  // show all gradient background
87 
88  // show corner annotations
90 }
91 
92 void QmitkMultiWidgetDecorationManager::ShowDecorations(bool show, const QStringList& decorations)
93 {
94  if (nullptr == m_MultiWidget)
95  {
96  return;
97  }
98 
99  if (decorations.isEmpty() || decorations.contains(mitk::IRenderWindowPart::DECORATION_BORDER))
100  {
102  }
103  if (decorations.isEmpty() || decorations.contains(mitk::IRenderWindowPart::DECORATION_LOGO))
104  {
105  ShowLogo(show);
106  }
107  if (decorations.isEmpty() || decorations.contains(mitk::IRenderWindowPart::DECORATION_MENU))
108  {
109  //m_MultiWidget->ActivateAllRenderWindowMenus(show);
110  }
111  if (decorations.isEmpty() || decorations.contains(mitk::IRenderWindowPart::DECORATION_BACKGROUND))
112  {
114  }
115  if (decorations.isEmpty() || decorations.contains(mitk::IRenderWindowPart::DECORATION_CORNER_ANNOTATION))
116  {
118  }
119 }
120 
121 bool QmitkMultiWidgetDecorationManager::IsDecorationVisible(const QString& decoration) const
122 {
124  {
126  }
127  else if (mitk::IRenderWindowPart::DECORATION_LOGO == decoration)
128  {
129  return IsLogoVisible();
130  }
131  else if (mitk::IRenderWindowPart::DECORATION_MENU == decoration)
132  {
133  //return IsMenuWidgetEnabled();
134  }
135  else if (mitk::IRenderWindowPart::DECORATION_BACKGROUND == decoration)
136  {
138  }
140  {
142  }
143 
144  return false;
145 }
146 
148 {
149  QStringList decorations;
152  return decorations;
153 }
154 
155 
157 {
158  m_LogoAnnotation->SetOpacity(0.5);
160  offset.Fill(0.03);
161  m_LogoAnnotation->SetOffsetVector(offset);
162  m_LogoAnnotation->SetRelativeSize(0.25);
163  m_LogoAnnotation->SetCornerPosition(1);
164  vtkSmartPointer<vtkImageData> vtkLogo = GetVtkLogo(path);
165 
166  SetLogo(vtkLogo);
167 }
168 
170 {
171  std::shared_ptr<QmitkRenderWindowWidget> renderWindowWidget = m_MultiWidget->GetLastRenderWindowWidget();
172  if (nullptr != renderWindowWidget)
173  {
174  m_LogoAnnotation->SetVisibility(show);
175  renderWindowWidget->RequestUpdate();
176  return;
177  }
178 
179  MITK_ERROR << "Logo can not be shown for an unknown widget.";
180 }
181 
183 {
184  return m_LogoAnnotation->IsVisible();
185 }
186 
188 {
189  switch (colormap)
190  {
192  {
194  float white[3] = { 1.0f, 1.0f, 1.0f };
195  SetAllDecorationColors(white);
196  break;
197  }
198  }
199 }
200 
201 void QmitkMultiWidgetDecorationManager::SetDecorationColor(const QString& widgetID, const mitk::Color& color)
202 {
203  std::shared_ptr<QmitkRenderWindowWidget> renderWindowWidget = m_MultiWidget->GetRenderWindowWidget(widgetID);
204  if (nullptr != renderWindowWidget)
205  {
206  renderWindowWidget->SetDecorationColor(color);
207  return;
208  }
209 
210  MITK_ERROR << "Decoration color can not be set for an unknown widget.";
211 }
212 
214 {
215  QmitkAbstractMultiWidget::RenderWindowWidgetMap renderWindowWidgets = m_MultiWidget->GetRenderWindowWidgets();
216  for (const auto& renderWindowWidget : renderWindowWidgets)
217  {
218  renderWindowWidget.second->SetDecorationColor(color);
219  }
220 }
221 
223 {
224  std::shared_ptr<QmitkRenderWindowWidget> renderWindowWidget = m_MultiWidget->GetRenderWindowWidget(widgetID);
225  if (nullptr != renderWindowWidget)
226  {
227  return renderWindowWidget->GetDecorationColor();
228  }
229 
230  MITK_ERROR << "Decoration color can not be retrieved for an unknown widget. Returning black color!";
231  float black[3] = { 0.0f, 0.0f, 0.0f };
232  return mitk::Color(black);
233 }
234 
235 void QmitkMultiWidgetDecorationManager::ShowColoredRectangle(const QString& widgetID, bool show)
236 {
237  std::shared_ptr<QmitkRenderWindowWidget> renderWindowWidget = m_MultiWidget->GetRenderWindowWidget(widgetID);
238  if (nullptr != renderWindowWidget)
239  {
240  renderWindowWidget->ShowColoredRectangle(show);
241  return;
242  }
243 
244  MITK_ERROR << "Colored rectangle can not be set for an unknown widget.";
245 }
246 
248 {
249  QmitkAbstractMultiWidget::RenderWindowWidgetMap renderWindowWidgets = m_MultiWidget->GetRenderWindowWidgets();
250  for (const auto& renderWindowWidget : renderWindowWidgets)
251  {
252  renderWindowWidget.second->ShowColoredRectangle(show);
253  }
254 }
255 
257 {
258  std::shared_ptr<QmitkRenderWindowWidget> renderWindowWidget = m_MultiWidget->GetRenderWindowWidget(widgetID);
259  if (nullptr != renderWindowWidget)
260  {
261  return renderWindowWidget->IsColoredRectangleVisible();
262  }
263 
264  MITK_ERROR << "Colored rectangle visibility can not be retrieved for an unknown widget. Returning 'false'.";
265  return false;
266 }
267 
269 {
270  QmitkAbstractMultiWidget::RenderWindowWidgetMap renderWindowWidgets = m_MultiWidget->GetRenderWindowWidgets();
271  bool allTrue = true;
272  for (const auto& renderWindowWidget : renderWindowWidgets)
273  {
274  allTrue = allTrue && renderWindowWidget.second->IsColoredRectangleVisible();
275  }
276 
277  return allTrue;
278 }
279 
280 void QmitkMultiWidgetDecorationManager::SetGradientBackgroundColors(const mitk::Color& upper, const mitk::Color& lower, const QString& widgetID)
281 {
282  std::shared_ptr<QmitkRenderWindowWidget> renderWindowWidget = m_MultiWidget->GetRenderWindowWidget(widgetID);
283  if (nullptr != renderWindowWidget)
284  {
285  renderWindowWidget->SetGradientBackgroundColors(upper, lower);
286  return;
287  }
288 
289  MITK_ERROR << "Background color gradient can not be set for an unknown widget.";
290 }
291 
293 {
294  QmitkAbstractMultiWidget::RenderWindowWidgetMap renderWindowWidgets = m_MultiWidget->GetRenderWindowWidgets();
295  for (const auto& renderWindowWidget : renderWindowWidgets)
296  {
297  renderWindowWidget.second->SetGradientBackgroundColors(upper, lower);
298  }
299 }
300 
302 {
303  float black[3] = { 0.0f, 0.0f, 0.0f };
304  SetAllGradientBackgroundColors(black, black);
305 }
306 
307 void QmitkMultiWidgetDecorationManager::ShowGradientBackground(const QString& widgetID, bool show)
308 {
309  std::shared_ptr<QmitkRenderWindowWidget> renderWindowWidget = m_MultiWidget->GetRenderWindowWidget(widgetID);
310  if (nullptr != renderWindowWidget)
311  {
312  renderWindowWidget->ShowGradientBackground(show);
313  return;
314  }
315 
316  MITK_ERROR << "Background color gradient can not be shown for an unknown widget.";
317 }
318 
320 {
321  QmitkAbstractMultiWidget::RenderWindowWidgetMap renderWindowWidgets = m_MultiWidget->GetRenderWindowWidgets();
322  for (const auto& renderWindowWidget : renderWindowWidgets)
323  {
324  renderWindowWidget.second->ShowGradientBackground(show);
325  }
326 }
327 
328 std::pair<mitk::Color, mitk::Color> QmitkMultiWidgetDecorationManager::GetGradientBackgroundColors(const QString& widgetID) const
329 {
330  std::shared_ptr<QmitkRenderWindowWidget> renderWindowWidget = m_MultiWidget->GetRenderWindowWidget(widgetID);
331  if (nullptr != renderWindowWidget)
332  {
333  return renderWindowWidget->GetGradientBackgroundColors();
334  }
335 
336  MITK_ERROR << "Background color gradient can not be retrieved for an unknown widget. Returning black color pair.";
337  float black[3] = { 0.0f, 0.0f, 0.0f };
338  return std::make_pair(mitk::Color(black), mitk::Color(black));
339 }
340 
342 {
343  std::shared_ptr<QmitkRenderWindowWidget> renderWindowWidget = m_MultiWidget->GetRenderWindowWidget(widgetID);
344  if (nullptr != renderWindowWidget)
345  {
346  return renderWindowWidget->IsGradientBackgroundOn();
347  }
348 
349  MITK_ERROR << "Background color gradient flag can not be retrieved for an unknown widget. Returning 'false'.";
350  return false;
351 }
352 
354 {
355  QmitkAbstractMultiWidget::RenderWindowWidgetMap renderWindowWidgets = m_MultiWidget->GetRenderWindowWidgets();
356  bool allTrue = true;
357  for (const auto& renderWindowWidget : renderWindowWidgets)
358  {
359  allTrue = allTrue && renderWindowWidget.second->IsGradientBackgroundOn();
360  }
361 
362  return allTrue;
363 }
364 
365 void QmitkMultiWidgetDecorationManager::SetCornerAnnotationText(const QString& widgetID, const std::string& cornerAnnotation)
366 {
367  std::shared_ptr<QmitkRenderWindowWidget> renderWindowWidget = m_MultiWidget->GetRenderWindowWidget(widgetID);
368  if (nullptr != renderWindowWidget)
369  {
370  renderWindowWidget->SetCornerAnnotationText(cornerAnnotation);
371  return;
372  }
373 
374  MITK_ERROR << "Corner annotation text can not be retrieved for an unknown widget.";
375 }
376 
377 std::string QmitkMultiWidgetDecorationManager::GetCornerAnnotationText(const QString& widgetID) const
378 {
379  std::shared_ptr<QmitkRenderWindowWidget> renderWindowWidget = m_MultiWidget->GetRenderWindowWidget(widgetID);
380  if (nullptr != renderWindowWidget)
381  {
382  return renderWindowWidget->GetCornerAnnotationText();
383  }
384 
385  MITK_ERROR << "Corner annotation text can not be retrieved for an unknown widget.";
386  return "";
387 }
388 
389 void QmitkMultiWidgetDecorationManager::ShowCornerAnnotation(const QString& widgetID, bool show)
390 {
391  std::shared_ptr<QmitkRenderWindowWidget> renderWindowWidget = m_MultiWidget->GetRenderWindowWidget(widgetID);
392  if (nullptr != renderWindowWidget)
393  {
394  renderWindowWidget->ShowCornerAnnotation(show);
395  return;
396  }
397 
398  MITK_ERROR << "Corner annotation can not be set for an unknown widget.";
399 }
400 
402 {
403  QmitkAbstractMultiWidget::RenderWindowWidgetMap renderWindowWidgets = m_MultiWidget->GetRenderWindowWidgets();
404  for (const auto& renderWindowWidget : renderWindowWidgets)
405  {
406  renderWindowWidget.second->ShowCornerAnnotation(show);
407  }
408 }
409 
411 {
412  std::shared_ptr<QmitkRenderWindowWidget> renderWindowWidget = m_MultiWidget->GetRenderWindowWidget(widgetID);
413  if (nullptr != renderWindowWidget)
414  {
415  return renderWindowWidget->IsCornerAnnotationVisible();
416  }
417 
418  MITK_ERROR << "Corner annotation visibility can not be retrieved for an unknown widget. Returning 'false'.";
419  return false;
420 }
421 
423 {
424  QmitkAbstractMultiWidget::RenderWindowWidgetMap renderWindowWidgets = m_MultiWidget->GetRenderWindowWidgets();
425  bool allTrue = true;
426  for (const auto& renderWindowWidget : renderWindowWidgets)
427  {
428  allTrue = allTrue && renderWindowWidget.second->IsCornerAnnotationVisible();
429  }
430 
431  return allTrue;
432 }
433 
435 // PRIVATE
437 vtkSmartPointer<vtkImageData> QmitkMultiWidgetDecorationManager::GetVtkLogo(const char* path)
438 {
439  QImage* qimage = new QImage(path);
440  vtkSmartPointer<vtkQImageToImageSource> qImageToVtk;
441  qImageToVtk = vtkSmartPointer<vtkQImageToImageSource>::New();
442 
443  qImageToVtk->SetQImage(qimage);
444  qImageToVtk->Update();
445  vtkSmartPointer<vtkImageData> vtkLogo = qImageToVtk->GetOutput();
446  return vtkLogo;
447 }
448 
449 void QmitkMultiWidgetDecorationManager::SetLogo(vtkSmartPointer<vtkImageData> vtkLogo)
450 {
451  std::shared_ptr<QmitkRenderWindowWidget> renderWindowWidget = m_MultiWidget->GetLastRenderWindowWidget();
452  if (nullptr != renderWindowWidget && m_LogoAnnotation.IsNotNull())
453  {
454  mitk::ManualPlacementAnnotationRenderer::AddAnnotation(m_LogoAnnotation.GetPointer(), renderWindowWidget->GetRenderWindow()->GetRenderer());
455  m_LogoAnnotation->SetLogoImage(vtkLogo);
456  mitk::BaseRenderer *renderer = mitk::BaseRenderer::GetInstance(renderWindowWidget->GetRenderWindow()->GetVtkRenderWindow());
457  m_LogoAnnotation->Update(renderer);
458  renderWindowWidget->RequestUpdate();
459  return;
460  }
461 
462  MITK_ERROR << "Logo can not be set for an unknown widget.";
463 }
void SetDecorationColor(const QString &widgetID, const mitk::Color &color)
void ShowGradientBackground(const QString &widgetID, bool show)
void SetCornerAnnotationText(const QString &widgetID, const std::string &cornerAnnotation)
RenderWindowWidgetMap GetRenderWindowWidgets() const
static BaseRenderer * GetInstance(vtkRenderWindow *renWin)
std::pair< mitk::Color, mitk::Color > GetGradientBackgroundColors(const QString &widgetID) const
void ShowDecorations(bool show, const QStringList &decorations)
Show or hide decorations like like colored borders or background, logos, menu widgets, logos and text annotations.
RenderWindowWidgetPointer GetRenderWindowWidget(int row, int column) const
#define MITK_ERROR
Definition: mitkLogMacros.h:20
Organizes the rendering process.
DataCollection - Class to facilitate loading/accessing structured data.
void SetGradientBackgroundColors(const mitk::Color &upper, const mitk::Color &lower, const QString &widgetID)
Set a background color gradient for a specific render window.
QmitkMultiWidgetDecorationManager(QmitkAbstractMultiWidget *multiWidget)
mitk::Color GetDecorationColor(const QString &widgetID) const
void ShowColoredRectangle(const QString &widgetID, bool show)
static Vector3D offset
bool IsDecorationVisible(const QString &decoration) const
Return if a specific decoration is visible.
bool IsCornerAnnotationVisible(const QString &widgetID) const
static const QString DECORATION_MENU
virtual QStringList Keys() const =0
virtual IPreferences::Pointer Parent() const =0
static const QString DECORATION_CORNER_ANNOTATION
itk::RGBPixel< float > Color
Color Standard RGB color typedef (float)
static void AddAnnotation(Annotation *Annotation, const std::string &rendererID)
virtual QString Get(const QString &key, const QString &def) const =0
void SetAllGradientBackgroundColors(const mitk::Color &upper, const mitk::Color &lower)
Set a background color gradient for all available render windows.
void ShowCornerAnnotation(const QString &widgetID, bool show)
static const QString DECORATION_BORDER
std::map< QString, std::shared_ptr< QmitkRenderWindowWidget > > RenderWindowWidgetMap
bool IsGradientBackgroundOn(const QString &widgetID) const
std::string GetCornerAnnotationText(const QString &widgetID) const
static const QString DECORATION_LOGO
The &#39;QmitkAbstractMultiWidget&#39; is a &#39;QWidget&#39; that can be subclassed to display multiple render windo...
RenderWindowWidgetPointer GetLastRenderWindowWidget() const
static const QString DECORATION_BACKGROUND
void DecorationPreferencesChanged(const berry::IBerryPreferences *preferences)
bool IsColoredRectangleVisible(const QString &widgetID) const
ObjectType * GetPointer() const