| 266 | } |
| 267 | |
| 268 | mitk::Label::Pointer mitk::LabelSetImageHelper::CreateNewLabel(const MultiLabelSegmentation* labelSetImage, const std::string& namePrefix, bool hideIDIfUnique) |
| 269 | { |
| 270 | if (nullptr == labelSetImage) |
| 271 | return nullptr; |
| 272 | |
| 273 | const unsigned int minDigitsCount = 2; |
| 274 | const std::regex genericLabelNameRegEx(namePrefix + " ([0-9]+)"); |
| 275 | int maxGenericLabelNumber = 0; |
| 276 | |
| 277 | std::vector<mitk::Color> usedColors; |
| 278 | for (auto & label : labelSetImage->GetLabels()) |
| 279 | { |
| 280 | auto labelName = label->GetName(); |
| 281 | std::smatch match; |
| 282 | |
| 283 | if (std::regex_match(labelName, match, genericLabelNameRegEx)) |
| 284 | maxGenericLabelNumber = std::max(maxGenericLabelNumber, std::stoi(match[1].str())); |
| 285 | |
| 286 | usedColors.push_back(label->GetColor()); |
| 287 | } |
| 288 | |
| 289 | auto newLabel = mitk::Label::New(); |
| 290 | if (hideIDIfUnique && 0 == maxGenericLabelNumber) |
| 291 | { |
| 292 | newLabel->SetName(namePrefix); |
| 293 | } |
| 294 | else |
| 295 | { |
| 296 | std::ostringstream name; |
| 297 | name << namePrefix << " " << std::setw(minDigitsCount) << std::setfill('0') << maxGenericLabelNumber + 1; |
| 298 | newLabel->SetName(name.str().c_str()); |
| 299 | } |
| 300 | |
| 301 | newLabel->SetColor(SuggestNewLabelColor(usedColors)); |
| 302 | |
| 303 | return newLabel; |
| 304 | } |
| 305 | |
| 306 | mitk::LabelSetImageHelper::GroupIDToLabelValueMapType |
| 307 | mitk::LabelSetImageHelper::SplitLabelValuesByGroup(const MultiLabelSegmentation* labelSetImage, const MultiLabelSegmentation::LabelValueVectorType& labelValues) |