From 0c0dc87e504f6979529bfaa752df9a4add341da9 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Thu, 3 Dec 2026 05:32:27 +0100 Subject: [PATCH] brokkr_reference fit: the trim deleted, a trace asked at its untrimmed 90th percentile (tol 5.2); m_per_px stated as a depth sensitivity, not an error bound No test claimed the trim (hand traces 3.76 against 3.26, the Orchid 0.80 against 0.69). Untrimmed, the traces to accept read 3.76 at most and the least to refuse 7.27: TOL 5.2, separation 1.39 each side. The clean-stroke test is named for the sensitivity it reads; fit_runs' docstring states the hand-trace overshoot (13 of 24, up to 2.45 times). Co-Authored-By: Claude Fable 5.2 --- surfaces/blender/brokkr_reference/__init__.py | 2 +- .../brokkr_reference/brokkr_actions.json | 6 +-- surfaces/blender/brokkr_reference/core.py | 29 +++++++------ surfaces/blender/tests/test_reference.py | 42 +++++++++---------- 4 files changed, 38 insertions(+), 41 deletions(-) diff --git a/surfaces/blender/brokkr_reference/__init__.py b/surfaces/blender/brokkr_reference/__init__.py index 96d6dab..d106882 100644 --- a/surfaces/blender/brokkr_reference/__init__.py +++ b/surfaces/blender/brokkr_reference/__init__.py @@ -218,7 +218,7 @@ class BROKKR_REFERENCE_OT_fit_shell(PolishOperator): object_name: bpy.props.StringProperty(name="Object", maxlen=63, description="A shell made by brokkr_kitbash.shell, unscaled; its place in the world is the sheet's frame") traces: bpy.props.StringProperty(name="Traces", maxlen=12000, description="A JSON array of {camera, box, run: {ring|column, from, to} on a loft or {verts: [v, ...]} on a free cage, side, line: [[u, v], ...]}") share: bpy.props.FloatProperty(name="Share", default=0.1, min=0.0009, max=10.0, description="A move of this share of the sheet's diagonal from the sheet as it stands costs what one pixel of miss does") - tol: bpy.props.FloatProperty(name="Tolerance", default=core.TOL, min=0.09, max=100.0, description="Pixels: nine tenths of every trace, its ends apart, must lie this near its built run, or the fit is refused") + tol: bpy.props.FloatProperty(name="Tolerance", default=core.TOL, min=0.09, max=100.0, description="Pixels: nine tenths of every trace must lie this near its built run, or the fit is refused") # the action table states share from 0.001 and tol from 0.1: a float property rounds those up, so its bounds stand just under def work(self, context): diff --git a/surfaces/blender/brokkr_reference/brokkr_actions.json b/surfaces/blender/brokkr_reference/brokkr_actions.json index aa4f7e2..a1d4856 100644 --- a/surfaces/blender/brokkr_reference/brokkr_actions.json +++ b/surfaces/blender/brokkr_reference/brokkr_actions.json @@ -136,7 +136,7 @@ }, { "name": "brokkr_reference.fit_shell", - "doc": "Fit a kitbash shell's sheet (a loft or a free cage) to traces of its hard crease and rim runs, each seen through a scene camera: the traced runs' cage points move until the runs as built draw on the traces. Returns the fitted sheet for brokkr_kitbash.shell only where nine tenths of every trace, 5% left out at each end, lies within tol px of its built run; otherwise it is refused naming the trace, its reading and the span. A very unsteady hand and a 1 to 2% overdraw read alike: each trace's reading (unexplained_px) and worst point (worst_px) are in the report to judge by. Writes nothing. Per moved point: metres of depth across its run per pixel, and the prior's share of that: under 0.2 the traces decide the point, over it the blocking holds it (docs/reference.md).", + "doc": "Fit a kitbash shell's sheet (a loft or a free cage) to traces of its hard crease and rim runs, each seen through a scene camera: the traced runs' cage points move until the runs as built draw on the traces. Returns the fitted sheet for brokkr_kitbash.shell only where nine tenths of every trace lies within tol px of its built run; otherwise it is refused naming the trace, its reading and the span. A very unsteady hand and a 1 to 2% overdraw read alike: each trace's reading (unexplained_px) and worst point (worst_px) are in the report to judge by. Writes nothing. Per moved point: its depth sensitivity (metres one pixel of trace error moves it along its sight line, across its run; a sensitivity, not an error bound) and the prior's share of that: under 0.2 the traces decide the point, over it the blocking holds it (docs/reference.md).", "changesScene": true, "editModeSafe": false, "result": "brokkr_mesh_polish_result", @@ -170,8 +170,8 @@ "type": "number", "minimum": 0.1, "maximum": 100, - "default": 5, - "doc": "pixels: nine tenths of every trace, its ends apart, must lie this near its built run, or the fit is refused" + "default": 5.2, + "doc": "pixels: nine tenths of every trace must lie this near its built run, or the fit is refused" } ] } diff --git a/surfaces/blender/brokkr_reference/core.py b/surfaces/blender/brokkr_reference/core.py index bb27391..69549b4 100644 --- a/surfaces/blender/brokkr_reference/core.py +++ b/surfaces/blender/brokkr_reference/core.py @@ -452,9 +452,8 @@ def along(line, segments, height, near=0.01, turn=20.0, cap=0.05): LEVELS = 2 # crease_run applied this many times gives the samples of a built run the fit draws: 4k - 3 for k cage points HARD = 1.0 - 1e-9 # a crease weight from here up is hard: the edge stays sharp at every level, which is what crease_run builds ROUNDS = 60 -TRIM = 0.05 # of a trace's length, left out at each end where a trace is asked whether its run explains it: a hand trace's tip is where two traces cannot agree -PART = 90 # the percentile of the rest of the trace's distances from its built run that fit_runs reads against tol -TOL = 5.0 # pixels. tests/test_reference.py FitTests states the sets TRIM, PART and TOL were read from, and what they do not separate +PART = 90 # the percentile of a trace's distances from its built run that fit_runs reads against tol: a hand trace's tip is where two traces cannot agree, and a tenth of it may stand off +TOL = 5.2 # pixels. tests/test_reference.py FitTests states the sets PART and TOL were read from, and what they do not separate RESULT_LIMIT = 16000 # characters of a host result Brokkr copies into a receipt before it truncates (brokkr_bridge's HOST_RESULT_LIMIT; this package imports nothing from Brokkr) @@ -540,20 +539,21 @@ def fit_runs(views, cage, runs, movable, mirror_of, share, diag, tol=TOL): mirror_of per vertex, the authored vertex it mirrors across x = 0, or itself: a mirrored half is the same parameters seen again, x negated share the prior: a move of share x diag from the cage as given costs what one pixel of miss does - tol pixels: of each trace less TRIM of its length at each end, PART in a hundred must lie this near its - built run as drawn + tol pixels: PART in a hundred of each trace must lie this near its built run as drawn The residual per run is the pixel distance from each built point (crease_run LEVELS times, drawn through the run's view) to the trace, and the run's two ends against the trace's; no point of the trace is matched to a point of the run beyond that. Gauss-Newton with Levenberg-Marquardt damping on the analytic Jacobian. Returns (V, report): the cage's vertices as fitted and {"traces": [{"unexplained_px": the reading tol is asked of, "worst_px": the whole trace's furthest point from the built run}], "points": [{"vertex", "moved_m", "m_per_px", - "prior_share"}], "rounds"}. m_per_px is how far the point slides in depth across its run per pixel of error in - the traces: along the part of its sight line that stands across the run's tangent there (the worst of the - traces that draw it), sqrt(r' S r) with S the point's block of the inverse of J'J, prior included (Triggs et - al. 2000, sections 9 and 10). A point's slide along its own run is left out: the traces do not decide it and it - does not move the built run. prior_share is m_per_px over share x diag: near 1 the traces say nothing about - the point's depth and it stands where it was blocked. + "prior_share"}], "rounds"}. m_per_px is the point's depth sensitivity: how many metres one pixel of error in + the traces moves that point along its sight line, taken on the part of the sight line that stands across the + run's tangent there (the worst of the traces that draw it), sqrt(r' S r) with S the point's block of the + inverse of J'J, prior included (Triggs et al. 2000, sections 9 and 10). A point's slide along its own run is + left out: the traces do not decide it and it does not move the built run. It is a sensitivity to one pixel on + one point and no bound on the fit's error: of 24 fits to hand traces whose wander holds over 30 px, 13 ended + further from the truth than tol x m_per_px, up to 2.45 times. prior_share is m_per_px over share x diag: near + 1 the traces say nothing about the point's depth and it stands where it was blocked. Raises ReferenceFitError for a run it cannot model (_hard_runs), and when a trace is not explained: the error names the trace, its reading and the span of it that lies further than tol from the built run, and carries the @@ -632,13 +632,12 @@ def fit_runs(views, cage, runs, movable, mirror_of, share, diag, tol=TOL): length = np.linalg.norm(np.diff(line, axis=0), axis=1).sum() dense = resampled(line, int(min(max(length, len(line)), 4000)) + 1) # a point each pixel along it off = _off(dense, u) - ends = int(TRIM * len(dense)) - reading = float(np.percentile(off[ends:len(dense) - ends], PART)) + reading = float(np.percentile(off, PART)) traces.append({"unexplained_px": round(reading, 3), "worst_px": round(float(off.max()), 3)}) if reading > tol and refused is None: - out = (ends + np.flatnonzero(off[ends:len(dense) - ends] > tol)) * length / (len(dense) - 1) + out = np.flatnonzero(off > tol) * length / (len(dense) - 1) refused = (f"{name} is not explained: {len(out) * length / (len(dense) - 1):.0f} px of the trace, between {out[0]:.0f} and {out[-1]:.0f} px along it, lie " - f"more than {tol:g} px from the run as built ({reading:.1f} px at the {PART}th of a hundred, {TRIM:.0%} of the trace left out at each end; up to " + f"more than {tol:g} px from the run as built ({reading:.1f} px at the {PART}th of a hundred; up to " f"{off.max():.1f} px). Nothing is returned as a fit. The trace draws something this run does not build (an overdrawn or doubled stroke, another " "edge, a bend the cage has too few points for): redraw it, or give the run more points. A very unsteady hand reads the same as a slight " "overdraw: if the trace is one clean stroke, ask again with tol over this reading") diff --git a/surfaces/blender/tests/test_reference.py b/surfaces/blender/tests/test_reference.py index 72d19d1..db8af73 100644 --- a/surfaces/blender/tests/test_reference.py +++ b/surfaces/blender/tests/test_reference.py @@ -483,18 +483,17 @@ class FitTests(unittest.TestCase): G7 a free cage's mirrored half read as the authored test_a_free_cage_is_fitted_by_its_vertex_chains G8 the prior in the Jacobian and not the residual test_one_trace_alone_reads_as_held_by_the_blocking - core.TRIM, core.PART and core.TOL were read from 296 fits kept outside the suite (108 hand traces by `hand`, + core.PART and core.TOL were read from 296 fits kept outside the suite (108 hand traces by `hand`, wander 1, 2 and 4 px; 108 strokes by `overdrawn` 1, 2, 3 and 5% off; the Orchid pair, moved and overdrawn). - Read as the PART-th percentile past TRIM at each end, the traces to accept read 3.26 px at most (the 72 hand - traces of wander 1 and 2 px; the Orchid pair 0.69) and the least to refuse 7.65 (the Orchid's traces overdrawn - 2%; the strokes 3% off 7.83): TOL is their geometric mean, separation 1.53 each side. The trace's worst point, + Read at the PART-th percentile, the traces to accept read 3.76 px at most (the 72 hand traces of wander 1 and + 2 px; the Orchid pair 0.80) and the least to refuse 7.27 (the Orchid's traces overdrawn 2%; the strokes 3% off + 7.70): TOL is their geometric mean, separation 1.39 each side. The trace's worst point, which that reading replaces, read 9.20 on the Orchid pair against 9.12 on its least 1% overdraw. What TOL does - not separate: 31 of the 36 hand traces of wander 4 px are accepted (they read up to 5.96), 9 of 27 strokes 1% - off and 3 of 18 Orchid 1% overdraws are accepted (from 2.63 and 4.27), and the strokes 2% off are refused from - 5.34 with no margin. A very unsteady hand and a slight overdraw read alike; the report carries the reading. + not separate: 31 of the 36 hand traces of wander 4 px are accepted (they read up to 5.84), 9 of 27 strokes 1% + off and 2 of 18 Orchid 1% overdraws are accepted (from 2.57 and 4.25), and of the strokes 2% off, which read + from 5.10, 2 of 27 are accepted. A very unsteady hand and a slight overdraw read alike; the report carries the reading. - Unclaimed, with readings: TRIM 0 (the hand traces read 3.76 against 3.26, the Orchid 0.80 against 0.69: - separation 1.15); F6, the Jacobian by differences (time only: tests/live/reference_fit.py's header); + Unclaimed, with readings: F6, the Jacobian by differences (time only: tests/live/reference_fit.py's header); the least, in place of the worst, of the traces that draw a point (the 18 pairs' greatest prior_share reads 0.060 against 0.080, both under PAIR_FROM_SINGLE; one point's two readings differ up to 4.3 times); the guard on a run seen end on (the reading is dropped either way).""" @@ -561,8 +560,8 @@ class FitTests(unittest.TestCase): def test_an_overdrawn_stroke_is_refused_naming_its_trace(self): """overdraw-refused, F1 and G6: the mirrored half's trace doubled back over part of itself 3% of its extent - off. All 27 are refused, naming the trace and the span that no built run draws; the least reads 7.83 px - against core.TOL, separation 1.57. F1 returns all 27 as fits, the worst 0.104 m off the truth. Asked with + off. All 27 are refused, naming the trace and the span that no built run draws; the least reads 7.70 px + against core.TOL, separation 1.48. F1 returns all 27 as fits, the worst 0.104 m off the truth. Asked with tol 1.1 times its own reading a stroke is accepted, and with tol that reading over 1.1 refused: tol is what the reading is held to (G6 holds it to 1.2 x tol).""" truth, document = blocked(0.2, 2.5, 0.05) @@ -586,11 +585,10 @@ class FitTests(unittest.TestCase): def test_hand_traces_are_explained_at_the_default(self): """G2: both halves traced by `hand` (wander 2 px, tips 6 px off), each of three views. All three are - accepted at core.TOL, reading 2.97 px at most (TOL over 1.68), while the worst point of a trace stands 6.94 - px off its run and, the tips left out, still 5.82 to 6.94: G2, which holds that point to TOL, refuses all - three. The fits end 20 to 64 mm off the true crease, up to 1.36 times TOL x the m_per_px they report: - m_per_px is what one pixel of error on a single point moves, and a wander that holds over 30 px moves - more.""" + accepted at core.TOL, reading 2.99 px at most (TOL over 1.74), while the worst point of each stands 6.08 to + 6.94 px off its run: G2, which holds that point to TOL, refuses all three. The fits end 20 to 64 mm off the + true crease, up to 1.3 times TOL x the m_per_px they report: m_per_px is a sensitivity, what one pixel of + error on a single point moves, and a wander that holds over 30 px moves more.""" truth, document = blocked(0.2, 2.5, 0.05) rng, most = np.random.default_rng(1), 0.0 for cam in fit_views(truth): @@ -600,10 +598,10 @@ class FitTests(unittest.TestCase): most = max(most, max(row["worst_px"] for row in out["traces"])) self.assertGreater(most, core.TOL * 1.2) - def test_a_clean_fit_is_within_its_own_reported_reach(self): - """accepted-bounded, on clean strokes only: strokes doubled back 0.2% off pass as explained, and each + def test_a_clean_fit_moves_less_than_its_reported_sensitivity(self): + """m_per_px as a sensitivity, on clean strokes only: strokes doubled back 0.2% off pass as explained, and each accepted fit stands within core.TOL x the worst m_per_px it reports of the truth: all 27 are accepted, the - worst 8.9 mm off, 0.161 of that reach. No mutant claims this bound, and hand traces pass it + worst 8.9 mm off, 0.16 of that. It is no error bound: no mutant claims it, and hand traces end past it (test_hand_traces_are_explained_at_the_default).""" truth, document = blocked(0.2, 2.5, 0.05) accepted, most = 0, 0.0 @@ -665,12 +663,12 @@ class FitTests(unittest.TestCase): def test_orchid_c09_hand_traces(self): """orchid-c09: the inboard edges of two petals traced by hand on one concept view, through a camera solved - from hand marks (13 px rms). At the default the pair is explained: its traces read 0.69 and 0.64 px (TOL - over 7.2), though the left trace's first 10 px stand up to 9.2 px off the built run, because the two + from hand marks (13 px rms). At the default the pair is explained: its traces read 0.80 and 0.68 px (TOL + over 6.5), though the left trace's first 10 px stand up to 9.2 px off the built run, because the two traces' tips are not one point and its mirror image through that camera; the gate on the worst point refused the pair for that. Its points read a prior_share of 0.018 at most; either trace alone reads 0.271 and up on every point: the bound is their geometric mean, separation 3.9 each side. The right trace - overdrawn 2% of its extent is refused nine ways of nine, reading 7.65 px and up.""" + overdrawn 2% of its extent is refused nine ways of nine, reading 7.27 px and up.""" left, right, side = self.orchid["left"], self.orchid["right"], self.orchid["left_side"] pair = self.orchid_fit([(side, left), (-side, right)]) self.assertLess(max(row["unexplained_px"] for row in pair["traces"]), core.TOL / 1.2)