Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
QmitkBinaryThresholdToolGUI.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 
16 
17 #include <qlabel.h>
18 #include <qlayout.h>
19 #include <qpushbutton.h>
20 #include <qslider.h>
21 
23 
25  : QmitkToolGUI(),
26  m_Slider(nullptr),
27  m_Spinner(nullptr),
28  m_isFloat(false),
29  m_RangeMin(0),
30  m_RangeMax(0),
31  m_ChangingSlider(false),
32  m_ChangingSpinner(false)
33 {
34  // create the visible widgets
35  QBoxLayout *mainLayout = new QVBoxLayout(this);
36 
37  QLabel *label = new QLabel("Threshold :", this);
38  QFont f = label->font();
39  f.setBold(false);
40  label->setFont(f);
41  mainLayout->addWidget(label);
42 
43  QBoxLayout *layout = new QHBoxLayout();
44 
45  m_Spinner = new QDoubleSpinBox();
46  m_Spinner->setMaximum(20);
47  m_Spinner->setMinimum(5);
48  m_Spinner->setValue(1);
49 
50  connect(m_Spinner, SIGNAL(valueChanged(double)), this, SLOT(OnSpinnerValueChanged()));
51  layout->addWidget(m_Spinner);
52 
53  // m_Slider = new QSlider( 5, 20, 1, 1, Qt::Horizontal, this );
54  m_Slider = new QSlider(Qt::Horizontal, this);
55  m_Slider->setMinimum(5);
56  m_Slider->setMaximum(20);
57  m_Slider->setPageStep(1);
58  m_Slider->setValue(1);
59  connect(m_Slider, SIGNAL(valueChanged(int)), this, SLOT(OnSliderValueChanged(int)));
60  layout->addWidget(m_Slider);
61 
62  mainLayout->addLayout(layout);
63 
64  QPushButton *okButton = new QPushButton("Confirm Segmentation", this);
65  connect(okButton, SIGNAL(clicked()), this, SLOT(OnAcceptThresholdPreview()));
66  okButton->setFont(f);
67  mainLayout->addWidget(okButton);
68 
69  connect(this, SIGNAL(NewToolAssociated(mitk::Tool *)), this, SLOT(OnNewToolAssociated(mitk::Tool *)));
70 }
71 
73 {
74  // !!!
75  if (m_BinaryThresholdTool.IsNotNull())
76  {
77  m_BinaryThresholdTool->IntervalBordersChanged -=
82  }
83 }
84 
86 {
87  if (m_BinaryThresholdTool.IsNotNull())
88  {
89  m_BinaryThresholdTool->IntervalBordersChanged -=
94  }
95 
96  m_BinaryThresholdTool = dynamic_cast<mitk::BinaryThresholdTool *>(tool);
97 
98  if (m_BinaryThresholdTool.IsNotNull())
99  {
100  m_BinaryThresholdTool->IntervalBordersChanged +=
103  m_BinaryThresholdTool->ThresholdingValueChanged += mitk::MessageDelegate1<QmitkBinaryThresholdToolGUI, double>(
105  }
106 }
107 
109 {
110  if (m_BinaryThresholdTool.IsNotNull())
111  {
112  m_ChangingSpinner = true;
113  double doubleVal = m_Spinner->value();
114  int intVal = this->DoubleToSliderInt(doubleVal);
115  m_BinaryThresholdTool->SetThresholdValue(doubleVal);
116  if (m_ChangingSlider == false)
117  m_Slider->setValue(intVal);
118  m_ChangingSpinner = false;
119  }
120 }
121 
123 {
124  if (m_BinaryThresholdTool.IsNotNull())
125  {
126  m_ChangingSlider = true;
127  double doubleVal = SliderIntToDouble(value);
128  if (m_ChangingSpinner == false)
129  m_Spinner->setValue(doubleVal);
130  m_ChangingSlider = false;
131  }
132 }
133 
135 {
137  QString segName = QString::fromStdString(m_BinaryThresholdTool->GetCurrentSegmentationName());
138 
139  dialog.SetSegmentationName(segName);
140  int result = dialog.exec();
141 
142  switch (result)
143  {
145  m_BinaryThresholdTool->SetOverwriteExistingSegmentation(false);
146  break;
148  m_BinaryThresholdTool->SetOverwriteExistingSegmentation(true);
149  break;
151  return;
152  }
153 
154  if (m_BinaryThresholdTool.IsNotNull())
155  {
156  this->thresholdAccepted();
157  m_BinaryThresholdTool->AcceptCurrentThresholdValue();
158  }
159 }
160 
161 void QmitkBinaryThresholdToolGUI::OnThresholdingIntervalBordersChanged(double lower, double upper, bool isFloat)
162 {
163  m_isFloat = isFloat;
164  m_RangeMin = lower;
165  m_RangeMax = upper;
166 
167  m_Spinner->setRange(lower, upper);
168  if (!m_isFloat)
169  {
170  m_Slider->setRange(int(lower), int(upper));
171  m_Spinner->setDecimals(0);
172  m_Spinner->setSingleStep(1);
173  }
174  else
175  {
176  m_Slider->setRange(0, 99);
177  m_Spinner->setDecimals(2);
178  m_Range = upper - lower;
179  m_Spinner->setSingleStep(m_Range / 100);
180  }
181 }
182 
184 {
185  m_Slider->setValue(DoubleToSliderInt(current));
186  m_Spinner->setValue(current);
187 }
188 
190 {
191  if (!m_isFloat)
192  {
193  return double(val);
194  }
195  else
196  {
197  return double(val * (m_Range) / 100 + m_RangeMin);
198  }
199 }
200 
202 {
203  if (!m_isFloat)
204  {
205  return int(val);
206  }
207  else
208  {
209  int intVal = int(((val - m_RangeMin) / m_Range) * 100);
210  return intVal;
211  }
212 }
Base class of all tools used by mitk::ToolManager.
Definition: mitkTool.h:86
bool m_ChangingSlider
helper bool values to find out, which of the GUI elements has been touched by the user...
bool m_isFloat
is image float or int?
MITK_TOOL_GUI_MACRO(, QmitkPixelManipulationToolGUI, "")
double SliderIntToDouble(int val)
When Slider (int value) has changed, we need to convert it to a respective double value for the spinn...
Calculates the segmented volumes for binary images.
mitk::BinaryThresholdTool::Pointer m_BinaryThresholdTool
void OnThresholdingIntervalBordersChanged(double lower, double upper, bool isFloat)
void OnSpinnerValueChanged()
Called when Spinner value has changed. Consider: Spinner contains DOUBLE values.
Base class for GUIs belonging to mitk::Tool classes.
Definition: QmitkToolGUI.h:32
void OnSliderValueChanged(int value)
Called when Slider value has changed. Consider: Slider contains INT values.
GUI for mitk::BinaryThresholdTool.
void thresholdAccepted()
Emitted when threshold Accepted.
#define MITKSEGMENTATIONUI_EXPORT
int DoubleToSliderInt(double val)
When Spinner (double value) has changed, we need to convert it to a respective int value for the slid...