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

Method AddLabel

Modules/Multilabel/src/mitkLabelSetImage.cpp:933–973  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

931}
932
933mitk::Label* mitk::MultiLabelSegmentation::AddLabel(mitk::Label* label, GroupIndexType groupID, bool addAsClone, bool correctLabelValue)
934{
935 if (nullptr == label) mitkThrow() << "Invalid use of AddLabel. label is not valid.";
936
937 mitk::Label::Pointer newLabel = label;
938
939 {
940 std::lock_guard<std::shared_mutex> guard(m_LabelNGroupMapsMutex);
941
942 unsigned int max_size = mitk::Label::MAX_LABEL_VALUE + 1;
943 if (m_LabelMap.size() >= max_size)
944 return nullptr;
945
946 if (addAsClone) newLabel = label->Clone();
947
948 auto pixelValue = newLabel->GetValue();
949 auto usedValues = this->GetUsedLabelValues();
950 auto finding = std::find(usedValues.begin(), usedValues.end(), pixelValue);
951
952 if (!usedValues.empty() && usedValues.end() != finding)
953 {
954 if (correctLabelValue)
955 {
956 pixelValue = this->GetUnusedLabelValue();
957 newLabel->SetValue(pixelValue);
958 }
959 else
960 {
961 mitkThrow() << "Cannot add label due to conflicting label value that already exists in the MultiLabelSegmentation. Conflicting label value: " << pixelValue;
962 }
963 }
964
965 this->AddLabelToMap(pixelValue, newLabel, groupID);
966 this->RegisterLabel(newLabel);
967 }
968
969 this->InvokeEvent(LabelAddedEvent(newLabel->GetValue()));
970 this->Modified();
971
972 return newLabel;
973}
974
975mitk::Label* mitk::MultiLabelSegmentation::AddLabelWithContent(Label* label, const Image* labelContent, GroupIndexType groupID, LabelValueType contentLabelValue, bool addAsClone, bool correctLabelValue)
976{

Calls 15

GetUsedLabelValuesMethod · 0.95
GetUnusedLabelValueMethod · 0.95
AddLabelToMapMethod · 0.95
RegisterLabelMethod · 0.95
NewFunction · 0.50
sizeMethod · 0.45
CloneMethod · 0.45
GetValueMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
emptyMethod · 0.45
SetValueMethod · 0.45