| 931 | } |
| 932 | |
| 933 | mitk::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 | |
| 975 | mitk::Label* mitk::MultiLabelSegmentation::AddLabelWithContent(Label* label, const Image* labelContent, GroupIndexType groupID, LabelValueType contentLabelValue, bool addAsClone, bool correctLabelValue) |
| 976 | { |