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

Method OnLabelAdded

Modules/SegmentationUI/src/QmitkMultiLabelTreeModel.cpp:933–984  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

931}
932
933void QmitkMultiLabelTreeModel::OnLabelAdded(LabelValueType labelValue)
934{
935 GroupIndexType groupIndex = m_Segmentation->GetGroupIndexOfLabel(labelValue);
936 auto label = m_Segmentation->GetLabel(labelValue);
937 if (label.IsNull()) mitkThrow() << "Invalid internal state. Segmentation signaled the addition of a label that does not exist in the segmentation. Invalid label value:" << labelValue;
938 if (labelValue == mitk::MultiLabelSegmentation::UNLABELED_VALUE) return;
939
940 auto groupItem = GetGroupItem(groupIndex, this->m_RootItem.get());
941
942 bool newLabelCreated = false;
943 auto instanceItem = AddLabelToGroupTree(label, groupItem, newLabelCreated);
944 m_NearestLabelValueToLastChange = labelValue;
945
946 m_ModelUpdateOngoing = true;
947 if (newLabelCreated)
948 {
949 if (groupItem->m_childItems.size() == 1)
950 { //first label added
951 auto groupIndex = GetIndexByItem(groupItem, this);
952 emit dataChanged(groupIndex, groupIndex);
953 this->beginInsertRows(groupIndex, instanceItem->ParentItem()->Row(), instanceItem->ParentItem()->Row());
954 this->endInsertRows();
955 }
956 else
957 { //whole new label level added to group item
958 auto groupIndex = GetIndexByItem(groupItem, this);
959 this->beginInsertRows(groupIndex, instanceItem->ParentItem()->Row(), instanceItem->ParentItem()->Row());
960 this->endInsertRows();
961 }
962 }
963 else
964 {
965 if (instanceItem->ParentItem()->m_childItems.size() < 3)
966 { //second instance item was added, so label item will now able to collapse
967 // -> the whole label node has to be updated.
968 auto labelIndex = GetIndexByItem(instanceItem->ParentItem(), this);
969 emit dataChanged(labelIndex, labelIndex);
970 this->beginInsertRows(labelIndex, 0, instanceItem->ParentItem()->m_childItems.size()-1);
971 this->endInsertRows();
972 }
973 else
974 {
975 // instance item was added to existing label item with multiple instances
976 //-> just notify the row insertion
977 auto labelIndex = GetIndexByItem(instanceItem->ParentItem(), this);
978 this->beginInsertRows(labelIndex, instanceItem->Row(), instanceItem->Row());
979 this->endInsertRows();
980 }
981 }
982 m_ModelUpdateOngoing = false;
983 emit modelChanged();
984}
985
986void QmitkMultiLabelTreeModel::OnLabelModified(LabelValueType labelValue)
987{

Callers 2

ITKEventHandlerMethod · 0.95
OnLabelModifiedMethod · 0.95

Calls 9

GetGroupItemFunction · 0.85
AddLabelToGroupTreeFunction · 0.85
GetIndexByItemFunction · 0.85
GetGroupIndexOfLabelMethod · 0.80
RowMethod · 0.80
ParentItemMethod · 0.80
GetLabelMethod · 0.45
IsNullMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected