Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
QmitkWatershedToolGUI.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 "QmitkWatershedToolGUI.h"
14 
16 #include "mitkProgressBar.h"
17 
18 #include <qapplication.h>
19 #include <qlabel.h>
20 #include <qlayout.h>
21 #include <qpainter.h>
22 #include <qpushbutton.h>
23 #include <qslider.h>
24 
26 
27 QmitkWatershedToolGUI::QmitkWatershedToolGUI() : QmitkToolGUI(), m_SliderThreshold(nullptr), m_SliderLevel(nullptr)
28 {
29  // create the visible widgets
30  QGridLayout *layout = new QGridLayout(this);
31  this->setContentsMargins(0, 0, 0, 0);
32 
33  QLabel *label = new QLabel("Threshold ", this);
34  QFont f = label->font();
35  f.setBold(false);
36  label->setFont(f);
37  layout->addWidget(label, 0, 0);
38 
39  QLabel *label2 = new QLabel("Level ", this);
40  f = label2->font();
41  f.setBold(false);
42  label2->setFont(f);
43  layout->addWidget(label2, 2, 0);
44 
45  m_ThresholdLabel = new QLabel(" 0.04", this);
46  f = m_ThresholdLabel->font();
47  f.setBold(false);
48  m_ThresholdLabel->setFont(f);
49  layout->addWidget(m_ThresholdLabel, 0, 1);
50 
51  m_SliderThreshold = new QSlider(Qt::Horizontal, this);
52  m_SliderThreshold->setMinimum(0);
53  m_SliderThreshold->setMaximum(100);
54  m_SliderThreshold->setPageStep(1);
55  m_SliderThreshold->setValue(4);
56  connect(m_SliderThreshold, SIGNAL(valueChanged(int)), this, SLOT(OnSliderValueThresholdChanged(int)));
57  layout->addWidget(m_SliderThreshold, 1, 0, 1, 2);
58 
59  m_LevelLabel = new QLabel(" 0.35", this);
60  f = m_LevelLabel->font();
61  f.setBold(false);
62  m_LevelLabel->setFont(f);
63  layout->addWidget(m_LevelLabel, 2, 1);
64 
65  m_SliderLevel = new QSlider(Qt::Horizontal, this);
66  m_SliderLevel->setMinimum(0);
67  m_SliderLevel->setMaximum(100);
68  m_SliderLevel->setPageStep(1);
69  m_SliderLevel->setValue(35);
70  connect(m_SliderLevel, SIGNAL(valueChanged(int)), this, SLOT(OnSliderValueLevelChanged(int)));
71  layout->addWidget(m_SliderLevel, 3, 0, 1, 2);
72 
73  QPushButton *okButton = new QPushButton("Run Segmentation", this);
74  connect(okButton, SIGNAL(clicked()), this, SLOT(OnCreateSegmentation()));
75  okButton->setFont(f);
76  layout->addWidget(okButton, 4, 0, 1, 2);
77 
78  m_InformationLabel = new QLabel("", this);
79  f = m_InformationLabel->font();
80  f.setBold(false);
81  m_InformationLabel->setFont(f);
82  layout->addWidget(m_InformationLabel, 5, 0, 1, 2);
83 
84  connect(this, SIGNAL(NewToolAssociated(mitk::Tool *)), this, SLOT(OnNewToolAssociated(mitk::Tool *)));
85 }
86 
88 {
89  if (m_WatershedTool.IsNotNull())
90  {
91  // m_WatershedTool->SizeChanged -= mitk::MessageDelegate1<QmitkWatershedToolGUI, int>( this,
92  // &QmitkWatershedToolGUI::OnSizeChanged );
93  }
94 }
95 
97 {
98  if (m_WatershedTool.IsNotNull())
99  {
100  // m_WatershedTool->SizeChanged -= mitk::MessageDelegate1<QmitkWatershedToolGUI, int>( this,
101  // &QmitkWatershedToolGUI::OnSizeChanged );
102  }
103 
104  m_WatershedTool = dynamic_cast<mitk::WatershedTool *>(tool);
107 
108  if (m_WatershedTool.IsNotNull())
109  {
110  // m_WatershedTool->SizeChanged += mitk::MessageDelegate1<QmitkWatershedToolGUI, int>( this,
111  // &QmitkWatershedToolGUI::OnSizeChanged );
112  }
113 }
114 
116 {
117  if (m_WatershedTool.IsNotNull())
118  {
119  double realValue = value / 100.;
120  m_WatershedTool->SetThreshold(realValue);
121  m_ThresholdLabel->setText(QString::number(realValue));
122  }
123 }
124 
126 {
127  if (m_WatershedTool.IsNotNull())
128  {
129  double realValue = value / 100.;
130  m_WatershedTool->SetLevel(realValue);
131  m_LevelLabel->setText(QString::number(realValue));
132  }
133 }
134 
136 {
137  QApplication::setOverrideCursor(Qt::BusyCursor);
138  m_InformationLabel->setText(QString("Please wait some time for computation..."));
139  m_InformationLabel->repaint();
140  QApplication::processEvents();
141 
142  m_WatershedTool->DoIt();
143  m_InformationLabel->setText(QString(""));
144  QApplication::setOverrideCursor(Qt::ArrowCursor);
145 
146  for (int i = 0; i < 60; ++i)
147  {
149  }
150 }
void Progress(unsigned int steps=1)
Sets the current amount of progress to current progress + steps.
Simple watershed segmentation tool.
Base class of all tools used by mitk::ToolManager.
Definition: mitkTool.h:86
double value
Definition: jsoncpp.h:350
void OnNewToolAssociated(mitk::Tool *)
GUI for mitk::WatershedTool.
QLabel * m_ThresholdLabel
Label showing the current threshold value.
MITK_TOOL_GUI_MACRO(, QmitkPixelManipulationToolGUI, "")
static ProgressBar * GetInstance()
static method to get the GUI dependent ProgressBar-instance so the methods for steps to do and progre...
QLabel * m_LevelLabel
Label showing the current level value.
void OnSliderValueThresholdChanged(int value)
Passes the chosen threshold value directly to the watershed tool.
Base class for GUIs belonging to mitk::Tool classes.
Definition: QmitkToolGUI.h:32
mitk::WatershedTool::Pointer m_WatershedTool
QLabel * m_InformationLabel
Label showing additional informations.
void OnCreateSegmentation()
Starts segmentation algorithm in the watershed tool.
void OnSliderValueLevelChanged(int value)
Passes the chosen level value directly to the watershed tool.
#define MITKSEGMENTATIONUI_EXPORT