Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
QmitkOtsuTool3DGUI.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 
13 #include "QmitkOtsuTool3DGUI.h"
15 
16 #include <QMessageBox>
17 #include <qlabel.h>
18 #include <qlayout.h>
19 #include <qlistwidget.h>
20 #include <qpushbutton.h>
21 #include <qspinbox.h>
22 
24 
26 {
27  m_Controls.setupUi(this);
28 
29  connect(m_Controls.previewButton, SIGNAL(clicked()), this, SLOT(OnSpinboxValueAccept()));
30  connect(m_Controls.m_selectionListWidget, SIGNAL(itemSelectionChanged()), this, SLOT(OnRegionSelectionChanged()));
31  connect(m_Controls.m_Spinbox, SIGNAL(valueChanged(int)), this, SLOT(OnRegionSpinboxChanged(int)));
32  connect(m_Controls.m_ConfSegButton, SIGNAL(clicked()), this, SLOT(OnSegmentationRegionAccept()));
33  connect(this, SIGNAL(NewToolAssociated(mitk::Tool *)), this, SLOT(OnNewToolAssociated(mitk::Tool *)));
34  connect(m_Controls.advancedSettingsButton, SIGNAL(toggled(bool)), this, SLOT(OnAdvancedSettingsButtonToggled(bool)));
35 
36  this->OnAdvancedSettingsButtonToggled(false);
37 }
38 
40 {
41 }
42 
44 {
45  // we have to change to minimum number of histogram bins accordingly
46  int curBinValue = m_Controls.m_BinsSpinBox->value();
47  if (curBinValue < numberOfRegions)
48  m_Controls.m_BinsSpinBox->setValue(numberOfRegions);
49 }
50 
52 {
53  m_SelectedItems = m_Controls.m_selectionListWidget->selectedItems();
54 
55  if (m_SelectedItems.size() == 0)
56  {
57  m_Controls.m_ConfSegButton->setEnabled(false);
58  m_OtsuTool3DTool->ShowMultiLabelResultNode(true);
59  return;
60  }
61 
62  if (m_OtsuTool3DTool.IsNotNull())
63  {
64  // update preview of region
65  QList<QListWidgetItem *>::Iterator it;
66  std::vector<int> regionIDs;
67  for (it = m_SelectedItems.begin(); it != m_SelectedItems.end(); ++it)
68  regionIDs.push_back((*it)->text().toInt());
69  m_OtsuTool3DTool->UpdateBinaryPreview(regionIDs);
70  m_Controls.m_ConfSegButton->setEnabled(true);
71  }
72 }
73 
74 void QmitkOtsuTool3DGUI::OnAdvancedSettingsButtonToggled(bool toggled)
75 {
76  m_Controls.m_ValleyCheckbox->setVisible(toggled);
77  m_Controls.binLabel->setVisible(toggled);
78  m_Controls.m_BinsSpinBox->setVisible(toggled);
79 
80  if (toggled)
81  {
82  int max = m_OtsuTool3DTool->GetNumberOfBins();
83  if (max >= m_Controls.m_BinsSpinBox->minimum())
84  {
85  m_Controls.m_BinsSpinBox->setMaximum(max);
86  }
87  }
88 }
89 
91 {
92  m_OtsuTool3DTool = dynamic_cast<mitk::OtsuTool3D *>(tool);
93 }
94 
96 {
98  QString segName = QString::fromStdString(m_OtsuTool3DTool->GetCurrentSegmentationName());
99 
100  dialog.SetSegmentationName(segName);
101  int result = dialog.exec();
102 
103  switch (result)
104  {
106  m_OtsuTool3DTool->SetOverwriteExistingSegmentation(false);
107  break;
109  m_OtsuTool3DTool->SetOverwriteExistingSegmentation(true);
110  break;
112  return;
113  }
114 
115  if (m_OtsuTool3DTool.IsNotNull() && m_Controls.m_selectionListWidget->currentItem() != nullptr)
116  {
117  m_OtsuTool3DTool->ConfirmSegmentation();
118  }
119 }
120 
122 {
123  if (m_NumberOfRegions == m_Controls.m_Spinbox->value() &&
124  m_UseValleyEmphasis == m_Controls.m_ValleyCheckbox->isChecked() &&
125  m_NumberOfBins == m_Controls.m_BinsSpinBox->value())
126  return;
127 
128  if (m_OtsuTool3DTool.IsNotNull())
129  {
130  try
131  {
132  int proceed;
133  QMessageBox *messageBox = new QMessageBox(QMessageBox::Question,
134  nullptr,
135  "The otsu segmentation computation may take several minutes depending "
136  "on the number of Regions you selected. Proceed anyway?",
137  QMessageBox::Ok | QMessageBox::Cancel);
138  if (m_Controls.m_Spinbox->value() >= 5)
139  {
140  proceed = messageBox->exec();
141  if (proceed != QMessageBox::Ok)
142  return;
143  }
144 
145  m_NumberOfRegions = m_Controls.m_Spinbox->value();
146  m_UseValleyEmphasis = m_Controls.m_ValleyCheckbox->isChecked();
147  m_NumberOfBins = m_Controls.m_BinsSpinBox->value();
148 
149  this->setCursor(Qt::WaitCursor);
151  this->setCursor(Qt::ArrowCursor);
152  }
153  catch (...)
154  {
155  this->setCursor(Qt::ArrowCursor);
156  QMessageBox *messageBox =
157  new QMessageBox(QMessageBox::Critical,
158  nullptr,
159  "itkOtsuFilter error: image dimension must be in {2, 3} and no RGB images can be handled.");
160  messageBox->exec();
161  delete messageBox;
162  return;
163  }
164  // insert regions into widget
165  QString itemName;
166  QListWidgetItem *item;
167  m_Controls.m_selectionListWidget->clear();
168  for (int i = 0; i < m_Controls.m_Spinbox->value(); ++i)
169  {
170  itemName = QString::number(i);
171  item = new QListWidgetItem(itemName);
172  m_Controls.m_selectionListWidget->addItem(item);
173  }
174  // deactivate 'confirm segmentation'-button
175  m_Controls.m_ConfSegButton->setEnabled(false);
176  }
177 }
178 
180 {
181  if (state == 1)
182  {
183  }
184 }
GUI for mitk::.
Base class of all tools used by mitk::ToolManager.
Definition: mitkTool.h:86
MITK_TOOL_GUI_MACRO(, QmitkPixelManipulationToolGUI, "")
void OnNewToolAssociated(mitk::Tool *)
QList< QListWidgetItem * > m_SelectedItems
Ui_QmitkOtsuToolWidgetControls m_Controls
Base class for GUIs belonging to mitk::Tool classes.
Definition: QmitkToolGUI.h:32
static T max(T x, T y)
Definition: svm.cpp:56
mitk::OtsuTool3D::Pointer m_OtsuTool3DTool
#define MITKSEGMENTATIONUI_EXPORT