diff --git a/Plugins/org.mitk.gui.qt.segmentation/files.cmake b/Plugins/org.mitk.gui.qt.segmentation/files.cmake index 38abb65df5..8d18612b19 100644 --- a/Plugins/org.mitk.gui.qt.segmentation/files.cmake +++ b/Plugins/org.mitk.gui.qt.segmentation/files.cmake @@ -1,81 +1,72 @@ set(SRC_CPP_FILES QmitkSegmentationPreferencePage.cpp QmitkNewSegmentationDialog.cpp - QmitkLabelSetWidget.cpp QmitkSegmentAnythingPreferencePage.cpp ) set(INTERNAL_CPP_FILES mitkPluginActivator.cpp QmitkSegmentationView.cpp QmitkSegmentationUtilitiesView.cpp QmitkSegmentationTaskListView.cpp QmitkAutocropAction.cpp QmitkAutocropLabelSetImageAction.cpp QmitkCreatePolygonModelAction.cpp QmitkLoadMultiLabelPresetAction.cpp QmitkSaveMultiLabelPresetAction.cpp QmitkConvertSurfaceToLabelAction.cpp QmitkConvertMaskToLabelAction.cpp QmitkConvertToMultiLabelSegmentationAction.cpp QmitkCreateMultiLabelSegmentationAction.cpp - Common/QmitkLabelsWidget.cpp - Common/QmitkLayersWidget.cpp ) set(UI_FILES src/QmitkSegmentationPreferencePageControls.ui src/QmitkSegmentAnythingPreferencePage.ui src/QmitkNewSegmentationDialog.ui - src/QmitkLabelSetWidgetControls.ui src/internal/QmitkSegmentationViewControls.ui src/internal/QmitkSegmentationUtilitiesViewControls.ui src/internal/QmitkSegmentationTaskListView.ui - src/internal/Common/QmitkLabelsWidgetControls.ui - src/internal/Common/QmitkLayersWidgetControls.ui ) set(MOC_H_FILES src/QmitkSegmentationPreferencePage.h src/QmitkSegmentAnythingPreferencePage.h src/QmitkNewSegmentationDialog.h - src/QmitkLabelSetWidget.h src/internal/mitkPluginActivator.h src/internal/QmitkSegmentationView.h src/internal/QmitkSegmentationUtilitiesView.h src/internal/QmitkSegmentationTaskListView.h src/internal/QmitkAutocropAction.h src/internal/QmitkAutocropLabelSetImageAction.h src/internal/QmitkCreatePolygonModelAction.h src/internal/QmitkLoadMultiLabelPresetAction.h src/internal/QmitkSaveMultiLabelPresetAction.h src/internal/QmitkConvertSurfaceToLabelAction.h src/internal/QmitkConvertMaskToLabelAction.h src/internal/QmitkConvertToMultiLabelSegmentationAction.h src/internal/QmitkCreateMultiLabelSegmentationAction.h - src/internal/Common/QmitkLabelsWidget.h - src/internal/Common/QmitkLayersWidget.h ) set(CACHED_RESOURCE_FILES resources/segmentation.svg resources/segmentation_utilities.svg resources/SegmentationTaskListIcon.svg plugin.xml ) set(QRC_FILES resources/segmentation.qrc resources/SegmentationUtilities.qrc resources/SegmentationTaskList.qrc ) set(CPP_FILES) foreach(file ${SRC_CPP_FILES}) set(CPP_FILES ${CPP_FILES} src/${file}) endforeach(file ${SRC_CPP_FILES}) foreach(file ${INTERNAL_CPP_FILES}) set(CPP_FILES ${CPP_FILES} src/internal/${file}) endforeach(file ${INTERNAL_CPP_FILES}) diff --git a/Plugins/org.mitk.gui.qt.segmentation/src/QmitkLabelSetWidget.cpp b/Plugins/org.mitk.gui.qt.segmentation/src/QmitkLabelSetWidget.cpp deleted file mode 100644 index 4cd0404652..0000000000 --- a/Plugins/org.mitk.gui.qt.segmentation/src/QmitkLabelSetWidget.cpp +++ /dev/null @@ -1,1191 +0,0 @@ -/*============================================================================ - -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 "QmitkLabelSetWidget.h" - -// mitk -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -// Qmitk -#include -#include -#include - -// Qt -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -// itk -#include - -QmitkLabelSetWidget::QmitkLabelSetWidget(QWidget *parent) - : QWidget(parent), m_DataStorage(nullptr), m_Completer(nullptr), m_ToolManager(nullptr), m_ProcessingManualSelection(false) -{ - m_Controls.setupUi(this); - - m_ColorSequenceRainbow.GoToBegin(); - - m_ToolManager = mitk::ToolManagerProvider::GetInstance()->GetToolManager(); - - m_Controls.m_LabelSearchBox->setAlwaysShowClearIcon(true); - m_Controls.m_LabelSearchBox->setShowSearchIcon(true); - - QStringList completionList; - completionList << ""; - m_Completer = new QCompleter(completionList, this); - m_Completer->setCaseSensitivity(Qt::CaseInsensitive); - m_Controls.m_LabelSearchBox->setCompleter(m_Completer); - - connect(m_Controls.m_LabelSearchBox, SIGNAL(returnPressed()), this, SLOT(OnSearchLabel())); - - auto* renameLabelShortcut = new QShortcut(QKeySequence(Qt::CTRL | Qt::Key::Key_L, Qt::CTRL | Qt::Key::Key_R), this); - connect(renameLabelShortcut, &QShortcut::activated, this, &QmitkLabelSetWidget::OnRenameLabelShortcutActivated); - - QStringListModel *completeModel = static_cast(m_Completer->model()); - completeModel->setStringList(GetLabelStringList()); - - m_Controls.m_LabelSearchBox->setEnabled(false); - - m_Controls.m_lblCaption->setText(""); - - InitializeTableWidget(); -} - -QmitkLabelSetWidget::~QmitkLabelSetWidget() {} - -void QmitkLabelSetWidget::OnTableViewContextMenuRequested(const QPoint & /*pos*/) -{ - int pixelValue = GetPixelValueOfSelectedItem(); - - if (-1 == pixelValue) - return; - - QMenu *menu = new QMenu(m_Controls.m_LabelSetTableWidget); - - if (m_Controls.m_LabelSetTableWidget->selectedItems().size() > 1) - { - QAction *mergeAction = new QAction(QIcon(":/Qmitk/MergeLabels.png"), "Merge selection on current label", this); - mergeAction->setEnabled(true); - QObject::connect(mergeAction, SIGNAL(triggered(bool)), this, SLOT(OnMergeLabels(bool))); - menu->addAction(mergeAction); - - QAction *removeLabelsAction = new QAction(QIcon(":/Qmitk/RemoveLabel.png"), "Remove selected labels", this); - removeLabelsAction->setEnabled(true); - QObject::connect(removeLabelsAction, SIGNAL(triggered(bool)), this, SLOT(OnRemoveLabels(bool))); - menu->addAction(removeLabelsAction); - - QAction *eraseLabelsAction = new QAction(QIcon(":/Qmitk/EraseLabel.png"), "Erase selected labels", this); - eraseLabelsAction->setEnabled(true); - QObject::connect(eraseLabelsAction, SIGNAL(triggered(bool)), this, SLOT(OnEraseLabels(bool))); - menu->addAction(eraseLabelsAction); - } - else - { - QAction *renameAction = new QAction(QIcon(":/Qmitk/RenameLabel.png"), "Rename...", this); - renameAction->setEnabled(true); - QObject::connect(renameAction, SIGNAL(triggered(bool)), this, SLOT(OnRenameLabel(bool))); - menu->addAction(renameAction); - - QAction *removeAction = new QAction(QIcon(":/Qmitk/RemoveLabel.png"), "Remove...", this); - removeAction->setEnabled(true); - QObject::connect(removeAction, SIGNAL(triggered(bool)), this, SLOT(OnRemoveLabel(bool))); - menu->addAction(removeAction); - - QAction *eraseAction = new QAction(QIcon(":/Qmitk/EraseLabel.png"), "Erase...", this); - eraseAction->setEnabled(true); - QObject::connect(eraseAction, SIGNAL(triggered(bool)), this, SLOT(OnEraseLabel(bool))); - menu->addAction(eraseAction); - - QAction *randomColorAction = new QAction(QIcon(":/Qmitk/RandomColor.png"), "Random color", this); - randomColorAction->setEnabled(true); - QObject::connect(randomColorAction, SIGNAL(triggered(bool)), this, SLOT(OnRandomColor(bool))); - menu->addAction(randomColorAction); - - QAction *viewOnlyAction = new QAction(QIcon(":/Qmitk/visible.png"), "View only", this); - viewOnlyAction->setEnabled(true); - QObject::connect(viewOnlyAction, SIGNAL(triggered(bool)), this, SLOT(OnSetOnlyActiveLabelVisible(bool))); - menu->addAction(viewOnlyAction); - - QAction *viewAllAction = new QAction(QIcon(":/Qmitk/visible.png"), "View all", this); - viewAllAction->setEnabled(true); - QObject::connect(viewAllAction, SIGNAL(triggered(bool)), this, SLOT(OnSetAllLabelsVisible(bool))); - menu->addAction(viewAllAction); - - QAction *hideAllAction = new QAction(QIcon(":/Qmitk/invisible.png"), "Hide all", this); - hideAllAction->setEnabled(true); - QObject::connect(hideAllAction, SIGNAL(triggered(bool)), this, SLOT(OnSetAllLabelsInvisible(bool))); - menu->addAction(hideAllAction); - - QAction *lockAllAction = new QAction(QIcon(":/Qmitk/lock.png"), "Lock all", this); - lockAllAction->setEnabled(true); - QObject::connect(lockAllAction, SIGNAL(triggered(bool)), this, SLOT(OnLockAllLabels(bool))); - menu->addAction(lockAllAction); - - QAction *unlockAllAction = new QAction(QIcon(":/Qmitk/unlock.png"), "Unlock all", this); - unlockAllAction->setEnabled(true); - QObject::connect(unlockAllAction, SIGNAL(triggered(bool)), this, SLOT(OnUnlockAllLabels(bool))); - menu->addAction(unlockAllAction); - - QAction *createSurfaceAction = new QAction(QIcon(":/Qmitk/CreateSurface.png"), "Create surface", this); - createSurfaceAction->setEnabled(true); - createSurfaceAction->setMenu(new QMenu()); - - QAction *tmp1 = createSurfaceAction->menu()->addAction(QString("Detailed")); - QAction *tmp2 = createSurfaceAction->menu()->addAction(QString("Smoothed")); - - QObject::connect(tmp1, SIGNAL(triggered(bool)), this, SLOT(OnCreateDetailedSurface(bool))); - QObject::connect(tmp2, SIGNAL(triggered(bool)), this, SLOT(OnCreateSmoothedSurface(bool))); - - menu->addAction(createSurfaceAction); - - QAction *createMaskAction = new QAction(QIcon(":/Qmitk/CreateMask.png"), "Create mask", this); - createMaskAction->setEnabled(true); - QObject::connect(createMaskAction, SIGNAL(triggered(bool)), this, SLOT(OnCreateMask(bool))); - - menu->addAction(createMaskAction); - - QAction *createCroppedMaskAction = new QAction(QIcon(":/Qmitk/CreateMask.png"), "Create cropped mask", this); - createCroppedMaskAction->setEnabled(true); - QObject::connect(createCroppedMaskAction, SIGNAL(triggered(bool)), this, SLOT(OnCreateCroppedMask(bool))); - - menu->addAction(createCroppedMaskAction); - - QSlider *opacitySlider = new QSlider; - opacitySlider->setMinimum(0); - opacitySlider->setMaximum(100); - opacitySlider->setOrientation(Qt::Horizontal); - QObject::connect(opacitySlider, SIGNAL(valueChanged(int)), this, SLOT(OnOpacityChanged(int))); - - QLabel *_OpacityLabel = new QLabel("Opacity: "); - QVBoxLayout *_OpacityWidgetLayout = new QVBoxLayout; - _OpacityWidgetLayout->setContentsMargins(4, 4, 4, 4); - _OpacityWidgetLayout->addWidget(_OpacityLabel); - _OpacityWidgetLayout->addWidget(opacitySlider); - QWidget *_OpacityWidget = new QWidget; - _OpacityWidget->setLayout(_OpacityWidgetLayout); - - QWidgetAction *OpacityAction = new QWidgetAction(this); - OpacityAction->setDefaultWidget(_OpacityWidget); - // QObject::connect( m_OpacityAction, SIGNAL( changed() ), this, SLOT( OpacityActionChanged() ) ); - auto workingImage = this->GetWorkingImage(); - auto activeLayer = workingImage->GetActiveLayer(); - auto label = workingImage->GetLabel(pixelValue, activeLayer); - - if (nullptr != label) - { - auto opacity = label->GetOpacity(); - opacitySlider->setValue(static_cast(opacity * 100)); - } - - menu->addAction(OpacityAction); - } - menu->popup(QCursor::pos()); -} - -void QmitkLabelSetWidget::OnUnlockAllLabels(bool /*value*/) -{ - GetWorkingImage()->GetActiveLabelSet()->SetAllLabelsLocked(false); - mitk::RenderingManager::GetInstance()->RequestUpdateAll(); -} - -void QmitkLabelSetWidget::OnLockAllLabels(bool /*value*/) -{ - GetWorkingImage()->GetActiveLabelSet()->SetAllLabelsLocked(true); - mitk::RenderingManager::GetInstance()->RequestUpdateAll(); -} - -void QmitkLabelSetWidget::OnSetAllLabelsVisible(bool /*value*/) -{ - GetWorkingImage()->GetActiveLabelSet()->SetAllLabelsVisible(true); - UpdateAllTableWidgetItems(); -} - -void QmitkLabelSetWidget::OnSetAllLabelsInvisible(bool /*value*/) -{ - GetWorkingImage()->GetActiveLabelSet()->SetAllLabelsVisible(false); - UpdateAllTableWidgetItems(); -} - -void QmitkLabelSetWidget::OnSetOnlyActiveLabelVisible(bool /*value*/) -{ - mitk::LabelSetImage *workingImage = GetWorkingImage(); - int pixelValue = GetPixelValueOfSelectedItem(); - - workingImage->GetActiveLabelSet()->SetAllLabelsVisible(false); - workingImage->GetLabel(pixelValue, workingImage->GetActiveLayer())->SetVisible(true); - - workingImage->GetActiveLabelSet()->UpdateLookupTable(pixelValue); - - this->WaitCursorOn(); - - const mitk::Point3D &pos = - workingImage->GetLabel(pixelValue, workingImage->GetActiveLayer())->GetCenterOfMassCoordinates(); - this->WaitCursorOff(); - if (pos.GetVnlVector().max_value() > 0.0) - { - emit goToLabel(pos); - } - - UpdateAllTableWidgetItems(); -} - -void QmitkLabelSetWidget::OnEraseLabel(bool /*value*/) -{ - int pixelValue = GetPixelValueOfSelectedItem(); - QString question = "Do you really want to erase the contents of label \""; - question.append( - QString::fromStdString(GetWorkingImage()->GetLabel(pixelValue, GetWorkingImage()->GetActiveLayer())->GetName())); - question.append("\"?"); - - QMessageBox::StandardButton answerButton = - QMessageBox::question(this, "Erase label", question, QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Yes); - - if (answerButton == QMessageBox::Yes) - { - this->WaitCursorOn(); - GetWorkingImage()->EraseLabel(pixelValue); - this->WaitCursorOff(); - mitk::RenderingManager::GetInstance()->RequestUpdateAll(); - } -} - -void QmitkLabelSetWidget::OnRemoveLabel(bool /*value*/) -{ - int pixelValue = GetPixelValueOfSelectedItem(); - QString question = "Do you really want to remove label \""; - question.append( - QString::fromStdString(GetWorkingImage()->GetLabel(pixelValue, GetWorkingImage()->GetActiveLayer())->GetName())); - question.append("\"?"); - - QMessageBox::StandardButton answerButton = - QMessageBox::question(this, "Remove label", question, QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Yes); - - if (answerButton == QMessageBox::Yes) - { - this->WaitCursorOn(); - GetWorkingImage()->RemoveLabel(pixelValue); - this->WaitCursorOff(); - } - - ResetAllTableWidgetItems(); -} - -void QmitkLabelSetWidget::OnRenameLabel(bool /*value*/) -{ - int pixelValue = GetPixelValueOfSelectedItem(); - QmitkNewSegmentationDialog dialog(this, this->GetWorkingImage(), QmitkNewSegmentationDialog::RenameLabel); - dialog.SetColor(GetWorkingImage()->GetActiveLabelSet()->GetLabel(pixelValue)->GetColor()); - dialog.SetName(QString::fromStdString(GetWorkingImage()->GetActiveLabelSet()->GetLabel(pixelValue)->GetName())); - - if (dialog.exec() == QDialog::Rejected) - { - return; - } - QString segmentationName = dialog.GetName(); - if (segmentationName.isEmpty()) - { - segmentationName = "Unnamed"; - } - - GetWorkingImage()->GetActiveLabelSet()->RenameLabel(pixelValue, segmentationName.toStdString(), dialog.GetColor()); - GetWorkingImage()->GetActiveLabelSet()->UpdateLookupTable(pixelValue); - - UpdateAllTableWidgetItems(); -} - -void QmitkLabelSetWidget::OnRenameLabelShortcutActivated() -{ - if (m_Controls.m_LabelSetTableWidget->selectedItems().size() == 1) - this->OnRenameLabel(true); -} - -void QmitkLabelSetWidget::OnCombineAndCreateMask(bool /*value*/) -{ - m_Controls.m_LabelSetTableWidget->selectedRanges(); - // ...to do... // -} - -void QmitkLabelSetWidget::OnCreateMasks(bool /*value*/) -{ - m_Controls.m_LabelSetTableWidget->selectedRanges(); - // ..to do.. // -} - -void QmitkLabelSetWidget::OnCombineAndCreateSurface(bool /*value*/) -{ - m_Controls.m_LabelSetTableWidget->selectedRanges(); - // ..to do.. // -} - -void QmitkLabelSetWidget::OnEraseLabels(bool /*value*/) -{ - QString question = "Do you really want to erase the selected labels?"; - - QMessageBox::StandardButton answerButton = QMessageBox::question( - this, "Erase selected labels", question, QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Yes); - - if (answerButton == QMessageBox::Yes) - { - QList ranges = m_Controls.m_LabelSetTableWidget->selectedRanges(); - if (ranges.isEmpty()) - return; - - std::vector VectorOfLablePixelValues; - foreach (QTableWidgetSelectionRange a, ranges) - for (int i = a.topRow(); i <= a.bottomRow(); i++) - VectorOfLablePixelValues.push_back(m_Controls.m_LabelSetTableWidget->item(i, 0)->data(Qt::UserRole).toInt()); - - this->WaitCursorOn(); - GetWorkingImage()->EraseLabels(VectorOfLablePixelValues); - this->WaitCursorOff(); - mitk::RenderingManager::GetInstance()->RequestUpdateAll(); - } -} - -void QmitkLabelSetWidget::OnRemoveLabels(bool /*value*/) -{ - QString question = "Do you really want to remove the selected labels?"; - QMessageBox::StandardButton answerButton = QMessageBox::question( - this, "Remove selected labels", question, QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Yes); - - if (answerButton == QMessageBox::Yes) - { - QList ranges = m_Controls.m_LabelSetTableWidget->selectedRanges(); - if (ranges.isEmpty()) - { - return; - } - - std::vector VectorOfLablePixelValues; - foreach (QTableWidgetSelectionRange a, ranges) - { - for (int i = a.topRow(); i <= a.bottomRow(); ++i) - { - VectorOfLablePixelValues.push_back(m_Controls.m_LabelSetTableWidget->item(i, 0)->data(Qt::UserRole).toInt()); - } - } - - this->WaitCursorOn(); - GetWorkingImage()->RemoveLabels(VectorOfLablePixelValues); - this->WaitCursorOff(); - } - - ResetAllTableWidgetItems(); -} - -void QmitkLabelSetWidget::OnMergeLabels(bool /*value*/) -{ - int pixelValue = GetPixelValueOfSelectedItem(); - QString question = "Do you really want to merge selected labels into \""; - question.append( - QString::fromStdString(GetWorkingImage()->GetLabel(pixelValue, GetWorkingImage()->GetActiveLayer())->GetName())); - question.append("\"?"); - - QMessageBox::StandardButton answerButton = QMessageBox::question( - this, "Merge selected label", question, QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Yes); - - if (answerButton == QMessageBox::Yes) - { - QList ranges = m_Controls.m_LabelSetTableWidget->selectedRanges(); - if (ranges.isEmpty()) - { - return; - } - - std::vector vectorOfSourcePixelValues; - foreach (QTableWidgetSelectionRange a, ranges) - { - for (int i = a.topRow(); i <= a.bottomRow(); ++i) - { - vectorOfSourcePixelValues.push_back(m_Controls.m_LabelSetTableWidget->item(i, 0)->data(Qt::UserRole).toInt()); - } - } - - this->WaitCursorOn(); - GetWorkingImage()->MergeLabels(pixelValue, vectorOfSourcePixelValues, GetWorkingImage()->GetActiveLayer()); - this->WaitCursorOff(); - - mitk::RenderingManager::GetInstance()->RequestUpdateAll(); - } -} - -void QmitkLabelSetWidget::OnLockedButtonClicked() -{ - int row = -1; - for (int i = 0; i < m_Controls.m_LabelSetTableWidget->rowCount(); ++i) - { - if (sender() == m_Controls.m_LabelSetTableWidget->cellWidget(i, LOCKED_COL)) - { - row = i; - } - } - if (row >= 0 && row < m_Controls.m_LabelSetTableWidget->rowCount()) - { - int pixelValue = m_Controls.m_LabelSetTableWidget->item(row, 0)->data(Qt::UserRole).toInt(); - GetWorkingImage() - ->GetLabel(pixelValue, GetWorkingImage()->GetActiveLayer()) - ->SetLocked(!GetWorkingImage()->GetLabel(pixelValue, GetWorkingImage()->GetActiveLayer())->GetLocked()); - } -} - -void QmitkLabelSetWidget::OnVisibleButtonClicked() -{ - int row = -1; - for (int i = 0; i < m_Controls.m_LabelSetTableWidget->rowCount(); ++i) - { - if (sender() == m_Controls.m_LabelSetTableWidget->cellWidget(i, VISIBLE_COL)) - { - row = i; - break; - } - } - - if (row >= 0 && row < m_Controls.m_LabelSetTableWidget->rowCount()) - { - QTableWidgetItem *item = m_Controls.m_LabelSetTableWidget->item(row, 0); - int pixelValue = item->data(Qt::UserRole).toInt(); - GetWorkingImage() - ->GetLabel(pixelValue, GetWorkingImage()->GetActiveLayer()) - ->SetVisible(!GetWorkingImage()->GetLabel(pixelValue, GetWorkingImage()->GetActiveLayer())->GetVisible()); - GetWorkingImage()->GetActiveLabelSet()->UpdateLookupTable(pixelValue); - } - - mitk::RenderingManager::GetInstance()->RequestUpdateAll(); -} - -void QmitkLabelSetWidget::OnColorButtonClicked() -{ - int row = -1; - for (int i = 0; i < m_Controls.m_LabelSetTableWidget->rowCount(); ++i) - { - if (sender() == m_Controls.m_LabelSetTableWidget->cellWidget(i, COLOR_COL)) - { - row = i; - } - } - - if (row >= 0 && row < m_Controls.m_LabelSetTableWidget->rowCount()) - { - int pixelValue = m_Controls.m_LabelSetTableWidget->item(row, 0)->data(Qt::UserRole).toInt(); - const mitk::Color &color = GetWorkingImage()->GetLabel(pixelValue, GetWorkingImage()->GetActiveLayer())->GetColor(); - QColor initial(color.GetRed() * 255, color.GetGreen() * 255, color.GetBlue() * 255); - QColor qcolor = QColorDialog::getColor(initial, nullptr, QString("Change color")); - if (!qcolor.isValid()) - { - return; - } - - QPushButton *button = static_cast(m_Controls.m_LabelSetTableWidget->cellWidget(row, COLOR_COL)); - if (!button) - { - return; - } - - button->setAutoFillBackground(true); - - QString styleSheet = "background-color:rgb("; - styleSheet.append(QString::number(qcolor.red())); - styleSheet.append(","); - styleSheet.append(QString::number(qcolor.green())); - styleSheet.append(","); - styleSheet.append(QString::number(qcolor.blue())); - styleSheet.append("); border: 0;"); - button->setStyleSheet(styleSheet); - - mitk::Color newColor; - newColor.SetRed(qcolor.red() / 255.0); - newColor.SetGreen(qcolor.green() / 255.0); - newColor.SetBlue(qcolor.blue() / 255.0); - - GetWorkingImage()->GetLabel(pixelValue, GetWorkingImage()->GetActiveLayer())->SetColor(newColor); - - GetWorkingImage()->GetActiveLabelSet()->UpdateLookupTable(pixelValue); - } -} - -void QmitkLabelSetWidget::OnRandomColor(bool /*value*/) -{ - int pixelValue = GetPixelValueOfSelectedItem(); - GetWorkingImage() - ->GetLabel(pixelValue, GetWorkingImage()->GetActiveLayer()) - ->SetColor(m_ColorSequenceRainbow.GetNextColor()); - GetWorkingImage()->GetActiveLabelSet()->UpdateLookupTable(pixelValue); - UpdateAllTableWidgetItems(); -} - -void QmitkLabelSetWidget::OnActiveLabelChanged(int pixelValue) -{ - mitk::LabelSetImage *workingImage = GetWorkingImage(); - assert(workingImage); - workingImage->GetActiveLabelSet()->SetActiveLabel(pixelValue); - // MITK_INFO << "Active Label set to << " << pixelValue; - - workingImage->Modified(); - mitk::RenderingManager::GetInstance()->RequestUpdateAll(); -} - -void QmitkLabelSetWidget::OnItemClicked(QTableWidgetItem *item) -{ - if (!item) - return; - - int pixelValue = item->data(Qt::UserRole).toInt(); - - QList ranges = m_Controls.m_LabelSetTableWidget->selectedRanges(); - if (!ranges.empty() && ranges.back().rowCount() == 1) - { - m_ProcessingManualSelection = true; - OnActiveLabelChanged(pixelValue); - m_ProcessingManualSelection = false; - mitk::RenderingManager::GetInstance()->RequestUpdateAll(); - } -} - -void QmitkLabelSetWidget::OnItemDoubleClicked(QTableWidgetItem *item) -{ - if (!item) - return; - - if (QApplication::queryKeyboardModifiers().testFlag(Qt::AltModifier)) - { - this->OnRenameLabelShortcutActivated(); - return; - } - - int pixelValue = item->data(Qt::UserRole).toInt(); - // OnItemClicked(item); <<-- Double click first call OnItemClicked - WaitCursorOn(); - mitk::LabelSetImage *workingImage = GetWorkingImage(); - workingImage->UpdateCenterOfMass(pixelValue, workingImage->GetActiveLayer()); - const mitk::Point3D &pos = - workingImage->GetLabel(pixelValue, workingImage->GetActiveLayer())->GetCenterOfMassCoordinates(); - WaitCursorOff(); - if (pos.GetVnlVector().max_value() > 0.0) - { - emit goToLabel(pos); - } - - workingImage->Modified(); - mitk::RenderingManager::GetInstance()->RequestUpdateAll(); -} - -void QmitkLabelSetWidget::SelectLabelByPixelValue(mitk::Label::PixelType pixelValue) -{ - if (m_ProcessingManualSelection || !GetWorkingImage()->ExistLabel(pixelValue)) - return; - - for (int row = 0; row < m_Controls.m_LabelSetTableWidget->rowCount(); row++) - { - if (m_Controls.m_LabelSetTableWidget->item(row, 0)->data(Qt::UserRole).toInt() == pixelValue) - { - m_Controls.m_LabelSetTableWidget->clearSelection(); - m_Controls.m_LabelSetTableWidget->selectRow(row); - m_Controls.m_LabelSetTableWidget->scrollToItem(m_Controls.m_LabelSetTableWidget->item(row, 0)); - return; - } - } -} - -void QmitkLabelSetWidget::InsertTableWidgetItem(mitk::Label *label) -{ - const mitk::Color &color = label->GetColor(); - - QString styleSheet = "background-color:rgb("; - styleSheet.append(QString::number(color[0] * 255)); - styleSheet.append(","); - styleSheet.append(QString::number(color[1] * 255)); - styleSheet.append(","); - styleSheet.append(QString::number(color[2] * 255)); - styleSheet.append("); border: 0;"); - - QTableWidget *tableWidget = m_Controls.m_LabelSetTableWidget; - int colWidth = (tableWidget->columnWidth(NAME_COL) < 180) ? 180 : tableWidget->columnWidth(NAME_COL) - 2; - QString text = fontMetrics().elidedText(label->GetName().c_str(), Qt::ElideMiddle, colWidth); - QTableWidgetItem *nameItem = new QTableWidgetItem(text); - nameItem->setTextAlignment(Qt::AlignCenter | Qt::AlignLeft); - // ---!--- - // IMPORTANT: ADD PIXELVALUE TO TABLEWIDGETITEM.DATA - nameItem->setData(Qt::UserRole, QVariant(label->GetValue())); - // ---!--- - - QPushButton *pbColor = new QPushButton(tableWidget); - pbColor->setFixedSize(24, 24); - pbColor->setCheckable(false); - pbColor->setAutoFillBackground(true); - pbColor->setToolTip("Change label color"); - pbColor->setStyleSheet(styleSheet); - - connect(pbColor, SIGNAL(clicked()), this, SLOT(OnColorButtonClicked())); - - QString transparentStyleSheet = QLatin1String("background-color: transparent; border: 0;"); - - QPushButton *pbLocked = new QPushButton(tableWidget); - pbLocked->setFixedSize(24, 24); - QIcon *iconLocked = new QIcon(); - auto lockIcon = QmitkStyleManager::ThemeIcon(QLatin1String(":/Qmitk/lock.svg")); - auto unlockIcon = QmitkStyleManager::ThemeIcon(QLatin1String(":/Qmitk/unlock.svg")); - iconLocked->addPixmap(lockIcon.pixmap(64), QIcon::Normal, QIcon::Off); - iconLocked->addPixmap(unlockIcon.pixmap(64), QIcon::Normal, QIcon::On); - pbLocked->setIcon(*iconLocked); - pbLocked->setIconSize(QSize(24, 24)); - pbLocked->setCheckable(true); - pbLocked->setToolTip("Lock/unlock label"); - pbLocked->setChecked(!label->GetLocked()); - pbLocked->setStyleSheet(transparentStyleSheet); - - connect(pbLocked, SIGNAL(clicked()), this, SLOT(OnLockedButtonClicked())); - - QPushButton *pbVisible = new QPushButton(tableWidget); - pbVisible->setFixedSize(24, 24); - pbVisible->setAutoRepeat(false); - QIcon *iconVisible = new QIcon(); - auto visibleIcon = QmitkStyleManager::ThemeIcon(QLatin1String(":/Qmitk/visible.svg")); - auto invisibleIcon = QmitkStyleManager::ThemeIcon(QLatin1String(":/Qmitk/invisible.svg")); - iconVisible->addPixmap(visibleIcon.pixmap(64), QIcon::Normal, QIcon::Off); - iconVisible->addPixmap(invisibleIcon.pixmap(64), QIcon::Normal, QIcon::On); - pbVisible->setIcon(*iconVisible); - pbVisible->setIconSize(QSize(24, 24)); - pbVisible->setCheckable(true); - pbVisible->setToolTip("Show/hide label"); - pbVisible->setChecked(!label->GetVisible()); - pbVisible->setStyleSheet(transparentStyleSheet); - - connect(pbVisible, SIGNAL(clicked()), this, SLOT(OnVisibleButtonClicked())); - - int row = tableWidget->rowCount(); - tableWidget->insertRow(row); - tableWidget->setRowHeight(row, 24); - tableWidget->setItem(row, 0, nameItem); - tableWidget->setCellWidget(row, 1, pbLocked); - tableWidget->setCellWidget(row, 2, pbColor); - tableWidget->setCellWidget(row, 3, pbVisible); - tableWidget->selectRow(row); - - // m_LabelSetImage->SetActiveLabel(label->GetPixelValue()); - // m_ToolManager->WorkingDataModified.Send(); - // emit activeLabelChanged(label->GetPixelValue()); - - if (row == 0) - { - tableWidget->hideRow(row); // hide exterior label - } -} - -void QmitkLabelSetWidget::UpdateAllTableWidgetItems(mitk::Label::PixelType /*lv*/) -{ - this->UpdateAllTableWidgetItems(); -} - -void QmitkLabelSetWidget::UpdateAllTableWidgetItems() -{ - mitk::LabelSetImage *workingImage = GetWorkingImage(); - if (!workingImage) - return; - - // add all labels - QTableWidget *tableWidget = m_Controls.m_LabelSetTableWidget; - m_LabelStringList.clear(); - for (int i = 0; i < tableWidget->rowCount(); ++i) - { - UpdateTableWidgetItem(tableWidget->item(i, 0)); - m_LabelStringList.append(tableWidget->item(i, 0)->text()); - } - - OnLabelListModified(m_LabelStringList); - - mitk::RenderingManager::GetInstance()->RequestUpdateAll(); -} - -void QmitkLabelSetWidget::UpdateTableWidgetItem(QTableWidgetItem *item) -{ - mitk::LabelSetImage *workingImage = GetWorkingImage(); - mitk::Label *label = workingImage->GetLabel(item->data(Qt::UserRole).toInt(), workingImage->GetActiveLayer()); - - const mitk::Color &color = label->GetColor(); - - QString styleSheet = "background-color:rgb("; - styleSheet.append(QString::number(color[0] * 255)); - styleSheet.append(","); - styleSheet.append(QString::number(color[1] * 255)); - styleSheet.append(","); - styleSheet.append(QString::number(color[2] * 255)); - styleSheet.append("); border: 0;"); - - QTableWidget *tableWidget = m_Controls.m_LabelSetTableWidget; - int colWidth = (tableWidget->columnWidth(NAME_COL) < 180) ? 180 : tableWidget->columnWidth(NAME_COL) - 2; - QString text = fontMetrics().elidedText(label->GetName().c_str(), Qt::ElideMiddle, colWidth); - item->setText(text); - - QPushButton *pbLocked = dynamic_cast(tableWidget->cellWidget(item->row(), 1)); - pbLocked->setChecked(!label->GetLocked()); - - QPushButton *pbColor = dynamic_cast(tableWidget->cellWidget(item->row(), 2)); - pbColor->setStyleSheet(styleSheet); - - QPushButton *pbVisible = dynamic_cast(tableWidget->cellWidget(item->row(), 3)); - pbVisible->setChecked(!label->GetVisible()); - - if (item->row() == 0) - { - tableWidget->hideRow(item->row()); // hide exterior label - } -} - -void QmitkLabelSetWidget::ResetAllTableWidgetItems(mitk::Label::PixelType /*lv*/) -{ - this->ResetAllTableWidgetItems(); -} - -void QmitkLabelSetWidget::ResetAllTableWidgetItems() -{ - QTableWidget *tableWidget = m_Controls.m_LabelSetTableWidget; - // remove all rows - while (tableWidget->rowCount()) - { - tableWidget->removeRow(0); - } - - mitk::DataNode * workingNode = GetWorkingNode(); - auto workingImage = dynamic_cast(workingNode->GetData()); - if (nullptr == workingImage) - { - return; - } - - // add all labels - m_LabelStringList.clear(); - - mitk::LabelSet::LabelContainerConstIteratorType it = workingImage->GetActiveLabelSet()->IteratorConstBegin(); - mitk::LabelSet::LabelContainerConstIteratorType end = workingImage->GetActiveLabelSet()->IteratorConstEnd(); - - int pixelValue = -1; - while (it != end) - { - InsertTableWidgetItem(it->second); - if (workingImage->GetActiveLabel(workingImage->GetActiveLayer()) == it->second) // get active - pixelValue = it->first; - m_LabelStringList.append(QString(it->second->GetName().c_str())); - it++; - } - - SelectLabelByPixelValue(pixelValue); - - OnLabelListModified(m_LabelStringList); - - std::stringstream captionText; - captionText << "Number of labels: " << workingImage->GetNumberOfLabels(workingImage->GetActiveLayer()) - 1; - m_Controls.m_lblCaption->setText(captionText.str().c_str()); - - mitk::RenderingManager::GetInstance()->RequestUpdateAll(); - - emit LabelSetWidgetReset(); -} - -int QmitkLabelSetWidget::GetPixelValueOfSelectedItem() -{ - if (m_Controls.m_LabelSetTableWidget->currentItem()) - { - return m_Controls.m_LabelSetTableWidget->currentItem()->data(Qt::UserRole).toInt(); - } - return -1; -} - -QStringList &QmitkLabelSetWidget::GetLabelStringList() -{ - return m_LabelStringList; -} - -void QmitkLabelSetWidget::InitializeTableWidget() -{ - auto* tableWidget = m_Controls.m_LabelSetTableWidget; - - tableWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); - tableWidget->setTabKeyNavigation(false); - tableWidget->setAlternatingRowColors(false); - tableWidget->setFocusPolicy(Qt::NoFocus); - tableWidget->setColumnCount(4); - tableWidget->resizeColumnToContents(NAME_COL); - tableWidget->setColumnWidth(LOCKED_COL, 25); - tableWidget->setColumnWidth(COLOR_COL, 25); - tableWidget->setColumnWidth(VISIBLE_COL, 25); - tableWidget->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch); - tableWidget->setContextMenuPolicy(Qt::CustomContextMenu); - tableWidget->horizontalHeader()->hide(); - tableWidget->setSortingEnabled(false); - tableWidget->verticalHeader()->hide(); - tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers); - - using Self = QmitkLabelSetWidget; - - connect(tableWidget, &QTableWidget::itemClicked, this, &Self::OnItemClicked); - connect(tableWidget, &QTableWidget::itemDoubleClicked, this, &Self::OnItemDoubleClicked); - connect(tableWidget, &QTableWidget::customContextMenuRequested, this, &Self::OnTableViewContextMenuRequested); - - auto* model = tableWidget->model(); - - connect(model, &QAbstractItemModel::rowsInserted, this, &Self::OnRowsInserted); - connect(model, &QAbstractItemModel::rowsRemoved, this, &Self::OnRowsRemoved); -} - -void QmitkLabelSetWidget::OnRowsInserted(const QModelIndex&, int, int) -{ - auto* tableWidget = m_Controls.m_LabelSetTableWidget; - - if (tableWidget->rowCount() > 4) - { - tableWidget->setMinimumHeight(160); - tableWidget->setMaximumHeight(tableWidget->minimumHeight()); - } -} - -void QmitkLabelSetWidget::OnRowsRemoved(const QModelIndex&, int, int) -{ - auto* tableWidget = m_Controls.m_LabelSetTableWidget; - - if (tableWidget->rowCount() <= 4) - { - tableWidget->setMinimumHeight(80); - tableWidget->setMaximumHeight(tableWidget->minimumHeight()); - } -} - -void QmitkLabelSetWidget::OnOpacityChanged(int value) -{ - int pixelValue = GetPixelValueOfSelectedItem(); - float opacity = static_cast(value) / 100.0f; - GetWorkingImage()->GetLabel(pixelValue, GetWorkingImage()->GetActiveLayer())->SetOpacity(opacity); - GetWorkingImage()->GetActiveLabelSet()->UpdateLookupTable(pixelValue); -} - -void QmitkLabelSetWidget::setEnabled(bool enabled) -{ - QWidget::setEnabled(enabled); - UpdateControls(); -} - -void QmitkLabelSetWidget::SetDataStorage(mitk::DataStorage *storage) -{ - m_DataStorage = storage; -} - -void QmitkLabelSetWidget::OnSearchLabel() -{ - std::string text = m_Controls.m_LabelSearchBox->text().toStdString(); - int pixelValue = -1; - int row = -1; - for (int i = 0; i < m_Controls.m_LabelSetTableWidget->rowCount(); ++i) - { - if (m_Controls.m_LabelSetTableWidget->item(i, 0)->text().toStdString().compare(text) == 0) - { - pixelValue = m_Controls.m_LabelSetTableWidget->item(i, 0)->data(Qt::UserRole).toInt(); - row = i; - break; - } - } - if (pixelValue == -1) - { - return; - } - - GetWorkingImage()->GetActiveLabelSet()->SetActiveLabel(pixelValue); - - QTableWidgetItem *nameItem = m_Controls.m_LabelSetTableWidget->item(row, NAME_COL); - if (!nameItem) - { - return; - } - - m_Controls.m_LabelSetTableWidget->clearSelection(); - m_Controls.m_LabelSetTableWidget->selectRow(row); - m_Controls.m_LabelSetTableWidget->scrollToItem(nameItem); - - GetWorkingImage()->GetActiveLabelSet()->SetActiveLabel(pixelValue); - - this->WaitCursorOn(); - mitk::Point3D pos = - GetWorkingImage()->GetLabel(pixelValue, GetWorkingImage()->GetActiveLayer())->GetCenterOfMassCoordinates(); - - m_ToolManager->WorkingDataChanged(); - - if (pos.GetVnlVector().max_value() > 0.0) - { - emit goToLabel(pos); - } - else - { - GetWorkingImage()->UpdateCenterOfMass(pixelValue, GetWorkingImage()->GetActiveLayer()); - mitk::Point3D pos = - GetWorkingImage()->GetLabel(pixelValue, GetWorkingImage()->GetActiveLayer())->GetCenterOfMassCoordinates(); - emit goToLabel(pos); - } - - this->WaitCursorOff(); -} - -void QmitkLabelSetWidget::OnLabelListModified(const QStringList &list) -{ - QStringListModel *completeModel = static_cast(m_Completer->model()); - completeModel->setStringList(list); -} - -mitk::LabelSetImage *QmitkLabelSetWidget::GetWorkingImage() -{ - mitk::DataNode *workingNode = GetWorkingNode(); - mitk::LabelSetImage *workingImage = dynamic_cast(workingNode->GetData()); - assert(workingImage); - return workingImage; -} - -mitk::DataNode *QmitkLabelSetWidget::GetWorkingNode() -{ - mitk::DataNode *workingNode = m_ToolManager->GetWorkingData(0); - assert(workingNode); - return workingNode; -} - -void QmitkLabelSetWidget::UpdateControls() -{ - mitk::DataNode *workingNode = m_ToolManager->GetWorkingData(0); - bool hasWorkingData = (workingNode != nullptr); - - m_Controls.m_LabelSetTableWidget->setEnabled(hasWorkingData); - m_Controls.m_LabelSearchBox->setEnabled(hasWorkingData); - - if (!hasWorkingData) - return; - - QStringListModel *completeModel = static_cast(m_Completer->model()); - completeModel->setStringList(GetLabelStringList()); -} - -void QmitkLabelSetWidget::OnCreateCroppedMask(bool) -{ - m_ToolManager->ActivateTool(-1); - - mitk::LabelSetImage *workingImage = GetWorkingImage(); - mitk::Image::Pointer maskImage; - int pixelValue = GetPixelValueOfSelectedItem(); - try - { - this->WaitCursorOn(); - - mitk::AutoCropImageFilter::Pointer cropFilter = mitk::AutoCropImageFilter::New(); - cropFilter->SetInput(workingImage->CreateLabelMask(pixelValue)); - cropFilter->SetBackgroundValue(0); - cropFilter->SetMarginFactor(1.15); - cropFilter->Update(); - - maskImage = cropFilter->GetOutput(); - - this->WaitCursorOff(); - } - catch (mitk::Exception &e) - { - this->WaitCursorOff(); - MITK_ERROR << "Exception caught: " << e.GetDescription(); - QMessageBox::information(this, "Create Mask", "Could not create a mask out of the selected label.\n"); - return; - } - - if (maskImage.IsNull()) - { - QMessageBox::information(this, "Create Mask", "Could not create a mask out of the selected label.\n"); - return; - } - - mitk::DataNode::Pointer maskNode = mitk::DataNode::New(); - std::string name = workingImage->GetLabel(pixelValue, workingImage->GetActiveLayer())->GetName(); - name += "-mask"; - maskNode->SetName(name); - maskNode->SetData(maskImage); - maskNode->SetBoolProperty("binary", true); - maskNode->SetBoolProperty("outline binary", true); - maskNode->SetBoolProperty("outline binary shadow", true); - maskNode->SetFloatProperty("outline width", 2.0); - maskNode->SetColor(workingImage->GetLabel(pixelValue, workingImage->GetActiveLayer())->GetColor()); - maskNode->SetOpacity(1.0); - - m_DataStorage->Add(maskNode, GetWorkingNode()); -} - -void QmitkLabelSetWidget::OnCreateMask(bool /*triggered*/) -{ - m_ToolManager->ActivateTool(-1); - - mitk::LabelSetImage *workingImage = GetWorkingImage(); - mitk::Image::Pointer maskImage; - int pixelValue = GetPixelValueOfSelectedItem(); - try - { - this->WaitCursorOn(); - maskImage = workingImage->CreateLabelMask(pixelValue); - this->WaitCursorOff(); - } - catch (mitk::Exception &e) - { - this->WaitCursorOff(); - MITK_ERROR << "Exception caught: " << e.GetDescription(); - QMessageBox::information(this, "Create Mask", "Could not create a mask out of the selected label.\n"); - return; - } - - if (maskImage.IsNull()) - { - QMessageBox::information(this, "Create Mask", "Could not create a mask out of the selected label.\n"); - return; - } - - mitk::DataNode::Pointer maskNode = mitk::DataNode::New(); - std::string name = workingImage->GetLabel(pixelValue, workingImage->GetActiveLayer())->GetName(); - name += "-mask"; - maskNode->SetName(name); - maskNode->SetData(maskImage); - maskNode->SetBoolProperty("binary", true); - maskNode->SetBoolProperty("outline binary", true); - maskNode->SetBoolProperty("outline binary shadow", true); - maskNode->SetFloatProperty("outline width", 2.0); - maskNode->SetColor(workingImage->GetLabel(pixelValue, workingImage->GetActiveLayer())->GetColor()); - maskNode->SetOpacity(1.0); - - m_DataStorage->Add(maskNode, GetWorkingNode()); -} - -void QmitkLabelSetWidget::OnToggleOutline(bool value) -{ - mitk::DataNode *workingNode = m_ToolManager->GetWorkingData(0); - assert(workingNode); - - workingNode->SetBoolProperty("labelset.contour.active", value); - workingNode->GetData()->Modified(); // fixme: workaround to force data-type rendering (and not only property-type) - mitk::RenderingManager::GetInstance()->RequestUpdateAll(); -} - -void QmitkLabelSetWidget::OnCreateSmoothedSurface(bool /*triggered*/) -{ - m_ToolManager->ActivateTool(-1); - - mitk::DataNode::Pointer workingNode = GetWorkingNode(); - mitk::LabelSetImage *workingImage = GetWorkingImage(); - int pixelValue = GetPixelValueOfSelectedItem(); - - mitk::LabelSetImageToSurfaceThreadedFilter::Pointer surfaceFilter = mitk::LabelSetImageToSurfaceThreadedFilter::New(); - - itk::SimpleMemberCommand::Pointer successCommand = - itk::SimpleMemberCommand::New(); - successCommand->SetCallbackFunction(this, &QmitkLabelSetWidget::OnThreadedCalculationDone); - surfaceFilter->AddObserver(mitk::ResultAvailable(), successCommand); - - itk::SimpleMemberCommand::Pointer errorCommand = - itk::SimpleMemberCommand::New(); - errorCommand->SetCallbackFunction(this, &QmitkLabelSetWidget::OnThreadedCalculationDone); - surfaceFilter->AddObserver(mitk::ProcessingError(), errorCommand); - - mitk::DataNode::Pointer groupNode = workingNode; - surfaceFilter->SetPointerParameter("Group node", groupNode); - surfaceFilter->SetPointerParameter("Input", workingImage); - surfaceFilter->SetParameter("RequestedLabel", pixelValue); - surfaceFilter->SetParameter("Smooth", true); - surfaceFilter->SetDataStorage(*m_DataStorage); - - mitk::StatusBar::GetInstance()->DisplayText("Surface creation is running in background..."); - - try - { - surfaceFilter->StartAlgorithm(); - } - catch (mitk::Exception &e) - { - MITK_ERROR << "Exception caught: " << e.GetDescription(); - QMessageBox::information(this, - "Create Surface", - "Could not create a surface mesh out of the selected label. See error log for details.\n"); - } -} - -void QmitkLabelSetWidget::OnCreateDetailedSurface(bool /*triggered*/) -{ - m_ToolManager->ActivateTool(-1); - - mitk::DataNode::Pointer workingNode = GetWorkingNode(); - mitk::LabelSetImage *workingImage = GetWorkingImage(); - int pixelValue = GetPixelValueOfSelectedItem(); - - mitk::LabelSetImageToSurfaceThreadedFilter::Pointer surfaceFilter = mitk::LabelSetImageToSurfaceThreadedFilter::New(); - - itk::SimpleMemberCommand::Pointer successCommand = - itk::SimpleMemberCommand::New(); - successCommand->SetCallbackFunction(this, &QmitkLabelSetWidget::OnThreadedCalculationDone); - surfaceFilter->AddObserver(mitk::ResultAvailable(), successCommand); - - itk::SimpleMemberCommand::Pointer errorCommand = - itk::SimpleMemberCommand::New(); - errorCommand->SetCallbackFunction(this, &QmitkLabelSetWidget::OnThreadedCalculationDone); - surfaceFilter->AddObserver(mitk::ProcessingError(), errorCommand); - - mitk::DataNode::Pointer groupNode = workingNode; - surfaceFilter->SetPointerParameter("Group node", groupNode); - surfaceFilter->SetPointerParameter("Input", workingImage); - surfaceFilter->SetParameter("RequestedLabel", pixelValue); - surfaceFilter->SetParameter("Smooth", false); - surfaceFilter->SetDataStorage(*m_DataStorage); - - mitk::StatusBar::GetInstance()->DisplayText("Surface creation is running in background..."); - - try - { - surfaceFilter->StartAlgorithm(); - } - catch (mitk::Exception &e) - { - MITK_ERROR << "Exception caught: " << e.GetDescription(); - QMessageBox::information(this, - "Create Surface", - "Could not create a surface mesh out of the selected label. See error log for details.\n"); - } -} - -void QmitkLabelSetWidget::WaitCursorOn() -{ - QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); -} - -void QmitkLabelSetWidget::WaitCursorOff() -{ - this->RestoreOverrideCursor(); -} - -void QmitkLabelSetWidget::RestoreOverrideCursor() -{ - QApplication::restoreOverrideCursor(); -} - -void QmitkLabelSetWidget::OnThreadedCalculationDone() -{ - mitk::StatusBar::GetInstance()->Clear(); -} diff --git a/Plugins/org.mitk.gui.qt.segmentation/src/QmitkLabelSetWidget.h b/Plugins/org.mitk.gui.qt.segmentation/src/QmitkLabelSetWidget.h deleted file mode 100644 index bf6dacb06b..0000000000 --- a/Plugins/org.mitk.gui.qt.segmentation/src/QmitkLabelSetWidget.h +++ /dev/null @@ -1,171 +0,0 @@ -/*============================================================================ - -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 QmitkLabelSetWidget_h -#define QmitkLabelSetWidget_h - -#include - -#include -#include -#include -#include - -class QmitkDataStorageComboBox; -class QCompleter; - -namespace mitk -{ - class LabelSetImage; - class LabelSet; - class Label; - class DataStorage; - class ToolManager; - class DataNode; -} - -class MITK_QT_SEGMENTATION QmitkLabelSetWidget : public QWidget -{ - Q_OBJECT - -public: - explicit QmitkLabelSetWidget(QWidget *parent = nullptr); - ~QmitkLabelSetWidget() override; - - void SetDataStorage(mitk::DataStorage *storage); - - void UpdateControls(); - - virtual void setEnabled(bool enabled); - - QStringList &GetLabelStringList(); - -signals: - - /// \brief Send a signal when it was requested to go to a label. - void goToLabel(const mitk::Point3D &); - void LabelSetWidgetReset(); - -public slots: - - /** - * @brief Updates the current labels in the label set widget table. For each label (widget item) the 'UpdateTableWidgetItem' is called. - * - * Updating means setting the color box of the table, setting the column with and fill it with the label name. - * Furthermore the two push buttons for locking and showing/hiding the layer are checked/unchecked. - * This functions only changes the appearance of the table widget and no render window update is necessary. - */ - void UpdateAllTableWidgetItems(); - void UpdateAllTableWidgetItems(mitk::Label::PixelType); - /** - * @brief Resets the current labels in the label set widget table. For each label a widget item is inserted into the table. - * - * Resetting means removing all rows of the widget table and inserting new rows (labels) from the active label set (= layer) of the current working node. - * The currently active label is selected and 'Number of labels' is set. - * As this function is typically used after one label has been removed or the reference node has been changed (e.g.) the render windows have to be updated. - */ - void ResetAllTableWidgetItems(); - void ResetAllTableWidgetItems(mitk::Label::PixelType); - - void SelectLabelByPixelValue(mitk::Label::PixelType pixelValue); - -private slots: - - // LabelSet dependent - void OnOpacityChanged(int); - void OnUnlockAllLabels(bool); - void OnLockAllLabels(bool); - void OnSetAllLabelsVisible(bool); - void OnSetAllLabelsInvisible(bool); - void OnSetOnlyActiveLabelVisible(bool); - void OnRandomColor(bool); - void OnRemoveLabel(bool); - void OnRemoveLabels(bool); - void OnRenameLabel(bool); - void OnRenameLabelShortcutActivated(); - void OnLockedButtonClicked(); - void OnVisibleButtonClicked(); - void OnColorButtonClicked(); - void OnItemClicked(QTableWidgetItem *item); - void OnItemDoubleClicked(QTableWidgetItem *item); - void OnTableViewContextMenuRequested(const QPoint &); - void InsertTableWidgetItem(mitk::Label *label); - void UpdateTableWidgetItem(QTableWidgetItem *item); - // reaction to "returnPressed" signal from ... - void OnSearchLabel(); - // reaction to the button "Change Label" - void OnActiveLabelChanged(int pixelValue); - - // LabelSetImage Dependent - void OnCreateDetailedSurface(bool); - void OnCreateSmoothedSurface(bool); - // reaction to the signal "createMask" from QmitkLabelSetTableWidget - void OnCreateMask(bool); - void OnCreateMasks(bool); - // reaction to the signal "createCroppedMask" from QmitkLabelSetTableWidget - void OnCreateCroppedMask(bool); - void OnCombineAndCreateMask(bool); - void OnCombineAndCreateSurface(bool); - void OnEraseLabel(bool); - void OnEraseLabels(bool); - void OnMergeLabels(bool); - - // reaction to signal "labelListModified" from QmitkLabelSetTableWidget - void OnLabelListModified(const QStringList &list); - // reaction to the signal "toggleOutline" from QmitkLabelSetTableWidget - void OnToggleOutline(bool); - void OnRowsInserted(const QModelIndex&, int, int); - void OnRowsRemoved(const QModelIndex&, int, int); - -private: - enum TableColumns - { - NAME_COL = 0, - LOCKED_COL, - COLOR_COL, - VISIBLE_COL - }; - - void WaitCursorOn(); - - void WaitCursorOff(); - - void RestoreOverrideCursor(); - - void OnThreadedCalculationDone(); - - void InitializeTableWidget(); - - int GetPixelValueOfSelectedItem(); - - mitk::LabelSetImage *GetWorkingImage(); - - mitk::DataNode *GetWorkingNode(); - - Ui::QmitkLabelSetWidgetControls m_Controls; - - mitk::ColorSequenceRainbow m_ColorSequenceRainbow; - - mitk::DataStorage *m_DataStorage; - - QCompleter *m_Completer; - - mitk::ToolManager *m_ToolManager; - - QStringList m_OrganColors; - - QStringList m_LabelStringList; - - bool m_ProcessingManualSelection; -}; - -#endif diff --git a/Plugins/org.mitk.gui.qt.segmentation/src/QmitkLabelSetWidgetControls.ui b/Plugins/org.mitk.gui.qt.segmentation/src/QmitkLabelSetWidgetControls.ui deleted file mode 100644 index 9549002939..0000000000 --- a/Plugins/org.mitk.gui.qt.segmentation/src/QmitkLabelSetWidgetControls.ui +++ /dev/null @@ -1,94 +0,0 @@ - - - QmitkLabelSetWidgetControls - - - - 0 - 0 - 312 - 137 - - - - - 0 - 0 - - - - - - - - 6 - - - 6 - - - 6 - - - 6 - - - - - - 0 - 0 - - - - Caption - - - - - - - - 0 - 0 - - - - - 0 - 80 - - - - - 16777215 - 80 - - - - QAbstractItemView::SelectRows - - - - - - - - 0 - 0 - - - - - - - - - ctkSearchBox - QLineEdit -
ctkSearchBox.h
-
-
- - -
diff --git a/Plugins/org.mitk.gui.qt.segmentation/src/internal/Common/QmitkLabelsWidget.cpp b/Plugins/org.mitk.gui.qt.segmentation/src/internal/Common/QmitkLabelsWidget.cpp deleted file mode 100644 index 656bd0c271..0000000000 --- a/Plugins/org.mitk.gui.qt.segmentation/src/internal/Common/QmitkLabelsWidget.cpp +++ /dev/null @@ -1,205 +0,0 @@ -/*============================================================================ - -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 "QmitkLabelsWidget.h" -#include - -// mitk -#include -#include -#include -#include -#include - -// Qmitk -#include -#include -#include - -#include "../QmitkSaveMultiLabelPresetAction.h" -#include "../QmitkLoadMultiLabelPresetAction.h" - -// Qt -#include -#include - -QmitkLabelsWidget::QmitkLabelsWidget(QWidget *parent) - : QWidget(parent) - , m_Controls(new Ui::QmitkLabelsWidgetControls) - , m_ToolManager(nullptr) - , m_DefaultLabelNaming(true) -{ - m_Controls->setupUi(this); - - m_ToolManager = mitk::ToolManagerProvider::GetInstance()->GetToolManager(); - - m_Controls->savePresetButton->setIcon(QmitkStyleManager::ThemeIcon(QStringLiteral(":/org_mitk_icons/icons/awesome/scalable/actions/document-save.svg"))); - m_Controls->loadPresetButton->setIcon(QmitkStyleManager::ThemeIcon(QStringLiteral(":/org_mitk_icons/icons/awesome/scalable/actions/document-open.svg"))); - - connect(m_Controls->newLabelButton, &QToolButton::clicked, this, &QmitkLabelsWidget::OnNewLabel); - connect(m_Controls->lockExteriorButton, &QToolButton::toggled, this, &QmitkLabelsWidget::OnLockExterior); - connect(m_Controls->savePresetButton, &QToolButton::clicked, this, &QmitkLabelsWidget::OnSavePreset); - connect(m_Controls->loadPresetButton, &QToolButton::clicked, this, &QmitkLabelsWidget::OnLoadPreset); - connect(m_Controls->showLabelTableButton, &QToolButton::toggled, this, &QmitkLabelsWidget::ShowLabelTable); - - auto* newLabelShortcut = new QShortcut(QKeySequence(Qt::CTRL | Qt::Key::Key_L, Qt::CTRL | Qt::Key::Key_N), this); - connect(newLabelShortcut, &QShortcut::activated, this, &QmitkLabelsWidget::OnNewLabelShortcutActivated); - - this->UpdateGUI(); -} - -QmitkLabelsWidget::~QmitkLabelsWidget() -{ - delete m_Controls; -} - -void QmitkLabelsWidget::UpdateGUI() -{ - m_Controls->newLabelButton->setEnabled(false); - m_Controls->lockExteriorButton->setEnabled(false); - m_Controls->lockExteriorButton->setChecked(false); - m_Controls->savePresetButton->setEnabled(false); - m_Controls->loadPresetButton->setEnabled(false); - m_Controls->showLabelTableButton->setEnabled(false); - m_Controls->showLabelTableButton->setChecked(false); - - mitk::LabelSetImage* workingImage = this->GetWorkingImage(); - if (nullptr == workingImage) - { - return; - } - - int activeLayer = workingImage->GetActiveLayer(); - m_Controls->lockExteriorButton->setEnabled(true); - m_Controls->lockExteriorButton->setChecked(workingImage->GetLabel(0, activeLayer)->GetLocked()); - m_Controls->showLabelTableButton->setEnabled(true); - m_Controls->showLabelTableButton->setChecked(true); - m_Controls->newLabelButton->setEnabled(true); - m_Controls->savePresetButton->setEnabled(true); - m_Controls->loadPresetButton->setEnabled(true); -} - -void QmitkLabelsWidget::SetDefaultLabelNaming(bool defaultLabelNaming) -{ - m_DefaultLabelNaming = defaultLabelNaming; -} - -mitk::LabelSetImage* QmitkLabelsWidget::GetWorkingImage() -{ - mitk::DataNode* workingNode = this->GetWorkingNode(); - if (nullptr == workingNode) - { - return nullptr; - } - - auto workingImage = dynamic_cast(workingNode->GetData()); - return workingImage; -} - -mitk::DataNode* QmitkLabelsWidget::GetWorkingNode() -{ - mitk::DataNode* referenceNode = m_ToolManager->GetWorkingData(0); - return referenceNode; -} - -void QmitkLabelsWidget::OnNewLabel() -{ - m_ToolManager->ActivateTool(-1); - - mitk::DataNode* workingNode = this->GetWorkingNode(); - if (nullptr == workingNode) - { - return; - } - - auto workingImage = dynamic_cast(workingNode->GetData()); - if (nullptr == workingImage) - { - return; - } - - mitk::Label::Pointer newLabel = mitk::LabelSetImageHelper::CreateNewLabel(workingImage); - - if (!m_DefaultLabelNaming) - { - QmitkNewSegmentationDialog dialog(this, workingImage); - dialog.SetName(QString::fromStdString(newLabel->GetName())); - dialog.SetColor(newLabel->GetColor()); - - if (QDialog::Rejected == dialog.exec()) - return; - - auto name = dialog.GetName(); - - if (!name.isEmpty()) - newLabel->SetName(name.toStdString()); - - newLabel->SetColor(dialog.GetColor()); - } - - workingImage->GetActiveLabelSet()->AddLabel(newLabel); - - this->UpdateGUI(); - emit LabelsChanged(); -} - -void QmitkLabelsWidget::OnNewLabelShortcutActivated() -{ - m_Controls->newLabelButton->click(); -} - -void QmitkLabelsWidget::OnLockExterior(bool checked) -{ - auto workingImage = this->GetWorkingImage(); - if (nullptr == workingImage) - { - return; - } - - workingImage->GetLabel(0)->SetLocked(checked); -} - -void QmitkLabelsWidget::OnSavePreset() -{ - auto workingNode = this->GetWorkingNode(); - QmitkAbstractNodeSelectionWidget::NodeList nodes; - nodes.append(workingNode); - - QmitkSaveMultiLabelPresetAction action; - action.Run(nodes); -} - -void QmitkLabelsWidget::OnLoadPreset() -{ - auto workingNode = this->GetWorkingNode(); - QmitkAbstractNodeSelectionWidget::NodeList nodes; - nodes.append(workingNode); - - QmitkLoadMultiLabelPresetAction action; - action.Run(nodes); -} - -void QmitkLabelsWidget::WaitCursorOn() -{ - QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); -} - -void QmitkLabelsWidget::WaitCursorOff() -{ - this->RestoreOverrideCursor(); -} - -void QmitkLabelsWidget::RestoreOverrideCursor() -{ - QApplication::restoreOverrideCursor(); -} - diff --git a/Plugins/org.mitk.gui.qt.segmentation/src/internal/Common/QmitkLabelsWidget.h b/Plugins/org.mitk.gui.qt.segmentation/src/internal/Common/QmitkLabelsWidget.h deleted file mode 100644 index e1ae7cf042..0000000000 --- a/Plugins/org.mitk.gui.qt.segmentation/src/internal/Common/QmitkLabelsWidget.h +++ /dev/null @@ -1,87 +0,0 @@ -/*============================================================================ - -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 QmitkLabelsWidget_h -#define QmitkLabelsWidget_h - -// mitk core -#include - -// Qt -#include - -namespace Ui -{ - class QmitkLabelsWidgetControls; -} - -namespace mitk -{ - class DataNode; - class Image; - class LabelSetImage; - class ToolManager; -} - -class QmitkLabelsWidget : public QWidget -{ - Q_OBJECT - -public: - - explicit QmitkLabelsWidget(QWidget* parent = nullptr); - ~QmitkLabelsWidget() override; - - void UpdateGUI(); - - void SetDefaultLabelNaming(bool defaultLabelNaming); - -Q_SIGNALS: - - void LabelsChanged(); - - void ShowLabelTable(bool); - -private: - - mitk::LabelSetImage* GetWorkingImage(); - - mitk::DataNode* GetWorkingNode(); - - // reaction to button "New Label" - void OnNewLabel(); - void OnNewLabelShortcutActivated(); - - // reaction to the button "Lock exterior" - void OnLockExterior(bool); - - // reaction to button "Save Preset" - void OnSavePreset(); - - // reaction to button "Load Preset" - void OnLoadPreset(); - - void WaitCursorOn(); - - void WaitCursorOff(); - - void RestoreOverrideCursor(); - - Ui::QmitkLabelsWidgetControls* m_Controls; - - mitk::ToolManager* m_ToolManager; - - bool m_DefaultLabelNaming; - -}; - -#endif diff --git a/Plugins/org.mitk.gui.qt.segmentation/src/internal/Common/QmitkLabelsWidgetControls.ui b/Plugins/org.mitk.gui.qt.segmentation/src/internal/Common/QmitkLabelsWidgetControls.ui deleted file mode 100644 index 35fb68f86b..0000000000 --- a/Plugins/org.mitk.gui.qt.segmentation/src/internal/Common/QmitkLabelsWidgetControls.ui +++ /dev/null @@ -1,188 +0,0 @@ - - - QmitkLabelsWidgetControls - - - - 0 - 0 - 300 - 75 - - - - - 0 - 0 - - - - - 6 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Labels - - - - - - Add a label to the current segmentation session - - - ... - - - - :/Qmitk/NewLabel_48x48.png:/Qmitk/NewLabel_48x48.png - - - - 28 - 28 - - - - true - - - - - - - Lock / unlock exterior - - - ... - - - - :/Qmitk/UnlockExterior_48x48.png - :/Qmitk/LockExterior_48x48.png:/Qmitk/UnlockExterior_48x48.png - - - - 28 - 28 - - - - true - - - true - - - - - - - Save labelset preset - - - ... - - - - :/org_mitk_icons/icons/awesome/scalable/actions/document-save.svg:/org_mitk_icons/icons/awesome/scalable/actions/document-save.svg - - - - 28 - 28 - - - - true - - - - - - - Load LabelSet Preset - - - ... - - - - :/org_mitk_icons/icons/awesome/scalable/actions/document-open.svg:/org_mitk_icons/icons/awesome/scalable/actions/document-open.svg - - - - 28 - 28 - - - - true - - - - - - - Qt::Horizontal - - - - 0 - 20 - - - - - - - - - 0 - 34 - - - - Show a table with all labels in the current segmentation session - - - >> - - - - 28 - 28 - - - - true - - - false - - - Qt::NoArrow - - - - - - - - - - - diff --git a/Plugins/org.mitk.gui.qt.segmentation/src/internal/Common/QmitkLayersWidget.cpp b/Plugins/org.mitk.gui.qt.segmentation/src/internal/Common/QmitkLayersWidget.cpp deleted file mode 100644 index fc0d43bdf8..0000000000 --- a/Plugins/org.mitk.gui.qt.segmentation/src/internal/Common/QmitkLayersWidget.cpp +++ /dev/null @@ -1,237 +0,0 @@ -/*============================================================================ - -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 "QmitkLayersWidget.h" -#include - -// mitk -#include -#include -#include - -// Qt -#include - -QmitkLayersWidget::QmitkLayersWidget(QWidget *parent) - : QWidget(parent) - , m_Controls(new Ui::QmitkLayersWidgetControls) - , m_ToolManager(nullptr) -{ - m_Controls->setupUi(this); - - m_ToolManager = mitk::ToolManagerProvider::GetInstance()->GetToolManager(); - - connect(m_Controls->addLayerButton, &QToolButton::clicked, this, &QmitkLayersWidget::OnAddLayer); - connect(m_Controls->deleteLayerButton, &QToolButton::clicked, this, &QmitkLayersWidget::OnDeleteLayer); - connect(m_Controls->previousLayerButton, &QToolButton::clicked, this, &QmitkLayersWidget::OnPreviousLayer); - connect(m_Controls->nextLayerButton, &QToolButton::clicked, this, &QmitkLayersWidget::OnNextLayer); - connect(m_Controls->activeLayerComboBox, QOverload::of(&QComboBox::currentIndexChanged), this, &QmitkLayersWidget::OnChangeLayer); - - this->UpdateGUI(); -} - -QmitkLayersWidget::~QmitkLayersWidget() -{ - delete m_Controls; -} - -void QmitkLayersWidget::UpdateGUI() -{ - m_Controls->addLayerButton->setEnabled(false); - m_Controls->deleteLayerButton->setEnabled(false); - m_Controls->previousLayerButton->setEnabled(false); - m_Controls->nextLayerButton->setEnabled(false); - m_Controls->activeLayerComboBox->setEnabled(false); - - mitk::LabelSetImage* workingImage = this->GetWorkingImage(); - if (nullptr == workingImage) - { - return; - } - - m_Controls->addLayerButton->setEnabled(true); - - m_Controls->activeLayerComboBox->blockSignals(true); - m_Controls->activeLayerComboBox->clear(); - - unsigned int numberOfLayers = workingImage->GetNumberOfLayers(); - for (unsigned int lidx = 0; lidx < numberOfLayers; ++lidx) - { - m_Controls->activeLayerComboBox->addItem(QString::number(lidx)); - } - - unsigned int activeLayer = workingImage->GetActiveLayer(); - m_Controls->activeLayerComboBox->setCurrentIndex(activeLayer); - m_Controls->activeLayerComboBox->blockSignals(false); - - m_Controls->deleteLayerButton->setEnabled(numberOfLayers > 1); - m_Controls->previousLayerButton->setEnabled(activeLayer > 0); - m_Controls->nextLayerButton->setEnabled(activeLayer != numberOfLayers - 1); - m_Controls->activeLayerComboBox->setEnabled(numberOfLayers > 0); -} - -mitk::LabelSetImage* QmitkLayersWidget::GetWorkingImage() -{ - mitk::DataNode* workingNode = GetWorkingNode(); - if (nullptr == workingNode) - { - return nullptr; - } - - auto workingImage = dynamic_cast(workingNode->GetData()); - return workingImage; -} - -mitk::DataNode* QmitkLayersWidget::GetWorkingNode() -{ - mitk::DataNode* workingNode = m_ToolManager->GetWorkingData(0); - return workingNode; -} - -void QmitkLayersWidget::OnAddLayer() -{ - m_ToolManager->ActivateTool(-1); - - auto workingImage = this->GetWorkingImage(); - if (nullptr == workingImage) - { - return; - } - - try - { - this->WaitCursorOn(); - workingImage->AddLayer(); - this->WaitCursorOff(); - } - catch (mitk::Exception& e) - { - this->WaitCursorOff(); - MITK_ERROR << "Exception caught: " << e.GetDescription(); - QMessageBox::information( - this, "Add layer", "Could not add a new layer. See error log for details.\n"); - return; - } - - this->UpdateGUI(); - emit LayersChanged(); -} - -void QmitkLayersWidget::OnDeleteLayer() -{ - m_ToolManager->ActivateTool(-1); - - auto workingImage = this->GetWorkingImage(); - if (nullptr == workingImage) - { - return; - } - - if (workingImage->GetNumberOfLayers() < 2) - { - return; - } - - QString question = "Do you really want to delete the current layer?"; - QMessageBox::StandardButton answerButton = QMessageBox::question( - this, "Delete layer", question, QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Yes); - - if (answerButton != QMessageBox::Yes) - { - return; - } - - try - { - this->WaitCursorOn(); - workingImage->RemoveLayer(); - this->WaitCursorOff(); - } - catch (mitk::Exception& e) - { - this->WaitCursorOff(); - MITK_ERROR << "Exception caught: " << e.GetDescription(); - QMessageBox::information( - this, "Delete layer", "Could not delete the currently active layer. See error log for details.\n"); - return; - } - - this->UpdateGUI(); - emit LayersChanged(); -} - -void QmitkLayersWidget::OnPreviousLayer() -{ - auto workingImage = this->GetWorkingImage(); - if (nullptr == workingImage) - { - return; - } - - this->OnChangeLayer(workingImage->GetActiveLayer() - 1); -} - -void QmitkLayersWidget::OnNextLayer() -{ - auto workingImage = this->GetWorkingImage(); - if (nullptr == workingImage) - { - return; - } - - this->OnChangeLayer(workingImage->GetActiveLayer() + 1); -} - -void QmitkLayersWidget::OnChangeLayer(int layer) -{ - m_ToolManager->ActivateTool(-1); - - auto workingImage = this->GetWorkingImage(); - if (nullptr == workingImage) - { - return; - } - - try - { - this->WaitCursorOn(); - workingImage->SetActiveLayer(layer); - this->WaitCursorOff(); - } - catch (mitk::Exception& e) - { - this->WaitCursorOff(); - MITK_ERROR << "Exception caught: " << e.GetDescription(); - QMessageBox::information( - this, "Change layer", "Could not change the layer. See error log for details.\n"); - return; - } - - this->UpdateGUI(); - emit LayersChanged(); -} - -void QmitkLayersWidget::WaitCursorOn() -{ - QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); -} - -void QmitkLayersWidget::WaitCursorOff() -{ - this->RestoreOverrideCursor(); -} - -void QmitkLayersWidget::RestoreOverrideCursor() -{ - QApplication::restoreOverrideCursor(); -} - diff --git a/Plugins/org.mitk.gui.qt.segmentation/src/internal/Common/QmitkLayersWidget.h b/Plugins/org.mitk.gui.qt.segmentation/src/internal/Common/QmitkLayersWidget.h deleted file mode 100644 index c87d796c5f..0000000000 --- a/Plugins/org.mitk.gui.qt.segmentation/src/internal/Common/QmitkLayersWidget.h +++ /dev/null @@ -1,79 +0,0 @@ -/*============================================================================ - -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 QmitkLayersWidget_h -#define QmitkLayersWidget_h - -// Qt -#include - -namespace Ui -{ - class QmitkLayersWidgetControls; -} - -namespace mitk -{ - class DataNode; - class LabelSetImage; - class ToolManager; -} - -class QmitkLayersWidget : public QWidget -{ - Q_OBJECT - -public: - - explicit QmitkLayersWidget(QWidget* parent = nullptr); - ~QmitkLayersWidget() override; - - void UpdateGUI(); - -Q_SIGNALS: - - void LayersChanged(); - -private: - - mitk::LabelSetImage* GetWorkingImage(); - - mitk::DataNode* GetWorkingNode(); - - // reaction to the button "Add Layer" - void OnAddLayer(); - - // reaction to the button "Delete Layer" - void OnDeleteLayer(); - - // reaction to the button "Previous Layer" - void OnPreviousLayer(); - - // reaction to the button "Next Layer" - void OnNextLayer(); - - // reaction to the combobox change "Change Layer" - void OnChangeLayer(int); - - void WaitCursorOn(); - - void WaitCursorOff(); - - void RestoreOverrideCursor(); - - Ui::QmitkLayersWidgetControls* m_Controls; - - mitk::ToolManager* m_ToolManager; - -}; - -#endif diff --git a/Plugins/org.mitk.gui.qt.segmentation/src/internal/Common/QmitkLayersWidgetControls.ui b/Plugins/org.mitk.gui.qt.segmentation/src/internal/Common/QmitkLayersWidgetControls.ui deleted file mode 100644 index f2941e4af5..0000000000 --- a/Plugins/org.mitk.gui.qt.segmentation/src/internal/Common/QmitkLayersWidgetControls.ui +++ /dev/null @@ -1,177 +0,0 @@ - - - QmitkLayersWidgetControls - - - - 0 - 0 - 300 - 75 - - - - - 0 - 0 - - - - - 6 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Layers - - - - - - Add a layer to the current segmentation session - - - ... - - - - :/Qmitk/AddLayer_48x48.png:/Qmitk/AddLayer_48x48.png - - - - 28 - 28 - - - - true - - - - - - - Delete the active layer - - - ... - - - - :/Qmitk/DeleteLayer_48x48.png:/Qmitk/DeleteLayer_48x48.png - - - - 28 - 28 - - - - true - - - - - - - Qt::Horizontal - - - - 0 - 0 - - - - - - - - Change to the previous available layer - - - ... - - - - :/Qmitk/PreviousLayer_48x48.png:/Qmitk/PreviousLayer_48x48.png - - - - 28 - 28 - - - - true - - - - - - - Change to the next available layer - - - ... - - - - :/Qmitk/NextLayer_48x48.png:/Qmitk/NextLayer_48x48.png - - - - 28 - 28 - - - - true - - - - - - - - 50 - 30 - - - - - 40 - 30 - - - - Switch to a layer - - - - 0 - - - - - - - - - - - -