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

◆ reconstruct() [1/2]

StateDecoder::ReconstructionResult MayaFlux::Nexus::StateDecoder::reconstruct ( Fabric &  fabric,
const std::string &  base_path 
)

Patch existing entities and construct missing ones from schema.

Entities whose id exists in the fabric are patched in place. Missing entities are constructed, their callables resolved via the fabric's function registry (left empty with a warning if absent), and wired. Restorable wiring kinds: every (with its scheduler tokens), move_to and commit_driven. Any other kind falls back to commit_driven with a warning. Entity ids are assigned by the Fabric, so a reconstructed entity may get a different id, which is warned. Hard failure (bad schema, unreadable EXR, dimension mismatch) sets last_error() and returns a zeroed result.

Parameters
fabricTarget fabric. May be empty, partial, or full.
base_pathPath stem without extension.
Returns
Counts and per-entity warnings.

Definition at line 754 of file Decoder.cpp.

755{
756 ReconstructionResult result;
757 m_last_error.clear();
758
759 const std::string json_path = base_path + ".json";
760 const std::string exr_path = base_path + ".exr";
761
762 IO::JSONSerializer ser;
763 auto schema_opt = ser.read<State::FabricSchema>(json_path);
764 if (!schema_opt) {
765 m_last_error = "Failed to load schema: " + ser.last_error();
767 return result;
768 }
769 const auto& schema = *schema_opt;
770
771 if (!version_supported(schema.version)) {
772 m_last_error = version_error(schema.version);
774 return result;
775 }
776
777 if (schema.entities.empty()) {
778 m_last_error = "Schema contains no entities: " + json_path;
780 return result;
781 }
782
783 auto pv_opt = load_exr(exr_path, static_cast<uint32_t>(schema.entities.size()), State::k_exr_rows, m_last_error);
784 if (!pv_opt) {
786 return result;
787 }
788 const auto* pixels = pv_opt->image.as_float();
789 const uint32_t width = pv_opt->width;
790
791 note_older_version(schema.version, result.warnings);
792
793 const auto existing_ids = fabric.all_ids();
794 const std::unordered_set<uint32_t> existing(existing_ids.begin(), existing_ids.end());
795
796 for (size_t i = 0; i < schema.entities.size(); ++i) {
797 const auto& entry = schema.entities[i];
798
799 if (!State::kind_known(entry.kind)) {
800 result.warnings.push_back("Unknown kind '" + entry.kind
801 + "' for id " + std::to_string(entry.id) + ", skipping");
802 ++result.skipped;
803 continue;
804 }
805
806 const Fields fields = read_fields(entry, *pixels, width, i, schema.ranges);
807
808 if (existing.contains(entry.id)) {
809 if (patch_entity(fabric, entry, fields, result.warnings)) {
810 ++result.patched;
811 } else {
812 ++result.skipped;
813 }
814 } else {
815 construct_entity(fabric, entry, fields, result.warnings);
816 ++result.constructed;
817 }
818 }
819
820 for (const auto& xrec : schema.expanses) {
821 switch (restore_expanse(fabric, xrec, result.warnings)) {
822 case Restored::Constructed:
823 ++result.constructed;
824 break;
825 case Restored::Patched:
826 ++result.patched;
827 break;
828 case Restored::Skipped:
829 ++result.skipped;
830 break;
831 }
832 }
833
835 "StateDecoder::reconstruct: constructed={} patched={} skipped={} warnings={}",
836 result.constructed, result.patched, result.skipped, result.warnings.size());
837
838 return result;
839}
#define MF_INFO(comp, ctx,...)
#define MF_ERROR(comp, ctx,...)
const std::vector< float > * pixels
Definition Decoder.cpp:48
uint32_t width
Cycle Behavior: The for_cycles(N) configuration controls how many times the capture operation execute...
@ 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::Nexus::Fabric::all_ids(), MayaFlux::Nexus::StateDecoder::ReconstructionResult::constructed, MayaFlux::Journal::FileIO, MayaFlux::Nexus::State::k_exr_rows, MayaFlux::Nexus::State::kind_known(), MayaFlux::IO::JSONSerializer::last_error(), m_last_error, MF_ERROR, MF_INFO, MayaFlux::Journal::Nexus, MayaFlux::Nexus::StateDecoder::ReconstructionResult::patched, pixels, MayaFlux::IO::JSONSerializer::read(), MayaFlux::Nexus::StateDecoder::ReconstructionResult::skipped, MayaFlux::Nexus::StateDecoder::ReconstructionResult::warnings, and width.

Referenced by reconstruct().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: