brokkr_reference.block_plate: every crown point says what decided it by its prior share, seam corners and sides' inner points included; a seam corner whose view runs along x = 0 goes to the plane and its guard; the views start a corner by metres a pixel against the prior's scale (START), not by degrees; the skirt in shares of the crown's extent; tests/fixtures/spectre_truth.json, SPECTRE's pass-3 roof built, rendered and traced off the renders: 39.1 mm from the truth as traced, 3.5 x noise x the coarser view's pixel at 1 and 2 px; FAIR 0.2 read against known truth (cut trace-block, Soul s1)
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
parent
4779e6cc5c
commit
fcf09bfae2
3 changed files with 235 additions and 35 deletions
|
|
@ -748,9 +748,9 @@ def fit_sheet(document, cage, frame, traces, cams, share=0.1, tol=TOL):
|
|||
FAIR = 0.2 # a side's second differences of this share of its chord cost what one pixel of miss does (0.02 held a bowed side straight; docs/reference.md)
|
||||
K_MAX = 6 # points a side grows to before its trace is refused as fit_runs refuses it
|
||||
SQUARE = 0.4 # the cosine between a plane's normal and a sight line under which a trace is not lifted onto it: past 66 degrees the lift stretches over 2.5 times
|
||||
PARALLAX = 9.7 # degrees between a corner's widest pair of sight lines under which the views do not start it: the geometric mean of 19, where a plate blocks from its views, and 5, where its corners land 0.25 to 1.5 m off (tests/test_reference.py BlockTests)
|
||||
START = 1.0 # a corner's views start it where one pixel moves their meeting point less than this x share x the plate's extent, the prior's own scale: past it the views alone hold the corner looser than the plane would (tests/test_reference.py BlockTests reads 0.50 at 19 degrees and 1.90 at 5, Paladin's lens and range)
|
||||
VIEWS = 0.2 # a prior_share under this: the views decide the point (fit_shell's line)
|
||||
FLARE, DROP, DOME = 0.06, 0.07, 0.02 # metres: a plate's skirt out from and back of its crown, and its centre's rise
|
||||
FLARE, DROP, DOME = 0.05, 0.06, 0.017 # of the crown's extent (its two furthest points): a plate's skirt out from and back of its crown, and its centre's rise. A template's proportions, not readings: the crown is what is solved
|
||||
TRACE_KEYS = ("camera", "box", "frame", "from", "to", "side", "line")
|
||||
|
||||
|
||||
|
|
@ -810,7 +810,9 @@ def triangulate(obs, seam=False):
|
|||
def plate_sheet(crown, corners, flare=FLARE, drop=DROP, dome=DOME, mirror=False, seam=(), facing=None):
|
||||
"""The free-cage document of a plate whose raised outline is `crown`, a closed ring of points in the plate's
|
||||
frame: the crown ring (vertices 0 to n - 1, in the ring's order), a skirt ring `flare` out from it and `drop`
|
||||
back of it (the chamfered wall), and one centre vertex `dome` proud of the ring's middle. Every crown side is
|
||||
back of it (the chamfered wall), and one centre vertex `dome` proud of the ring's middle; the three are shares
|
||||
of the crown's extent, the distance between its two furthest points, so a plate of any size has the same
|
||||
proportions. Every crown side is
|
||||
creased 1; `corners` (ring indices) are pinned 1 on crown and skirt, so the crown between two corners is one
|
||||
hard run, and the points between them are free to round it. The centre is the cage's pole unless the ring has
|
||||
four points. `facing` is a direction the outer face looks along; the ring is taken as wound that way, or the
|
||||
|
|
@ -822,6 +824,8 @@ def plate_sheet(crown, corners, flare=FLARE, drop=DROP, dome=DOME, mirror=False,
|
|||
face of three points of x = 0 is its own reflection and the cage's parser refuses it."""
|
||||
P = np.asarray(crown, float)
|
||||
n, seam = len(P), set(seam) if mirror else set()
|
||||
extent = float(np.linalg.norm(P[:, None] - P[None], axis=2).max())
|
||||
flare, drop, dome = flare * extent, drop * extent, dome * extent
|
||||
Q = np.roll(P, -1, axis=0)
|
||||
normal = _unit(np.cross(P, Q).sum(0)) # Newell's: the ring's own facing, counter-clockwise seen from where it points
|
||||
flip = facing is not None and float(normal @ np.asarray(facing, float)) < 0
|
||||
|
|
@ -940,21 +944,32 @@ def block_plate(views, plate, traces, parse, plane=None, share=0.1, tol=TOL):
|
|||
if not per_side[i]:
|
||||
raise ReferenceFitError(f"the side from {name!r} to {names[(i + 1) % N]!r} is traced in no view: every side of the outline is traced, or the plate is given fewer corners")
|
||||
lines = sum(len(json.dumps(trace.get("line"), separators=(",", ":"))) for trace in traces)
|
||||
size = 44 * (2 * N * (K_MAX - 1) + 1) + 34 * N * (K_MAX - 1) + lines + 90 * len(traces) + 150 * N + 400
|
||||
size = 44 * (2 * N * (K_MAX - 1) + 1) + 34 * N * (K_MAX - 1) + 62 * N * (K_MAX - 2) + lines + 90 * len(traces) + 190 * N + 400
|
||||
if size > RESULT_LIMIT:
|
||||
raise ReferenceFitError(f"traces: the sheet and its report could be about {size} characters, over the {RESULT_LIMIT} a receipt carries: nothing was solved. "
|
||||
"Trace with fewer points, or block the plate as two")
|
||||
|
||||
start, parallax, decided = np.zeros((N, 3)), np.zeros(N), np.zeros(N, bool)
|
||||
start, parallax, decided, loose = np.zeros((N, 3)), np.zeros(N), np.zeros(N, bool), np.full(N, np.inf)
|
||||
obs = [[(cam, F, 1, np.mean(pixels, axis=0)) for cam, F, pixels, _ in seen_by[i].values()] for i in range(N)]
|
||||
for i in range(N):
|
||||
if i in held or len(obs[i]) >= 2:
|
||||
start[i], parallax[i], _, _ = triangulate(obs[i], seam=i in held)
|
||||
decided[i] = i in held or parallax[i] >= PARALLAX
|
||||
if len(obs[i]) >= 2:
|
||||
start[i], parallax[i], _, loose[i] = triangulate(obs[i], seam=i in held)
|
||||
met = np.isfinite(loose)
|
||||
if met.any(): # the plate's extent as its views draw it: the corners' pixels at the range of where the sight lines meet, which a depth error hardly moves
|
||||
middle, drawn = start[met].mean(0), {}
|
||||
for i in range(N):
|
||||
for view, (cam, F, pixels, _) in seen_by[i].items():
|
||||
drawn.setdefault(view, (cam, F, []))[2].append(np.mean(pixels, axis=0))
|
||||
extent = max(float(np.linalg.norm(np.ptp(pixels, axis=0))) * float(np.linalg.norm(_sight(cam, F, cam["c"])[0] - middle)) / cam["f"] for cam, F, pixels in drawn.values())
|
||||
decided = loose < START * share * extent
|
||||
for i in held: # x = 0 meets a sight line that crosses it; one that runs along it within what SQUARE allows a plane is no meeting
|
||||
if not decided[i] and max(abs(float(_sight(cam, F, np.mean(pixels, axis=0))[1][0])) for cam, F, pixels, _ in seen_by[i].values()) >= SQUARE:
|
||||
start[i], decided[i] = triangulate(obs[i], seam=True)[0], True
|
||||
if plane is None:
|
||||
if decided.sum() < 3:
|
||||
raise ReferenceFitError(f"plane: none was given, and {', '.join(repr(names[i]) for i in np.flatnonzero(~decided))} are seen by one view only (or by views under "
|
||||
f"{PARALLAX:g} degrees apart): three corners the views or the seam decide make the plane. Give plane, or trace those corners in another view")
|
||||
raise ReferenceFitError(f"plane: none was given, and {', '.join(repr(names[i]) for i in np.flatnonzero(~decided))} are decided by no view (seen by one only, by views so close that a pixel "
|
||||
f"moves where they meet over {START * share:g} of the plate's extent, or on the seam by a view that runs along x = 0): three corners the views or the seam "
|
||||
"decide make the plane. Give plane, or trace those corners in another view")
|
||||
point = start[decided].mean(0)
|
||||
_, spread, axes = np.linalg.svd(start[decided] - point)
|
||||
if spread[1] < 1e-6 * max(spread[0], 1e-12):
|
||||
|
|
@ -979,6 +994,8 @@ def block_plate(views, plate, traces, parse, plane=None, share=0.1, tol=TOL):
|
|||
f"only depth this corner has. A trace lifted onto it stretches past {1 / SQUARE:g} times: turn plane to the face the view shows, or trace the corner in another view")
|
||||
lifted.append(o + d * (((point - o) @ normal) / (d @ normal)))
|
||||
start[i] = np.mean(lifted, axis=0)
|
||||
if i in held:
|
||||
start[i, 0] = 0.0
|
||||
free_ = [i for i in range(N) if i not in held]
|
||||
|
||||
def crossed(corners_, what):
|
||||
|
|
@ -1058,12 +1075,22 @@ def block_plate(views, plate, traces, parse, plane=None, share=0.1, tol=TOL):
|
|||
document = build(crown)
|
||||
parsed(document)
|
||||
by_vertex = {row_["vertex"]: row_ for row_ in report["points"]}
|
||||
|
||||
def decided_at(v):
|
||||
"""What decided a crown point's depth, by its prior share: the prior (the plane, and a side's fairness) from VIEWS up, whatever the point is."""
|
||||
row_ = by_vertex[v]
|
||||
return {"decided_by": "plane" if row_["prior_share"] >= VIEWS else "mirror" if v in on_seam else "views", "m_per_px": round(row_["m_per_px"], 4), "prior_share": round(row_["prior_share"], 3)}
|
||||
|
||||
corners = []
|
||||
for i, name in enumerate(names):
|
||||
row_ = by_vertex[int(first[i])]
|
||||
corners.append({"name": name, "decided_by": "mirror" if i in held else "views" if row_["prior_share"] < VIEWS else "plane", "parallax_deg": round(float(parallax[i]), 1),
|
||||
"m_per_px": round(row_["m_per_px"], 4), "prior_share": round(row_["prior_share"], 3)})
|
||||
sides = [{"from": names[i], "to": names[(i + 1) % N], "points": count[i], "traces": [report["traces"][k] for k in per_side[i]]} for i in range(N)]
|
||||
said = decided_at(int(first[i]))
|
||||
corners.append({"name": name, "decided_by": said["decided_by"], "parallax_deg": round(float(parallax[i]), 1), "m_per_px": said["m_per_px"], "prior_share": said["prior_share"]})
|
||||
sides = []
|
||||
for i in range(N):
|
||||
inner = [decided_at(v) for v in chains[i][1:-1]]
|
||||
sides.append({"from": names[i], "to": names[(i + 1) % N], "points": count[i], "inner": inner,
|
||||
"decided_by": "corners" if not inner else "plane" if any(point["decided_by"] == "plane" for point in inner) else inner[0]["decided_by"],
|
||||
"traces": [report["traces"][k] for k in per_side[i]]})
|
||||
fit_traces, left_out = [], []
|
||||
for k, (trace, (i, forward)) in enumerate(zip(traces, runs_of)):
|
||||
if (trace.get("side", 1) == -1 and not mirror) or trace.get("frame") is not None:
|
||||
|
|
|
|||
1
surfaces/blender/tests/fixtures/spectre_truth.json
vendored
Normal file
1
surfaces/blender/tests/fixtures/spectre_truth.json
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
{"note":"SPECTRE's roof (spectre_cages.roof at nibu/fable-spectre-3 14d834c: a hard mirrored cage of 11 vertices) built by brokkr_kitbash.shell at one level with the hull's jaw, flank and cheeks (thickness 0.1, bevel 0.016), rendered by Blender 5.3's Workbench through spectre_skel.cameras() at the sheet's own pixel size (hero 756 x 706, side 264 x 348), the hull posed per view by frames. truth is the cage: Blender built each of its vertices within built_off_m of it (the bevel). strokes are the roof's edges traced from the two renders, not projected: along each edge the drawn edge is the strongest brightness step within 2.5 px across it, a straight stroke is laid through the steps found on each segment, and strokes meet where they cross. drawn is the least share of a segment's length where a step was found, off_projection_px how far the stroke's points stand from the truth's projection. The ridge is traced in the side view only: the hero draws no step along it (its two facets shade alike). closing marks the strokes an agent closes the outline with (the rear edge, and the lip in the side view, half drawn).","cameras":{"hero":{"C":[-9.721115556958573,18.859090658741355,5.242272804029844],"R":[[-0.862189601405842,-0.5065857195259607,0.0],[0.034125232508362004,-0.05807984607580026,0.9977285201827507],[-0.5054350202883507,0.8602311551276064,0.06736319480204615]],"f":1785.0,"c":[378.0,353.0]},"side":{"C":[60.84416742645475,1.422308134553987,3.13474760877321],"R":[[3.061616997868383e-16,1.0,0.0],[0.011634411213376642,-3.5620111131064444e-18,0.9999323179474289],[0.9999323179474289,-3.0614097813457806e-16,-0.011634411213376642]],"f":2200.0,"c":[892.0,532.0]}},"frames":{"hero":[[1.0,0.0,0.0,0.0],[0.0,0.9986295347545738,0.052335956242943835,-0.2773805680876023],[0.0,-0.052335956242943835,0.9986295347545738,0.007263465800758873],[0.0,0.0,0.0,1.0]],"side":[[1.0,0.0,0.0,0.0],[0.0,1.0,0.0,0.0],[0.0,-0.0,1.0,0.0],[0.0,0.0,0.0,1.0]]},"plates":{"roof":{"loop":["ridge_rear","r4","r3","r2","r1","nose","a","b","c","d","e"],"seam":["ridge_rear","r4","r3","r2","r1","nose"],"truth":{"nose":[0.0,3.33,6.34],"r1":[0.0,2.82,6.735],"r2":[0.0,1.76,7.05],"r3":[0.0,1.0,7.5],"r4":[0.0,-0.8,7.8],"ridge_rear":[0.0,-1.9,7.95],"a":[0.77,2.57,6.475],"b":[0.6,1.9,6.83],"c":[0.69,1.0,7.34],"d":[0.64,-0.8,7.65],"e":[0.62,-1.9,7.8]},"built_off_m":0.0151,"strokes":[{"view":"side","side":1,"through":["ridge_rear","r4","r3","r2","r1","nose"],"line":[[772.01,383.39],[811.74,388.89],[876.96,399.88],[904.51,416.13],[941.84,427.31],[961.08,441.58]],"closing":false,"drawn":1.0,"off_projection_px":0.69},{"view":"hero","side":-1,"through":["nose","a"],"line":[[325.08,142.53],[427.02,126.4]],"closing":false,"drawn":1.0,"off_projection_px":0.86},{"view":"side","side":1,"through":["nose","a"],"line":[[961.51,439.35],[933.43,437.76]],"closing":true,"drawn":0.53,"off_projection_px":2.49},{"view":"hero","side":-1,"through":["a","b","c","d","e"],"line":[[426.46,125.71],[442.01,93.62],[487.59,47.65],[551.9,26.85],[587.64,18.75]],"closing":false,"drawn":0.71,"off_projection_px":0.98},{"view":"side","side":1,"through":["a","b","c","d","e"],"line":[[933.68,435.98],[908.72,424.05],[876.26,405.25],[810.61,394.34],[770.7,387.55]],"closing":false,"drawn":0.76,"off_projection_px":1.64},{"view":"hero","side":-1,"through":["e","ridge_rear"],"line":[[587.54,18.26],[541.95,9.26]],"closing":true,"drawn":1.0,"off_projection_px":0.09},{"view":"side","side":1,"through":["e","ridge_rear"],"line":[[769.96,387.04],[772.42,383.77]],"closing":true,"drawn":1.0,"off_projection_px":0.82}]}}}
|
||||
|
|
@ -778,34 +778,71 @@ def blocked_plate(views, traces, **more):
|
|||
return core.block_plate(views, {"corners": PLATE}, traces, kit.sheet, **more)
|
||||
|
||||
|
||||
def rendered(name, corners, sigma=0.0, close=0.0, seed=0):
|
||||
"""(views, plate, traces, the true sides, the fixture's plate) of a plate of tests/fixtures/spectre_truth.json
|
||||
with `corners` of its loop named: each stroke traced from the renders is cut at the named corners it passes
|
||||
through, every point `sigma` px off, a closing stroke moved `close` px as one."""
|
||||
fixture = json.loads((Path(__file__).resolve().parent / "fixtures" / "spectre_truth.json").read_text(encoding="utf-8"))
|
||||
plate, rng, views, traces = fixture["plates"][name], np.random.default_rng(seed), [], []
|
||||
for stroke in plate["strokes"]:
|
||||
line = np.array(stroke["line"]) + (rng.normal(0, sigma, (len(stroke["line"]), 2)) if sigma else 0.0)
|
||||
if stroke["closing"] and close:
|
||||
turn = rng.uniform(0, 2 * math.pi)
|
||||
line = line + close * np.array([math.cos(turn), math.sin(turn)])
|
||||
cuts = [k for k, corner in enumerate(stroke["through"]) if corner in corners]
|
||||
for a, b in zip(cuts, cuts[1:]):
|
||||
traces.append({"camera": stroke["view"], "from": stroke["through"][a], "to": stroke["through"][b], "side": stroke["side"], "line": line[a:b + 1].tolist(),
|
||||
**({"frame": fixture["frames"]["hero"]} if stroke["view"] == "hero" else {})})
|
||||
views.append((fixture["cameras"][stroke["view"]], fixture["frames"][stroke["view"]]))
|
||||
loop, named = plate["loop"], [corner for corner in plate["loop"] if corner in corners]
|
||||
sides = []
|
||||
for i, corner in enumerate(named):
|
||||
a, b = loop.index(corner), loop.index(named[(i + 1) % len(named)])
|
||||
sides.append(np.array([plate["truth"][loop[k % len(loop)]] for k in range(a, (b if b > a else b + len(loop)) + 1)]))
|
||||
return views, {"corners": named, "mirror": True, "seam": [corner for corner in plate["seam"] if corner in corners]}, traces, sides, (fixture, plate)
|
||||
|
||||
|
||||
def off_rendered(out, sides):
|
||||
"""(the furthest a blocked corner stands from its own, the furthest a side as built and its true edge, a polyline
|
||||
through the truth's corners, stand apart either way), metres."""
|
||||
verts, chains = np.array(out["sheet"]["verts"]), crown_chains(out)
|
||||
edge = 0.0
|
||||
for chain, side in zip(chains, sides):
|
||||
built = core.crease_run(core.crease_run(verts[chain]))
|
||||
edge = max(edge, float(core._off(built, side).max()), float(core._off(core.resampled(side, 300), built).max()))
|
||||
return max(float(np.linalg.norm(verts[chain[0]] - side[0])) for chain, side in zip(chains, sides)), edge
|
||||
|
||||
|
||||
@unittest.skipIf(np is None, "numpy")
|
||||
class BlockTests(unittest.TestCase):
|
||||
"""block_plate: a plate's first cage from traces of its outline. Bounds follow
|
||||
lodur:ruling:deterministic-bound-margin; the other numbers are tolerances round a known truth. Mutants, each
|
||||
run once on a copy:
|
||||
M1 no end terms test_spectre_roof_and_cheek
|
||||
M2 a point prior (fit_shell's) for the plane distance test_one_view_and_a_plane_block_a_bowed_plate
|
||||
M3 a seam corner's x free test_spectre_roof_and_cheek
|
||||
M5 the 66 degree guard off test_a_plane_far_off_square_on_to_its_one_view_is_refused
|
||||
M2 a point prior (fit_shell's) for the plane distance test_one_view_and_a_plane_block_a_bowed_plate, test_fairness_is_set_by_the_rendered_roof
|
||||
M3 a seam corner's x free test_spectre_roof_and_cheek, test_the_rendered_roof_blocks_from_traces_of_its_renders
|
||||
M4 no fairness test_fairness_is_set_by_the_rendered_roof
|
||||
M5 the 66 degree guard off test_a_plane_far_off_square_on_to_its_one_view_is_refused, test_a_seam_corner_says_what_decided_it
|
||||
M6 no growth (K_MAX 2) test_a_side_grows_until_its_trace_is_explained, test_spectre_roof_and_cheek
|
||||
M4 no fairness test_spectre_roof_and_cheek
|
||||
F5 FAIR 0.5, F05 FAIR 0.05 test_fairness_is_set_by_the_rendered_roof; test_a_side_grows_until_its_trace_is_explained
|
||||
S1 a seam point labelled mirror whatever its share test_a_seam_corner_says_what_decided_it
|
||||
S2 a seam corner never sent to the plane's guard test_a_seam_corner_says_what_decided_it
|
||||
I1 a side's label from its first point only, never plane test_a_side_says_what_decided_its_inner_points
|
||||
T06 START 0.6, T3 START 3.3 test_views_5_degrees_apart_take_their_depth_from_a_plane_or_are_refused
|
||||
K1 a skirt of fixed metres test_a_plate_keeps_its_proportions_at_any_size
|
||||
|
||||
M4 is claimed by one reading, SPECTRE's brow (a median of 8.4 mm with fairness, 19.8 without), against a
|
||||
reference that is itself a fit. Against a known truth it reads the other way: the bowed plate of
|
||||
test_a_side_grows_until_its_trace_is_explained ends 41.6 mm off with fairness and 12.1 without, the one-view
|
||||
bowed plate 85.1 mm with it and 2.7 without, the twisted plate at 19 degrees and 1.5 px 135.1 either way. FAIR
|
||||
0.2 came from five-point chains under noise (research probe-synthetic-sensitivity); a side grown only as far
|
||||
as its trace asks has less for fairness to hold.
|
||||
|
||||
The twisted, bowed plate does not block within 1.35 x noise x m_per_px, the probe's figure for five-point
|
||||
chains: its bow toward the first camera is 56 mm, under 2 px at 60 degrees, the default tol explains it with a
|
||||
straight side, and what is left is the bow (test_a_twisted_bowed_plate_blocks_from_two_views)."""
|
||||
What the blocking is worth against a known truth is test_the_rendered_roof_blocks_from_traces_of_its_renders:
|
||||
a built plate, rendered, its edges traced off the renders. test_spectre_roof_and_cheek and
|
||||
test_paladin_plates_one_view_each read agreement with another fit and with a harness's lift on the same
|
||||
pixels, not accuracy."""
|
||||
|
||||
def test_a_twisted_bowed_plate_blocks_from_two_views(self):
|
||||
"""block-synthetic. Views 60 and 19 degrees apart, traces 0.5 and 1.5 px off: every trace is explained with
|
||||
two points a side, and the crown as built ends 39.3, 52.1 (60 degrees) and 65.0, 135.1 mm (19) from the
|
||||
truth, 1.46 to 4.23 times noise x the worst corner's m_per_px. At 60 degrees every corner is decided by the
|
||||
views (prior_share 0.138 at most, under core.VIEWS by 1.45); at 19 the plane has 0.30 to 0.38 of each."""
|
||||
truth: the 56 mm bow toward the first camera reads under 2 px, the default tol explains it with a straight
|
||||
side, and the bow is the error. At 60 degrees every corner is decided by the views (prior_share 0.138 at
|
||||
most, under core.VIEWS by 1.45); at 19 the plane has 0.30 to 0.38 of each. A side of two points has no
|
||||
point of its own: it says corners."""
|
||||
sides = pentagon(0.08)
|
||||
for apart, sigma, most, by in ((60, 0.5, 0.06, "views"), (60, 1.5, 0.08, "views"), (19, 0.5, 0.1, "plane"), (19, 1.5, 0.2, "plane")):
|
||||
out = blocked_plate(*plate_traces([plate_camera(0), plate_camera(apart)], sides, sigma))
|
||||
|
|
@ -813,19 +850,29 @@ class BlockTests(unittest.TestCase):
|
|||
self.assertEqual({corner["decided_by"] for corner in out["corners"]}, {by}, (apart, sigma))
|
||||
self.assertLess(max(abs(corner["parallax_deg"] - apart) for corner in out["corners"]), 1.5)
|
||||
self.assertEqual(out["plane"]["from"], "corners")
|
||||
self.assertEqual([(side["decided_by"], side["inner"]) for side in out["sides"]], [("corners", [])] * 5)
|
||||
kit.sheet(out["sheet"])
|
||||
|
||||
def test_views_5_degrees_apart_take_their_depth_from_a_plane_or_are_refused(self):
|
||||
"""block-low-parallax. At 5 degrees the corners triangulate 0.25 to 1.5 m off (the probe): under
|
||||
core.PARALLAX the views start no corner. With a plane every corner is decided by it (prior_share 0.795 to
|
||||
0.838); with none the plate is refused naming the corners."""
|
||||
"""block-low-parallax, T06, T3. The views start a corner where one pixel moves their meeting point less than
|
||||
core.START x share x the plate's extent, the prior's own scale. At Paladin's lens and range that reads 0.74
|
||||
of the scale at 19 degrees (test_a_twisted_bowed_plate_blocks_from_two_views blocks there; T06 refuses it)
|
||||
and 2.77 at 5, where the corners triangulate 0.25 to 1.5 m off: no corner is started. With a plane every
|
||||
corner is decided by it (prior_share 0.795 to 0.838); with none the plate is refused naming the corners (T3
|
||||
blocks it). The line is metres a pixel, not degrees: through a lens three times as long the same plate 7
|
||||
degrees apart reads 0.66 and blocks from its views, 60.5 mm from the truth (65.0 at 19 degrees through the
|
||||
short lens)."""
|
||||
views, traces = plate_traces([plate_camera(0), plate_camera(5)], pentagon(0.08), 0.5)
|
||||
out = blocked_plate(views, traces, plane=ON_Y)
|
||||
self.assertEqual([corner["decided_by"] for corner in out["corners"]], ["plane"] * 5)
|
||||
self.assertGreater(min(corner["prior_share"] for corner in out["corners"]), 0.7)
|
||||
self.assertEqual(out["plane"]["from"], "given")
|
||||
with self.assertRaisesRegex(core.ReferenceFitError, r"^plane: none was given, and 'c0', 'c1', 'c2', 'c3', 'c4' are seen by one view only"):
|
||||
with self.assertRaisesRegex(core.ReferenceFitError, r"^plane: none was given, and 'c0', 'c1', 'c2', 'c3', 'c4' are decided by no view"):
|
||||
blocked_plate(views, traces)
|
||||
sides = pentagon(0.08)
|
||||
out = blocked_plate(*plate_traces([plate_camera(0, f=1989.0), plate_camera(7, f=1989.0)], sides, 0.5))
|
||||
self.assertEqual(out["plane"]["from"], "corners")
|
||||
self.assertLess(off_plate(out, sides), 0.1)
|
||||
|
||||
def test_a_side_grows_until_its_trace_is_explained(self):
|
||||
"""block-growth, M6. A straight-sided plate blocks with its corners alone, 1.9 mm from the truth (the plane
|
||||
|
|
@ -842,6 +889,66 @@ class BlockTests(unittest.TestCase):
|
|||
self.assertLess(max(trace["unexplained_px"] for side in out["sides"] for trace in side["traces"]), core.TOL / 1.2)
|
||||
self.assertLess(off_plate(out, sides), 0.06)
|
||||
|
||||
def test_a_side_says_what_decided_its_inner_points(self):
|
||||
"""interior-points (Soul s1), I1. The bowed pentagon from exact traces 60 degrees apart, asked at tol 0.1:
|
||||
the sides grow to 4, 4, 4, 3, 4 points and every trace reads under 0.12 px, every corner is decided by the
|
||||
views, and the side from c3 still ends 52.8 mm off the truth (the others 2.4 to 7.4). Its one inner point
|
||||
has prior_share 0.405, twice core.VIEWS: the side says plane, and its inner point says why. A side whose
|
||||
trace is explained is not thereby a side the views decided."""
|
||||
sides = pentagon(0.08)
|
||||
out = blocked_plate(*plate_traces([plate_camera(0), plate_camera(60)], sides), tol=0.1)
|
||||
self.assertEqual([side["points"] for side in out["sides"]], [4, 4, 4, 3, 4])
|
||||
self.assertEqual([len(side["inner"]) for side in out["sides"]], [2, 2, 2, 1, 2])
|
||||
self.assertEqual({corner["decided_by"] for corner in out["corners"]}, {"views"})
|
||||
self.assertLess(max(trace["unexplained_px"] for side in out["sides"] for trace in side["traces"]), 0.12)
|
||||
off = [float(off_run(out, chain, side).max()) for chain, side in zip(crown_chains(out), sides)]
|
||||
self.assertEqual(int(np.argmax(off)), 3)
|
||||
self.assertEqual((out["sides"][3]["decided_by"], out["sides"][3]["inner"][0]["decided_by"]), ("plane", "plane"))
|
||||
self.assertGreater(out["sides"][3]["inner"][0]["prior_share"], 1.2 * core.VIEWS)
|
||||
self.assertEqual(set(out["sides"][3]["inner"][0]), {"decided_by", "m_per_px", "prior_share"})
|
||||
|
||||
def test_a_seam_corner_says_what_decided_it(self):
|
||||
"""seam-corner-grazing (Soul s1), S1, S2, M5. A mirrored plate, its seam a to b on x = 0, traced in one view
|
||||
0.5 px off with the plane y = 0.05 given. From 60 degrees off the mirror plane the seam's corners are
|
||||
decided by it (prior_share 0.135 and 0.117, under core.VIEWS by 1.48; 7 mm off). From 10 degrees the sight
|
||||
lines run along x = 0: the seam's corners are lifted onto the plane as any corner one view sees, and read
|
||||
plane (0.571 and 0.513; 33 mm off): S1 reads them mirror. With a plane the view also runs along (its
|
||||
normal 73 degrees off x) there is no depth at all, and the plate is refused naming the seam's corner: S2
|
||||
and M5 block it."""
|
||||
P, names = np.array([[0, 0, 0.6], [0, 0, -0.6], [0.5, 0.1, -0.5], [0.45, 0.1, 0.5]]), ["a", "b", "c", "d"]
|
||||
|
||||
def block(azimuth, normal):
|
||||
rng, cam, traces = np.random.default_rng(1), plate_camera(azimuth), []
|
||||
for i in range(4):
|
||||
u = core.project(cam, P[[i, (i + 1) % 4]])
|
||||
traces.append({"from": names[i], "to": names[(i + 1) % 4], "side": 1, "line": (np.linspace(u[0], u[1], 6) + rng.normal(0, 0.5, (6, 2))).tolist()})
|
||||
return core.block_plate([(cam, EYE)] * 4, {"corners": names, "mirror": True, "seam": ["a", "b"]}, traces, kit.sheet, plane={"point": [0, 0.05, 0], "normal": normal})
|
||||
|
||||
out = block(60, [0, 1, 0])
|
||||
self.assertEqual([corner["decided_by"] for corner in out["corners"]], ["mirror", "mirror", "plane", "plane"])
|
||||
self.assertLess(max(corner["prior_share"] for corner in out["corners"][:2]), core.VIEWS / 1.2)
|
||||
self.assertLess(max(float(np.linalg.norm(np.array(out["sheet"]["verts"])[k] - P[k])) for k in (0, 1)), 0.012)
|
||||
out = block(10, [0, 1, 0])
|
||||
self.assertEqual([corner["decided_by"] for corner in out["corners"]], ["plane"] * 4)
|
||||
self.assertGreater(min(corner["prior_share"] for corner in out["corners"][:2]), 1.2 * core.VIEWS)
|
||||
self.assertEqual([float(x) for x in np.array(out["sheet"]["verts"])[:2, 0]], [0.0, 0.0])
|
||||
with self.assertRaisesRegex(core.ReferenceFitError, r"^plate\.corners\[0\] 'a': the plane stands 83 degrees off square-on to the view of traces\[0\]"):
|
||||
block(10, [1, 0.3, 0])
|
||||
|
||||
def test_a_plate_keeps_its_proportions_at_any_size(self):
|
||||
"""plate-template (Soul s1), K1. The pentagon at 0.1, 1 and 10 times its size through cameras as many times
|
||||
as far: the skirt stands 0.078 of the crown's extent from the crown and the centre 0.017 of it proud at
|
||||
every size, where a skirt of fixed metres stood 0.81 of a 0.11 m plate's extent out and 0.008 of an 11 m
|
||||
one's. The crown blocks within a ten-thousandth of the extent at each."""
|
||||
for scale in (0.1, 1.0, 10.0):
|
||||
sides = [side * scale for side in pentagon(0.0, twist=0.0)]
|
||||
out = blocked_plate(*plate_traces([plate_camera(0, distance=17.6 * scale), plate_camera(60, distance=17.6 * scale)], sides))
|
||||
verts = np.array(out["sheet"]["verts"])
|
||||
extent = float(np.linalg.norm(verts[:5, None] - verts[None, :5], axis=2).max())
|
||||
self.assertAlmostEqual(float(np.linalg.norm(verts[5:10] - verts[:5], axis=1).mean()) / extent, math.hypot(core.FLARE, core.DROP), places=4)
|
||||
self.assertAlmostEqual(float(np.linalg.norm(verts[10] - verts[:5].mean(0))) / extent, core.DOME, places=4)
|
||||
self.assertLess(off_plate(out, sides), 1e-4 * extent)
|
||||
|
||||
def test_one_view_and_a_plane_block_a_bowed_plate(self):
|
||||
"""M2. A flat plate in the plane it is given, its sides bowed 35% in the plate, traced exactly in one view
|
||||
30 degrees off square-on: every corner is decided by the plane, the sides grow to three points and the
|
||||
|
|
@ -900,6 +1007,71 @@ class BlockTests(unittest.TestCase):
|
|||
self.assertEqual(out["sheet"]["mirror"], True)
|
||||
self.assertEqual(out["sheet"]["poles"], [seam[0], seam[1], len(out["sheet"]["verts"]) - 1])
|
||||
|
||||
def test_the_rendered_roof_blocks_from_traces_of_its_renders(self):
|
||||
"""block-truth (Soul s1, real-readings-not-accuracy), M3. SPECTRE's pass-3 roof, a hard mirrored cage of 11
|
||||
known vertices, built by brokkr_kitbash.shell, rendered through SPECTRE's two solved cameras at the
|
||||
sheet's pixel size and its edges traced off the renders (tests/fixtures/spectre_truth.json says how). The
|
||||
ridge is traced in the side view alone, the lip, the outer edge and the rear edge in the hero's mirrored
|
||||
half and in the side view, 62 degrees apart; the side view's pixel is 27.6 mm across at the plate, the
|
||||
hero's 11.6.
|
||||
|
||||
Every corner named: the ridge's six are decided by the mirror plane, the outer edge's five by the views
|
||||
(prior_share 0.038 at most). From the traces as taken the worst corner stands 39.1 mm from the truth, 1.42
|
||||
of the side view's pixels (Blender builds the cage's vertices up to 15.1 mm inside it, the bevel; a
|
||||
stroke stands up to 2.5 px from the truth's projection). With every traced point 1 px off, twelve draws:
|
||||
68.6 mm at the median, 96.1 at most; 2 px: 125.1 and 190.1. That is 3.5 x the noise x the coarser view's
|
||||
pixel, and the bounds are tolerances 1.2 over it: no mutant is claimed by a margin here (M1 reads 49.3,
|
||||
116.6 and 206.5, under 1.3 away). M3 lands the ridge off x = 0 and is refused. The same readings are 4.6
|
||||
to 7.5 x noise x a view-decided corner's m_per_px, and a seam corner's m_per_px (0.0008) says nothing of
|
||||
its 98 mm: m_per_px is a depth sensitivity, and most of this error lies across the sight line."""
|
||||
corners = ["ridge_rear", "r4", "r3", "r2", "r1", "nose", "a", "b", "c", "d", "e"]
|
||||
views, plate, traces, sides, (fixture, record) = rendered("roof", corners)
|
||||
middle = np.mean(list(record["truth"].values()), axis=0)
|
||||
pixel = max(float(np.linalg.norm(np.array(cam["C"]) - middle)) / cam["f"] for cam in fixture["cameras"].values())
|
||||
self.assertAlmostEqual(pixel, 0.0276, places=4)
|
||||
out = core.block_plate(views, plate, traces, kit.sheet)
|
||||
self.assertEqual([corner["decided_by"] for corner in out["corners"]], ["mirror"] * 6 + ["views"] * 5)
|
||||
self.assertLess(max(corner["prior_share"] for corner in out["corners"]), core.VIEWS / 1.2)
|
||||
self.assertGreater(min(corner["parallax_deg"] for corner in out["corners"][6:]), 59)
|
||||
self.assertEqual([side["points"] for side in out["sides"]], [2] * 11)
|
||||
self.assertEqual(float(np.abs(np.array(out["sheet"]["verts"])[:6, 0]).max()), 0.0)
|
||||
self.assertLess(off_rendered(out, sides)[0], 1.7 * pixel)
|
||||
for sigma in (1.0, 2.0):
|
||||
worst = []
|
||||
for seed in range(12):
|
||||
views, plate, traces, sides, _ = rendered("roof", corners, sigma, seed=seed)
|
||||
worst.append(off_rendered(core.block_plate(views, plate, traces, kit.sheet), sides)[0])
|
||||
self.assertLess(max(worst), 4.2 * sigma * pixel, sigma)
|
||||
self.assertLess(float(np.median(worst)), 2.8 * sigma * pixel, sigma)
|
||||
|
||||
def test_fairness_is_set_by_the_rendered_roof(self):
|
||||
"""fair (Soul s1, fair-default-tuned-to-a-fit), F5, M4, M2. The rendered roof with four corners named
|
||||
(ridge_rear, nose, a, e), so the ridge and the outer edge are one side each and grow through their knees:
|
||||
from the traces as taken they grow to three points and stand 196.0 mm from the true edges at most, the
|
||||
hard knees cut by a run that reads as explained within tol (5.2 px is 144 mm in the side view). With every
|
||||
point 2 px off and the closing strokes moved 3 px, 24 draws: 15 block, and nine tenths of those stand
|
||||
within 196.9 mm. FAIR 0.5 reads 369.5 there, no fairness 394.0, M2 388.8: the bound is the geometric mean
|
||||
of 196.9 and 369.5, separation 1.37 each side. Over ten cells of known truth at 1 and 2 px (this roof four
|
||||
ways, and the bowed pentagon at 60 and 30 degrees and in one view) the mean of the cells' 90th percentiles
|
||||
reads 194, 184, 178, 178, 179, 186, 193, 196 mm at FAIR 0.1, 0.15, 0.2, 0.25, 0.3, 0.4, 0.5, 1 and the
|
||||
worst draw 301, 275, 273, 272, 312, 382, 494, 577: 0.2 stands at the low of both. From exact traces weaker
|
||||
fairness is nearer the truth (the bowed pentagon: 41.6 mm at 0.2, 16.2 at 0.5, 12.1 with none); nobody
|
||||
traces exactly, and at 1 px the difference is 16 mm at 60 degrees and the other way at 30."""
|
||||
corners = ["ridge_rear", "nose", "a", "e"]
|
||||
views, plate, traces, sides, _ = rendered("roof", corners)
|
||||
out = core.block_plate(views, plate, traces, kit.sheet)
|
||||
self.assertEqual([side["points"] for side in out["sides"]], [3, 2, 3, 2])
|
||||
self.assertLess(off_rendered(out, sides)[1], 0.235)
|
||||
edges = []
|
||||
for seed in range(24):
|
||||
views, plate, traces, sides, _ = rendered("roof", corners, 2.0, 3.0, seed)
|
||||
try:
|
||||
edges.append(off_rendered(core.block_plate(views, plate, traces, kit.sheet), sides)[1])
|
||||
except core.ReferenceFitError:
|
||||
pass
|
||||
self.assertGreaterEqual(len(edges), 12)
|
||||
self.assertLess(sorted(edges)[math.ceil(0.9 * len(edges)) - 1], 0.270)
|
||||
|
||||
def test_paladin_plates_one_view_each(self):
|
||||
"""block-paladin (tests/fixtures/paladin_plates.json). Paladin's 16 traced plates, each a polygon traced in
|
||||
one view with the plane the agent gave it: every corner is decided by the plane (prior_share 1.00 to 2.13:
|
||||
|
|
|
|||
Loading…
Reference in a new issue