File size: 3,386 Bytes
ceea884
 
 
 
 
 
 
1fc7ce0
ceea884
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1fc7ce0
ceea884
 
 
 
 
 
 
 
 
 
1fc7ce0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ceea884
 
 
 
 
 
 
 
1fc7ce0
ceea884
 
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
"""μ§€μ—­ λ§΅ μ„Όμ„œ 볡셀 μ›”λ“œ 선택 (nusim.render.regionmap.sensor_world) β€” 데이터셋 없이."""

import json

import numpy as np

from nusim.io.ply import _ORIGIN_TAG
from nusim.render.heights import LIFT_VERSION
from nusim.render.regionmap import sensor_world
from nusim.render.segmap import SEGMAP_VERSION
from nusim.sim.voxels import VOXELS_VERSION


def _seg(d, name, origin):
    m = d / name
    m.mkdir(parents=True)
    (m / "point_cloud.ply").write_text(f"ply\ncomment {_ORIGIN_TAG} {origin[0]} {origin[1]} {origin[2]}\nend_header\n")
    return m


def test_stale_world_still_used_with_its_own_origin(tmp_path):
    d = tmp_path / "scene-x"
    s1 = _seg(d, "seg1", (10, 20, 1))
    (d / "world.vox").write_bytes(b"VOX2")
    # seg1 만 ν•™μŠ΅λμ„ λ•Œ λ§Œλ“  μ›”λ“œ (origin 기둝 μ „ ν˜•μ‹)
    (d / "export.json").write_text(json.dumps({"version": SEGMAP_VERSION, "voxels": VOXELS_VERSION,
                                               "models": ["seg1:1"], "lift": LIFT_VERSION}))
    s0 = _seg(d, "seg0", (0, 0, 0))  # κ·Έ λ’€ seg0 이 ν•™μŠ΅λ¨ β†’ 첫 ꡬ간과 원점이 λ°”λ€Œμ—ˆλ‹€
    segs = [({"k": 0}, s0), ({"k": 1}, s1)]
    assert sensor_world(tmp_path, "scene-x", segs) is None  # 엄격: λ‚‘μŒ
    p, o = sensor_world(tmp_path, "scene-x", segs, strict=False)
    assert p == d / "world.vox" and np.allclose(o, [10, 20, 1])  # μ›”λ“œλ₯Ό λ§Œλ“  seg1 원점
    j = json.loads((d / "export.json").read_text())
    (d / "export.json").write_text(json.dumps({**j, "origin": [5, 6, 7]}))
    assert np.allclose(sensor_world(tmp_path, "scene-x", segs, strict=False)[1], [5, 6, 7])
    (d / "export.json").write_text(json.dumps({**j, "voxels": VOXELS_VERSION - 1}))
    assert sensor_world(tmp_path, "scene-x", segs, strict=False) is None  # 볡셀 μ•Œκ³ λ¦¬μ¦˜μ΄ λ°”λ€Œλ©΄ μ•ˆ μ“΄λ‹€
    (d / "export.json").write_text(json.dumps({**j, "lift": LIFT_VERSION - 1}))
    assert sensor_world(tmp_path, "scene-x", segs, strict=False) is None  # 높이 배치 이전 (평면 포즈) μ›”λ“œ


def test_world_stale_when_pitch_units_change(tmp_path):
    """ꡬ간 ν•˜λ‚˜λ₯Ό 높이 λ³΅μ›μœΌλ‘œ λ‹€μ‹œ ν•™μŠ΅ν•˜λ©΄ (render/heights.py) κ·Έ μ”¬μ˜ 볡셀 κΈ°ν•˜κ°€ ꡬ간 λͺ¨λΈκ³Ό μ–΄κΈ‹λ‚œλ‹€ β†’ λ‹€μ‹œ λ§Œλ“ λ‹€."""
    d = tmp_path / "scene-z"
    s0 = _seg(d, "seg0", (0, 0, 0))
    (d / "world.vox").write_bytes(b"VOX2")
    (d / "export.json").write_text(json.dumps({"version": SEGMAP_VERSION, "voxels": VOXELS_VERSION, "models": ["seg0:1"],
                                               "lift": LIFT_VERSION, "pitch_units": [], "origin": [0, 0, 0]}))
    segs = [({"k": 0}, s0)]
    assert sensor_world(tmp_path, "scene-z", segs, strict=False) is not None
    (s0 / "report.json").write_text(json.dumps({"config": {"ego_z": "pitch"}}))
    assert sensor_world(tmp_path, "scene-z", segs, strict=False) is None


def test_unsplit_scene_model_is_scene_dir(tmp_path):
    d = tmp_path / "scene-y"
    d.mkdir()
    (d / "point_cloud.ply").write_text(f"ply\ncomment {_ORIGIN_TAG} 1 2 3\nend_header\n")
    (d / "world.vox").write_bytes(b"VOX2")
    (d / "export.json").write_text(json.dumps({"version": SEGMAP_VERSION, "voxels": VOXELS_VERSION,
                                               "models": ["scene-y:1"], "lift": LIFT_VERSION}))
    p, o = sensor_world(tmp_path, "scene-y", [({"k": 0}, d)], strict=False)
    assert np.allclose(o, [1, 2, 3])