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

Method DeserializeLabelFromJSON

Modules/Multilabel/src/mitkMultiLabelIOHelper.cpp:710–814  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

708}
709
710mitk::Label::Pointer mitk::MultiLabelIOHelper::DeserializeLabelFromJSON(const nlohmann::json& labelJson)
711{
712 Label::Pointer resultLabel = Label::New();
713
714 for (const auto& [key, jValue] : labelJson.items())
715 {
716 auto internalKey = EnsureCorrectPropertyName(key);
717
718 if (internalKey == "name")
719 {
720 std::string name;
721 if (GetValueFromJson(labelJson, "name", name))
722 resultLabel->SetName(name);
723 }
724 else if (internalKey == "value")
725 {
726 Label::PixelType value = 1;
727 if (GetValueFromJson(labelJson, "value", value))
728 resultLabel->SetValue(value);
729 }
730 else if (internalKey == "color")
731 {
732 Color color;
733 if (jValue.contains("value"))
734 { // "old" property passed serialization
735 auto jcolor = jValue["value"];
736 color.SetRed(jcolor[0].get<float>());
737 color.SetGreen(jcolor[1].get<float>());
738 color.SetBlue(jcolor[2].get<float>());
739 }
740 else
741 { // simple new serialization directly as array
742 if (jValue[0].is_number_float())
743 { //assume color coded in float (0.0..1.0)
744 color.SetRed(jValue[0].get<float>());
745 color.SetGreen(jValue[1].get<float>());
746 color.SetBlue(jValue[2].get<float>());
747 }
748 else
749 { //assume color coded in int (0..255)
750 color.SetRed(jValue[0].get<unsigned int>()/255.f);
751 color.SetGreen(jValue[1].get<unsigned int>()/255.f);
752 color.SetBlue(jValue[2].get<unsigned int>()/255.f);
753 }
754 }
755 resultLabel->SetColor(color);
756 }
757 else if (internalKey == "locked")
758 {
759 bool locked = false;
760 if (GetValueFromJson(labelJson, "locked", locked))
761 resultLabel->SetLocked(locked);
762 }
763 else if (internalKey == "opacity")
764 {
765 float opacity = 1.;
766 if (GetValueFromJson(labelJson, "opacity", opacity))
767 resultLabel->SetOpacity(opacity);

Callers

nothing calls this directly

Calls 15

GetValueFromJsonFunction · 0.85
containsMethod · 0.80
SetLockedMethod · 0.80
SetTrackingUIDMethod · 0.80
SetTrackingIDMethod · 0.80
NewFunction · 0.50
SetNameMethod · 0.45
SetValueMethod · 0.45
SetColorMethod · 0.45
SetOpacityMethod · 0.45
SetVisibleMethod · 0.45

Tested by

no test coverage detected