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