Reconstruct crossing permission from observed approach geometry

This commit is contained in:
DCCONSTRUCTIONS
2026-10-10 01:19:52 +03:00
parent 04b940e8e1
commit d0f6c80ee2
3 changed files with 133 additions and 18 deletions
+56 -4
View File
@@ -89,7 +89,8 @@ def test_grouping_does_not_join_distant_markings(module):
assert sorted(map(len, groups)) == [2, 4]
def test_unknown_crossing_ground_reaches_semantic_memory(monkeypatch, module):
@pytest.mark.parametrize("half_hidden", [False, True])
def test_unknown_crossing_ground_reaches_semantic_memory(monkeypatch, module, half_hidden):
composition = importlib.import_module('continuous_composition')
labels, points, pixels, pose = scene(); g = gate(module)
enter(g, (labels, points, pixels, pose))
@@ -100,10 +101,12 @@ def test_unknown_crossing_ground_reaches_semantic_memory(monkeypatch, module):
obj.crossing = g
obj.optics = SimpleNamespace(lens_axes=np.array([np.eye(3)]),
rectify_forward=lambda *a: (np.zeros((600,800,3),np.uint8), None))
obj.camera_source = SimpleNamespace(indices=lambda *a:pixels,
semantic_pixels=lambda *a:np.ones(len(points),bool))
visible = points[:, 1] >= 0 if half_hidden else np.ones(len(points), bool)
observed_pixels = tuple(p[visible] for p in pixels)
obj.camera_source = SimpleNamespace(indices=lambda *a:observed_pixels,
semantic_pixels=lambda *a:np.ones(int(visible.sum()),bool))
monkeypatch.setattr(composition, 'project', lambda *a:(None, np.zeros(len(points)),
np.zeros(len(points)), np.ones(len(points),bool)))
np.zeros(len(points)), visible))
obj.models = SimpleNamespace(labels={}, surface=lambda rgb:{'segmentation.labels':labels,
'segmentation.surface':np.isin(labels, (1,2,3)), 'segmentation.known':labels != 0})
observation = dict(calibration={'lens_axes':[np.eye(3)], 'intrinsics':[1,1,1,1]},
@@ -118,3 +121,52 @@ def test_unknown_crossing_ground_reaches_semantic_memory(monkeypatch, module):
permitted_points = set(map(tuple, samples[samples[:,3] == 1, :3]))
assert all(tuple(p) in permitted_points for p in points[expected_unknown])
assert not any(tuple(p) in permitted_points for p in points[np.abs(points[:,1]) > 1.1])
if half_hidden:
hidden_ground = g.ground_mask(points) & ~visible
assert hidden_ground.any()
assert all(tuple(p) in permitted_points for p in points[hidden_ground])
def test_approach_measurements_survive_a_narrow_near_camera_view(module):
labels, points, pixels, pose = scene(); g = gate(module)
# See the complete marking from farther away, without granting admission.
far = pose.copy(); far[0] = -3
assert not g.observe(labels, points, pixels, far, 10.)[1]['admitted']
# At the entry, the crop sees only a narrow strip, not the crossing width.
seen = np.abs(points[:, 1]) < .3
narrow = (labels, points[seen], tuple(p[seen] for p in pixels), pose)
g.observe(*narrow, 11.)
g.observe(*narrow, 11.4)
_, status = g.observe(*narrow, 11.8)
assert status['admitted']
intended = (points[:, 0] > 1.1) & (points[:, 0] < 6) & (np.abs(points[:, 1]) < .9)
assert g.ground_mask(points)[intended].all()
# A memory-free crop does not have enough width to invent a crossing.
assert not enter(gate(module), narrow)[1]['admitted']
def test_exit_sidewalk_need_not_be_coplanar_with_road(module):
data = scene(); labels, points, pixels, _ = data
sidewalk = labels[pixels] == 1
points[sidewalk, 2] = .15
mask, status = enter(gate(module), data)
assert status['admitted']
assert mask[pixels][labels[pixels] == 3].all()
# Permission is not a certificate that this physical step can be crossed.
# Raised exit ground still relies on its own sidewalk and support evidence.
assert not mask[pixels][sidewalk].any()
def test_small_exit_fragment_is_not_a_rover_width_exit(module):
data = scene(); labels, points, pixels, _ = data
bad = (points[:, 0] >= 6.5) & (np.abs(points[:, 1]) >= .3)
labels[pixels[0][bad], pixels[1][bad]] = 0
_, state = enter(gate(module), data)
assert state['exit_points'] > 3
assert not state['admitted'] and not state['observed_exit']
def test_retained_crossing_does_not_admit_new_ground_above_or_outside_it(module):
g = gate(module); assert enter(g, scene())[1]['admitted']
points = np.array([[3, 0, 0], [3, 0, .4], [3, 2, 0], [3, 0, -1.]])
assert g.ground_mask(points).tolist() == [True, False, False, False]