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])
|