Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
QmitkFastMarchingToolGUI.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_slAlpha->setDecimals(2);
198  m_slSigma->setDecimals(2);
199  m_slBeta->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::FastMarchingTool *>(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  m_FastMarchingTool->SetLowerThreshold(this->m_slwThreshold->minimumValue());
247  m_FastMarchingTool->SetUpperThreshold(this->m_slwThreshold->maximumValue());
248  m_FastMarchingTool->SetStoppingValue(this->m_slStoppingValue->value());
249  m_FastMarchingTool->SetSigma(this->m_slSigma->value());
250  m_FastMarchingTool->SetAlpha(this->m_slAlpha->value());
251  m_FastMarchingTool->SetBeta(this->m_slBeta->value());
252  m_FastMarchingTool->Update();
253 }
254 
255 void QmitkFastMarchingToolGUI::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 {
303  if (m_FastMarchingTool.IsNotNull())
304  {
305  m_btConfirm->setEnabled(false);
306  m_FastMarchingTool->ConfirmSegmentation();
307  }
308 }
309 
311 {
312  this->m_TimeStepper = stepper;
313 }
314 
316 {
317  // event from image navigator recieved - timestep has changed
318  m_FastMarchingTool->SetCurrentTimeStep(m_TimeStepper->GetPos());
319 }
320 
322 {
323  // event from image navigator recieved - timestep has changed
324  m_FastMarchingTool->ClearSeeds();
325  m_btConfirm->setEnabled(false);
326  this->Update();
327 }
328 
330 {
331  if (value)
332  QApplication::setOverrideCursor(QCursor(Qt::BusyCursor));
333  else
334  QApplication::restoreOverrideCursor();
335 }
336 
338 {
339  this->setEnabled(true);
340  this->m_btConfirm->setEnabled(true);
341 }
MITK_TOOL_GUI_MACRO(, QmitkPixelManipulationToolGUI,"")
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)
mitk::FastMarchingTool::Pointer m_FastMarchingTool
mitk::Stepper::Pointer m_TimeStepper
void OnThresholdChanged(int current)
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
FastMarching semgentation tool.
GUI for mitk::FastMarchingTool.
#define MITKSEGMENTATIONUI_EXPORT