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