Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
QmitkSliceWidget.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 #include "QmitkSliceWidget.h"
14 #include "QmitkStepperAdapter.h"
15 #include "mitkCameraController.h"
16 #include "mitkImage.h"
18 #include <QMenu>
19 #include <QMouseEvent>
20 #include <mitkCameraController.h>
22 
23 QmitkSliceWidget::QmitkSliceWidget(QWidget *parent, const char *name, Qt::WindowFlags f) : QWidget(parent, f)
24 {
25  this->setupUi(this);
26 
27  if (name != nullptr)
28  this->setObjectName(name);
29 
30  popUp = new QMenu(this);
31  popUp->addAction("Axial");
32  popUp->addAction("Frontal");
33  popUp->addAction("Sagittal");
34 
35  QObject::connect(popUp, SIGNAL(triggered(QAction *)), this, SLOT(ChangeView(QAction *)));
36  setPopUpEnabled(false);
37 
38  m_SlicedGeometry = nullptr;
40 
41  QHBoxLayout *hlayout = new QHBoxLayout(container);
42  hlayout->setMargin(0);
43 
44  // create widget
45  QString composedName("QmitkSliceWidget::");
46  if (!this->objectName().isEmpty())
47  composedName += this->objectName();
48  else
49  composedName += "QmitkGLWidget";
50  m_RenderWindow = new QmitkRenderWindow(container, composedName);
51  m_Renderer = m_RenderWindow->GetRenderer();
52  hlayout->addWidget(m_RenderWindow);
53 
54  new QmitkStepperAdapter(m_NavigatorWidget, m_RenderWindow->GetSliceNavigationController()->GetSlice(), "navigation");
55 
57 }
58 
60 {
61  return m_Renderer;
62 }
63 
65 {
66  return SelectionFrame;
67 }
68 
70 {
71  m_DataStorage = storage;
72  m_Renderer->SetDataStorage(m_DataStorage);
73 }
74 
76 {
77  return m_DataStorage;
78 }
79 
80 void QmitkSliceWidget::SetData(mitk::DataStorage::SetOfObjects::ConstIterator it)
81 {
82  SetData(it->Value(), m_View);
83 }
84 
85 void QmitkSliceWidget::SetData(mitk::DataStorage::SetOfObjects::ConstIterator it,
87 {
88  SetData(it->Value(), view);
89 }
90 
92 {
93  try
94  {
95  if (m_DataStorage.IsNotNull())
96  {
97  m_DataStorage->Add(node);
98  }
99  }
100  catch (...)
101  {
102  }
103  SetData(node, m_View);
104 }
105 
107 {
108  mitk::Image::Pointer image = dynamic_cast<mitk::Image *>(node->GetData());
109 
110  if (image.IsNull())
111  {
112  MITK_WARN << "QmitkSliceWidget data is not an image!";
113  return;
114  }
115 
116  m_SlicedGeometry = image->GetSlicedGeometry();
117  this->InitWidget(view);
118 }
119 
121 {
122  m_View = viewDirection;
123 
125 
126  if (viewDirection == mitk::SliceNavigationController::Axial)
127  {
128  controller->SetViewDirection(mitk::SliceNavigationController::Axial);
129  }
130  else if (viewDirection == mitk::SliceNavigationController::Frontal)
131  {
132  controller->SetViewDirection(mitk::SliceNavigationController::Frontal);
133  }
134  // init sagittal view
135  else
136  {
137  controller->SetViewDirection(mitk::SliceNavigationController::Sagittal);
138  }
139 
140  if (m_SlicedGeometry.IsNull())
141  {
142  return;
143  }
144 
145  mitk::BaseGeometry::Pointer geometry = static_cast<mitk::BaseGeometry *>(m_SlicedGeometry->Clone().GetPointer());
146 
147  const mitk::BoundingBox::Pointer boundingbox = m_DataStorage->ComputeVisibleBoundingBox(GetRenderer(), nullptr);
148 
149  if (boundingbox->GetPoints()->Size() > 0)
150  {
151  // let's see if we have data with a limited live-span ...
152  mitk::TimeBounds timebounds = m_DataStorage->ComputeTimeBounds(GetRenderer(), nullptr);
153 
155  timeGeometry->Initialize(geometry, 1);
156 
157  {
158  timeGeometry->SetFirstTimePoint(timebounds[0]);
159  timeGeometry->SetStepDuration(1.0);
160  }
161 
162  if (timeGeometry->GetBoundingBoxInWorld()->GetDiagonalLength2() >= mitk::eps)
163  {
164  controller->SetInputWorldTimeGeometry(timeGeometry);
165  controller->Update();
166  }
167  }
168 
171 }
172 
174 {
177 }
178 
180 {
181  if (e->button() == Qt::RightButton && popUpEnabled)
182  {
183  popUp->popup(QCursor::pos());
184  }
185 }
186 
187 void QmitkSliceWidget::wheelEvent(QWheelEvent *e)
188 {
189  int val = m_NavigatorWidget->GetPos();
190 
191  if (e->orientation() * e->delta() > 0)
192  {
193  m_NavigatorWidget->SetPos(val + 1);
194  }
195  else
196  {
197  if (val > 0)
198  m_NavigatorWidget->SetPos(val - 1);
199  }
200 }
201 
203 {
204  if (val->text() == "Axial")
205  {
207  }
208  else if (val->text() == "Frontal")
209  {
211  }
212  else if (val->text() == "Sagittal")
213  {
215  }
216 }
217 
219 {
220  popUpEnabled = b;
221 }
222 
224 {
225  return m_NavigatorWidget;
226 }
227 
229 {
230  levelWindow->setEnabled(enable);
231  if (!enable)
232  {
233  levelWindow->setMinimumWidth(0);
234  levelWindow->setMaximumWidth(0);
235  }
236  else
237  {
238  levelWindow->setMinimumWidth(28);
239  levelWindow->setMaximumWidth(28);
240  }
241 }
242 
244 {
245  return levelWindow->isEnabled();
246 }
247 
249 {
250  return m_RenderWindow;
251 }
252 
254 {
256 }
257 
259 {
261 }
262 
264 {
265  return m_RenderWindow->GetController();
266 }
virtual mitk::CameraRotationController * GetCameraRotationController()
mitk::Stepper * GetSlice()
Get the Stepper through the slices.
Data management class that handles &#39;was created by&#39; relations.
itk::FixedArray< ScalarType, 2 > TimeBounds
Standard typedef for time-bounds.
mitk::CameraRotationController * GetCameraRotationController() const
Baseclass for renderer slice-/camera-control.
void setPopUpEnabled(bool b)
void SetInputWorldTimeGeometry(const mitk::TimeGeometry *geometry)
mitk::BaseController * GetController() const
QmitkSliceWidget(QWidget *parent=nullptr, const char *name=nullptr, Qt::WindowFlags f=nullptr)
QFrame * GetSelectionFrame()
void InitWidget(mitk::SliceNavigationController::ViewDirection viewDirection)
Controls the selection of the slice the associated BaseRenderer will display.
mitk::SliceNavigationController::ViewDirection m_View
mitk::VtkPropRenderer * GetRenderer()
Helper class to connect Qt-based navigators to instances of Stepper.
#define MITK_WARN
Definition: mitkLogMacros.h:19
mitk::StandaloneDataStorage * GetDataStorage()
QmitkRenderWindow * GetRenderWindow()
static RenderingManager * GetInstance()
virtual CameraController * GetCameraController()
ViewDirection
Possible view directions, Original will uses the PlaneGeometry instances in a SlicedGeometry3D provid...
void SetLevelWindowEnabled(bool enable)
Image class for storing images.
Definition: mitkImage.h:72
void mousePressEvent(QMouseEvent *e) override
MITK implementation of the QVTKWidget.
virtual mitk::VtkPropRenderer * GetRenderer()
mitk::Image::Pointer image
mitk::SliceNavigationController * GetSliceNavigationController() const
void SetData(mitk::DataStorage::SetOfObjects::ConstIterator it)
void RequestUpdate(vtkRenderWindow *renderWindow)
void ChangeView(QAction *val)
MITKCORE_EXPORT const ScalarType eps
QmitkSliderNavigatorWidget * GetNavigatorWidget()
virtual mitk::SliceNavigationController * GetSliceNavigationController()
void Fit()
Fit Adjust the camera, so that the world bounding box is fully visible.
void wheelEvent(QWheelEvent *e) override
QmitkRenderWindow * m_RenderWindow
virtual void Update()
Do the actual creation and send it to the connected observers (renderers)
BaseGeometry Describes the geometry of a data object.
virtual mitk::BaseController * GetController()
void SetDataStorage(mitk::StandaloneDataStorage::Pointer storage)