File size: 2,272 Bytes
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 | """μ§μ λ§΅ μΌμ 볡μ
μλ μ ν (nusim.render.regionmap.sensor_world) β λ°μ΄ν°μ
μμ΄."""
import json
import numpy as np
from nusim.io.ply import _ORIGIN_TAG
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"]}))
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 # 볡μ
μκ³ λ¦¬μ¦μ΄ λ°λλ©΄ μ μ΄λ€
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"]}))
p, o = sensor_world(tmp_path, "scene-y", [({"k": 0}, d)], strict=False)
assert np.allclose(o, [1, 2, 3])
|