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