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

Method MergeToolUses

Modules/Multilabel/src/mitkLabel.cpp:564–603  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

562}
563
564void mitk::Label::MergeToolUses(const Label* other)
565{
566 if (nullptr == other)
567 mitkThrow() << "Invalid call of Label::MergeToolUses. Passed label is null.";
568
569 const auto otherType = other->GetAlgorithmType();
570 if (otherType == AlgorithmType::Undefined)
571 return; // the source declared no origin: nothing meaningful to propagate
572
573 // Mix the algorithm type (same rule as AddToolUse), so even a source that carries a type but no
574 // named tool (e.g. a vendor MANUAL label) still influences the merged result.
575 const auto currentType = this->GetAlgorithmType();
576 if (currentType == AlgorithmType::Undefined)
577 this->SetAlgorithmType(otherType);
578 else if (currentType != otherType)
579 this->SetAlgorithmType(AlgorithmType::SEMIAUTOMATIC);
580
581 if (!other->HasAlgorithmName())
582 return;
583
584 const std::string otherName = other->GetAlgorithmName();
585 const std::string internalPrefix = DEFAULT_ALGORITHM_NAME + PREFIX_SEPARATOR;
586 const std::string toolChain = otherName.starts_with(internalPrefix)
587 ? otherName.substr(internalPrefix.size())
588 : otherName;
589 if (toolChain.empty() || toolChain == DEFAULT_ALGORITHM_NAME)
590 return; // bare prefix only: the type mix above is the whole story
591
592 // Replay each recorded tool name so the target's chain reflects the merged origin. AddToolUse
593 // de-duplicates against names already present and re-affirms the type mix harmlessly.
594 std::string::size_type start = 0;
595 while (start != std::string::npos)
596 {
597 const auto sep = toolChain.find(TOOL_SEPARATOR, start);
598 const auto token = toolChain.substr(start, sep == std::string::npos ? std::string::npos : sep - start);
599 if (!token.empty())
600 this->AddToolUse(otherType, token);
601 start = sep == std::string::npos ? std::string::npos : sep + TOOL_SEPARATOR.size();
602 }
603}
604
605
606void mitk::Label::Update(const Label* templateLabel, bool updateLabelValue)

Callers 3

TestMergeToolUsesMethod · 0.80
OnMergeLabelsMethod · 0.80

Calls 8

GetAlgorithmTypeMethod · 0.95
SetAlgorithmTypeMethod · 0.95
AddToolUseMethod · 0.95
HasAlgorithmNameMethod · 0.80
GetAlgorithmNameMethod · 0.80
sizeMethod · 0.45
emptyMethod · 0.45
findMethod · 0.45

Tested by 2

TestMergeToolUsesMethod · 0.64
OnMergeLabelsMethod · 0.64