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

Method CreateNewLabel

Modules/Multilabel/src/mitkLabelSetImageHelper.cpp:268–304  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

266}
267
268mitk::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
306mitk::LabelSetImageHelper::GroupIDToLabelValueMapType
307mitk::LabelSetImageHelper::SplitLabelValuesByGroup(const MultiLabelSegmentation* labelSetImage, const MultiLabelSegmentation::LabelValueVectorType& labelValues)

Callers

nothing calls this directly

Calls 6

GetLabelsMethod · 0.80
NewFunction · 0.50
GetNameMethod · 0.45
GetColorMethod · 0.45
SetNameMethod · 0.45
SetColorMethod · 0.45

Tested by

no test coverage detected