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

Method SerializeLabelToJSON

Modules/Multilabel/src/mitkMultiLabelIOHelper.cpp:604–637  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

602}
603
604nlohmann::json mitk::MultiLabelIOHelper::SerializeLabelToJSON(const Label* label)
605{
606 if (nullptr == label)
607 {
608 mitkThrow() << "Invalid call of GetLabelAsJSON. Passed label pointer is null.";
609 }
610
611 nlohmann::json j;
612 j["name"] = label->GetName();
613
614 j["value"] = label->GetValue();
615
616 j["color"] = { label->GetColor().GetRed(), label->GetColor().GetGreen(), label->GetColor().GetBlue() };
617
618 j["locked"] = label->GetLocked();
619 j["opacity"] = label->GetOpacity();
620 j["visible"] = label->GetVisible();
621 // Only emit tracking keys when the value is non-empty. Has*() on the
622 // loaded label then reflects "source carried a real value", uniformly
623 // across DICOM SEG and native JSON. mitk::Label has no UID auto-
624 // generation; the older empty-string-stamp pattern guarded against a
625 // behaviour that does not exist.
626 if (!label->GetTrackingID().empty())
627 j["tracking_id"] = label->GetTrackingID();
628 if (!label->GetTrackingUID().empty())
629 j["tracking_uid"] = label->GetTrackingUID();
630 if (!label->GetDescription().empty())
631 j["description"] = label->GetDescription();
632
633 // Serialize any other custom properties
634 SerializeLabelCustomPropertiesToJSON(label, j);
635
636 return j;
637};
638
639namespace
640{

Callers

nothing calls this directly

Calls 11

GetTrackingIDMethod · 0.80
GetTrackingUIDMethod · 0.80
GetNameMethod · 0.45
GetValueMethod · 0.45
GetColorMethod · 0.45
GetLockedMethod · 0.45
GetOpacityMethod · 0.45
GetVisibleMethod · 0.45
emptyMethod · 0.45
GetDescriptionMethod · 0.45

Tested by

no test coverage detected