File size: 1,790 Bytes
ddacca5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
"""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