"""Build and write one final spatial-code JSON file per scene.""" from __future__ import annotations import os from encoder import config from encoder import geometric as geometry_math from encoder import run as perceive def build_spatial_code_for( scene, depth, input_selection, tracking, frame_count=config.FRAMES_PER_VIDEO, rebuild=False, spatial_code_format="explicit", ): """Build a spatial code from cached or newly adapted scene geometry.""" spatial_code_format = perceive.adapters.validate_spatial_code_format( spatial_code_format ) geometry, how = perceive.cache_or_load( scene, depth, input_selection, tracking, frame_count, rebuild ) code, *_ = geometry_math.build_spatial_code(geometry, spatial_code_format) return code, how def write_spatial_code_for( scene, depth, input_selection, tracking, frame_count=config.FRAMES_PER_VIDEO, rebuild=False, spatial_code_format="explicit", ): """Build and write one scene's spatial-code JSON.""" code, how = build_spatial_code_for( scene, depth, input_selection, tracking, frame_count, rebuild, spatial_code_format, ) path = config.spatial_code_path( scene, depth, input_selection, tracking, frame_count, spatial_code_format, ) os.makedirs(os.path.dirname(path), exist_ok=True) geometry_math.dump_spatial_code(code, path) return code, how, path