| 602 | } |
| 603 | |
| 604 | nlohmann::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 | |
| 639 | namespace |
| 640 | { |
nothing calls this directly
no test coverage detected