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