Medical Imaging Interaction Toolkit  2016.11.0
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,
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 
20 
21 #include <qlabel.h>
22 #include <qlayout.h>
23 #include <qpushbutton.h>
24 #include <qslider.h>
25 
27 
29  : QmitkToolGUI(),
30  m_Slider(NULL),
31  m_Spinner(NULL),
32  m_isFloat(false),
33  m_RangeMin(0),
34  m_RangeMax(0),
35  m_ChangingSlider(false),
36  m_ChangingSpinner(false)
37 {
38  // create the visible widgets
39  QBoxLayout *mainLayout = new QVBoxLayout(this);
40 
41  QLabel *label = new QLabel("Threshold :", this);
42  QFont f = label->font();
43  f.setBold(false);
44  label->setFont(f);
45  mainLayout->addWidget(label);
46 
47  QBoxLayout *layout = new QHBoxLayout();
48 
49  m_Spinner = new QDoubleSpinBox();
50  m_Spinner->setMaximum(20);
51  m_Spinner->setMinimum(5);
52  m_Spinner->setValue(1);
53 
54  connect(m_Spinner, SIGNAL(valueChanged(double)), this, SLOT(OnSpinnerValueChanged()));
55  layout->addWidget(m_Spinner);
56 
57  // m_Slider = new QSlider( 5, 20, 1, 1, Qt::Horizontal, this );
58  m_Slider = new QSlider(Qt::Horizontal, this);
59  m_Slider->setMinimum(5);
60  m_Slider->setMaximum(20);
61  m_Slider->setPageStep(1);
62  m_Slider->setValue(1);
63  connect(m_Slider, SIGNAL(valueChanged(int)), this, SLOT(OnSliderValueChanged(int)));
64  layout->addWidget(m_Slider);
65 
66  mainLayout->addLayout(layout);
67 
68  QPushButton *okButton = new QPushButton("Confirm Segmentation", this);
69  connect(okButton, SIGNAL(clicked()), this, SLOT(OnAcceptThresholdPreview()));
70  okButton->setFont(f);
71  mainLayout->addWidget(okButton);
72 
73  connect(this, SIGNAL(NewToolAssociated(mitk::Tool *)), this, SLOT(OnNewToolAssociated(mitk::Tool *)));
74 }
75 
77 {
78  // !!!
79  if (m_BinaryThresholdTool.IsNotNull())
80  {
81  m_BinaryThresholdTool->IntervalBordersChanged -=
86  }
87 }
88 
90 {
91  if (m_BinaryThresholdTool.IsNotNull())
92  {
93  m_BinaryThresholdTool->IntervalBordersChanged -=
98  }
99 
100  m_BinaryThresholdTool = dynamic_cast<mitk::BinaryThresholdTool *>(tool);
101 
102  if (m_BinaryThresholdTool.IsNotNull())
103  {
104  m_BinaryThresholdTool->IntervalBordersChanged +=
109  }
110 }
111 
113 {
114  if (m_BinaryThresholdTool.IsNotNull())
115  {
116  m_ChangingSpinner = true;
117  double doubleVal = m_Spinner->value();
118  int intVal = this->DoubleToSliderInt(doubleVal);
119  m_BinaryThresholdTool->SetThresholdValue(doubleVal);
120  if (m_ChangingSlider == false)
121  m_Slider->setValue(intVal);
122  m_ChangingSpinner = false;
123  }
124 }
125 
127 {
128  if (m_BinaryThresholdTool.IsNotNull())
129  {
130  m_ChangingSlider = true;
131  double doubleVal = SliderIntToDouble(value);
132  if (m_ChangingSpinner == false)
133  m_Spinner->setValue(doubleVal);
134  m_ChangingSlider = false;
135  }
136 }
137 
139 {
141  QString segName = QString::fromStdString(m_BinaryThresholdTool->GetCurrentSegmentationName());
142 
143  dialog.SetSegmentationName(segName);
144  int result = dialog.exec();
145 
146  switch (result)
147  {
149  m_BinaryThresholdTool->SetOverwriteExistingSegmentation(false);
150  break;
152  m_BinaryThresholdTool->SetOverwriteExistingSegmentation(true);
153  break;
155  return;
156  }
157 
158  if (m_BinaryThresholdTool.IsNotNull())
159  {
160  this->thresholdAccepted();
161  m_BinaryThresholdTool->AcceptCurrentThresholdValue();
162  }
163 }
164 
165 void QmitkBinaryThresholdToolGUI::OnThresholdingIntervalBordersChanged(double lower, double upper, bool isFloat)
166 {
167  m_isFloat = isFloat;
168  m_RangeMin = lower;
169  m_RangeMax = upper;
170 
171  m_Spinner->setRange(lower, upper);
172  if (!m_isFloat)
173  {
174  m_Slider->setRange(int(lower), int(upper));
175  m_Spinner->setDecimals(0);
176  m_Spinner->setSingleStep(1);
177  }
178  else
179  {
180  m_Slider->setRange(0, 99);
181  m_Spinner->setDecimals(2);
182  m_Range = upper - lower;
183  m_Spinner->setSingleStep(m_Range / 100);
184  }
185 }
186 
188 {
189  m_Slider->setValue(DoubleToSliderInt(current));
190  m_Spinner->setValue(current);
191 }
192 
194 {
195  if (!m_isFloat)
196  {
197  return double(val);
198  }
199  else
200  {
201  return double(val * (m_Range) / 100 + m_RangeMin);
202  }
203 }
204 
206 {
207  if (!m_isFloat)
208  {
209  return int(val);
210  }
211  else
212  {
213  int intVal = int(((val - m_RangeMin) / m_Range) * 100);
214  return intVal;
215  }
216 }
MITK_TOOL_GUI_MACRO(, QmitkPixelManipulationToolGUI,"")
Base class of all tools used by mitk::ToolManager.
Definition: mitkTool.h:92
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?
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:36
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...