Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
QmitkDataNodeOpenInAction.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 
13 // mitk gui qt application plugin
15 
16 // mitk core
17 #include <mitkImage.h>
18 #include <mitkRenderingManager.h>
19 
20 // qt
21 #include <QMessageBox>
22 #include <QMenu>
23 
25  : QAction(parent)
26  , QmitkAbstractDataNodeAction(workbenchPartSite)
27 {
28  setText(tr("Open in"));
30 }
31 
33  : QAction(parent)
34  , QmitkAbstractDataNodeAction(berry::IWorkbenchPartSite::Pointer(workbenchPartSite))
35 {
36  setText(tr("Open in"));
38 }
39 
41 {
42  if (m_ControlledRenderer != controlledRenderer)
43  {
44  // set the new set of controlled renderer
45  m_ControlledRenderer = controlledRenderer;
46  }
47 }
48 
50 {
51  setCheckable(true);
52 
53  setMenu(new QMenu);
54  connect(menu(), &QMenu::aboutToShow, this, &QmitkDataNodeOpenInAction::OnMenuAboutToShow);
55 
57 }
58 
59 void QmitkDataNodeOpenInAction::OnMenuAboutToShow()
60 {
61  menu()->clear();
62  QAction* action;
63 
64  QStringList rendererNames;
65  for (const auto& renderer : m_ControlledRenderer)
66  {
67  rendererNames.append(renderer->GetName());
68  }
69 
70  rendererNames.sort();
71  for (const auto& rendererName : rendererNames)
72  {
73  action = menu()->addAction(rendererName);
74  connect(action, &QAction::triggered, this, &QmitkDataNodeOpenInAction::OnActionTriggered);
75  }
76 }
77 
78 void QmitkDataNodeOpenInAction::OnActionTriggered(bool /*checked*/)
79 {
80  auto dataNode = GetSelectedNode();
81  if (dataNode.IsNull())
82  {
83  return;
84  }
85 
86  QAction* senderAction = qobject_cast<QAction*>(QObject::sender());
87  if (nullptr == senderAction)
88  {
89  return;
90  }
91 
92  std::string selectedRenderer = senderAction->text().toStdString();
93  mitk::BaseRenderer* renderer = mitk::BaseRenderer::GetByName(selectedRenderer);
94  if (nullptr == renderer)
95  {
96  return;
97  }
98 
99  auto image = dynamic_cast<mitk::Image*>(dataNode->GetData());
100  if (nullptr == image)
101  {
102  return;
103  }
104 
105  mitk::RenderingManager::GetInstance()->InitializeView(renderer->GetRenderWindow(), image->GetTimeGeometry());
106 }
107 
109 {
110  const mitk::RenderingManager::RenderWindowVector allRegisteredRenderWindows =
112  mitk::BaseRenderer *baseRenderer = nullptr;
113  m_ControlledRenderer.clear();
114  for (const auto& renderWindow : allRegisteredRenderWindows)
115  {
116  baseRenderer = mitk::BaseRenderer::GetInstance(renderWindow);
117  if (nullptr != baseRenderer)
118  {
119  m_ControlledRenderer.push_back(baseRenderer);
120  }
121  }
122 }
static BaseRenderer * GetInstance(vtkRenderWindow *renWin)
Organizes the rendering process.
std::vector< mitk::BaseRenderer * > RendererVector
QmitkDataNodeOpenInAction(QWidget *parent, berry::IWorkbenchPartSite::Pointer workbenchPartSite)
static RenderingManager * GetInstance()
The custom viewer plugin implements simple viewer functionality presented in a customized look and feel It was developed to demonstrate extensibility and customizability of the blueberry application framework As an example for the GUI customization capabilities provided by the BlueBerry application the custom viewer plugin was developed It features simple viewer functionality presented in a customized look and feel The custom viewer consists of two i e a viewer perspective and a DICOM perspective As part of the viewer an instance of QmitkDataManagerView allows for data selection Visualization of the selected data is then performed by a simple render window view According data can either be directly loaded from file or be imported as DICOM data DICOM import functionality is accessible from the DICOM perspective incorporating the QmitkDicomExternalDataWidget The customization of Qt Stylesheets is used to give the application a non native look and feel This is further emphasized by a Tab Widget like unification of the perspectives with the according perspective bar In addition to an absence of menu
Image class for storing images.
Definition: mitkImage.h:72
mitk::DataNode::Pointer GetSelectedNode() const
std::vector< vtkRenderWindow * > RenderWindowVector
mitk::Image::Pointer image
vtkRenderWindow * GetRenderWindow() const
Access the RenderWindow into which this renderer renders.
static BaseRenderer * GetByName(const std::string &name)
virtual bool InitializeView(vtkRenderWindow *renderWindow, const BaseGeometry *geometry, bool initializeGlobalTimeSNC=false)
const RenderWindowVector & GetAllRegisteredRenderWindows()