MCPcopy Create free account
hub / github.com/MITK/MITK / RemoveGroupInternal

Method RemoveGroupInternal

Modules/SegmentationUI/src/QmitkMultiLabelInspector.cpp:839–898  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

837}
838
839void QmitkMultiLabelInspector::RemoveGroupInternal(const mitk::MultiLabelSegmentation::GroupIndexType& groupID)
840{
841 if (!m_AllowLabelModification)
842 mitkThrow() << "QmitkMultiLabelInspector is configured incorrectly. Set AllowLabelModification to true to allow the usage of RemoveLabel.";
843
844 if (m_Segmentation.IsNull())
845 return;
846
847 if (m_Segmentation->GetNumberOfGroups() < 2)
848 return;
849
850 try
851 {
852 this->WaitCursorOn();
853 mitk::SegGroupRemoveUndoRedoHelper undoRedoGenerator(m_Segmentation, { groupID });
854 auto deletedGroupName = mitk::LabelSetImageHelper::CreateDisplayGroupName(m_Segmentation, groupID);
855
856 m_ModelManipulationOngoing = true;
857 m_Segmentation->RemoveGroup(groupID);
858 m_ModelManipulationOngoing = false;
859
860 undoRedoGenerator.RegisterUndoRedoOperationEvent("Remove group \"" + deletedGroupName + "\"");
861 this->WaitCursorOff();
862 }
863 catch (mitk::Exception& e)
864 {
865 m_ModelManipulationOngoing = false;
866 this->WaitCursorOff();
867 MITK_ERROR << "Exception caught: " << e.GetDescription();
868 QMessageBox::information(this, "Delete group", "Could not delete the currently active group. See error log for details.");
869 return;
870 }
871
872 auto validSelectedLabels = FilterValidLabels(m_LastValidSelectedLabels, this->GetMultiLabelSegmentation());
873 if (validSelectedLabels.empty())
874 {
875 auto newLabelValue = m_Model->GetNearestLabelValueToLastChange();
876 if (newLabelValue != mitk::MultiLabelSegmentation::UNLABELED_VALUE)
877 {
878 this->SetSelectedLabel(newLabelValue);
879
880 auto index = m_Model->indexOfLabel(newLabelValue); //we have to get index again, because it could have changed due to remove operation.
881 if (index.isValid())
882 {
883 m_Controls->view->expand(index.parent());
884 }
885 else
886 {
887 mitkThrow() << "Segmentation or QmitkMultiLabelTreeModel is in an invalid state. Label is not present in the model after adding it to the segmentation. Label value: " << newLabelValue;
888 }
889 }
890 else
891 {
892 this->SetSelectedLabels({});
893 }
894 }
895
896 emit ModelUpdated();

Callers 2

RemoveGroupMethod · 0.95
OnDeleteGroupMethod · 0.95

Calls 15

WaitCursorOnMethod · 0.95
WaitCursorOffMethod · 0.95
SetSelectedLabelMethod · 0.95
SetSelectedLabelsMethod · 0.95
FilterValidLabelsFunction · 0.85
GetNumberOfGroupsMethod · 0.80
indexOfLabelMethod · 0.80
IsNullMethod · 0.45
RemoveGroupMethod · 0.45

Tested by

no test coverage detected