Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
QmitkFastMarchingTool3DGUI.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 
18 
20 
21 #include "mitkBaseRenderer.h"
22 #include "mitkStepper.h"
23 #include <QApplication>
24 #include <QGroupBox>
25 #include <QMessageBox>
26 #include <ctkRangeWidget.h>
27 #include <ctkSliderWidget.h>
28 #include <qlabel.h>
29 #include <qlayout.h>
30 #include <qpushbutton.h>
31 
33 
35 {
36  this->setContentsMargins(0, 0, 0, 0);
37 
38  // create the visible widgets
39  QVBoxLayout *widgetLayout = new QVBoxLayout(this);
40  widgetLayout->setContentsMargins(0, 0, 0, 0);
41 
42  QFont fntHelp;
43  fntHelp.setBold(true);
44 
45  QLabel *lblHelp = new QLabel(this);
46  lblHelp->setText("Press shift-click to add seeds repeatedly.");
47  lblHelp->setFont(fntHelp);
48 
49  widgetLayout->addWidget(lblHelp);
50 
51  // Sigma controls
52  {
53  QHBoxLayout *hlayout = new QHBoxLayout();
54  hlayout->setSpacing(2);
55 
56  QLabel *lbl = new QLabel(this);
57  lbl->setText("Sigma: ");
58  hlayout->addWidget(lbl);
59 
60  QSpacerItem *sp2 = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
61  hlayout->addItem(sp2);
62 
63  widgetLayout->addItem(hlayout);
64  }
65 
66  m_slSigma = new ctkSliderWidget(this);
67  m_slSigma->setMinimum(0.1);
68  m_slSigma->setMaximum(5.0);
69  m_slSigma->setPageStep(0.1);
70  m_slSigma->setSingleStep(0.01);
71  m_slSigma->setValue(1.0);
72  m_slSigma->setTracking(false);
73  m_slSigma->setToolTip("The \"sigma\" parameter in the Gradient Magnitude filter.");
74  connect(m_slSigma, SIGNAL(valueChanged(double)), this, SLOT(OnSigmaChanged(double)));
75  widgetLayout->addWidget(m_slSigma);
76 
77  // Alpha controls
78  {
79  QHBoxLayout *hlayout = new QHBoxLayout();
80  hlayout->setSpacing(2);
81 
82  QLabel *lbl = new QLabel(this);
83  lbl->setText("Alpha: ");
84  hlayout->addWidget(lbl);
85 
86  QSpacerItem *sp2 = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
87  hlayout->addItem(sp2);
88 
89  widgetLayout->addItem(hlayout);
90  }
91 
92  m_slAlpha = new ctkSliderWidget(this);
93  m_slAlpha->setMinimum(-10);
94  m_slAlpha->setMaximum(0);
95  m_slAlpha->setPageStep(0.1);
96  m_slAlpha->setSingleStep(0.01);
97  m_slAlpha->setValue(-2.5);
98  m_slAlpha->setTracking(false);
99  m_slAlpha->setToolTip("The \"alpha\" parameter in the Sigmoid mapping filter.");
100  connect(m_slAlpha, SIGNAL(valueChanged(double)), this, SLOT(OnAlphaChanged(double)));
101  widgetLayout->addWidget(m_slAlpha);
102 
103  // Beta controls
104  {
105  QHBoxLayout *hlayout = new QHBoxLayout();
106  hlayout->setSpacing(2);
107 
108  QLabel *lbl = new QLabel(this);
109  lbl->setText("Beta: ");
110  hlayout->addWidget(lbl);
111 
112  QSpacerItem *sp2 = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
113  hlayout->addItem(sp2);
114 
115  widgetLayout->addLayout(hlayout);
116  }
117 
118  m_slBeta = new ctkSliderWidget(this);
119  m_slBeta->setMinimum(0);
120  m_slBeta->setMaximum(100);
121  m_slBeta->setPageStep(0.1);
122  m_slBeta->setSingleStep(0.01);
123  m_slBeta->setValue(3.5);
124  m_slBeta->setTracking(false);
125  m_slBeta->setToolTip("The \"beta\" parameter in the Sigmoid mapping filter.");
126  connect(m_slBeta, SIGNAL(valueChanged(double)), this, SLOT(OnBetaChanged(double)));
127  widgetLayout->addWidget(m_slBeta);
128 
129  // stopping value controls
130  {
131  QHBoxLayout *hlayout = new QHBoxLayout();
132  hlayout->setSpacing(2);
133 
134  QLabel *lbl = new QLabel(this);
135  lbl->setText("Stopping value: ");
136  hlayout->addWidget(lbl);
137 
138  QSpacerItem *sp2 = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
139  hlayout->addItem(sp2);
140 
141  widgetLayout->addLayout(hlayout);
142  }
143 
144  m_slStoppingValue = new ctkSliderWidget(this);
145  m_slStoppingValue->setMinimum(0);
146  m_slStoppingValue->setMaximum(10000);
147  m_slStoppingValue->setPageStep(10);
148  m_slStoppingValue->setSingleStep(1);
149  m_slStoppingValue->setValue(2000);
150  m_slStoppingValue->setDecimals(0);
151  m_slStoppingValue->setTracking(false);
152  m_slStoppingValue->setToolTip("The \"stopping value\" parameter in the fast marching 3D algorithm");
153  connect(m_slStoppingValue, SIGNAL(valueChanged(double)), this, SLOT(OnStoppingValueChanged(double)));
154  widgetLayout->addWidget(m_slStoppingValue);
155 
156  // threshold controls
157  {
158  QHBoxLayout *hlayout = new QHBoxLayout();
159  hlayout->setSpacing(2);
160 
161  QLabel *lbl = new QLabel(this);
162  lbl->setText("Threshold: ");
163  hlayout->addWidget(lbl);
164 
165  QSpacerItem *sp2 = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
166  hlayout->addItem(sp2);
167 
168  widgetLayout->addLayout(hlayout);
169  }
170 
171  m_slwThreshold = new ctkRangeWidget(this);
172  m_slwThreshold->setMinimum(-100);
173  m_slwThreshold->setMaximum(5000);
174  m_slwThreshold->setMinimumValue(-100);
175  m_slwThreshold->setMaximumValue(2000);
176  m_slwThreshold->setDecimals(0);
177  m_slwThreshold->setTracking(false);
178  m_slwThreshold->setToolTip("The lower and upper thresholds for the final thresholding");
179  connect(m_slwThreshold, SIGNAL(valuesChanged(double, double)), this, SLOT(OnThresholdChanged(double, double)));
180  widgetLayout->addWidget(m_slwThreshold);
181 
182  m_btClearSeeds = new QPushButton("Clear");
183  m_btClearSeeds->setToolTip("Clear current result and start over again");
184  widgetLayout->addWidget(m_btClearSeeds);
185  connect(m_btClearSeeds, SIGNAL(clicked()), this, SLOT(OnClearSeeds()));
186 
187  m_btConfirm = new QPushButton("Confirm Segmentation");
188  m_btConfirm->setToolTip("Incorporate current result in your working session.");
189  m_btConfirm->setEnabled(false);
190  widgetLayout->addWidget(m_btConfirm);
191  connect(m_btConfirm, SIGNAL(clicked()), this, SLOT(OnConfirmSegmentation()));
192 
193  connect(this, SIGNAL(NewToolAssociated(mitk::Tool *)), this, SLOT(OnNewToolAssociated(mitk::Tool *)));
194 
195  this->setEnabled(false);
196 
197  m_slSigma->setDecimals(2);
198  m_slBeta->setDecimals(2);
199  m_slAlpha->setDecimals(2);
200 }
201 
203 {
204  if (m_FastMarchingTool.IsNotNull())
205  {
206  m_FastMarchingTool->CurrentlyBusy -=
208  m_FastMarchingTool->RemoveReadyListener(
210  }
211 }
212 
214 {
215  if (m_FastMarchingTool.IsNotNull())
216  {
217  m_FastMarchingTool->CurrentlyBusy -=
219  m_FastMarchingTool->RemoveReadyListener(
221  }
222 
223  m_FastMarchingTool = dynamic_cast<mitk::FastMarchingTool3D *>(tool);
224 
225  if (m_FastMarchingTool.IsNotNull())
226  {
227  m_FastMarchingTool->CurrentlyBusy +=
229  m_FastMarchingTool->AddReadyListener(
231 
232  // listen to timestep change events
235  if (renderer.IsNotNull() && !m_TimeIsConnected)
236  {
237  new QmitkStepperAdapter(this, renderer->GetSliceNavigationController()->GetTime(), "stepper");
238  // connect(m_TimeStepper, SIGNAL(Refetch()), this, SLOT(Refetch()));
239  m_TimeIsConnected = true;
240  }
241  }
242 }
243 
245 {
246  if (m_FastMarchingTool.IsNotNull())
247  {
248  m_FastMarchingTool->SetLowerThreshold(this->m_slwThreshold->minimumValue());
249  m_FastMarchingTool->SetUpperThreshold(this->m_slwThreshold->maximumValue());
250  m_FastMarchingTool->SetStoppingValue(this->m_slStoppingValue->value());
251  m_FastMarchingTool->SetSigma(this->m_slSigma->value());
252  m_FastMarchingTool->SetAlpha(this->m_slAlpha->value());
253  m_FastMarchingTool->SetBeta(this->m_slBeta->value());
254  m_FastMarchingTool->Update();
255  }
256 }
257 
258 void QmitkFastMarchingTool3DGUI::OnThresholdChanged(double lower, double upper)
259 {
260  if (m_FastMarchingTool.IsNotNull())
261  {
262  m_FastMarchingTool->SetLowerThreshold(lower);
263  m_FastMarchingTool->SetUpperThreshold(upper);
264  this->Update();
265  }
266 }
267 
269 {
270  if (m_FastMarchingTool.IsNotNull())
271  {
272  m_FastMarchingTool->SetBeta(value);
273  this->Update();
274  }
275 }
276 
278 {
279  if (m_FastMarchingTool.IsNotNull())
280  {
281  m_FastMarchingTool->SetSigma(value);
282  this->Update();
283  }
284 }
285 
287 {
288  if (m_FastMarchingTool.IsNotNull())
289  {
290  m_FastMarchingTool->SetAlpha(value);
291  this->Update();
292  }
293 }
294 
296 {
297  if (m_FastMarchingTool.IsNotNull())
298  {
299  m_FastMarchingTool->SetStoppingValue(value);
300  this->Update();
301  }
302 }
303 
305 {
307  QString segName = QString::fromStdString(m_FastMarchingTool->GetCurrentSegmentationName());
308 
309  dialog.SetSegmentationName(segName);
310  int result = dialog.exec();
311 
312  switch (result)
313  {
315  m_FastMarchingTool->SetOverwriteExistingSegmentation(false);
316  break;
318  m_FastMarchingTool->SetOverwriteExistingSegmentation(true);
319  break;
321  return;
322  }
323  if (m_FastMarchingTool.IsNotNull())
324  {
325  m_btConfirm->setEnabled(false);
326  m_FastMarchingTool->ConfirmSegmentation();
327  }
328 }
329 
331 {
332  this->m_TimeStepper = stepper;
333 }
334 
336 {
337  // event from image navigator recieved - timestep has changed
338  m_FastMarchingTool->SetCurrentTimeStep(m_TimeStepper->GetPos());
339 }
340 
342 {
343  // event from image navigator recieved - timestep has changed
344  m_FastMarchingTool->ClearSeeds();
345  m_btConfirm->setEnabled(false);
346  this->Update();
347 }
348 
350 {
351  if (value)
352  QApplication::setOverrideCursor(QCursor(Qt::BusyCursor));
353  else
354  QApplication::restoreOverrideCursor();
355 }
356 
358 {
359  this->setEnabled(true);
360  this->m_btConfirm->setEnabled(true);
361 }
MITK_TOOL_GUI_MACRO(, QmitkPixelManipulationToolGUI,"")
GUI for mitk::FastMarchingTool.
Base class of all tools used by mitk::ToolManager.
Definition: mitkTool.h:92
static BaseRenderer * GetInstance(vtkRenderWindow *renWin)
static vtkRenderWindow * GetRenderWindowByName(const std::string &name)
FastMarching semgentation tool.
void OnThresholdChanged(int current)
mitk::FastMarchingTool3D::Pointer m_FastMarchingTool
Helper class to connect Qt-based navigators to instances of Stepper.
Base class for GUIs belonging to mitk::Tool classes.
Definition: QmitkToolGUI.h:36
Helper class to step through a list.
Definition: mitkStepper.h:51
mitk::Stepper::Pointer m_TimeStepper
#define MITKSEGMENTATIONUI_EXPORT