"""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, video=False, da3_path=None, sam3_path=None, ): """Build a spatial code from cached or newly adapted scene geometry.""" if video: input_selection = config.VIDEO_INPUT_SELECTION kwargs = {"video": video} if da3_path is not None: kwargs["da3_path"] = da3_path if sam3_path is not None: kwargs["sam3_path"] = sam3_path geometry, how = perceive.cache_or_load( scene, depth, input_selection, tracking, frame_count, rebuild, **kwargs ) code, *_ = geometry_math.build_spatial_code(geometry, "explicit") return code, how def write_spatial_code_for( scene, depth, input_selection, tracking, frame_count=config.FRAMES_PER_VIDEO, rebuild=False, video=False, da3_path=None, sam3_path=None, ): """Build and write one scene's spatial-code JSON.""" if video: input_selection = config.VIDEO_INPUT_SELECTION code, how = build_spatial_code_for( scene, depth, input_selection, tracking, frame_count, rebuild, video, da3_path, sam3_path, ) path = config.spatial_code_path( scene, depth, input_selection, tracking, frame_count, "explicit", ) os.makedirs(os.path.dirname(path), exist_ok=True) geometry_math.dump_spatial_code(code, path) return code, how, path