From 72282df458b512f93d6fd666aeb81b71eba3cd34 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Thu, 3 Dec 2026 00:30:34 +0100 Subject: [PATCH] brokkr_reference.flow_score: the hiding margin is the edge's own connected piece's; docs for skipped points A box joined into one mesh with a ground kept the whole mesh's margin and its edge was hidden only from 16% of the box's diagonal (finding hiding-margin-same-mesh). built_edges now measures the connected part of the mesh the edge lies on; the object met is still measured whole, and docs/reference.md says so. Live: reference_lift.py 32 of 32 with the joined-mesh check (mutant O10, the whole mesh's diagonal, fails it), reference.py 14 of 14, Blender 5.3 on Starfire. docs/reference.md: lift_pair's skipped points, SKIP, TURN, SHARE and the readings. Co-Authored-By: Claude Fable 5.2 --- surfaces/blender/brokkr_reference/__init__.py | 23 +++++++++--- surfaces/blender/docs/reference.md | 37 ++++++++++++------- .../blender/tests/live/reference.result.json | 12 ++++-- surfaces/blender/tests/live/reference_lift.py | 21 +++++++++-- .../tests/live/reference_lift.result.json | 11 +++++- 5 files changed, 77 insertions(+), 27 deletions(-) diff --git a/surfaces/blender/brokkr_reference/__init__.py b/surfaces/blender/brokkr_reference/__init__.py index d596b41..2cd7956 100644 --- a/surfaces/blender/brokkr_reference/__init__.py +++ b/surfaces/blender/brokkr_reference/__init__.py @@ -98,7 +98,7 @@ def record(context, name, box): core.numbers(box, 4, "box") if box.strip() else None) -HIDE = 1e-3 # of an object's diagonal: a sight line stops this share of the edge's own object short of the edge, so that the edge's own faces do not hide it; a surface nearer the edge than that hides it only from further than this share of its own object +HIDE = 1e-3 # of a diagonal: a sight line stops this share of the edge's own piece of mesh short of the edge, so that the edge's own faces do not hide it; a surface nearer the edge than that hides it only from further than this share of its own object def _diagonal(obj, placed, dg): @@ -111,9 +111,10 @@ def built_edges(context, cam, objects, angle): more than `angle` degrees, one of them toward the camera), contours (one face toward the camera, the other away) and open borders, each kept where two of three points along it are hidden behind nothing: a ray from the camera toward the point meets no surface nearer it than the hiding margin: HIDE of the diagonal of the edge's - own object or of the object met, the smaller of the two, so the margin is the same share of the parts involved - at any scale and whatever else the scene holds (a ground plane, a hull). Past the own object's margin the ray - is cast once more, and the first surface it meets there decides. `objects` are the meshes read; anything the + own piece (the connected part of its mesh it lies on: a box joined into one mesh with a ground is still a + box) or of the object met, the smaller of the two, so the margin is the same share of the parts involved at + any scale and whatever else the scene or the mesh holds (a ground plane, a hull). Past the own piece's margin + the ray is cast once more, and the first surface it meets there decides; the object met is measured whole. `objects` are the meshes read; anything the scene renders hides. Returns {kind: [[u0, v0, u1, v1], ...]} in the record's pixels.""" scene, dg = context.scene, context.evaluated_depsgraph_get() eye, out, cos_a = np.array(cam["C"]), {"crease": [], "contour": [], "border": []}, math.cos(math.radians(angle)) @@ -128,7 +129,6 @@ def built_edges(context, cam, objects, angle): for obj in objects: ev = obj.evaluated_get(dg) - short = HIDE * _diagonal(obj, obj.matrix_world, dg) me = ev.to_mesh() nv, ne, nl, nf = len(me.vertices), len(me.edges), len(me.loops), len(me.polygons) if not nf: @@ -155,8 +155,21 @@ def built_edges(context, cam, objects, angle): crease = two & ((normal[f0] * normal[f1]).sum(1) < cos_a) & (toward[f0] | toward[f1]) contour = two & (toward[f0] != toward[f1]) ends = ends.reshape(-1, 2) + piece, shorts = np.arange(nv), {} # each vertex's connected piece, named by its least vertex + while True: + low = np.minimum(piece[ends[:, 0]], piece[ends[:, 1]]) + spread = piece.copy() + np.minimum.at(spread, ends[:, 0], low) + np.minimum.at(spread, ends[:, 1], low) + spread = spread[spread] + if (spread == piece).all(): + break + piece = spread for k in np.nonzero(crease | contour | (count == 1))[0]: a, b = co[ends[k, 0]], co[ends[k, 1]] + if piece[ends[k, 0]] not in shorts: + shorts[piece[ends[k, 0]]] = HIDE * float(np.linalg.norm(np.ptp(co[piece == piece[ends[k, 0]]], axis=0))) + short = shorts[piece[ends[k, 0]]] if sum(not hidden(a + t * (b - a), short) for t in (0.2, 0.5, 0.8)) >= 2: (u0, v0), (u1, v1) = core.project(cam, [a, b]) out["contour" if contour[k] else "crease" if crease[k] else "border"].append([float(u0), float(v0), float(u1), float(v1)]) diff --git a/surfaces/blender/docs/reference.md b/surfaces/blender/docs/reference.md index d18a741..9ae88d5 100644 --- a/surfaces/blender/docs/reference.md +++ b/surfaces/blender/docs/reference.md @@ -117,7 +117,7 @@ and focal length trade against each other (a dolly zoom) and the picture barely those would be called best. It is an **equal-error band, not a confidence interval**: it says which lenses the marks cannot tell apart, and on probes a few such bands excluded the true lens. A band that ends at 4000 or at 4 was stopped by the bound. -- For flat marks (`planarity` under 0.057, `core.PLANAR`) a band that reaches one end of the range is reported as +- For flat marks (`planarity` under 0.12, `core.PLANAR`) a band that reaches one end of the range is reported as the whole range, 4 to 4000. What closes the other end of such a band is a tilt of the plane traded against the lens, and the marks' error sets that either way: a square-on plane's band read 309 to 4000 mm on one seed with the true lens at 50. This gives up the one-sided reading ("at least 300 mm") for flat marks; marks with depth @@ -158,7 +158,7 @@ x axis; the pair is triangulated as one point seen by the camera and by the came The report: `crease` (`[[x, y, z], ...]` in the frame, x >= 0, in the order of `line_a`), `side` (+1 or -1: the side of the frame `line_a` is on), `unmatched` (points of `line_a` whose line to the vanishing point never meets -`line_b`; they are left out), `ambiguous` (points whose line meets `line_b` more than once), `kink`, `cage`, `miss` and +`line_b`; they are left out), `ambiguous` (points whose line meets `line_b` more than once), `skipped`, `cage`, `miss` and `curve`. The camera is read back from the object (`core.camera_of`): a perspective camera with a horizontal sensor fit. The curve is for the eye; the report is the truth. @@ -167,16 +167,23 @@ a line folds back, the crease can: the crossings of all the points are chosen to crease turns least in all (the sum of its turns at each point, by dynamic programming), so no point is settled before the points after it are read. Wherever each point's true crossing is among its crossings, that is the true crease. Where it is not (most often the last point of `line_a`, whose mirror is the very end of `line_b`, meeting -only the doubled strokes) the smoothest crease still kinks at that point. `kink` is the worst turn at a point that -had a choice, over the crease's median turn, and a lift whose `kink` is over 3.1 (`core.KINK`) is refused: draw -`line_b` as one stroke. +only the doubled strokes) every crossing of that point kinks the crease, and the point is given none: it is left +out of `crease` and named in `skipped`, the indices of such points among the `samples` of `line_a`. Only a point +with more than one crossing can be skipped. A skip costs 2.8 (`core.SKIP`) times the crease's median turn, and the +turn is read across the gap, so a skip cannot hide a turn. The median is never read as less than 0.061 radians +(`core.TURN`), so a crease of straight runs and corners, whose median turn is nothing, lifts whole. A lift that +skips more than 0.24 (`core.SHARE`) of the points that met `line_b` is refused, and no more than that are skipped +in a row: draw `line_b` as one stroke. On 189 exact strokes of `line_b` doubled back beside themselves (a tenth to nine tenths of the crease, three -views) 174 lift exactly, with `kink` at most 1.25, and 15 are refused, `kink` 7.7 to 66, all on the view 10 degrees -above the crease; none lifts wrong. On hand-traced lines the refusal is blunt: with the same folds drawn on -twelve-point traces 0.5 and 1.5 px off, it refuses 20% and 50% of the lifts the fold did not harm (108 of 540, 264 -of 533), and passes none of 27 and 3 of 34 that it did, the three within 1.8 cm of the unfolded lift. A trace's own wobble turns the crease as -much as a wrong crossing does, and no reading of the lift tells them apart. A lift with no ambiguous +views) every one lifts exactly, none refused; 15, all on the view 10 degrees above the crease, skip their last +point. On hand-traced lines (the same folds on traces 0.25 to 3 px off: twelve jittered points, thirty, and a slow +wobble; 11340 strokes) none is refused, 1824 skip a point or more, at most 4 of 23, and 475 lift more than 5 mm +worse than the same trace unfolded, 131 of them more than 20 mm: 21 of the 3780 wobbled, 130 of the twelve-point +and 324 of the thirty-point, where a 1 px tremor already stands in for a wrong crossing. A trace's own wobble +turns the crease as much as a wrong crossing does, and no reading of the lift tells them apart: `skipped` says +what was left out, not that the rest is right. A scribbled `line_b` can lift 0.07 m off with nothing skipped and +takes seconds. A lift with no ambiguous point has no choice anywhere and is never refused. A line whose first or last point is given twice is refused: that end of `line_b` has no direction to run on in. @@ -220,9 +227,11 @@ direction; `off` the mean distance to such an edge in % of the height, capped at share that is on. The edges themselves are not returned and not kept: they are computed on each call. The hiding test's sight line stops short of each point by a thousandth (`HIDE`) of the diagonal of the edge's own -object, so that the edge's own faces do not hide it. A surface of another object nearer the edge than that hides -it when it stands further off than a thousandth of its own diagonal: the margin is the smaller of the two objects', -whatever else the scene holds. A strip 0.3% of a box's diagonal in front of an edge hides it at scales 0.01, 1 and +piece, the connected part of its mesh that it lies on, so that the edge's own faces do not hide it: a box joined +into one mesh with a ground 200 times its size keeps the box's margin. A surface nearer the edge than that hides +it when it stands further off than a thousandth of the diagonal of the object it belongs to, measured whole: the +margin is the smaller of the two, whatever else the scene holds. A greeble modelled into its hull's own connected +surface has the hull's margin, and a surface nearer it than a thousandth of the hull does not hide it. A strip 0.3% of a box's diagonal in front of an edge hides it at scales 0.01, 1 and 100, and with a ground 20 or 40 times the box among the meshes read; chips a fortieth of a box hide its edge from 0.05% of its diagonal. Past the own object's margin the first surface met decides. Edges read true from cameras to about 20000 diagonals off, where the ray's own rounding reaches the margin. The action writes nothing to the scene (its row says `changesScene` @@ -243,7 +252,7 @@ cam = core.solve(world, pixels, box, model="auto") # dicts by name; the u_v = core.project(cam, points) # where it draws world points origin, direction = core.ray(cam, (u, v)) # a pixel's line of sight point = core.lift(cam, (u, v), plane_point, plane_normal) # a traced pixel on a plane -out = core.pair(cam, frame, line_a, line_b) # crease, side, ambiguous, unmatched, kink +out = core.pair(cam, frame, line_a, line_b) # crease, side, ambiguous, unmatched, skipped cage = core.cage_through(out["crease"]) # the column whose built crease passes through it score = core.along(line, segments, height) # on, off, run against [u0, v0, u1, v1] segments params = core.blender(cam, 1000) # matrix_world, lens, shifts, resolution diff --git a/surfaces/blender/tests/live/reference.result.json b/surfaces/blender/tests/live/reference.result.json index 55664b6..757834d 100644 --- a/surfaces/blender/tests/live/reference.result.json +++ b/surfaces/blender/tests/live/reference.result.json @@ -12,7 +12,9 @@ "brokkr_mesh_polish.scrub_markings", "brokkr_mesh_polish.cut_parts", "brokkr_mesh_polish.pick", - "brokkr_reference.solve_camera" + "brokkr_reference.solve_camera", + "brokkr_reference.lift_pair", + "brokkr_reference.flow_score" ] }, { @@ -119,13 +121,15 @@ "brokkr_mesh_polish.scrub_markings", "brokkr_mesh_polish.cut_parts", "brokkr_mesh_polish.pick", - "brokkr_reference.solve_camera" + "brokkr_reference.solve_camera", + "brokkr_reference.lift_pair", + "brokkr_reference.flow_score" ], "record": { "lens": 50.02266319807241, "lens_band": [ - 50.02266319807241, - 50.02266319807241 + 45.26237741142627, + 61.09781880064287 ], "lens_at_bound": null, "rms": 0.03555833513434369, diff --git a/surfaces/blender/tests/live/reference_lift.py b/surfaces/blender/tests/live/reference_lift.py index 2c453f1..f16031a 100644 --- a/surfaces/blender/tests/live/reference_lift.py +++ b/surfaces/blender/tests/live/reference_lift.py @@ -13,7 +13,8 @@ core.crease_run against Blender's own subdivision. times over: each reads the hidden edge as seen. O4, no margin at all, loses seen edges to their own faces here and at the first box). The margin is the objects' own: a box over a ground 20 and 40 times its size, a small box over a ground behind a long strip (O7, a share of the largest mesh - read), two chips before a large box (O9, no second cast). Cameras 30 and 144 diagonals off + read), two chips before a large box (O9, no second cast); a box, a ground and a strip joined + into one mesh, where the margin is the box's own connected piece's (O10, the whole mesh's). Cameras 30 and 144 diagonals off still read every edge (O5, HIDE at 1e-6, loses four contours at 144) blender --background --factory-startup --python-exit-code 1 --python surfaces/blender/tests/live/reference_lift.py -- @@ -145,8 +146,8 @@ try: before = sorted(o.name for o in bpy.data.objects) receipt, lifted = send("brokkr_reference.lift_pair", camera_name="Truth", frame_name="Hull", line_a=traced(truth, world(-1)), line_b=traced(truth, world(1))) off = lifted and float(core._off(np.array(lifted["crease"]), crease).max()) - check("lift_pair: accepted, 24 points on the crease within 1 mm, on the frame's -x side, none ambiguous or unmatched, no object made", - receipt["status"] == "accepted" and len(lifted["crease"]) == 24 and off < 1e-3 and lifted["side"] == -1 and lifted["ambiguous"] == 0 and lifted["unmatched"] == 0 + check("lift_pair: accepted, 24 points on the crease within 1 mm, on the frame's -x side, none ambiguous, skipped or unmatched, no object made", + receipt["status"] == "accepted" and len(lifted["crease"]) == 24 and off < 1e-3 and lifted["side"] == -1 and lifted["ambiguous"] == 0 and lifted["skipped"] == [] and lifted["unmatched"] == 0 and lifted["curve"] is None and sorted(o.name for o in bpy.data.objects) == before, [receipt["message"], off]) through = lifted and float(np.abs(core.crease_run(lifted["cage"])[0::2] - np.array(lifted["crease"])).max()) check("the cage column's built crease passes through the lifted crease, and draws within 1 px of both lines", @@ -270,6 +271,20 @@ try: walled = front(staged, line, {}) check(f"a box {2 * half:g} across over a ground {ground:g} across, every mesh read: its front edge is seen, and a strip 1% of the box's diagonal in front hides it " f"(a margin of the ground's is {1e-3 * ground * math.sqrt(2.0) / (0.01 * DIAGONAL * half):.1f} times the gap)", bare == (1.0, 3, 6) and walled == (0.0, 2, 6), [bare, walled]) + # the box, the ground and the strip joined into one mesh: the margin is the box's own piece's (O10, the whole mesh's diagonal, reads on 1: the ground's margin is 16 times the gap) + staged, edge, line = stage(0.05, 20.0) + screen(staged, "Wall", edge.mean(0), 0.01 * DIAGONAL * 0.05, 0.02, 0.15) + bm = bmesh.new() + for obj in [o for o in bpy.data.objects if o.type == "MESH"]: + bm.from_mesh(obj.data) + bpy.data.objects.remove(obj) + mesh = bpy.data.meshes.new("Joined") + bm.to_mesh(mesh) + bm.free() + scene.collection.objects.link(bpy.data.objects.new("Joined", mesh)) + bpy.context.view_layer.update() + walled = front(staged, line, {}) + check("a box 0.1 across, a ground 20 across and a strip 1% of the box's diagonal in front of the box's edge, all one mesh: hidden, the margin is the edge's own connected piece's (O10 reads on 1)", walled[0] == 0.0, walled) # a small box's edge behind a strip far longer than the box, over a ground: the margin is the box's, not the strip's or the ground's (O7, a share of the largest mesh read, reads on 1) staged, edge, line = stage(0.05, 4.0) gap = math.sqrt(1e-3 * DIAGONAL * 0.05 * 1e-3 * math.hypot(0.02, 4.0)) # the geometric mean of the box's margin and the strip's, 4.8 from each diff --git a/surfaces/blender/tests/live/reference_lift.result.json b/surfaces/blender/tests/live/reference_lift.result.json index e80de0e..2cad035 100644 --- a/surfaces/blender/tests/live/reference_lift.result.json +++ b/surfaces/blender/tests/live/reference_lift.result.json @@ -23,7 +23,7 @@ "detail": 4.76837158203125e-07 }, { - "name": "lift_pair: accepted, 24 points on the crease within 1 mm, on the frame's -x side, none ambiguous or unmatched, no object made", + "name": "lift_pair: accepted, 24 points on the crease within 1 mm, on the frame's -x side, none ambiguous, skipped or unmatched, no object made", "ok": true, "detail": [ "Operator brokkr_reference.lift_pair finished.", @@ -299,6 +299,15 @@ ] ] }, + { + "name": "a box 0.1 across, a ground 20 across and a strip 1% of the box's diagonal in front of the box's edge, all one mesh: hidden, the margin is the edge's own connected piece's (O10 reads on 1)", + "ok": true, + "detail": [ + 0.0, + 2, + 6 + ] + }, { "name": "a box 0.1 across over a ground 4 across, with a strip 4 long standing between the two margins in front of its edge: hidden, the margin is the smaller object's (O7 reads on 1)", "ok": true,