diff --git a/Modules/SegmentationUI/Qmitk/QmitkAutoSegmentationToolGUIBase.cpp b/Modules/SegmentationUI/Qmitk/QmitkAutoSegmentationToolGUIBase.cpp new file mode 100644 index 0000000000..f69fb70889 --- /dev/null +++ b/Modules/SegmentationUI/Qmitk/QmitkAutoSegmentationToolGUIBase.cpp @@ -0,0 +1,124 @@ +/*============================================================================ + +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 "QmitkAutoSegmentationToolGUIBase.h" + +#include +#include +#include +#include + +QmitkAutoSegmentationToolGUIBase::QmitkAutoSegmentationToolGUIBase() : QmitkToolGUI() +{ + connect(this, SIGNAL(NewToolAssociated(mitk::Tool *)), this, SLOT(OnNewToolAssociated(mitk::Tool *))); +} + +QmitkAutoSegmentationToolGUIBase::~QmitkAutoSegmentationToolGUIBase() +{ + if (m_Tool.IsNotNull()) + { + m_Tool->CurrentlyBusy -= mitk::MessageDelegate1(this, &QmitkAutoSegmentationToolGUIBase::BusyStateChanged); + } +} + +void QmitkAutoSegmentationToolGUIBase::OnNewToolAssociated(mitk::Tool *tool) +{ + if (m_Tool.IsNotNull()) + { + this->DisconnectOldTool(m_Tool); + } + + m_Tool = dynamic_cast(tool); + + if (nullptr == m_MainLayout) + { + // create the visible widgets + m_MainLayout = new QVBoxLayout(this); + + this->InitializeUI(m_MainLayout); + } + + if (m_Tool.IsNotNull()) + { + this->ConnectNewTool(m_Tool); + } +} + +void QmitkAutoSegmentationToolGUIBase::OnAcceptPreview() +{ + if (m_Tool.IsNotNull()) + { + if (m_CheckCreateNew->isChecked()) + { + m_Tool->SetOverwriteExistingSegmentation(false); + } + else + { + m_Tool->SetOverwriteExistingSegmentation(true); + } + + m_Tool->SetCreateAllTimeSteps(m_CheckProcessAll->isChecked()); + + m_Tool->ConfirmSegmentation(); + } +} + +void QmitkAutoSegmentationToolGUIBase::DisconnectOldTool(mitk::AutoSegmentationWithPreviewTool* oldTool) +{ + oldTool->CurrentlyBusy -= mitk::MessageDelegate1(this, &QmitkAutoSegmentationToolGUIBase::BusyStateChanged); +} + +void QmitkAutoSegmentationToolGUIBase::ConnectNewTool(mitk::AutoSegmentationWithPreviewTool* newTool) +{ + newTool->CurrentlyBusy += + mitk::MessageDelegate1(this, &QmitkAutoSegmentationToolGUIBase::BusyStateChanged); + + newTool->SetOverwriteExistingSegmentation(true); + m_CheckProcessAll->setVisible(newTool->GetTargetSegmentationNode()->GetData()->GetTimeSteps() > 1); +} + +void QmitkAutoSegmentationToolGUIBase::InitializeUI(QBoxLayout* mainLayout) +{ + m_ConfirmSegBtn = new QPushButton("Confirm Segmentation", this); + connect(m_ConfirmSegBtn, SIGNAL(clicked()), this, SLOT(OnAcceptPreview())); + + mainLayout->addWidget(m_ConfirmSegBtn); + + m_CheckProcessAll = new QCheckBox("Process all time steps", this); + m_CheckProcessAll->setChecked(false); + m_CheckProcessAll->setToolTip("Process/overwrite all time steps of the dynamic segmentation and not just the currently visible time step."); + mainLayout->addWidget(m_CheckProcessAll); + + m_CheckCreateNew = new QCheckBox("Create as new segmentation", this); + m_CheckCreateNew->setChecked(false); + m_CheckCreateNew->setToolTip("Add the confirmed segmentation as a new segmentation instead of overwriting the currently selected."); + mainLayout->addWidget(m_CheckCreateNew); +} + +void QmitkAutoSegmentationToolGUIBase::BusyStateChanged(bool isBusy) +{ + if (isBusy) + { + QApplication::setOverrideCursor(QCursor(Qt::BusyCursor)); + } + else + { + QApplication::restoreOverrideCursor(); + } + + if (nullptr != m_MainLayout) + { + m_ConfirmSegBtn->setEnabled(!isBusy); + m_CheckProcessAll->setEnabled(!isBusy); + m_CheckCreateNew->setEnabled(!isBusy); + } +} diff --git a/Modules/SegmentationUI/Qmitk/QmitkAutoSegmentationToolGUIBase.h b/Modules/SegmentationUI/Qmitk/QmitkAutoSegmentationToolGUIBase.h new file mode 100644 index 0000000000..460c2bd708 --- /dev/null +++ b/Modules/SegmentationUI/Qmitk/QmitkAutoSegmentationToolGUIBase.h @@ -0,0 +1,68 @@ +/*============================================================================ + +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 QmitkAutoSegmentationToolGUIBase_h_Included +#define QmitkAutoSegmentationToolGUIBase_h_Included + +#include "QmitkToolGUI.h" +#include +#include +#include + +#include "mitkAutoSegmentationWithPreviewTool.h" + +#include + +/** + \ingroup org_mitk_gui_qt_interactivesegmentation_internal + \brief GUI base clase for tools derived from mitk::AutoSegmentationTool. +*/ +class MITKSEGMENTATIONUI_EXPORT QmitkAutoSegmentationToolGUIBase : public QmitkToolGUI +{ + Q_OBJECT + +public: + mitkClassMacro(QmitkAutoSegmentationToolGUIBase, QmitkToolGUI); + itkCloneMacro(Self); + +protected slots: + + void OnNewToolAssociated(mitk::Tool *); + + void OnAcceptPreview(); + +protected: + QmitkAutoSegmentationToolGUIBase(); + ~QmitkAutoSegmentationToolGUIBase() override; + + virtual void DisconnectOldTool(mitk::AutoSegmentationWithPreviewTool* oldTool); + virtual void ConnectNewTool(mitk::AutoSegmentationWithPreviewTool* newTool); + virtual void InitializeUI(QBoxLayout* mainLayout); + + void BusyStateChanged(bool isBusy) override; + + template + TTool* GetConnectedToolAs() + { + return dynamic_cast(m_Tool.GetPointer()); + }; + +private: + QCheckBox* m_CheckProcessAll = nullptr; + QCheckBox* m_CheckCreateNew = nullptr; + QPushButton* m_ConfirmSegBtn = nullptr; + QBoxLayout* m_MainLayout = nullptr; + + mitk::AutoSegmentationWithPreviewTool::Pointer m_Tool; +}; + +#endif diff --git a/Modules/SegmentationUI/Qmitk/QmitkBinaryThresholdToolGUI.cpp b/Modules/SegmentationUI/Qmitk/QmitkBinaryThresholdToolGUI.cpp index 7c720d4a58..fc1cdf2592 100644 --- a/Modules/SegmentationUI/Qmitk/QmitkBinaryThresholdToolGUI.cpp +++ b/Modules/SegmentationUI/Qmitk/QmitkBinaryThresholdToolGUI.cpp @@ -1,168 +1,31 @@ /*============================================================================ 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 "QmitkBinaryThresholdToolGUI.h" #include #include #include #include #include MITK_TOOL_GUI_MACRO(MITKSEGMENTATIONUI_EXPORT, QmitkBinaryThresholdToolGUI, "") QmitkBinaryThresholdToolGUI::QmitkBinaryThresholdToolGUI() - : QmitkToolGUI() + : QmitkBinaryThresholdToolGUIBase(false) { - // create the visible widgets - QBoxLayout *mainLayout = new QVBoxLayout(this); - - QLabel *label = new QLabel("Threshold :", this); - QFont f = label->font(); - f.setBold(false); - label->setFont(f); - mainLayout->addWidget(label); - - QBoxLayout *layout = new QHBoxLayout(); - - m_ThresholdSlider = new ctkSliderWidget(); - connect( - m_ThresholdSlider, SIGNAL(valueChanged(double)), this, SLOT(OnSliderValueChanged(double))); - layout->addWidget(m_ThresholdSlider); - mainLayout->addLayout(layout); - m_ThresholdSlider->setSingleStep(0.01); - - QPushButton *okButton = new QPushButton("Confirm Segmentation", this); - connect(okButton, SIGNAL(clicked()), this, SLOT(OnAcceptThresholdPreview())); - okButton->setFont(f); - mainLayout->addWidget(okButton); - - m_CheckProcessAll = new QCheckBox("Process all time steps", this); - m_CheckProcessAll->setChecked(false); - m_CheckProcessAll->setToolTip("Process/overwrite all time steps of the dynamic segmentation and not just the currently visible time step."); - - mainLayout->addWidget(m_CheckProcessAll); - - m_CheckCreateNew = new QCheckBox("Create as new segmentation", this); - m_CheckCreateNew->setChecked(false); - m_CheckCreateNew->setToolTip("Add the confirmed segmentation as a new segmentation instead of overwriting the currently selected."); - mainLayout->addWidget(m_CheckCreateNew); - - connect(this, SIGNAL(NewToolAssociated(mitk::Tool *)), this, SLOT(OnNewToolAssociated(mitk::Tool *))); } QmitkBinaryThresholdToolGUI::~QmitkBinaryThresholdToolGUI() { - if (m_BinaryThresholdTool.IsNotNull()) - { - m_BinaryThresholdTool->CurrentlyBusy -= - mitk::MessageDelegate1(this, &QmitkBinaryThresholdToolGUI::BusyStateChanged); - m_BinaryThresholdTool->IntervalBordersChanged -= - mitk::MessageDelegate3( - this, &QmitkBinaryThresholdToolGUI::OnThresholdingIntervalBordersChanged); - m_BinaryThresholdTool->ThresholdingValuesChanged -= mitk::MessageDelegate2( - this, &QmitkBinaryThresholdToolGUI::OnThresholdingValuesChanged); - } } -void QmitkBinaryThresholdToolGUI::OnNewToolAssociated(mitk::Tool *tool) -{ - if (m_BinaryThresholdTool.IsNotNull()) - { - m_BinaryThresholdTool->CurrentlyBusy -= - mitk::MessageDelegate1(this, &QmitkBinaryThresholdToolGUI::BusyStateChanged); - m_BinaryThresholdTool->IntervalBordersChanged -= - mitk::MessageDelegate3( - this, &QmitkBinaryThresholdToolGUI::OnThresholdingIntervalBordersChanged); - m_BinaryThresholdTool->ThresholdingValuesChanged -= mitk::MessageDelegate2( - this, &QmitkBinaryThresholdToolGUI::OnThresholdingValuesChanged); - } - - m_BinaryThresholdTool = dynamic_cast(tool); - - if (m_BinaryThresholdTool.IsNotNull()) - { - m_BinaryThresholdTool->CurrentlyBusy += - mitk::MessageDelegate1(this, &QmitkBinaryThresholdToolGUI::BusyStateChanged); - m_BinaryThresholdTool->IntervalBordersChanged += - mitk::MessageDelegate3( - this, &QmitkBinaryThresholdToolGUI::OnThresholdingIntervalBordersChanged); - m_BinaryThresholdTool->ThresholdingValuesChanged += mitk::MessageDelegate2( - this, &QmitkBinaryThresholdToolGUI::OnThresholdingValuesChanged); - - m_BinaryThresholdTool->SetOverwriteExistingSegmentation(true); - m_CheckProcessAll->setVisible(m_BinaryThresholdTool->GetTargetSegmentationNode()->GetData()->GetTimeSteps()>1); - } -} - -void QmitkBinaryThresholdToolGUI::OnAcceptThresholdPreview() -{ - if (m_BinaryThresholdTool.IsNotNull()) - { - if (m_CheckCreateNew->isChecked()) - { - m_BinaryThresholdTool->SetOverwriteExistingSegmentation(false); - } - else - { - m_BinaryThresholdTool->SetOverwriteExistingSegmentation(true); - } - - m_BinaryThresholdTool->SetCreateAllTimeSteps(m_CheckProcessAll->isChecked()); - - this->thresholdAccepted(); - m_BinaryThresholdTool->ConfirmSegmentation(); - } -} - -void QmitkBinaryThresholdToolGUI::OnThresholdingIntervalBordersChanged(double lower, double upper, bool isFloat) -{ - m_InternalUpdate = true; - if (!isFloat) - { - m_ThresholdSlider->setRange(int(lower), int(upper)); - m_ThresholdSlider->setSingleStep(1); - m_ThresholdSlider->setDecimals(0); - } - else - { - m_ThresholdSlider->setRange(lower, upper); - } - m_InternalUpdate = false; -} - -void QmitkBinaryThresholdToolGUI::OnThresholdingValuesChanged(mitk::ScalarType lower, mitk::ScalarType /*upper*/) -{ - m_ThresholdSlider->setValue(lower); -} - -void QmitkBinaryThresholdToolGUI::OnSliderValueChanged(double value) -{ - if (m_BinaryThresholdTool.IsNotNull() && !m_InternalUpdate) - { - m_BinaryThresholdTool->SetThresholdValue(value); - } -} - -void QmitkBinaryThresholdToolGUI::BusyStateChanged(bool value) -{ - if (value) - { - QApplication::setOverrideCursor(QCursor(Qt::BusyCursor)); - } - else - { - QApplication::restoreOverrideCursor(); - } - - m_ThresholdSlider->setEnabled(!value); -} diff --git a/Modules/SegmentationUI/Qmitk/QmitkBinaryThresholdToolGUI.h b/Modules/SegmentationUI/Qmitk/QmitkBinaryThresholdToolGUI.h index 5696c1ff98..e62d8fc8fc 100644 --- a/Modules/SegmentationUI/Qmitk/QmitkBinaryThresholdToolGUI.h +++ b/Modules/SegmentationUI/Qmitk/QmitkBinaryThresholdToolGUI.h @@ -1,80 +1,50 @@ /*============================================================================ 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 QmitkBinaryThresholdToolGUI_h_Included #define QmitkBinaryThresholdToolGUI_h_Included -#include "QmitkToolGUI.h" +#include "QmitkBinaryThresholdToolGUIBase.h" #include "mitkBinaryThresholdTool.h" #include #include "ctkSliderWidget.h" #include /** \ingroup org_mitk_gui_qt_interactivesegmentation_internal \brief GUI for mitk::BinaryThresholdTool. This GUI shows a slider to change the tool's threshold and an OK button to accept a preview for actual thresholding. There is only a slider for INT values in QT. So, if the working image has a float/double pixeltype, we need to convert the original float intensity into a respective int value for the slider. The slider range is then between 0 and 99. If the pixeltype is INT, then we do not need any conversion. Last contributor: $Author$ */ -class MITKSEGMENTATIONUI_EXPORT QmitkBinaryThresholdToolGUI : public QmitkToolGUI +class MITKSEGMENTATIONUI_EXPORT QmitkBinaryThresholdToolGUI : public QmitkBinaryThresholdToolGUIBase { Q_OBJECT public: - mitkClassMacro(QmitkBinaryThresholdToolGUI, QmitkToolGUI); + mitkClassMacro(QmitkBinaryThresholdToolGUI, QmitkBinaryThresholdToolGUIBase); itkFactorylessNewMacro(Self); itkCloneMacro(Self); - void OnThresholdingIntervalBordersChanged(double lower, double upper, bool isFloat); - void OnThresholdingValuesChanged(mitk::ScalarType lower, mitk::ScalarType upper); - -signals: - - /// \brief Emitted when threshold Accepted - void thresholdAccepted(); - - /// \brief Emitted when threshold Canceled - void thresholdCanceled(); - -public slots: - -protected slots: - - void OnNewToolAssociated(mitk::Tool *); - void OnAcceptThresholdPreview(); - - void OnSliderValueChanged(double value); - protected: QmitkBinaryThresholdToolGUI(); ~QmitkBinaryThresholdToolGUI() override; - - void BusyStateChanged(bool) override; - - ctkSliderWidget* m_ThresholdSlider = nullptr; - QCheckBox* m_CheckProcessAll = nullptr; - QCheckBox* m_CheckCreateNew = nullptr; - - bool m_InternalUpdate = false; - - mitk::BinaryThresholdTool::Pointer m_BinaryThresholdTool; }; #endif diff --git a/Modules/SegmentationUI/Qmitk/QmitkBinaryThresholdToolGUIBase.cpp b/Modules/SegmentationUI/Qmitk/QmitkBinaryThresholdToolGUIBase.cpp new file mode 100644 index 0000000000..8750a67213 --- /dev/null +++ b/Modules/SegmentationUI/Qmitk/QmitkBinaryThresholdToolGUIBase.cpp @@ -0,0 +1,187 @@ +/*============================================================================ + +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 "QmitkBinaryThresholdToolGUIBase.h" + +#include "mitkBinaryThresholdBaseTool.h" +#include "mitkBinaryThresholdTool.h" + +#include +#include +#include +#include + +QmitkBinaryThresholdToolGUIBase::QmitkBinaryThresholdToolGUIBase(bool ulMode) : QmitkAutoSegmentationToolGUIBase(), m_ULMode(ulMode) +{ +} + +QmitkBinaryThresholdToolGUIBase::~QmitkBinaryThresholdToolGUIBase() +{ + auto tool = this->GetConnectedToolAs(); + + if (nullptr != tool) + { + tool->IntervalBordersChanged -= + mitk::MessageDelegate3( + this, &QmitkBinaryThresholdToolGUIBase::OnThresholdingIntervalBordersChanged); + tool->ThresholdingValuesChanged -= + mitk::MessageDelegate2( + this, &QmitkBinaryThresholdToolGUIBase::OnThresholdingValuesChanged); + } +} + +void QmitkBinaryThresholdToolGUIBase::OnThresholdingIntervalBordersChanged(double lower, double upper, bool isFloat) +{ + m_InternalUpdate = true; + + if (m_ULMode) + { + if (!isFloat) + { + m_ThresholdRange->setRange(int(lower), int(upper)); + m_ThresholdRange->setSingleStep(1); + m_ThresholdRange->setDecimals(0); + } + else + { + m_ThresholdRange->setRange(lower, upper); + } + } + else + { + if (!isFloat) + { + m_ThresholdSlider->setRange(int(lower), int(upper)); + m_ThresholdSlider->setSingleStep(1); + m_ThresholdSlider->setDecimals(0); + } + else + { + m_ThresholdSlider->setRange(lower, upper); + } + } + + m_InternalUpdate = false; +} + +void QmitkBinaryThresholdToolGUIBase::OnThresholdingValuesChanged(mitk::ScalarType lower, mitk::ScalarType upper) +{ + if (m_ULMode) + { + m_ThresholdRange->setValues(lower, upper); + } + else + { + m_ThresholdSlider->setValue(lower); + } +} + +void QmitkBinaryThresholdToolGUIBase::OnThresholdRangeChanged(double min, double max) +{ + auto tool = this->GetConnectedToolAs(); + + if (nullptr != tool && !m_InternalUpdate) + { + tool->SetThresholdValues(min, max); + } +} + +void QmitkBinaryThresholdToolGUIBase::OnThresholdSliderChanged(double value) +{ + auto tool = this->GetConnectedToolAs(); + + if (nullptr != tool && !m_InternalUpdate) + { + tool->SetThresholdValue(value); + } +} + +void QmitkBinaryThresholdToolGUIBase::DisconnectOldTool(mitk::AutoSegmentationWithPreviewTool* oldTool) +{ + Superclass::DisconnectOldTool(oldTool); + + auto tool = dynamic_cast(oldTool); + + if (nullptr != tool) + { + tool->IntervalBordersChanged -= + mitk::MessageDelegate3( + this, &QmitkBinaryThresholdToolGUIBase::OnThresholdingIntervalBordersChanged); + tool->ThresholdingValuesChanged -= + mitk::MessageDelegate2( + this, &QmitkBinaryThresholdToolGUIBase::OnThresholdingValuesChanged); + } +} + +void QmitkBinaryThresholdToolGUIBase::ConnectNewTool(mitk::AutoSegmentationWithPreviewTool* newTool) +{ + Superclass::ConnectNewTool(newTool); + + auto tool = dynamic_cast(newTool); + + if (nullptr != tool) + { + tool->IntervalBordersChanged += + mitk::MessageDelegate3( + this, &QmitkBinaryThresholdToolGUIBase::OnThresholdingIntervalBordersChanged); + tool->ThresholdingValuesChanged += + mitk::MessageDelegate2( + this, &QmitkBinaryThresholdToolGUIBase::OnThresholdingValuesChanged); + } +} + +void QmitkBinaryThresholdToolGUIBase::InitializeUI(QBoxLayout* mainLayout) +{ + QLabel* label = new QLabel("Threshold :", this); + QFont f = label->font(); + f.setBold(false); + label->setFont(f); + mainLayout->addWidget(label); + + QBoxLayout* layout = new QHBoxLayout(); + + if (m_ULMode) + { + m_ThresholdRange = new ctkRangeWidget(); + connect( + m_ThresholdRange, SIGNAL(valuesChanged(double, double)), this, SLOT(OnThresholdRangeChanged(double, double))); + layout->addWidget(m_ThresholdRange); + m_ThresholdRange->setSingleStep(0.01); + } + else + { + m_ThresholdSlider = new ctkSliderWidget(); + connect( + m_ThresholdSlider, SIGNAL(valueChanged(double)), this, SLOT(OnThresholdSliderChanged(double))); + layout->addWidget(m_ThresholdSlider); + m_ThresholdSlider->setSingleStep(0.01); + } + + mainLayout->addLayout(layout); + + Superclass::InitializeUI(mainLayout); +} + +void QmitkBinaryThresholdToolGUIBase::BusyStateChanged(bool value) +{ + Superclass::BusyStateChanged(value); + + if (m_ThresholdRange) + { + m_ThresholdRange->setEnabled(!value); + } + + if (m_ThresholdSlider) + { + m_ThresholdSlider->setEnabled(!value); + } +} diff --git a/Modules/SegmentationUI/Qmitk/QmitkBinaryThresholdToolGUIBase.h b/Modules/SegmentationUI/Qmitk/QmitkBinaryThresholdToolGUIBase.h new file mode 100644 index 0000000000..47f25dd544 --- /dev/null +++ b/Modules/SegmentationUI/Qmitk/QmitkBinaryThresholdToolGUIBase.h @@ -0,0 +1,63 @@ +/*============================================================================ + +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 QmitkBinaryThresholdToolGUIBase_h_Included +#define QmitkBinaryThresholdToolGUIBase_h_Included + +#include "QmitkAutoSegmentationToolGUIBase.h" +#include "ctkRangeWidget.h" +#include "ctkSliderWidget.h" + +#include + +/** + \ingroup org_mitk_gui_qt_interactivesegmentation_internal + \brief Base GUI for mitk::BinaryThresholdTool. + + This GUI shows a slider to change the tool's threshold and an OK button to accept a preview for actual thresholding. +*/ +class MITKSEGMENTATIONUI_EXPORT QmitkBinaryThresholdToolGUIBase : public QmitkAutoSegmentationToolGUIBase +{ + Q_OBJECT + +public: + mitkClassMacro(QmitkBinaryThresholdToolGUIBase, QmitkAutoSegmentationToolGUIBase); + + void OnThresholdingIntervalBordersChanged(double lower, double upper, bool isFloat); + void OnThresholdingValuesChanged(mitk::ScalarType lower, mitk::ScalarType upper); + +protected slots: + + void OnThresholdRangeChanged(double min, double max); + void OnThresholdSliderChanged(double value); + +protected: + QmitkBinaryThresholdToolGUIBase(bool ulMode); + ~QmitkBinaryThresholdToolGUIBase() override; + + void DisconnectOldTool(mitk::AutoSegmentationWithPreviewTool* oldTool) override; + void ConnectNewTool(mitk::AutoSegmentationWithPreviewTool* newTool) override; + void InitializeUI(QBoxLayout* mainLayout) override; + + void BusyStateChanged(bool) override; + + ctkRangeWidget* m_ThresholdRange = nullptr; + ctkSliderWidget* m_ThresholdSlider = nullptr; + + /** Indicates if the tool UI is used for a tool with upper an lower threshold (true) + ore only with one threshold (false)*/ + bool m_ULMode; + + bool m_InternalUpdate = false; +}; + +#endif diff --git a/Modules/SegmentationUI/Qmitk/QmitkBinaryThresholdULToolGUI.cpp b/Modules/SegmentationUI/Qmitk/QmitkBinaryThresholdULToolGUI.cpp index 5954acff4c..1eab27a6fb 100644 --- a/Modules/SegmentationUI/Qmitk/QmitkBinaryThresholdULToolGUI.cpp +++ b/Modules/SegmentationUI/Qmitk/QmitkBinaryThresholdULToolGUI.cpp @@ -1,163 +1,30 @@ /*============================================================================ 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 "QmitkBinaryThresholdULToolGUI.h" #include #include #include #include #include MITK_TOOL_GUI_MACRO(MITKSEGMENTATIONUI_EXPORT, QmitkBinaryThresholdULToolGUI, "") -QmitkBinaryThresholdULToolGUI::QmitkBinaryThresholdULToolGUI() : QmitkToolGUI() +QmitkBinaryThresholdULToolGUI::QmitkBinaryThresholdULToolGUI() : QmitkBinaryThresholdToolGUIBase(true) { - // create the visible widgets - QBoxLayout *mainLayout = new QVBoxLayout(this); - - QLabel *label = new QLabel("Threshold :", this); - QFont f = label->font(); - f.setBold(false); - label->setFont(f); - mainLayout->addWidget(label); - - QBoxLayout *layout = new QHBoxLayout(); - - m_DoubleThresholdSlider = new ctkRangeWidget(); - connect( - m_DoubleThresholdSlider, SIGNAL(valuesChanged(double, double)), this, SLOT(OnThresholdsChanged(double, double))); - layout->addWidget(m_DoubleThresholdSlider); - mainLayout->addLayout(layout); - m_DoubleThresholdSlider->setSingleStep(0.01); - - QPushButton *okButton = new QPushButton("Confirm Segmentation", this); - connect(okButton, SIGNAL(clicked()), this, SLOT(OnAcceptThresholdPreview())); - okButton->setFont(f); - mainLayout->addWidget(okButton); - - m_CheckProcessAll = new QCheckBox("Process all time steps", this); - m_CheckProcessAll->setChecked(false); - m_CheckProcessAll->setToolTip("Process/overwrite all time steps of the dynamic segmentation and not just the currently visible time step."); - mainLayout->addWidget(m_CheckProcessAll); - - m_CheckCreateNew = new QCheckBox("Create as new segmentation", this); - m_CheckCreateNew->setChecked(false); - m_CheckCreateNew->setToolTip("Add the confirmed segmentation as a new segmentation instead of overwriting the currently selected."); - mainLayout->addWidget(m_CheckCreateNew); - - connect(this, SIGNAL(NewToolAssociated(mitk::Tool *)), this, SLOT(OnNewToolAssociated(mitk::Tool *))); } QmitkBinaryThresholdULToolGUI::~QmitkBinaryThresholdULToolGUI() { - if (m_BinaryThresholdULTool.IsNotNull()) - { - m_BinaryThresholdULTool->CurrentlyBusy -= - mitk::MessageDelegate1(this, &QmitkBinaryThresholdULToolGUI::BusyStateChanged); - m_BinaryThresholdULTool->IntervalBordersChanged -= - mitk::MessageDelegate3( - this, &QmitkBinaryThresholdULToolGUI::OnThresholdingIntervalBordersChanged); - m_BinaryThresholdULTool->ThresholdingValuesChanged -= - mitk::MessageDelegate2( - this, &QmitkBinaryThresholdULToolGUI::OnThresholdingValuesChanged); - } -} - -void QmitkBinaryThresholdULToolGUI::OnNewToolAssociated(mitk::Tool *tool) -{ - if (m_BinaryThresholdULTool.IsNotNull()) - { - m_BinaryThresholdULTool->CurrentlyBusy -= - mitk::MessageDelegate1(this, &QmitkBinaryThresholdULToolGUI::BusyStateChanged); - m_BinaryThresholdULTool->IntervalBordersChanged -= - mitk::MessageDelegate3( - this, &QmitkBinaryThresholdULToolGUI::OnThresholdingIntervalBordersChanged); - m_BinaryThresholdULTool->ThresholdingValuesChanged -= - mitk::MessageDelegate2( - this, &QmitkBinaryThresholdULToolGUI::OnThresholdingValuesChanged); - } - - m_BinaryThresholdULTool = dynamic_cast(tool); - - if (m_BinaryThresholdULTool.IsNotNull()) - { - m_BinaryThresholdULTool->CurrentlyBusy += - mitk::MessageDelegate1(this, &QmitkBinaryThresholdULToolGUI::BusyStateChanged); - m_BinaryThresholdULTool->IntervalBordersChanged += - mitk::MessageDelegate3( - this, &QmitkBinaryThresholdULToolGUI::OnThresholdingIntervalBordersChanged); - m_BinaryThresholdULTool->ThresholdingValuesChanged += - mitk::MessageDelegate2( - this, &QmitkBinaryThresholdULToolGUI::OnThresholdingValuesChanged); - - m_BinaryThresholdULTool->SetOverwriteExistingSegmentation(true); - m_CheckProcessAll->setVisible(m_BinaryThresholdULTool->GetTargetSegmentationNode()->GetData()->GetTimeSteps() > 1); - } -} - -void QmitkBinaryThresholdULToolGUI::OnAcceptThresholdPreview() -{ - if (m_BinaryThresholdULTool.IsNotNull()) - { - if (m_CheckCreateNew->isChecked()) - { - m_BinaryThresholdULTool->SetOverwriteExistingSegmentation(false); - } - else - { - m_BinaryThresholdULTool->SetOverwriteExistingSegmentation(true); - } - - m_BinaryThresholdULTool->SetCreateAllTimeSteps(m_CheckProcessAll->isChecked()); - - m_BinaryThresholdULTool->ConfirmSegmentation(); - } -} - -void QmitkBinaryThresholdULToolGUI::OnThresholdingIntervalBordersChanged(double lower, double upper, bool isFloat) -{ - if (!isFloat) - { - m_DoubleThresholdSlider->setRange(int(lower), int(upper)); - m_DoubleThresholdSlider->setSingleStep(1); - m_DoubleThresholdSlider->setDecimals(0); - } - else - { - m_DoubleThresholdSlider->setRange(lower, upper); - } } -void QmitkBinaryThresholdULToolGUI::OnThresholdingValuesChanged(mitk::ScalarType lower, mitk::ScalarType upper) -{ - m_DoubleThresholdSlider->setValues(lower, upper); -} - -void QmitkBinaryThresholdULToolGUI::OnThresholdsChanged(double min, double max) -{ - m_BinaryThresholdULTool->SetThresholdValues(min, max); -} - -void QmitkBinaryThresholdULToolGUI::BusyStateChanged(bool value) -{ - if (value) - { - QApplication::setOverrideCursor(QCursor(Qt::BusyCursor)); - } - else - { - QApplication::restoreOverrideCursor(); - } - - m_DoubleThresholdSlider->setEnabled(!value); -} diff --git a/Modules/SegmentationUI/Qmitk/QmitkBinaryThresholdULToolGUI.h b/Modules/SegmentationUI/Qmitk/QmitkBinaryThresholdULToolGUI.h index ec0c130821..b903df1e58 100644 --- a/Modules/SegmentationUI/Qmitk/QmitkBinaryThresholdULToolGUI.h +++ b/Modules/SegmentationUI/Qmitk/QmitkBinaryThresholdULToolGUI.h @@ -1,68 +1,42 @@ /*============================================================================ 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 QmitkBinaryThresholdULToolGUI_h_Included #define QmitkBinaryThresholdULToolGUI_h_Included -#include "QmitkToolGUI.h" -#include "ctkRangeWidget.h" -#include -#include "mitkBinaryThresholdULTool.h" +#include "QmitkBinaryThresholdToolGUIBase.h" #include /** \ingroup org_mitk_gui_qt_interactivesegmentation_internal \brief GUI for mitk::BinaryThresholdTool. This GUI shows a slider to change the tool's threshold and an OK button to accept a preview for actual thresholding. Last contributor: $Author$ */ -class MITKSEGMENTATIONUI_EXPORT QmitkBinaryThresholdULToolGUI : public QmitkToolGUI +class MITKSEGMENTATIONUI_EXPORT QmitkBinaryThresholdULToolGUI : public QmitkBinaryThresholdToolGUIBase { Q_OBJECT public: - mitkClassMacro(QmitkBinaryThresholdULToolGUI, QmitkToolGUI); + mitkClassMacro(QmitkBinaryThresholdULToolGUI, QmitkBinaryThresholdToolGUIBase); itkFactorylessNewMacro(Self); itkCloneMacro(Self); - void OnThresholdingIntervalBordersChanged(double lower, double upper, bool isFloat); - void OnThresholdingValuesChanged(mitk::ScalarType lower, mitk::ScalarType upper); - -signals: - -public slots: - -protected slots: - - void OnNewToolAssociated(mitk::Tool *); - - void OnAcceptThresholdPreview(); - - void OnThresholdsChanged(double min, double max); - protected: QmitkBinaryThresholdULToolGUI(); ~QmitkBinaryThresholdULToolGUI() override; - - void BusyStateChanged(bool) override; - - ctkRangeWidget *m_DoubleThresholdSlider; - QCheckBox* m_CheckProcessAll = nullptr; - QCheckBox* m_CheckCreateNew = nullptr; - - mitk::BinaryThresholdULTool::Pointer m_BinaryThresholdULTool; }; #endif diff --git a/Modules/SegmentationUI/files.cmake b/Modules/SegmentationUI/files.cmake index d84231e8a4..4608c0821b 100644 --- a/Modules/SegmentationUI/files.cmake +++ b/Modules/SegmentationUI/files.cmake @@ -1,84 +1,88 @@ set( CPP_FILES Qmitk/QmitkAdaptiveRegionGrowingToolGUI.cpp +Qmitk/QmitkAutoSegmentationToolGUIBase.cpp +Qmitk/QmitkBinaryThresholdToolGUIBase.cpp Qmitk/QmitkBinaryThresholdToolGUI.cpp Qmitk/QmitkBinaryThresholdULToolGUI.cpp Qmitk/QmitkCalculateGrayValueStatisticsToolGUI.cpp Qmitk/QmitkConfirmSegmentationDialog.cpp Qmitk/QmitkCopyToClipBoardDialog.cpp Qmitk/QmitkDrawPaintbrushToolGUI.cpp Qmitk/QmitkErasePaintbrushToolGUI.cpp Qmitk/QmitkFastMarchingTool3DGUI.cpp Qmitk/QmitkFastMarchingToolGUI.cpp Qmitk/QmitkLiveWireTool2DGUI.cpp Qmitk/QmitkNewSegmentationDialog.cpp Qmitk/QmitkOtsuTool3DGUI.cpp Qmitk/QmitkPaintbrushToolGUI.cpp Qmitk/QmitkPickingToolGUI.cpp Qmitk/QmitkPixelManipulationToolGUI.cpp Qmitk/QmitkSlicesInterpolator.cpp Qmitk/QmitkToolGUI.cpp Qmitk/QmitkToolGUIArea.cpp Qmitk/QmitkToolSelectionBox.cpp Qmitk/QmitkWatershedToolGUI.cpp #Added from ML Qmitk/QmitkLabelSetWidget.cpp Qmitk/QmitkSurfaceStampWidget.cpp Qmitk/QmitkMaskStampWidget.cpp Qmitk/QmitkSliceBasedInterpolatorWidget.cpp Qmitk/QmitkSurfaceBasedInterpolatorWidget.cpp Qmitk/QmitkSearchLabelDialog.cpp Qmitk/QmitkSimpleLabelSetListWidget.cpp ) set(MOC_H_FILES Qmitk/QmitkAdaptiveRegionGrowingToolGUI.h +Qmitk/QmitkAutoSegmentationToolGUIBase.h +Qmitk/QmitkBinaryThresholdToolGUIBase.h Qmitk/QmitkBinaryThresholdToolGUI.h Qmitk/QmitkBinaryThresholdULToolGUI.h Qmitk/QmitkCalculateGrayValueStatisticsToolGUI.h Qmitk/QmitkConfirmSegmentationDialog.h Qmitk/QmitkCopyToClipBoardDialog.h Qmitk/QmitkDrawPaintbrushToolGUI.h Qmitk/QmitkErasePaintbrushToolGUI.h Qmitk/QmitkFastMarchingTool3DGUI.h Qmitk/QmitkFastMarchingToolGUI.h Qmitk/QmitkLiveWireTool2DGUI.h Qmitk/QmitkNewSegmentationDialog.h Qmitk/QmitkOtsuTool3DGUI.h Qmitk/QmitkPaintbrushToolGUI.h Qmitk/QmitkPickingToolGUI.h Qmitk/QmitkPixelManipulationToolGUI.h Qmitk/QmitkSlicesInterpolator.h Qmitk/QmitkToolGUI.h Qmitk/QmitkToolGUIArea.h Qmitk/QmitkToolSelectionBox.h Qmitk/QmitkWatershedToolGUI.h #Added from ML Qmitk/QmitkLabelSetWidget.h Qmitk/QmitkSurfaceStampWidget.h Qmitk/QmitkMaskStampWidget.h Qmitk/QmitkSliceBasedInterpolatorWidget.h Qmitk/QmitkSurfaceBasedInterpolatorWidget.h Qmitk/QmitkSearchLabelDialog.h Qmitk/QmitkSimpleLabelSetListWidget.h ) set(UI_FILES Qmitk/QmitkAdaptiveRegionGrowingToolGUIControls.ui Qmitk/QmitkConfirmSegmentationDialog.ui Qmitk/QmitkOtsuToolWidgetControls.ui Qmitk/QmitkPickingToolGUIControls.ui Qmitk/QmitkLiveWireTool2DGUIControls.ui Qmitk/QmitkWatershedToolGUIControls.ui #Added from ML Qmitk/QmitkLabelSetWidgetControls.ui Qmitk/QmitkSurfaceStampWidgetGUIControls.ui Qmitk/QmitkMaskStampWidgetGUIControls.ui Qmitk/QmitkSliceBasedInterpolatorWidgetGUIControls.ui Qmitk/QmitkSurfaceBasedInterpolatorWidgetGUIControls.ui Qmitk/QmitkSearchLabelDialogGUI.ui ) set(QRC_FILES resources/SegmentationUI.qrc )