diff --git a/Modules/SegmentationUI/Qmitk/QmitkWatershedToolGUI.cpp b/Modules/SegmentationUI/Qmitk/QmitkWatershedToolGUI.cpp index 41c3151292..fda699f8d4 100644 --- a/Modules/SegmentationUI/Qmitk/QmitkWatershedToolGUI.cpp +++ b/Modules/SegmentationUI/Qmitk/QmitkWatershedToolGUI.cpp @@ -1,199 +1,139 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ #include "QmitkWatershedToolGUI.h" +#include "mitkWatershedTool.h" #include MITK_TOOL_GUI_MACRO(MITKSEGMENTATIONUI_EXPORT, QmitkWatershedToolGUI, "") -QmitkWatershedToolGUI::QmitkWatershedToolGUI() : QmitkToolGUI() +QmitkWatershedToolGUI::QmitkWatershedToolGUI() : QmitkAutoMLSegmentationToolGUIBase() +{ +} + +void QmitkWatershedToolGUI::ConnectNewTool(mitk::AutoSegmentationWithPreviewTool* newTool) +{ + Superclass::ConnectNewTool(newTool); + + auto tool = dynamic_cast(newTool); + if (nullptr != tool) + { + tool->SetLevel(m_Level); + tool->SetThreshold(m_Threshold); + } + + newTool->IsTimePointChangeAwareOff(); +} + +void QmitkWatershedToolGUI::InitializeUI(QBoxLayout* mainLayout) { m_Controls.setupUi(this); m_Controls.thresholdSlider->setMinimum(0); //We set the threshold maximum to 0.5 to avoid crashes in the watershed filter //see T27703 for more details. m_Controls.thresholdSlider->setMaximum(0.5); m_Controls.thresholdSlider->setValue(m_Threshold); m_Controls.thresholdSlider->setPageStep(0.01); m_Controls.thresholdSlider->setSingleStep(0.001); m_Controls.thresholdSlider->setDecimals(4); m_Controls.levelSlider->setMinimum(0); m_Controls.levelSlider->setMaximum(1); m_Controls.levelSlider->setValue(m_Level); m_Controls.levelSlider->setPageStep(0.1); m_Controls.levelSlider->setSingleStep(0.01); connect(m_Controls.previewButton, SIGNAL(clicked()), this, SLOT(OnSettingsAccept())); - connect(m_Controls.m_selectionListWidget, &QmitkSimpleLabelSetListWidget::SelectedLabelsChanged, this, &QmitkWatershedToolGUI::OnRegionSelectionChanged); connect(m_Controls.levelSlider, SIGNAL(valueChanged(double)), this, SLOT(OnLevelChanged(double))); connect(m_Controls.thresholdSlider, SIGNAL(valueChanged(double)), this, SLOT(OnThresholdChanged(double))); - connect(m_Controls.m_ConfSegButton, SIGNAL(clicked()), this, SLOT(OnSegmentationRegionAccept())); - connect(this, SIGNAL(NewToolAssociated(mitk::Tool *)), this, SLOT(OnNewToolAssociated(mitk::Tool *))); -} - -QmitkWatershedToolGUI::~QmitkWatershedToolGUI() -{ - if (m_WatershedTool.IsNotNull()) - { - m_WatershedTool->CurrentlyBusy -= - mitk::MessageDelegate1(this, &QmitkWatershedToolGUI::BusyStateChanged); - } -} - -void QmitkWatershedToolGUI::OnRegionSelectionChanged(const QmitkSimpleLabelSetListWidget::LabelVectorType& selectedLabels) -{ - if (m_WatershedTool.IsNotNull()) - { - mitk::AutoMLSegmentationWithPreviewTool::SelectedLabelVectorType labelIDs; - for (const auto& label : selectedLabels) - { - labelIDs.push_back(label->GetValue()); - } - - m_WatershedTool->SetSelectedLabels(labelIDs); - m_WatershedTool->UpdatePreview(); - - m_Controls.m_ConfSegButton->setEnabled(!labelIDs.empty()); - } -} -void QmitkWatershedToolGUI::OnNewToolAssociated(mitk::Tool *tool) -{ - if (m_WatershedTool.IsNotNull()) - { - m_WatershedTool->CurrentlyBusy -= - mitk::MessageDelegate1(this, &QmitkWatershedToolGUI::BusyStateChanged); - } - - m_WatershedTool = dynamic_cast(tool); - - if (m_WatershedTool.IsNotNull()) - { - m_WatershedTool->CurrentlyBusy += - mitk::MessageDelegate1(this, &QmitkWatershedToolGUI::BusyStateChanged); - - m_WatershedTool->SetLevel(m_Level); - m_WatershedTool->SetThreshold(m_Threshold); + mainLayout->addLayout(m_Controls.verticalLayout); - m_WatershedTool->SetOverwriteExistingSegmentation(true); - m_WatershedTool->IsTimePointChangeAwareOff(); - m_Controls.m_CheckProcessAll->setVisible(m_WatershedTool->GetTargetSegmentationNode()->GetData()->GetTimeSteps() > 1); - } -} - -void QmitkWatershedToolGUI::OnSegmentationRegionAccept() -{ - QString segName = QString::fromStdString(m_WatershedTool->GetCurrentSegmentationName()); - - if (m_WatershedTool.IsNotNull()) - { - if (this->m_Controls.m_CheckCreateNew->isChecked()) - { - m_WatershedTool->SetOverwriteExistingSegmentation(false); - } - else - { - m_WatershedTool->SetOverwriteExistingSegmentation(true); - } - - m_WatershedTool->SetCreateAllTimeSteps(this->m_Controls.m_CheckProcessAll->isChecked()); - - this->m_Controls.m_ConfSegButton->setEnabled(false); - m_WatershedTool->ConfirmSegmentation(); - } + Superclass::InitializeUI(mainLayout); } void QmitkWatershedToolGUI::OnSettingsAccept() { - if (m_WatershedTool.IsNotNull()) + auto tool = this->GetConnectedToolAs(); + if (nullptr != tool) { try { m_Threshold = m_Controls.thresholdSlider->value(); m_Level = m_Controls.levelSlider->value(); - m_WatershedTool->SetThreshold(m_Threshold); - m_WatershedTool->SetLevel(m_Level); + tool->SetThreshold(m_Threshold); + tool->SetLevel(m_Level); - m_WatershedTool->UpdatePreview(); + tool->UpdatePreview(); } catch (const std::exception& e) { this->setCursor(Qt::ArrowCursor); std::stringstream stream; stream << "Error while generation watershed segmentation. Reason: " << e.what(); QMessageBox* messageBox = new QMessageBox(QMessageBox::Critical, nullptr, stream.str().c_str()); messageBox->exec(); delete messageBox; MITK_ERROR << stream.str(); return; } catch (...) { this->setCursor(Qt::ArrowCursor); std::stringstream stream; stream << "Unkown error occured while generation watershed segmentation."; QMessageBox* messageBox = new QMessageBox(QMessageBox::Critical, nullptr, stream.str().c_str()); messageBox->exec(); delete messageBox; MITK_ERROR << stream.str(); return; } - m_Controls.m_selectionListWidget->SetLabelSetImage(m_WatershedTool->GetMLPreview()); - m_WatershedTool->IsTimePointChangeAwareOn(); + this->SetLabelSetPreview(tool->GetMLPreview()); + tool->IsTimePointChangeAwareOn(); } } -void QmitkWatershedToolGUI::BusyStateChanged(bool value) +void QmitkWatershedToolGUI::EnableWidgets(bool enabled) { - if (value) - { - QApplication::setOverrideCursor(QCursor(Qt::BusyCursor)); - } - else - { - QApplication::restoreOverrideCursor(); - } - - m_Controls.levelSlider->setEnabled(!value); - m_Controls.thresholdSlider->setEnabled(!value); - m_Controls.m_ConfSegButton->setEnabled(!m_WatershedTool->GetSelectedLabels().empty() && !value); - m_Controls.m_CheckProcessAll->setEnabled(!value); - m_Controls.m_CheckCreateNew->setEnabled(!value); - m_Controls.previewButton->setEnabled(!value); + Superclass::EnableWidgets(enabled); + m_Controls.levelSlider->setEnabled(enabled); + m_Controls.thresholdSlider->setEnabled(enabled); + m_Controls.previewButton->setEnabled(enabled); } void QmitkWatershedToolGUI::OnLevelChanged(double value) { - if (m_WatershedTool.IsNotNull()) + auto tool = this->GetConnectedToolAs(); + if (nullptr != tool) { - m_WatershedTool->SetLevel(value); + tool->SetLevel(value); } } void QmitkWatershedToolGUI::OnThresholdChanged(double value) { - if (m_WatershedTool.IsNotNull()) + auto tool = this->GetConnectedToolAs(); + if (nullptr != tool) { - m_WatershedTool->SetThreshold(value); + tool->SetThreshold(value); } } diff --git a/Modules/SegmentationUI/Qmitk/QmitkWatershedToolGUI.h b/Modules/SegmentationUI/Qmitk/QmitkWatershedToolGUI.h index c5b8bbe5f1..193257e01f 100644 --- a/Modules/SegmentationUI/Qmitk/QmitkWatershedToolGUI.h +++ b/Modules/SegmentationUI/Qmitk/QmitkWatershedToolGUI.h @@ -1,71 +1,66 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ #ifndef QmitkWatershedToolGUI_h_Included #define QmitkWatershedToolGUI_h_Included -#include "QmitkToolGUI.h" -#include "mitkWatershedTool.h" +#include "QmitkAutoMLSegmentationToolGUIBase.h" #include "ui_QmitkWatershedToolGUIControls.h" #include /** \ingroup org_mitk_gui_qt_interactivesegmentation_internal \brief GUI for mitk::WatershedTool. \sa mitk::WatershedTool This GUI shows two sliders to change the watershed parameters. It executes the watershed algorithm by clicking on the button. */ -class MITKSEGMENTATIONUI_EXPORT QmitkWatershedToolGUI : public QmitkToolGUI +class MITKSEGMENTATIONUI_EXPORT QmitkWatershedToolGUI : public QmitkAutoMLSegmentationToolGUIBase { Q_OBJECT public: - mitkClassMacro(QmitkWatershedToolGUI, QmitkToolGUI); + mitkClassMacro(QmitkWatershedToolGUI, QmitkAutoMLSegmentationToolGUIBase); itkFactorylessNewMacro(Self); itkCloneMacro(Self); protected slots : - void OnNewToolAssociated(mitk::Tool *); - void OnSettingsAccept(); - void OnSegmentationRegionAccept(); - - void OnRegionSelectionChanged(const QmitkSimpleLabelSetListWidget::LabelVectorType& selectedLabels); - void OnLevelChanged(double value); void OnThresholdChanged(double value); protected: QmitkWatershedToolGUI(); - ~QmitkWatershedToolGUI() override; + ~QmitkWatershedToolGUI() = default; + + void ConnectNewTool(mitk::AutoSegmentationWithPreviewTool* newTool) override; + void InitializeUI(QBoxLayout* mainLayout) override; - void BusyStateChanged(bool value) override; + void EnableWidgets(bool enabled) override; //Recommendation from ITK is to have a threshold:level ration around 1:100 //we set Level a bit higher. This provokes more oversegmentation, //but produces less objects in the first run and profits form the fact that //decreasing level is quite fast in the filter. double m_Level = 0.6; double m_Threshold = 0.004; Ui_QmitkWatershedToolGUIControls m_Controls; - mitk::WatershedTool::Pointer m_WatershedTool; }; #endif diff --git a/Modules/SegmentationUI/Qmitk/QmitkWatershedToolGUIControls.ui b/Modules/SegmentationUI/Qmitk/QmitkWatershedToolGUIControls.ui index 4c4931c08a..4ce970d215 100644 --- a/Modules/SegmentationUI/Qmitk/QmitkWatershedToolGUIControls.ui +++ b/Modules/SegmentationUI/Qmitk/QmitkWatershedToolGUIControls.ui @@ -1,160 +1,109 @@ QmitkWatershedToolGUIControls 0 0 192 352 0 0 100 0 100000 100000 QmitkOtsuToolWidget + + 0 + + + 0 + + + 0 + + + 0 + Level: 0 0 Threshold: - - - - - 0 - 0 - - - - - 10000000 - 10000000 - - - - 0 0 100000 16777215 Preview - - - - false - - - - 0 - 0 - - - - - 100000 - 16777215 - - - - Confirm Segmentation - - - - - - - Process/overwrite all time steps of the dynamic segmentation and not just the currently visible time step. - - - Process all time steps - - - - - - - Add the confirmed segmentation as a new segmentation instead of overwriting the currently selected. - - - Create as new segmentation - - - - - QmitkSimpleLabelSetListWidget - QWidget -
QmitkSimpleLabelSetListWidget.h
-
ctkSliderWidget QWidget
ctkSliderWidget.h
1