| 455 | {}; |
| 456 | |
| 457 | nlohmann::json mitk::MultiLabelIOHelper::SerializeMultLabelGroupsToJSON(const mitk::MultiLabelSegmentation* inputImage, |
| 458 | GroupFileNameCallback groupFileNameCallback, LabelFileNameCallback labelFileNameCallback, |
| 459 | LabelFileValueCallback labelFileValueCallback) |
| 460 | { |
| 461 | if (nullptr == inputImage) |
| 462 | { |
| 463 | mitkThrow() << "Invalid call of SerializeMultLabelGroupsToJSON. Passed image pointer is null."; |
| 464 | } |
| 465 | |
| 466 | nlohmann::json result; |
| 467 | |
| 468 | for (MultiLabelSegmentation::GroupIndexType i = 0; i < inputImage->GetNumberOfGroups(); i++) |
| 469 | { |
| 470 | nlohmann::json jgroup; |
| 471 | nlohmann::json jlabels; |
| 472 | |
| 473 | for (const auto& label : inputImage->GetConstLabelsByValue(inputImage->GetLabelValuesByGroup(i))) |
| 474 | { |
| 475 | auto jLabel = SerializeLabelToJSON(label); |
| 476 | if (nullptr != labelFileNameCallback) |
| 477 | { |
| 478 | auto labelFile = labelFileNameCallback(inputImage, label->GetValue()); |
| 479 | jLabel["_file"] = labelFile; |
| 480 | } |
| 481 | if (nullptr != labelFileValueCallback) |
| 482 | { |
| 483 | auto labelValue = labelFileValueCallback(inputImage, label->GetValue()); |
| 484 | if (labelValue != label->GetValue()) |
| 485 | { |
| 486 | jLabel["_file_value"] = labelValue; |
| 487 | } |
| 488 | } |
| 489 | jlabels.emplace_back(jLabel); |
| 490 | } |
| 491 | |
| 492 | if (!jlabels.empty()) |
| 493 | { |
| 494 | jgroup["labels"] = jlabels; |
| 495 | } |
| 496 | |
| 497 | const auto& name = inputImage->GetGroupName(i); |
| 498 | if (!name.empty()) |
| 499 | { |
| 500 | jgroup["name"] = name; |
| 501 | } |
| 502 | |
| 503 | if (nullptr != groupFileNameCallback) |
| 504 | { |
| 505 | auto groupFile = groupFileNameCallback(inputImage, i); |
| 506 | jgroup["_file"] = groupFile; |
| 507 | } |
| 508 | |
| 509 | result.emplace_back(jgroup); |
| 510 | } |
| 511 | return result; |
| 512 | }; |
| 513 | |
| 514 | std::vector<mitk::MultiLabelIOHelper::LabelGroupMetaData> mitk::MultiLabelIOHelper::DeserializeMultiLabelGroupsFromJSON(const nlohmann::json& listOfLabelGroups) |
nothing calls this directly
no test coverage detected