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

Function ExtractLayer

Modules/SceneSerialization/src/mitkSceneJsonReader.cpp:405–430  ·  view source on GitHub ↗

* \brief Extract the integer `layer` property value from a node JSON object * for pre-Add ordering. * * Accepts both the simple primitive form (`"layer": 2`) and the tagged * object form (`"layer": {"type": "IntProperty", "value": 2}`) via the * standard property converter. Returns 0 if no usable layer value is * present or if the property is of a non-integer type. */

Source from the content-addressed store, hash-verified

403 * present or if the property is of a non-integer type.
404 */
405 int ExtractLayer(const json &nodeJson)
406 {
407 const auto propsIt = nodeJson.find(FIELD_PROPERTIES);
408 if (propsIt == nodeJson.end() || !propsIt->is_object())
409 return 0;
410 auto layerIt = propsIt->find(PROPERTY_LAYER);
411 if (layerIt == propsIt->end() || layerIt->is_null())
412 return 0;
413 try
414 {
415 mitk::BaseProperty::Pointer prop = mitk::ConvertPropertyFromSelfContainedJson(*layerIt);
416 if (auto *intProp = dynamic_cast<mitk::IntProperty *>(prop.GetPointer()))
417 return intProp->GetValue();
418 }
419 catch (const mitk::Exception &)
420 {
421 // Ignore — sort falls back to layer 0 for this node.
422 }
423 catch (const std::exception &)
424 {
425 // ConvertPropertyFromSelfContainedJson can also propagate non-mitk
426 // exceptions (e.g. nlohmann::json::out_of_range on a malformed tagged
427 // value). Treat the same as a missing/unusable layer: fall back to 0.
428 }
429 return 0;
430 }
431}
432
433mitk::SceneJsonReader::SceneJsonReader() = default;

Callers 1

LoadSceneMethod · 0.85

Calls 4

GetPointerMethod · 0.80
findMethod · 0.45
endMethod · 0.45
GetValueMethod · 0.45

Tested by

no test coverage detected