Medical Imaging Interaction Toolkit  2018.4.99-9a29ffc6
Medical Imaging Interaction Toolkit
QmitkRenderWindowDataStorageInspector.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 // render window manager UI module
15 
16 #include "QmitkCustomVariants.h"
17 
18 // mitk core
19 #include <mitkBaseRenderer.h>
20 
21 // qt
22 #include <QSignalMapper>
23 
26 {
27  m_Controls.setupUi(this);
28 
29  // initialize the render window layer controller and the render window view direction controller
30  m_RenderWindowLayerController = std::make_unique<mitk::RenderWindowLayerController>();
31  m_RenderWindowViewDirectionController = std::make_unique<mitk::RenderWindowViewDirectionController>();
32 
33  m_StorageModel = std::make_unique<QmitkRenderWindowDataStorageTreeModel>(this);
34 
35  m_Controls.renderWindowTreeView->setModel(m_StorageModel.get());
36  m_Controls.renderWindowTreeView->setHeaderHidden(true);
37  m_Controls.renderWindowTreeView->setEditTriggers(QAbstractItemView::NoEditTriggers);
38  m_Controls.renderWindowTreeView->setSelectionBehavior(QAbstractItemView::SelectRows);
39  m_Controls.renderWindowTreeView->setSelectionMode(QAbstractItemView::ExtendedSelection);
40  m_Controls.renderWindowTreeView->setAlternatingRowColors(true);
41  m_Controls.renderWindowTreeView->setDragEnabled(true);
42  m_Controls.renderWindowTreeView->setDropIndicatorShown(true);
43  m_Controls.renderWindowTreeView->setAcceptDrops(true);
44  m_Controls.renderWindowTreeView->setContextMenuPolicy(Qt::CustomContextMenu);
45 
46  SetUpConnections();
47 }
48 
50 {
51  return m_Controls.renderWindowTreeView;
52 }
53 
54 const QAbstractItemView* QmitkRenderWindowDataStorageInspector::GetView() const
55 {
56  return m_Controls.renderWindowTreeView;
57 }
58 
60 {
61  m_Controls.renderWindowTreeView->setSelectionMode(mode);
62 }
63 
65 {
66  return m_Controls.renderWindowTreeView->selectionMode();
67 }
68 
69 void QmitkRenderWindowDataStorageInspector::Initialize()
70 {
72  {
73  return;
74  }
75 
76  auto dataStorage = m_DataStorage.Lock();
77 
78  m_StorageModel->SetDataStorage(dataStorage);
79  m_StorageModel->SetNodePredicate(m_NodePredicate);
80 
81  m_RenderWindowLayerController->SetDataStorage(dataStorage);
82  m_RenderWindowViewDirectionController->SetDataStorage(dataStorage);
83 
84  m_Connector->SetView(m_Controls.renderWindowTreeView);
85 }
86 
87 void QmitkRenderWindowDataStorageInspector::SetUpConnections()
88 {
89  connect(m_StorageModel.get(), &QAbstractItemModel::rowsInserted, this, &QmitkRenderWindowDataStorageInspector::ModelRowsInserted);
90 
91  connect(m_Controls.pushButtonSetAsBaseLayer, &QPushButton::clicked, this, &QmitkRenderWindowDataStorageInspector::SetAsBaseLayer);
92  connect(m_Controls.pushButtonResetRenderer, &QPushButton::clicked, this, &QmitkRenderWindowDataStorageInspector::ResetRenderer);
93 
94  QSignalMapper* changeViewDirectionSignalMapper = new QSignalMapper(this);
95  changeViewDirectionSignalMapper->setMapping(m_Controls.radioButtonAxial, QString("axial"));
96  changeViewDirectionSignalMapper->setMapping(m_Controls.radioButtonCoronal, QString("coronal"));
97  changeViewDirectionSignalMapper->setMapping(m_Controls.radioButtonSagittal, QString("sagittal"));
98  changeViewDirectionSignalMapper->setMapping(m_Controls.radioButton3D, QString("3D"));
99  connect(changeViewDirectionSignalMapper, static_cast<void(QSignalMapper::*)(const QString&)>(&QSignalMapper::mapped), this, &QmitkRenderWindowDataStorageInspector::ChangeViewDirection);
100 
101  connect(m_Controls.radioButtonAxial, &QPushButton::clicked, changeViewDirectionSignalMapper, static_cast<void(QSignalMapper::*)()>(&QSignalMapper::map));
102  connect(m_Controls.radioButtonCoronal, &QPushButton::clicked, changeViewDirectionSignalMapper, static_cast<void(QSignalMapper::*)()>(&QSignalMapper::map));
103  connect(m_Controls.radioButtonSagittal, &QPushButton::clicked, changeViewDirectionSignalMapper, static_cast<void(QSignalMapper::*)()>(&QSignalMapper::map));
104  connect(m_Controls.radioButton3D, &QPushButton::clicked, changeViewDirectionSignalMapper, static_cast<void(QSignalMapper::*)()>(&QSignalMapper::map));
105 }
106 
108 {
109  m_StorageModel->SetControlledRenderer(controlledRenderer);
110  m_RenderWindowLayerController->SetControlledRenderer(controlledRenderer);
111  m_RenderWindowViewDirectionController->SetControlledRenderer(controlledRenderer);
112 }
113 
115 {
116  mitk::BaseRenderer* selectedRenderer = mitk::BaseRenderer::GetByName(renderWindowId.toStdString());
117  if (nullptr == selectedRenderer)
118  {
119  return;
120  }
121 
122  m_StorageModel->SetCurrentRenderer(selectedRenderer);
123  mitk::SliceNavigationController::ViewDirection viewDirection = selectedRenderer->GetSliceNavigationController()->GetDefaultViewDirection();
124  switch (viewDirection)
125  {
127  m_Controls.radioButtonAxial->setChecked(true);
128  break;
130  m_Controls.radioButtonCoronal->setChecked(true);
131  break;
133  m_Controls.radioButtonSagittal->setChecked(true);
134  break;
135  default:
136  break;
137  }
138 }
139 
140 void QmitkRenderWindowDataStorageInspector::ModelRowsInserted(const QModelIndex& parent, int /*start*/, int /*end*/)
141 {
142  m_Controls.renderWindowTreeView->setExpanded(parent, true);
143 }
144 
145 void QmitkRenderWindowDataStorageInspector::SetAsBaseLayer()
146 {
147  QModelIndex selectedIndex = m_Controls.renderWindowTreeView->currentIndex();
148  if (selectedIndex.isValid())
149  {
150  QVariant qvariantDataNode = m_StorageModel->data(selectedIndex, Qt::UserRole);
151  if (qvariantDataNode.canConvert<mitk::DataNode*>())
152  {
153  mitk::DataNode* dataNode = qvariantDataNode.value<mitk::DataNode*>();
154  m_RenderWindowLayerController->SetBaseDataNode(dataNode, m_StorageModel->GetCurrentRenderer());
155  m_Controls.renderWindowTreeView->clearSelection();
156  }
157  }
158 }
159 
160 void QmitkRenderWindowDataStorageInspector::ResetRenderer()
161 {
162  m_RenderWindowLayerController->ResetRenderer(true, m_StorageModel->GetCurrentRenderer());
163  m_Controls.renderWindowTreeView->clearSelection();
164 }
165 
166 void QmitkRenderWindowDataStorageInspector::ChangeViewDirection(const QString& viewDirection)
167 {
168  m_RenderWindowViewDirectionController->SetViewDirectionOfRenderer(viewDirection.toStdString(), m_StorageModel->GetCurrentRenderer());
169 }
QAbstractItemView * GetView() override
See &#39;QmitkAbstractDataStorageInspector&#39;.
itk::SmartPointer< T > Lock() const
Organizes the rendering process.
mitk::NodePredicateBase::ConstPointer m_NodePredicate
SelectionMode GetSelectionMode() const override
See &#39;QmitkAbstractDataStorageInspector&#39;.
mitk::WeakPointer< mitk::DataStorage > m_DataStorage
void SetControlledRenderer(mitk::RenderWindowLayerUtilities::RendererVector controlledRenderer)
Set the controlled base renderer.
std::vector< BaseRenderer * > RendererVector
ViewDirection
Possible view directions, Original will uses the PlaneGeometry instances in a SlicedGeometry3D provid...
void SetActiveRenderWindow(const QString &renderWindowId)
Set the currently selected render window.
bool IsExpired() const noexcept
void SetSelectionMode(SelectionMode mode) override
See &#39;QmitkAbstractDataStorageInspector&#39;.
MITKMATCHPOINTREGISTRATION_EXPORT ResultImageType::Pointer map(const InputImageType *input, const RegistrationType *registration, bool throwOnOutOfInputAreaError=false, const double &paddingValue=0, const ResultImageGeometryType *resultGeometry=nullptr, bool throwOnMappingError=true, const double &errorValue=0, mitk::ImageMappingInterpolator::Type interpolatorType=mitk::ImageMappingInterpolator::Linear)
static BaseRenderer * GetByName(const std::string &name)
QAbstractItemView::SelectionMode SelectionMode
virtual SliceNavigationController * GetSliceNavigationController()
std::unique_ptr< QmitkModelViewSelectionConnector > m_Connector
This abstract class is a convenient base class for easy implementation of widgets that offer a specif...
Class for nodes of the DataTree.
Definition: mitkDataNode.h:57