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

Method LoadScene

Modules/SceneSerialization/src/mitkSceneJsonReader.cpp:436–1003  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

434mitk::SceneJsonReader::~SceneJsonReader() = default;
435
436bool mitk::SceneJsonReader::LoadScene(const std::string &sceneSourcePath, DataStorage *storage, bool clearStorageFirst)
437{
438 if (storage == nullptr)
439 {
440 mitkThrow() << "SceneJsonReader::LoadScene called with null DataStorage.";
441 }
442
443 // ---- 1. read and parse -------------------------------------------------
444
445 std::ifstream in(sceneSourcePath);
446 if (!in.good())
447 {
448 mitkThrow() << "Could not open scene file '" << sceneSourcePath << "' for reading.";
449 }
450
451 json document;
452 try
453 {
454 in >> document;
455 }
456 catch (const json::exception &e)
457 {
458 mitkThrow() << "Scene file '" << sceneSourcePath << "' is not valid JSON: " << e.what();
459 }
460
461 // ---- 2. validate root --------------------------------------------------
462
463 if (!document.is_object())
464 {
465 mitkThrow() << "Scene file '" << sceneSourcePath << "' root must be a JSON object.";
466 }
467
468 const auto typeIt = document.find(FIELD_TYPE);
469 if (typeIt == document.end() || !typeIt->is_string() || typeIt->get<std::string>() != SCENE_TYPE)
470 {
471 mitkThrow() << "Scene file '" << sceneSourcePath << "' has missing or wrong 'type' field (expected '"
472 << SCENE_TYPE << "').";
473 }
474
475 const auto versionIt = document.find(FIELD_VERSION);
476 if (versionIt == document.end() || !versionIt->is_number_integer())
477 {
478 mitkThrow() << "Scene file '" << sceneSourcePath << "' has missing or non-integer 'version' field.";
479 }
480 const int version = versionIt->get<int>();
481 if (version != SUPPORTED_VERSION)
482 {
483 mitkThrow() << "Scene file '" << sceneSourcePath << "' has unsupported version " << version
484 << " (supported: " << SUPPORTED_VERSION << ").";
485 }
486
487 WarnUnknownKeys(document, ROOT_KNOWN_KEYS, "root");
488
489 const auto metadataIt = document.find(FIELD_METADATA);
490 if (metadataIt != document.end() && metadataIt->is_object())
491 {
492 WarnUnknownKeys(*metadataIt, METADATA_KNOWN_KEYS, "metadata");
493 }

Callers

nothing calls this directly

Calls 15

WarnUnknownKeysFunction · 0.85
ValidatePropertyMapShapeFunction · 0.85
ResolvePathFunction · 0.85
ResolvePropertyMapFunction · 0.85
ParseLoadStyleFunction · 0.85
ApplyResolvedPropertyMapFunction · 0.85
LoadFunction · 0.85
ExtractLayerFunction · 0.85
ApplyPropertyMapFunction · 0.85
StripTransientPropertiesFunction · 0.85
whatMethod · 0.80

Tested by

no test coverage detected