MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ decode()

bool MayaFlux::Nexus::StateDecoder::decode ( Fabric &  fabric,
const std::string &  base_path 
)

Decode and apply to fabric.

Parameters
fabricTarget fabric. Must already contain entities with ids matching the schema. Expanses are restored too; one that matches an Expanse already on the Fabric is left in place and only has its box updated.
base_pathPath stem without extension, same value passed to StateEncoder::encode.
Returns
True on success. Partial patches (some ids missing) still return true; failures are logged.

Definition at line 676 of file Decoder.cpp.

677{
678 m_last_error.clear();
679 m_patched_count = 0;
680 m_missing_count = 0;
681
682 const std::string json_path = base_path + ".json";
683 const std::string exr_path = base_path + ".exr";
684
685 IO::JSONSerializer ser;
686 auto schema_opt = ser.read<State::FabricSchema>(json_path);
687 if (!schema_opt) {
688 m_last_error = "Failed to load schema: " + ser.last_error();
690 return false;
691 }
692 const auto& schema = *schema_opt;
693
694 if (!version_supported(schema.version)) {
695 m_last_error = version_error(schema.version);
697 return false;
698 }
699
700 if (schema.entities.empty()) {
701 m_last_error = "Schema contains no entities: " + json_path;
703 return false;
704 }
705
706 auto pv_opt = load_exr(exr_path, static_cast<uint32_t>(schema.entities.size()), State::k_exr_rows, m_last_error);
707 if (!pv_opt) {
709 return false;
710 }
711 const auto* pixels = pv_opt->image.as_float();
712 const uint32_t width = pv_opt->width;
713
714 std::vector<std::string> warnings;
715 note_older_version(schema.version, warnings);
716
717 for (size_t i = 0; i < schema.entities.size(); ++i) {
718 const auto& entry = schema.entities[i];
719
720 if (!State::kind_known(entry.kind)) {
721 warnings.push_back("unknown kind '" + entry.kind + "' for id "
722 + std::to_string(entry.id) + ", skipping");
724 continue;
725 }
726
727 const Fields fields = read_fields(entry, *pixels, width, i, schema.ranges);
728 if (patch_entity(fabric, entry, fields, warnings)) {
730 } else {
731 warnings.push_back("id " + std::to_string(entry.id) + " not found as "
732 + entry.kind + ", skipping");
734 }
735 }
736
737 for (const auto& xrec : schema.expanses) {
738 restore_expanse(fabric, xrec, warnings);
739 }
740
741 log_warnings(warnings);
742
744 "StateDecoder: patched {} entities ({} missing) from {} + {}",
745 m_patched_count, m_missing_count, exr_path, json_path);
746
747 return true;
748}
#define MF_INFO(comp, ctx,...)
#define MF_ERROR(comp, ctx,...)
const std::vector< float > * pixels
Definition Decoder.cpp:48
uint32_t width
@ FileIO
Filesystem I/O operations.
@ Nexus
Spatial indexing and scheduling for user-defined behaviour.
bool kind_known(std::string_view s)
Return true if s maps to a known Fabric::Kind token.
Definition Schema.hpp:469
constexpr uint32_t k_exr_rows
RGBA32F EXR layout constants shared between encoder and decoder.
Definition Schema.hpp:47

References MayaFlux::Journal::FileIO, MayaFlux::Nexus::State::k_exr_rows, MayaFlux::Nexus::State::kind_known(), MayaFlux::IO::JSONSerializer::last_error(), m_last_error, m_missing_count, m_patched_count, MF_ERROR, MF_INFO, MayaFlux::Journal::Nexus, pixels, MayaFlux::IO::JSONSerializer::read(), and width.

+ Here is the call graph for this function: