diff --git a/surfaces/blender/brokkr_reference/__init__.py b/surfaces/blender/brokkr_reference/__init__.py index d106882..7a3b619 100644 --- a/surfaces/blender/brokkr_reference/__init__.py +++ b/surfaces/blender/brokkr_reference/__init__.py @@ -14,6 +14,8 @@ cameras, scores and a fitted sheet. The edges flow_score reads are computed on e fit_shell reads a shell's request through brokkr_kitbash (the sheet's one parser) and returns a sheet; it writes nothing. brokkr_kitbash.shell is the cage's one writer: the caller applies the fitted sheet with it. +block_plate returns a plate's first sheet from traces of its outline, checked by the same parser, and the traces as +fit_shell takes them; it writes nothing either. """ bl_info = {"name": "Brokkr Reference", "author": "GameCult", "version": (0, 1, 0), "blender": (4, 2, 0), "category": "Camera", "description": "Solve a reference view's camera from marked points; agent-callable through Brokkr."} @@ -263,7 +265,63 @@ class BROKKR_REFERENCE_OT_fit_shell(PolishOperator): return {"object": obj.name, **out, "seconds": round(time.perf_counter() - started, 3)} -classes = (BROKKR_REFERENCE_OT_solve_camera, BROKKR_REFERENCE_OT_flow_score, BROKKR_REFERENCE_OT_fit_shell) +class BROKKR_REFERENCE_OT_block_plate(PolishOperator): + """Block a plate's first free cage from traces of its outline through solved cameras, each trace naming the two + corners it runs between, and say what decided each corner's depth; nothing is written""" + bl_idname = "brokkr_reference.block_plate" + bl_label = "Block Plate From Traces" + frame_object: bpy.props.StringProperty(name="Frame", maxlen=63, description="An empty or object, unscaled, whose place in the world is the plate's frame") + plate: bpy.props.StringProperty(name="Plate", maxlen=2000, description="JSON {corners: [names in the outline's order], mirror, seam: [corners on x = 0]}") + traces: bpy.props.StringProperty(name="Traces", maxlen=12000, description="A JSON array of {camera, box, frame, from, to, side, line: [[u, v], ...]}") + plane: bpy.props.StringProperty(name="Plane", maxlen=200, description="'' for the plane through the corners the views decide, or 'x,y,z; nx,ny,nz' in the frame") + share: bpy.props.FloatProperty(name="Share", default=0.1, min=0.0009, max=10.0, description="A crown point this share of the plate's extent off the plane 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 must lie this near its built side, or the side gains a point") + + def work(self, context): + try: + import brokkr_kitbash + except ImportError as error: + raise Refused(f"block_plate needs the brokkr_kitbash add-on beside this one ({error}).") from None + obj = bpy.data.objects.get(self.frame_object) + if obj is None or obj.name not in context.scene.objects: + raise Refused(f"frame_object {self.frame_object!r} is not an object of this scene.") + if max(abs(v - 1.0) for v in obj.matrix_world.to_scale()) > 1e-6: + raise Refused(f"frame_object {obj.name!r} is scaled {tuple(round(v, 6) for v in obj.matrix_world.to_scale())}: a plate is in metres of its frame. Apply or clear the scale.") + try: + plate, traces = json.loads(self.plate), json.loads(self.traces) + except ValueError as error: + raise Refused(f"plate and traces must be JSON ({error}).") from None + if not isinstance(traces, list) or not all(isinstance(trace, dict) for trace in traces): + raise Refused("traces must be a JSON array of objects {camera, box, frame, from, to, side, line}.") + plane = None + if self.plane.strip(): + halves = self.plane.split(";") + try: + if len(halves) != 2: + raise core.ReferenceFitError(f"plane {self.plane.strip()!r} is not 'x,y,z; nx,ny,nz'") + plane = {"point": core.numbers(halves[0], 3, "plane's point"), "normal": core.numbers(halves[1], 3, "plane's normal")} + except core.ReferenceFitError as refusal: + raise Refused(f"{refusal}.") from None + own, views = [list(row) for row in obj.matrix_world], [] + for k, trace in enumerate(traces): + box = trace.get("box") + if box is not None and not (isinstance(box, list) and len(box) == 4 and all(isinstance(v, (int, float)) and not isinstance(v, bool) for v in box)): + raise Refused(f"traces[{k}].box must be [u0, v0, u1, v1], or absent for the render's own frame.") + if not isinstance(trace.get("camera"), str): + raise Refused(f"traces[{k}].camera must name a camera object.") + try: + views.append((record(context, trace["camera"], "" if box is None else ",".join(repr(float(v)) for v in box)), trace.get("frame") or own)) + except (Refused, core.ReferenceFitError) as refusal: + raise Refused(f"traces[{k}]: {refusal}") from None + started = time.perf_counter() + try: + out = core.block_plate(views, plate, traces, brokkr_kitbash.core.sheet, plane=plane, share=self.share, tol=self.tol) + except core.ReferenceFitError as refusal: + raise Refused(f"{refusal}. Nothing changed.") from None + return {"frame_object": obj.name, **out, "seconds": round(time.perf_counter() - started, 3)} + + +classes = (BROKKR_REFERENCE_OT_solve_camera, BROKKR_REFERENCE_OT_flow_score, BROKKR_REFERENCE_OT_fit_shell, BROKKR_REFERENCE_OT_block_plate) def register(): diff --git a/surfaces/blender/brokkr_reference/brokkr_actions.json b/surfaces/blender/brokkr_reference/brokkr_actions.json index a1d4856..d86e468 100644 --- a/surfaces/blender/brokkr_reference/brokkr_actions.json +++ b/surfaces/blender/brokkr_reference/brokkr_actions.json @@ -174,6 +174,63 @@ "doc": "pixels: nine tenths of every trace must lie this near its built run, or the fit is refused" } ] + }, + { + "name": "brokkr_reference.block_plate", + "doc": "Block a plate's first free cage from traces of its outline, each seen through a scene camera and naming the two consecutive corners it runs between: the only correspondence is a trace's ends to its corners. The crown (the corners and each side's points between) is solved until the sides as built draw on the traces; a side whose trace is not explained gains a point, up to 6. Depth comes from the views where two see a corner and a pixel moves their meeting point less than share x the plate's extent, from x = 0 for a mirrored plate's seam corners whose view crosses it, and otherwise from a plane: the one given, or the one through the corners the views and the seam decide. Every corner, and every point between corners (sides[].inner), says what decided it by its prior_share: plane from 0.2 up, else mirror on the seam, else views; a side says corners, views, mirror or plane. A corner one view sees, a seam corner seen along x = 0 included, is refused when the plane stands over 66 degrees off that view. Returns the sheet for brokkr_kitbash.shell, checked by its parser, and fit_traces for brokkr_reference.fit_shell (left_out lists the traces fit_shell cannot state: another frame, or a partner's side -1). Writes nothing (docs/reference.md).", + "changesScene": true, + "editModeSafe": false, + "result": "brokkr_mesh_polish_result", + "fields": [ + { + "name": "frame_object", + "type": "string", + "required": true, + "minLength": 1, + "maxLength": 63, + "doc": "an empty or object, unscaled, whose place in the world is the plate's frame" + }, + { + "name": "plate", + "type": "string", + "required": true, + "minLength": 2, + "maxLength": 2000, + "doc": "JSON {corners: [names, in the outline's order], mirror: true or false, seam: [the corners on x = 0 of a mirrored plate, two or more next to each other]}; side i runs from corner i to corner i + 1 and is one hard crease" + }, + { + "name": "traces", + "type": "string", + "required": true, + "minLength": 2, + "maxLength": 12000, + "doc": "a JSON array of {camera, box, frame, from, to, side, line}: camera a camera object's name; box [u0,v0,u1,v1], its frame on the image, absent for the render's own; frame a 4 x 4 (rows), the part's pose in that view, absent for frame_object's; from and to two consecutive corners; side 1, or -1 for the mirrored half or the partner across the frame's x = 0; line [[u,v],...] drawn from `from` to `to`" + }, + { + "name": "plane", + "type": "string", + "required": false, + "maxLength": 200, + "default": "", + "doc": "'' for the plane through the corners the views and the seam decide, or 'x,y,z; nx,ny,nz' in the frame: a point of the plane and its normal" + }, + { + "name": "share", + "type": "number", + "minimum": 0.001, + "maximum": 10, + "default": 0.1, + "doc": "the prior: a crown point this share of the corners' extent off the plane costs what one pixel of miss does" + }, + { + "name": "tol", + "type": "number", + "minimum": 0.1, + "maximum": 100, + "default": 5.2, + "doc": "pixels: nine tenths of every trace must lie this near its built side, or the side gains a point" + } + ] } ] } diff --git a/surfaces/blender/brokkr_reference/core.py b/surfaces/blender/brokkr_reference/core.py index 69549b4..eba3289 100644 --- a/surfaces/blender/brokkr_reference/core.py +++ b/surfaces/blender/brokkr_reference/core.py @@ -37,6 +37,13 @@ only where the built runs explain every trace; docs/reference.md, "fit_shell", s fit_runs(views, cage, runs, movable, mirror_of, share, diag, tol) the moved cage and the report fit_sheet(document, cage, frame, traces, cams, share, tol) the same for a sheet's named runs: the fitted sheet + +A plate's first cage is blocked from traces of its outline, each naming the two corners it runs between: the crown +is solved by fit_runs with a plane and fairness for its prior; docs/reference.md, "block_plate". + + triangulate(obs, seam) where sight lines meet, and how far apart they stand + plate_sheet(crown, corners, flare, drop, dome, mirror, seam, facing) the crown, skirt and centre free-cage document + block_plate(views, plate, traces, parse, plane, share, tol) the blocked sheet and what decided each crown point """ from __future__ import annotations @@ -527,7 +534,7 @@ def _hard_runs(cage, runs): "more hard edges meet, or on the rim") -def fit_runs(views, cage, runs, movable, mirror_of, share, diag, tol=TOL): +def fit_runs(views, cage, runs, movable, mirror_of, share, diag, tol=TOL, prior_rows=None): """Move a cage's points until its hard runs, as built and as cameras draw them, lie on their traces. views [(camera record, frame)]: the frame is the 4 x 4 that carries the cage to the world @@ -538,7 +545,10 @@ def fit_runs(views, cage, runs, movable, mirror_of, share, diag, tol=TOL): movable (vertices, 3) of bool: the coordinates that may move. Only authored vertices move 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 + share the prior's weight: a prior row that reads share x diag metres costs what one pixel of miss does + prior_rows (A, b) in metres over the movable coordinates, in the order of movable's True entries: the prior is + the rows A p - b. None is the identity, A = I and b the cage as given: a move from where each + point was blocked. block_plate gives distances to a plane and a side's second differences instead 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 @@ -581,6 +591,9 @@ def fit_runs(views, cage, runs, movable, mirror_of, share, diag, tol=TOL): prepared.append((run["name"], views[run["view"]], line, W, source, np.stack([flip[chain], np.ones(len(chain)), np.ones(len(chain))], 1), column.reshape(-1, 3)[source])) # the parameter column of each chain point's coordinate, -1 where held p0 = V0.ravel()[index] + A0, b0 = (np.eye(len(p0)), p0) if prior_rows is None else (np.asarray(prior_rows[0], float), np.asarray(prior_rows[1], float)) + if A0.ndim != 2 or A0.shape != (len(b0), len(p0)): + raise ReferenceFitError(f"prior_rows must be (A, b) with a column of A per movable coordinate ({len(p0)}) and a row per entry of b") def terms(p): """(residual, Jacobian, each run's built points as drawn) at parameters p.""" @@ -603,7 +616,7 @@ def fit_runs(views, cage, runs, movable, mirror_of, share, diag, tol=TOL): res += [dist, u[0] - line[0], u[-1] - line[-1]] rows.append(block) drawn.append((u, dist)) - return np.concatenate(res + [prior * (p - p0)]), np.vstack(rows + [prior * np.eye(len(p))]), drawn + return np.concatenate(res + [prior * (A0 @ p - b0)]), np.vstack(rows + [prior * A0]), drawn p, lam, rounds = p0.copy(), 1e-3, 0 r, J, drawn = terms(p) @@ -730,6 +743,372 @@ def fit_sheet(document, cage, frame, traces, cams, share=0.1, tol=TOL): return {"sheet": out, "traces": report["traces"], "points": points} +# --- a plate's first cage from its traces ------------------------------------------------------------------------------ + +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 +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. 1 is the prior's own unit, not a derived value: tests/test_reference.py BlockTests pins it between a plate that must block (its third corner starts at 0.831, views 16.5 degrees apart at Paladin's lens and range) and one that must be refused (11 degrees: it turns to blocked between 1.22 and 1.23) +VIEWS = 0.2 # a prior_share under this: the views decide the point (fit_shell's line) +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") + + +def _unit(v): + v = np.asarray(v, float) + return v / max(float(np.linalg.norm(v)), 1e-12) + + +def _partner(frame, side): + """The frame a trace's side is seen through: the part's own, or for side -1 its reflection across the frame's + x = 0 (the mirrored half of a plate, or the plate's partner on the other limb).""" + F = np.array(frame, float) + if side == -1: + F[:3, 0] = -F[:3, 0] + return F + + +def _sight(cam, frame, pixel): + """A pixel's line of sight (origin, unit direction) in a frame's own coordinates.""" + o, d = ray(cam, pixel) + inv = np.linalg.inv(np.asarray(frame, float)) + return inv[:3, :3] @ o + inv[:3, 3], _unit(inv[:3, :3] @ d) + + +def triangulate(obs, seam=False): + """Where sight lines meet. `obs` is [(camera record, frame, side, pixel)]: the pixel each view draws one point + of the frame at, side -1 a view of the point's reflection across x = 0. The midpoint of the sight lines, then + Gauss-Newton on the reprojection; `seam` holds the point on x = 0, which one view then decides. Returns (the + point in the frame, parallax_deg: the angle between the widest pair of sight lines, the worst reprojection miss + in pixels, m_per_px: the most one pixel of error moves the point). One sight line and no seam is no point.""" + frames = [_partner(frame, side) for _, frame, side, _ in obs] + rays = [_sight(cam, F, pixel) for (cam, _, _, pixel), F in zip(obs, frames)] + free = [1, 2] if seam else [0, 1, 2] + if len(rays) < 2 and not seam: + raise ReferenceFitError("one sight line meets nothing: a point is triangulated from two or more views, or held on the mirror plane") + A, b = np.zeros((3, 3)), np.zeros(3) + for o, d in rays: + P = np.eye(3) - np.outer(d, d) + A, b = A + P, b + P @ o + X = np.zeros(3) + X[free] = np.linalg.lstsq(A[:, free], b, rcond=None)[0] + + def terms(X): + drawn = [_drawn(cam, F, X[None]) for (cam, _, _, _), F in zip(obs, frames)] + if any(seen_ is None for seen_ in drawn): + raise ReferenceFitError("the sight lines meet behind a camera") + return np.concatenate([seen_[0][0] - np.asarray(pixel, float) for seen_, (_, _, _, pixel) in zip(drawn, obs)]), np.vstack([seen_[1][0] for seen_ in drawn])[:, free] + + for _ in range(10): + r, J = terms(X) + X[free] -= np.linalg.lstsq(J, r, rcond=None)[0] + r, J = terms(X) + parallax = max((math.degrees(math.acos(min(1.0, abs(float(a[1] @ c[1]))))) for a in rays for c in rays), default=0.0) + return X, parallax, float(np.abs(r).max()), float(math.sqrt(max(np.linalg.eigvalsh(np.linalg.pinv(J.T @ J)).max(), 0.0))) + + +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; 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 + sheet is flipped. + + mirror: `seam` names the ring's points on x = 0 (one unbroken stretch of it). The crown between them is the + crease the two halves meet at: it has no skirt, the skirt of its two ends stands on x = 0, and those ends are + poles (six edges meet there once the half is reflected). The centre stands in the half, not on the plane: a + 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 + out_ = -normal if flip else normal + middle = P.mean(0) + walled = [i for i in range(n) if not (i in seam and (i - 1) % n in seam and (i + 1) % n in seam)] # a point inside the seam has no skirt + skirt = {} + for i in walled: + away = (P[i] - middle) - out_ * ((P[i] - middle) @ out_) + back = out_.copy() + if i in seam: + away[0], back[0] = 0.0, 0.0 + point = P[i] + _unit(away) * flare - back * drop + if i in seam: + point[0] = 0.0 + skirt[i] = point + under = {i: n + m for m, i in enumerate(walled)} + centre = n + len(walled) + verts = [[round(float(x), 6) + 0.0 for x in p] for p in list(P) + [skirt[i] for i in walled] + [middle + out_ * dome]] + faces, creases = [], [] + for i in range(n): + j = (i + 1) % n + faces.append([i, j, centre]) + creases.append([i, j, 1.0]) + if not (i in seam and j in seam): + faces.append([under[i], under[j], j, i]) + pinned = [[i, 1.0] for i in corners] + [[under[i], 1.0] for i in corners if i in under] + poles = ([] if n == 4 else [centre]) + sorted(i for i in seam if i in under) + document = {"verts": verts, "faces": faces, "creases": creases, "corners": pinned, "poles": sorted(poles), "rim": 0.0} + if mirror: + document["mirror"] = True + if flip: + document["flip"] = True + return document + + +def block_plate(views, plate, traces, parse, plane=None, share=0.1, tol=TOL): + """A plate's first cage from traces of its outline across solved views; docs/reference.md, "block_plate". + + plate {"corners": [names, in loop order], "mirror": bool, "seam": [corner names on x = 0]}: side i runs from + corner i to corner i + 1 and is one hard crease of the crown + traces [{"from", "to": two consecutive corners, "side": 1, or -1 for the mirrored half or partner, "line": + [[u, v], ...] drawn from `from` to `to`}]; "camera", "box" and "frame" are the caller's and are echoed + views per trace, (camera record, the 4 x 4 that carries the plate's coordinates to the world as that view + poses the part): the plate's own frame, or the trace's "frame" where it states one + parse brokkr_kitbash.core.sheet, the cage's one parser: every sheet built here goes through it + plane {"point", "normal"} in the plate's coordinates, or None for the plane through the corners the views + or the seam decide + + The one correspondence is a trace's two ends to its named corners. The crown's points (the corners and each + side's points between them) are solved by fit_runs: its residual on every trace, and for a prior each crown + point's distance to the plane (one pixel per share x diag, diag the corners' extent) and each side's second + differences (one pixel per FAIR x the side's chord). A distance to a plane does not resist a move in the + plane, so the views decide wherever they see. A side starts as its two corners; a side with a trace not + explained gains a point and the plate is solved again, to K_MAX points. Skirt and centre are rebuilt from the + solved crown (plate_sheet). Returns {"sheet", "fit_traces", "left_out", "corners", "sides", "plane", "rounds"}; + raises ReferenceFitError naming the field for everything it refuses. + + A corner starts where its views meet when a pixel moves that point less than START x share x the plate's + extent; a seam corner where its sight line crosses x = 0, unless the line runs along the plane (SQUARE); any + other on the plane, lifted and guarded by SQUARE. What decided a point is read after the solve from its + prior_share, the same for every crown point: "plane" from VIEWS up (the prior holds its depth: the plane, and + for a side's inner points its fairness), else "mirror" on the seam, else "views". corners[] and each side's + "inner" (its points between corners) carry {"decided_by", "m_per_px", "prior_share"}; a side's own + "decided_by" is "corners" with no inner point, "plane" when any inner point is, else its inner points'.""" + if not isinstance(plate, dict) or set(plate) - {"corners", "mirror", "seam"}: + raise ReferenceFitError("plate must be {corners, mirror, seam}") + names, mirror, seam_names = plate.get("corners"), plate.get("mirror", False), plate.get("seam", []) + if not isinstance(names, list) or len(names) < 3 or not all(isinstance(name, str) and name for name in names) or len(set(names)) != len(names): + raise ReferenceFitError("plate.corners must be three or more different names, in the outline's order") + if not isinstance(mirror, bool): + raise ReferenceFitError(f"plate.mirror must be true or false, not {mirror!r}") + N, at = len(names), {name: i for i, name in enumerate(names)} + if not isinstance(seam_names, list) or any(name not in at for name in seam_names) or len(set(seam_names)) != len(seam_names): + raise ReferenceFitError("plate.seam must name corners of plate.corners, none twice") + held = {at[name] for name in seam_names} + if mirror != bool(held) or (mirror and (not 2 <= len(held) < N or sum(1 for i in held if (i + 1) % N not in held) != 1)): + raise ReferenceFitError("plate.seam must name two or more corners next to each other in the outline, and not all of them, on a mirrored plate, and none otherwise: " + "the halves meet along the sides between them. A plate that only has a partner across x = 0 is not mirrored: trace the partner with side -1") + if not isinstance(traces, list) or not traces: + raise ReferenceFitError("traces must be an array of one or more {camera, box, frame, from, to, side, line}") + if len(views) != len(traces): + raise ReferenceFitError(f"views must be one (camera, frame) a trace: {len(views)} for {len(traces)} traces") + seen_by, per_side, runs_of, frames = [dict() for _ in names], [[] for _ in names], [], [] + for k, trace in enumerate(traces): + where = f"traces[{k}]" + if not isinstance(trace, dict) or set(trace) - set(TRACE_KEYS): + raise ReferenceFitError(f"{where} must be {{camera, box, frame, from, to, side, line}}") + a, b, side = trace.get("from"), trace.get("to"), trace.get("side", 1) + if a not in at or b not in at: + raise ReferenceFitError(f"{where}.from and .to must name corners of plate.corners, not {a!r} and {b!r}") + step = (at[b] - at[a]) % N + if step not in (1, N - 1): + raise ReferenceFitError(f"{where}.from {a!r} and .to {b!r} are not consecutive corners: a trace is one side of the outline, drawn from one corner to the next") + if side not in (1, -1) or isinstance(side, bool): + raise ReferenceFitError(f"{where}.side must be 1, or -1 for the mirrored half or partner, not {side!r}") + cam, frame = views[k] + if cam is None: + raise ReferenceFitError(f"{where}.camera {trace.get('camera')!r} is no camera of this plate") + try: + F = np.array(frame, float) + except (TypeError, ValueError): + F = np.zeros(0) + if F.shape != (4, 4) or not np.isfinite(F).all() or np.abs(F[:3, :3].T @ F[:3, :3] - np.eye(3)).max() > 1e-5 or np.abs(F[3] - [0, 0, 0, 1]).max() > 1e-9: + raise ReferenceFitError(f"{where}.frame must be a 4 x 4 that only turns and moves the part: a scaled or sheared frame is not metres of the plate") + try: + line = np.array(trace.get("line"), float) + except (TypeError, ValueError): + line = np.zeros(0) + if line.ndim != 2 or line.shape[1] != 2 or len(line) < 2 or not np.isfinite(line).all() or np.linalg.norm(np.diff(line, axis=0), axis=1).sum() < 1e-9: + raise ReferenceFitError(f"{where}.line must be two or more [u, v] points, not all in one place") + F = _partner(F, side) + frames.append(F) + i = at[a] if step == 1 else at[b] + per_side[i].append(k) + runs_of.append((i, step == 1)) + view = (json.dumps([cam["C"], cam["R"], cam["f"], cam["c"]], default=float), F.tobytes()) + for corner, pixel in ((at[a], line[0]), (at[b], line[-1])): + seen_by[corner].setdefault(view, (cam, F, [], k))[2].append(pixel) + for i, name in enumerate(names): + if not seen_by[i]: + raise ReferenceFitError(f"plate.corners[{i}] {name!r}: no trace ends at it. Every corner is the end of a traced side") + for i, name in enumerate(names): + 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) + 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, 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 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 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): + raise ReferenceFitError("plane: none was given, and the corners the views decide stand in one line. Give plane") + normal, source = axes[2], "corners" + else: + try: + point, normal = np.array(plane["point"], float), np.array(plane["normal"], float) + fine = point.shape == (3,) and normal.shape == (3,) and np.isfinite(point).all() and np.isfinite(normal).all() and np.linalg.norm(normal) > 1e-9 + except (TypeError, ValueError, KeyError): + fine = False + if not fine: + raise ReferenceFitError("plane must be {point: [x, y, z], normal: [x, y, z]} in the plate's frame, the normal not zero") + normal, source = _unit(normal), "given" + for i in np.flatnonzero(~decided): + lifted = [] + for cam, F, pixels, k in seen_by[i].values(): + o, d = _sight(cam, F, np.mean(pixels, axis=0)) + square = abs(float(normal @ d)) + if square < SQUARE: + raise ReferenceFitError(f"plate.corners[{i}] {names[i]!r}: the plane stands {math.degrees(math.acos(square)):.0f} degrees off square-on to the view of traces[{k}], the " + 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): + side_ = 1.0 if sum(1 for i in free_ if corners_[i, 0] > 0) * 2 >= len(free_) else -1.0 + for i in free_: + if mirror and corners_[i, 0] * side_ <= 0: + raise ReferenceFitError(f"plate.corners[{i}] {names[i]!r} {what} at x = {corners_[i, 0]:.3f}, across the mirror plane from the plate's other corners. A corner on the " + "plane is named in plate.seam; one off it is traced where the views agree which side it is on") + + crossed(start, "starts") + diag = float(np.linalg.norm(np.ptp(start, axis=0))) + toward = _sight(views[0][0], frames[0], np.asarray(traces[0]["line"], float)[0])[0] - start.mean(0) + count, solves = [2] * N, 0 + while True: + solves += 1 + first = np.concatenate([[0], np.cumsum([k - 1 for k in count])]) # ring index of each corner; first[N] is the ring's size + n = int(first[N]) + ring = np.concatenate([np.linspace(start[i], start[(i + 1) % N], count[i])[:-1] for i in range(N)]) + chains = [[int(first[i]) + m for m in range(count[i] - 1)] + [int(first[i + 1]) % n] for i in range(N)] + on_seam = {v for i in range(N) if i in held and (i + 1) % N in held for v in chains[i]} | {int(first[i]) for i in held} + build = lambda crown: plate_sheet(crown, [int(first[i]) for i in range(N)], mirror=mirror, seam=sorted(on_seam), facing=toward) # noqa: E731 + + def parsed(document): + try: + return parse(document) + except Exception as refusal: # the parser's own error type is its package's + raise ReferenceFitError(f"sheet: the cage's parser does not take the plate as blocked ({refusal})") from None + + cage = parsed(build(ring)) + movable = np.zeros((len(cage.V), 3), bool) + movable[:n] = True + movable[sorted(on_seam), 0] = False + index = np.flatnonzero(movable.ravel()) + column = np.full(movable.size, -1) + column[index] = np.arange(len(index)) + column = column.reshape(-1, 3) + V0, A, b = np.asarray(cage.V, float), [], [] + + def row(parts, weight): + """One prior row: weight x the sum of factor x coordinate over `parts`, the held coordinates on its right side.""" + line_, right = np.zeros(len(index)), 0.0 + for v, c, factor in parts: + if column[v, c] >= 0: + line_[column[v, c]] += weight * factor + else: + right -= weight * factor * V0[v, c] + A.append(line_) + b.append(right) + + for v in range(n): + row([(v, c, normal[c]) for c in range(3)], 1.0) + b[-1] += float(normal @ point) + for i, chain in enumerate(chains): + fair = share * diag / (FAIR * max(float(np.linalg.norm(start[(i + 1) % N] - start[i])), 1e-9)) + for m in range(1, len(chain) - 1): + for c in range(3): + row([(chain[m - 1], c, 1.0), (chain[m], c, -2.0), (chain[m + 1], c, 1.0)], fair) + runs = [{"name": f"traces[{k}]", "chain": chains[i] if forward else chains[i][::-1], "view": k, "line": trace["line"]} for k, (trace, (i, forward)) in enumerate(zip(traces, runs_of))] + try: + V, report = fit_runs([(cam, F) for (cam, _), F in zip(views, frames)], cage, runs, movable, cage.mirror_of, share, diag, tol, prior_rows=(np.array(A), np.array(b))) + except ReferenceFitError as refusal: + rows = getattr(refusal, "traces", None) + if rows is None: + raise + grow = sorted({runs_of[k][0] for k, row_ in enumerate(rows) if row_["unexplained_px"] > tol}) + full = [i for i in grow if count[i] >= K_MAX] + if full: + error = ReferenceFitError(f"the side from {names[full[0]]!r} to {names[(full[0] + 1) % N]!r} is not explained at {K_MAX} points, the most a side is given: {refusal}") + error.traces = rows + raise error from None + for i in grow: + count[i] += 1 + continue + break + crown = V[:n] + crossed(crown[first[:N]], "ends") + 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): + 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: + left_out.append(k) # fit_shell takes one frame, the shell's own, and side -1 only as a mirrored sheet's other half + continue + fit_traces.append({**{key: trace[key] for key in ("camera", "box") if key in trace}, "run": {"verts": chains[i] if forward else chains[i][::-1]}, "side": trace.get("side", 1), "line": trace["line"]}) + return {"sheet": document, "fit_traces": fit_traces, "left_out": left_out, "corners": corners, "sides": sides, + "plane": {"point": [round(float(x), 6) for x in point], "normal": [round(float(x), 6) for x in normal], "from": source}, "rounds": solves} + + # --- fields ---------------------------------------------------------------------------------------------------------- diff --git a/surfaces/blender/docs/reference.md b/surfaces/blender/docs/reference.md index bbde414..24d0846 100644 --- a/surfaces/blender/docs/reference.md +++ b/surfaces/blender/docs/reference.md @@ -274,6 +274,170 @@ fitted; a run's depth with no mirror partner, no second view and no mirror plane The acceptance reads nine tenths of a trace: it passes a short doubled stretch and a tip that stands off, and reports both as `worst_px`. `m_per_px` is a sensitivity to one pixel, not an error bound. +## block_plate: a plate's first cage from its traces + +`fit_shell` refines a cage somebody blocked. `brokkr_reference.block_plate` makes the first one. A plate is a +closed outline of named corners in order; side i runs from corner i to corner i + 1 and is one hard crease of the +plate's crown. A trace is one side drawn in one view, `{camera, box, frame, from, to, side, line}`: `from` and `to` +are two consecutive corners and the line is drawn from the one to the other. That is the only correspondence +there is: a trace's two ends are its two corners. Every other point of the crown is placed by `fit_shell`'s +residual, the pixel distance from the side as built to the trace. Nothing matches a point of one trace to a +point of another. + +`frame_object` is the plate's frame. A trace's `frame` is the part's pose in that view where it differs (a limb +swung, a hull pitched); `side` -1 is a view of the plate's reflection across the frame's x = 0, which is the +other half of a mirrored plate or the same plate on the partner limb. `plate` is `{corners, mirror, seam}`. On a +mirrored plate `seam` names the corners on x = 0, two or more next to each other: they are held there, the sides +between them lie on it, and one view decides them. + +Where a corner's depth comes from, in this order: + +- **the views**, where two or more see it and one pixel moves the point their sight lines meet at less than + `share` x the plate's extent, the prior's own scale. Past that the views alone hold the corner looser than the + plane would and are not used as its start. That factor of 1 is the prior's own unit, not a derived value; the + tests pin it between a plate that blocks and one that is refused. The line is metres a pixel, so it moves + with lens and range: a 1.2 m plate 17.6 m off at 663 px has three corners started at 0.72 of the scale with + its views 19 degrees apart, 0.83 at 16.5, between 1.22 and 1.23 at 11 and 2.73 at 5. With no plane given it blocks down to + 16.5 degrees (73 mm from the truth) and is refused at 11, where it would have stood 104 mm off: the line + switches blocking and refusal, it is no cliff in accuracy. At 5 degrees its corners landed 0.25 to 1.5 m off; + through a lens three times as long it starts at 0.65 at 7 degrees and blocks. +- **the mirror plane**, for a seam corner whose sight line crosses x = 0 at 24 degrees or more. +- **a plane**, for the rest: `plane` (`x,y,z; nx,ny,nz`, a point and the normal, in the frame), or with none given + the plane through the corners the views and the seam decide, three or more. A corner one view sees is lifted + onto it, and refused when the plane stands more than 66 degrees off square-on to that view: the lift stretches + past 2.5 times there. A seam corner whose one view runs along x = 0 is such a corner: it is lifted onto the + plane, held on x = 0, and refused by the same 66 degrees. + +That is where a corner starts. What the report says decided it is read after the solve, from the point's own +prior share, whatever kind of point it is. + +The crown is then solved by the same solver as `fit_shell`, with a different prior: each crown point's distance +to the plane costs a pixel per `share` x the corners' extent, and each side's second differences a pixel per 0.2 +x its chord. A distance to a plane does not resist a move in the plane, so the views decide wherever they see, +and a view that sees nothing along its own sight line leaves that to the plane. A side starts as its two +corners. After each solve a side with a trace not explained (the same nine tenths within `tol`) gains one point +and the plate is solved again, to six points a side; past that it is refused as `fit_shell` refuses a trace. + +The cage is the crown ring, a skirt 0.05 of the crown's extent out and 0.06 back of it, and one centre vertex +0.017 proud (the extent is the distance between the crown's two furthest points, so a plate of any size has the +same proportions): every crown side +creased 1, the named corners pinned, the centre the declared pole unless the crown has four points. On a +mirrored plate the seam's sides have no skirt and the seam's two ends are poles too. The skirt and centre are +rebuilt from the solved crown and never solved. The sheet goes through `brokkr_kitbash`'s parser before it is +returned, and `brokkr_kitbash.shell` builds it; `block_plate` writes nothing. + +The report: `sheet`; `fit_traces`, the traces as `fit_shell` takes them (each side a run of authored vertices), +and `left_out`, the traces `fit_shell` cannot state (one with its own `frame`, or a partner's side -1 on a plate +that is not mirrored); per corner `decided_by`, `parallax_deg`, `m_per_px` and `prior_share`; per side its +points, each trace's readings, `inner` (the same `decided_by`, `m_per_px` and `prior_share` for each point between +its corners) and its own `decided_by`; `plane` with `from` `given` or `corners`; `rounds`, the solves it took. + +`decided_by` is read from `prior_share` for every crown point: `plane` from 0.2 up, the prior (the plane, and +for a side's inner points its fairness) holding the depth; under 0.2 `mirror` for a point on the seam and +`views` for any other. A seam corner seen from 10 degrees off the mirror plane reads `plane` (0.57), not +`mirror`. A side says `corners` when it has no point of its own, `plane` when any inner point does, else what +its inner points say: a side can read as explained to 0.1 px and stand 53 mm off with its one inner point at +0.41, and then it says `plane`. + +Refused, naming the field: a corner no trace ends at, a side traced in no view, a trace whose corners are not +consecutive, an unknown camera, a scaled frame, a seam that is not one stretch of the outline, no plane where +fewer than three corners are decided, the 66 degrees, a mirrored plate's corner that starts or ends across x = 0 +from the others (name it in `seam`, or trace it where the views agree), a side not explained at six points, a +sheet the cage's parser does not take, and a result that could pass the 16000 characters a receipt carries. + +Measured against a known truth (`tests/test_reference.py` BlockTests, Python 3.13 on Starfire; +`tests/fixtures/spectre_truth.json`), on one plate through one pair of views. SPECTRE's pass-3 roof, a hard +mirrored cage of 11 vertices, was built by `brokkr_kitbash.shell` and rendered in Blender 5.3 through SPECTRE's +two solved cameras at the sheet's pixel size. Its edges were traced off the renders: the ridge in the side +view, the lip, outer edge and rear edge in the hero's mirrored half and the side view, 62 degrees apart. The +side view's pixel is 27.6 mm across at the plate. + +How the traces were taken. No hand drew them. A search follows a seed polyline, takes the strongest brightness +step within a window across each edge, lays a straight stroke through the steps found on each segment, and ends +each stroke where it crosses its neighbours. The seed is the truth's projection moved off the answer, in eight +families: the whole seed by 0.5, 1 or 1.5 px in a drawn direction (a 2.5 px window), or each of its vertices by +a normal draw of 1 or 2 px (3.5 px), 2 px (5 px), 3 px (6 px) or 4 px (8 px). Every corner is named. A take's +worst point stands far from the truth's projection, 3 to 12 px at the families' medians: two strokes that run +nearly along each other cross far from the corner. Forty fresh draws a family (the fixture holds twelve of +each of six, 72 takes, which the test blocks; the 2 px, 5 px and the 4 px, 8 px families are in neither): + +| seed | window | blocked of 40 | worst traced point, px: median, most | worst corner, mm: median, most | worst corner over worst point x 27.6 mm, at most | +| --- | --- | --- | --- | --- | --- | +| moved 0.5 px as one | 2.5 px | 40 | 3.4, 30.2 | 47, 913 | 1.11 | +| moved 1 px as one | 2.5 px | 39 | 3.5, 30.4 | 67, 916 | 1.15 | +| moved 1.5 px as one | 2.5 px | 39 | 3.6, 24.9 | 66, 370 | 1.19 | +| each vertex 1 px | 3.5 px | 35 | 8.5, 28.2 | 171, 559 | 1.13 | +| each vertex 2 px | 3.5 px | 35 | 9.1, 28.8 | 153, 745 | 1.14 | +| each vertex 2 px | 5 px | 30 | 9.4, 41.5 | 170, 512 | 1.25 | +| each vertex 3 px | 6 px | 17 | 10.2, 73.6 | 231, 2038 | 1.15 | +| each vertex 4 px | 8 px | 8 | 12.0, 29.0 | 322, 417 | 1.33 | + +The fixture's 72 takes read 1.18 at most (62 block; nine are refused at a side not explained at six points, +one at the cage's parser). These ratios are not the bound. A take's worst point is one far crossing, and it +inflates what the corner is measured against: the worst a trace does for its worst point is to have no +outlier, every point the same d px off the truth's projection. With no search, the truth's projection moved: + +| every traced point d px off | worst corner over d x 27.6 mm, at most | +| --- | --- | +| each view moved as one, 12 directions by 12, at 1, 2, 3 px (all 144 block) | 1.505, 1.504, 1.502 (1.10 at the median) | +| each stroke its own direction, searched | 1.58 | +| each point its own direction, searched, at 1 and 3 px | 1.67, 1.66 | + +The bound: worst corner <= 2.08 x d x pixel, d the furthest any traced point stands from the truth's +projection and pixel the coarser view's. 2.08 is the geometric mean of the 1.505 and of 2.865, what the +blocking reads on the same 144 without its end terms; it stands 1.25 over the worst a search found, which is +not the worst there is, and 1.57 over the worst family of takes. The test holds the 144, the searched worst +at 1 and 3 px and the 72 takes to it. It is a reading on one plate through one pair of views, 62 degrees +apart, not a law, and it says a plate is as good as its worst traced point: one stroke end 30 px off puts a +corner 0.9 m off, and nothing in the report says so, because that trace is explained. No bound is given in +the traces' rms: against it the fixture's takes run 0.57 to 5.3. The same search seeded on the truth's +projection itself, with a 2.5 px window, reads 39 mm; that is the window ending every stroke within 2.5 px of +the answer, and it is not an accuracy. + +The error is not a multiple of `m_per_px` either: a seam corner 98 mm off reports 0.0008 m a pixel, because +`m_per_px` is depth along the sight line and most of this error lies across it. With only four corners named, +the roof's ridge and outer edge are one side each and are built as smooth runs through their hard knees: +explained within `tol`, 196 mm from the true edges (5.2 px is 144 mm there). Name a hard corner as a corner. + +Fairness, 0.2 x a side's chord, is set by known truth at traced noise. Over ten cells at 1 and 2 px (the rendered +roof with four corners named, its strokes those of the search seeded on the truth with the noise added, with +and without closing strokes moved 3 px, and a bowed pentagon at 60 and 30 degrees and in one view), 168 draws: +the mean of the cells' 90th percentiles and the worst draw, in mm, over the draws that blocked, and the draws +refused, which no percentile counts: + +| FAIR | 0.1 | 0.15 | 0.2 | 0.25 | 0.3 | 0.4 | 0.5 | 1 | +| --- | --- | --- | --- | --- | --- | --- | --- | --- | +| mean 90th percentile | 194 | 184 | 178 | 178 | 179 | 186 | 193 | 196 | +| worst draw | 301 | 275 | 273 | 272 | 312 | 382 | 494 | 577 | +| refused of 168 | 19 | 20 | 23 | 24 | 24 | 25 | 26 | 27 | + +A higher FAIR, which is weaker fairness, refuses more draws, so each column's percentiles are +over a different set. On other seeds (Soul's probe, verdict cut-trace-block.s2, FAIR 0.1, 0.2, 0.3, 0.5) the +mean 90th percentile read 216, 188, 216, 250, the worst draw 542, 855, 679, 807 and the refused 18, 21, 26, +27; on a third (verdict cut-trace-block.s3, all eight) 196, 196, 195, 202, 199, 220, 234, 255, the worst draw +652, 876, 690, 843, 871, 500, 673, 741 and the refused 10, 15, 20, 20, 22, 22, 23, 23. FAIR is flat from 0.1 +to 0.3 and worse above: 0.2 and 0.25 tie in the table, and 0.1 to 0.2 stand within 1 mm on the third set. 0.2 +is kept as a point on that plateau, not a resolved lowest. From +exact traces weaker fairness is nearer the truth (a pentagon bowed 35% of its sides: 42 mm at 0.2, 16 at 0.5, +12 with none). + +Agreement with other fits, which is not accuracy. SPECTRE's second-pass roof from its hand traces: the ridge +7.3 mm at most and the brow a median of 8.4 mm from the cage `fit_shell` had fitted to the same pixels; with +1 px of noise on those traces the brow's median read 11 to 75 mm over six draws (Soul's probe, verdict cut-trace-block.s1). Paladin's 16 plates, each a polygon traced in +one view with the plane its agent gave: every corner decided by the plane, the crown within 1 mm of the one +the harness had lifted onto the same plane. Its two thigh shields traced as partners are refused, a side 19 px +unexplained: the sheet draws two different polygons, not one plate and its reflection. RAPTOR's hull plate +bearing the 27 (`tests/fixtures/raptor_plates.json`), marked by eye in the hero and the SIDE view: seven hull +marks admit no hero camera under 25 px rms, so the sheet's two views do not draw one hull; through that camera +the plate blocks with its sight lines 34 to 40 degrees apart and the prior holding 0.17 to 0.20 of each corner. + +What it gives up. One outline loop a plate: a plate that wraps a corner is two plates, and creases inside the +outline are not blocked. A bend smaller than `tol` is built straight, and a hard knee inside a side is rounded. +Fairness holds a grown side flatter than its trace while the trace still reads as explained (the side's +`decided_by` says when the prior holds it). The plane through the decided corners is a guess at a twisted +plate, and where one view sees a corner the plane is all the depth it has. Every crown point carries a skirt +vertex, so a point a side grows costs two. + ## What it cannot do It solves one pinhole camera for one view: no lens distortion, no two views solved together, one turned group and @@ -281,6 +445,8 @@ no other pose. It does not find the points; marking them is the caller's. Points points on rigid features of one body, because the build's pose is not the drawing's. It does not say whether the subject is the right size: a build twice too large is the same picture from twice as far. +`block_plate` blocks one outline loop a plate and no crease inside it. + ## From a script ```python @@ -291,6 +457,7 @@ origin, direction = core.ray(cam, (u, v)) # a pixel's line of point = core.lift(cam, (u, v), plane_point, plane_normal) # a traced pixel on a plane run = core.crease_run(column) # the hard crease Blender builds from a cage column fit = core.fit_sheet(sheet, cage, frame, traces, cams) # the fitted sheet and its report; cage is brokkr_kitbash.core.sheet(sheet) +out = core.block_plate(views, plate, traces, parse) # a plate's first sheet and what decided each corner; parse is brokkr_kitbash.core.sheet 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 cam2 = core.camera_of(params, box) # and back @@ -301,4 +468,6 @@ through the action and rendered again; `reference.result.json` is its last run) (`crease_run` against Blender's own subdivision, a box and a folded sheet scored by `flow_score`; `reference_flow.result.json` is its last run) and `tests/live/reference_fit.py` (a mirrored loft and a mirrored free cage, each blocked off its design, fitted through the action and rebuilt by `brokkr_kitbash.shell`; -`reference_fit.result.json` is its last run). +`reference_fit.result.json` is its last run) and `tests/live/reference_block.py` (a bowed plate and a mirrored plate +blocked through the action from traces alone, built by `brokkr_kitbash.shell` and handed to `fit_shell`; +`reference_block.result.json` is its last run). diff --git a/surfaces/blender/tests/fixtures/paladin_plates.json b/surfaces/blender/tests/fixtures/paladin_plates.json new file mode 100644 index 0000000..a89bd01 --- /dev/null +++ b/surfaces/blender/tests/fixtures/paladin_plates.json @@ -0,0 +1 @@ +{"note":"Paladin's 16 traced plates as e688951 (nibu/fable-paladin-2) blocked them, dumped from one Blender 5.3 run of its build (experiments/mechs/paladin.py as far as its last traced plate, against this repo's add-ons): per plate the view, the limb's frame as built, the plane the agent gave (point and normal in that frame), and the traced polygon of paladin_form.TRACES, a pixel a corner, moved by the camera's miss at the joints the build named, one two-point trace a side. reference.crown is the crown the build lifted onto the plane and reference.fit_prior_share the least and greatest prior_share its fit_shell read. ThighShield.partners is ThighR.Shield with ThighL.Shield's polygon as its partner (side -1, the left thigh's frame), corners paired by the nearest lifted crown: the two polygons are not one plate mirrored, their lifted corners stand 0.16 to 0.77 m apart. ShinR.Upper has five corners and ShinL.Upper four: no pairing.","cameras":{"hero":{"C":[3.166359458844853,18.291375677273702,5.974887522617769],"R":[[-0.9954714736026896,0.08115547119873885,0.049500855929980235],[0.07193169063267664,0.30264152317512244,0.9503862058831489],[0.06214802592210706,0.9496430371169752,-0.3071086532959184]],"f":662.9901734726185,"c":[130.21617396138112,-8.096494835726665]},"rear":{"C":[-22.074827146253003,-40.54367537122909,4.880872134117224],"R":[[0.8803045809036056,-0.470549824446539,0.06038797523893856],[-0.054618671581600865,0.02591956697507224,0.998170815423135],[-0.47125433213370943,-0.8819926523283265,-0.002883692781031549]],"f":2046.1791620298611,"c":[521.0,255.0]},"side":{"C":[74.22580229606024,1.0919442264947585,3.1052411455157483],"R":[[3.061616997868383e-16,1.0,0.0],[0.027200224236332445,-8.327666886778697e-18,0.9996300054527641],[0.9996300054527641,-3.060484216273447e-16,-0.027200224236332445]],"f":2919.7828838468417,"c":[787.5,255.0]}},"frames":{"f0":[[0.999706864,0.009348843,0.022330457,-2.854834557],[-8.7e-08,0.922424495,-0.386177242,0.434564203],[-0.024208475,0.386064053,0.922154129,6.620359421],[0.0,0.0,0.0,1.0]],"f1":[[1.0,0.0,0.0,-3.099999905],[0.0,1.0,0.0,0.350000024],[0.0,0.0,1.0,8.384795189],[0.0,0.0,0.0,1.0]],"f2":[[1.0,0.0,0.0,3.099999905],[0.0,1.0,0.0,0.350000024],[0.0,0.0,1.0,8.384795189],[0.0,0.0,0.0,1.0]],"f3":[[0.996464431,-0.024993408,0.080212094,-1.635337234],[3.2e-08,0.954726696,0.297484338,0.857389331],[-0.084015772,-0.296432555,0.951351285,3.586615086],[0.0,0.0,0.0,1.0]],"f4":[[0.991480708,0.034509547,-0.125598863,1.737102032],[-8.8e-08,0.964264691,0.264940679,0.861362159],[0.130253524,-0.26268363,0.956049919,3.599395275],[0.0,0.0,0.0,1.0]],"f5":[[0.996464431,0.034608867,0.076556362,-1.485286713],[3.2e-08,0.911213994,-0.411933333,0.050000001],[-0.084015772,0.410476923,0.907992363,5.366280079],[0.0,0.0,0.0,1.0]],"f6":[[0.991480708,-0.053919706,-0.118569165,1.504706502],[-8.8e-08,0.91029495,-0.413960278,0.050000001],[0.130253524,0.41043362,0.902539909,5.368373394],[0.0,0.0,0.0,1.0]]},"plates":{"ForearmL.Front":{"plate":{"corners":["c0","c1","c2","c3"]},"plane":{"point":[0,0.5,-1.0],"normal":[0.12,1,0.05]},"traces":[{"view":"hero","frame":"f0","from":"c0","to":"c1","side":1,"line":[[300.352,206.901],[318.352,203.901]]},{"view":"hero","frame":"f0","from":"c1","to":"c2","side":1,"line":[[318.352,203.901],[341.352,244.901]]},{"view":"hero","frame":"f0","from":"c2","to":"c3","side":1,"line":[[341.352,244.901],[326.352,253.901]]},{"view":"hero","frame":"f0","from":"c3","to":"c0","side":1,"line":[[326.352,253.901],[300.352,206.901]]}],"reference":{"crown":[[-0.06885,0.55132,-1.86109],[-0.4718,0.58919,-1.65145],[-0.13752,0.49637,-0.59739],[0.3254,0.44428,-0.66659]],"fit_prior_share":[0.957,0.966],"fit_refused":null}},"ForearmL.Outer":{"plate":{"corners":["c0","c1","c2","c3"]},"plane":{"point":[-0.36,0.38,-1.0],"normal":[-0.6,0.8,0]},"traces":[{"view":"hero","frame":"f0","from":"c0","to":"c1","side":1,"line":[[317.352,185.901],[327.352,186.901]]},{"view":"hero","frame":"f0","from":"c1","to":"c2","side":1,"line":[[327.352,186.901],[351.352,240.901]]},{"view":"hero","frame":"f0","from":"c2","to":"c3","side":1,"line":[[351.352,240.901],[343.352,247.901]]},{"view":"hero","frame":"f0","from":"c3","to":"c0","side":1,"line":[[343.352,247.901],[317.352,185.901]]}],"reference":{"crown":[[-0.69888,0.12584,-1.5561],[-1.06198,-0.14649,-1.2766],[-0.58265,0.21301,-0.00603],[-0.20602,0.49549,-0.11596]],"fit_prior_share":[0.998,1.0],"fit_refused":null}},"PauldronL.Front":{"plate":{"corners":["c0","c1","c2","c3","c4","c5"]},"plane":{"point":[0,1.34,0.1],"normal":[-0.22,1,0.3]},"traces":[{"view":"hero","frame":"f1","from":"c0","to":"c1","side":1,"line":[[287.046,82.555],[302.046,85.555]]},{"view":"hero","frame":"f1","from":"c1","to":"c2","side":1,"line":[[302.046,85.555],[327.046,125.555]]},{"view":"hero","frame":"f1","from":"c2","to":"c3","side":1,"line":[[327.046,125.555],[332.046,139.555]]},{"view":"hero","frame":"f1","from":"c3","to":"c4","side":1,"line":[[332.046,139.555],[319.046,155.555]]},{"view":"hero","frame":"f1","from":"c4","to":"c5","side":1,"line":[[319.046,155.555],[292.046,143.555]]},{"view":"hero","frame":"f1","from":"c5","to":"c0","side":1,"line":[[292.046,143.555],[287.046,82.555]]}],"reference":{"crown":[[1.08317,1.83903,-0.76912],[0.39257,1.75937,-1.01002],[-0.03547,1.53706,-0.58287],[0.04478,1.4498,-0.23316],[0.5966,1.26801,0.77746],[1.01705,1.34934,0.81469]],"fit_prior_share":[0.892,0.996],"fit_refused":null}},"PauldronL.Rear":{"plate":{"corners":["c0","c1","c2","c3","c4","c5"]},"plane":{"point":[0,-1.34,0.1],"normal":[-0.2,-1,0.3]},"traces":[{"view":"rear","frame":"f1","from":"c0","to":"c1","side":1,"line":[[439.3,45.444],[466.3,20.444]]},{"view":"rear","frame":"f1","from":"c1","to":"c2","side":1,"line":[[466.3,20.444],[479.3,28.444]]},{"view":"rear","frame":"f1","from":"c2","to":"c3","side":1,"line":[[479.3,28.444],[481.3,100.444]]},{"view":"rear","frame":"f1","from":"c3","to":"c4","side":1,"line":[[481.3,100.444],[466.3,115.444]]},{"view":"rear","frame":"f1","from":"c4","to":"c5","side":1,"line":[[466.3,115.444],[440.3,86.444]]},{"view":"rear","frame":"f1","from":"c5","to":"c0","side":1,"line":[[440.3,86.444],[439.3,45.444]]}],"reference":{"crown":[[-0.0372,-1.32587,0.12231],[0.48584,-1.60647,-0.46435],[0.84109,-1.57086,-0.10881],[0.91968,-1.10828,1.48552],[0.64337,-1.00748,1.63731],[0.00516,-1.0639,1.02376]],"fit_prior_share":[0.93,0.999],"fit_refused":null}},"PauldronR.Front":{"plate":{"corners":["c0","c1","c2","c3","c4","c5"]},"plane":{"point":[0,1.34,0.1],"normal":[0.22,1,0.3]},"traces":[{"view":"hero","frame":"f2","from":"c0","to":"c1","side":1,"line":[[96.805,67.754],[112.805,54.754]]},{"view":"hero","frame":"f2","from":"c1","to":"c2","side":1,"line":[[112.805,54.754],[131.805,55.754]]},{"view":"hero","frame":"f2","from":"c2","to":"c3","side":1,"line":[[131.805,55.754],[132.805,108.754]]},{"view":"hero","frame":"f2","from":"c3","to":"c4","side":1,"line":[[132.805,108.754],[119.805,122.754]]},{"view":"hero","frame":"f2","from":"c4","to":"c5","side":1,"line":[[119.805,122.754],[98.805,104.754]]},{"view":"hero","frame":"f2","from":"c5","to":"c0","side":1,"line":[[98.805,104.754],[96.805,67.754]]}],"reference":{"crown":[[-0.3798,1.47361,-0.06685],[-0.90805,1.72094,-0.50389],[-1.2103,1.67902,-0.14251],[-1.15307,1.24243,1.27081],[-0.66791,1.13033,1.28871],[-0.2769,1.15587,0.91682]],"fit_prior_share":[0.908,0.988],"fit_refused":null}},"PauldronR.Outer":{"plate":{"corners":["c0","c1","c2","c3","c4"]},"plane":{"point":[0.72,1.0,0.0],"normal":[0.75,0.6,0.3]},"traces":[{"view":"hero","frame":"f2","from":"c0","to":"c1","side":1,"line":[[95.805,69.754],[98.805,104.754]]},{"view":"hero","frame":"f2","from":"c1","to":"c2","side":1,"line":[[98.805,104.754],[83.805,119.754]]},{"view":"hero","frame":"f2","from":"c2","to":"c3","side":1,"line":[[83.805,119.754],[58.805,106.754]]},{"view":"hero","frame":"f2","from":"c3","to":"c4","side":1,"line":[[58.805,106.754],[56.805,99.754]]},{"view":"hero","frame":"f2","from":"c4","to":"c0","side":1,"line":[[56.805,99.754],[95.805,69.754]]}],"reference":{"crown":[[0.67692,1.02494,0.05783],[0.60612,1.21248,-0.14025],[-0.03193,2.2109,-0.54198],[-0.3535,2.44436,-0.20497],[-0.24172,1.83683,0.73064]],"fit_prior_share":[0.652,0.942],"fit_refused":null}},"ShinL.Inner":{"plate":{"corners":["c0","c1","c2","c3"]},"plane":{"point":[0.64,0.1,-1.2],"normal":[1,0.5,0]},"traces":[{"view":"hero","frame":"f3","from":"c0","to":"c1","side":1,"line":[[267.281,315.546],[285.281,302.546]]},{"view":"hero","frame":"f3","from":"c1","to":"c2","side":1,"line":[[285.281,302.546],[288.281,333.546]]},{"view":"hero","frame":"f3","from":"c2","to":"c3","side":1,"line":[[288.281,333.546],[275.281,345.546]]},{"view":"hero","frame":"f3","from":"c3","to":"c0","side":1,"line":[[275.281,345.546],[267.281,315.546]]}],"reference":{"crown":[[0.08941,1.20119,-0.07078],[-0.09318,1.56637,0.37388],[-0.0563,1.49259,1.02156],[0.2009,0.97821,0.50136]],"fit_prior_share":[0.933,0.992],"fit_refused":null}},"ShinL.Lower":{"plate":{"corners":["c0","c1","c2","c3"]},"plane":{"point":[0,0.7,-1.4],"normal":[-0.1,1,-0.08]},"traces":[{"view":"hero","frame":"f3","from":"c0","to":"c1","side":1,"line":[[291.746,334.445],[312.746,329.445]]},{"view":"hero","frame":"f3","from":"c1","to":"c2","side":1,"line":[[312.746,329.445],[303.746,352.445]]},{"view":"hero","frame":"f3","from":"c2","to":"c3","side":1,"line":[[303.746,352.445],[279.746,346.445]]},{"view":"hero","frame":"f3","from":"c3","to":"c0","side":1,"line":[[279.746,346.445],[291.746,334.445]]}],"reference":{"crown":[[-0.14864,0.7707,-0.33047],[-0.74551,0.69397,-0.54349],[-0.95935,0.71544,-0.00781],[-0.4394,0.76223,-0.07285]],"fit_prior_share":[0.937,0.998],"fit_refused":null}},"ShinL.Upper":{"plate":{"corners":["c0","c1","c2","c3"]},"plane":{"point":[0,0.86,-0.1],"normal":[-0.1,1,0.1]},"traces":[{"view":"hero","frame":"f3","from":"c0","to":"c1","side":1,"line":[[288.746,297.445],[305.746,296.445]]},{"view":"hero","frame":"f3","from":"c1","to":"c2","side":1,"line":[[305.746,296.445],[312.746,327.445]]},{"view":"hero","frame":"f3","from":"c2","to":"c3","side":1,"line":[[312.746,327.445],[291.746,332.445]]},{"view":"hero","frame":"f3","from":"c3","to":"c0","side":1,"line":[[291.746,332.445],[288.746,297.445]]}],"reference":{"crown":[[-0.42465,0.80781,-0.0027],[-0.94727,0.74963,0.05646],[-0.80695,0.69339,0.75912],[-0.38584,0.73396,0.77458]],"fit_prior_share":[0.909,0.942],"fit_refused":null}},"ShinR.Lower":{"plate":{"corners":["c0","c1","c2","c3","c4"]},"plane":{"point":[0,0.7,-1.4],"normal":[0.1,1,-0.08]},"traces":[{"view":"hero","frame":"f4","from":"c0","to":"c1","side":1,"line":[[113.561,326.916],[150.561,324.916]]},{"view":"hero","frame":"f4","from":"c1","to":"c2","side":1,"line":[[150.561,324.916],[147.561,358.916]]},{"view":"hero","frame":"f4","from":"c2","to":"c3","side":1,"line":[[147.561,358.916],[139.561,395.916]]},{"view":"hero","frame":"f4","from":"c3","to":"c4","side":1,"line":[[139.561,395.916],[111.561,398.916]]},{"view":"hero","frame":"f4","from":"c4","to":"c0","side":1,"line":[[111.561,398.916],[113.561,326.916]]}],"reference":{"crown":[[0.00201,0.6732,-1.73254],[-0.60378,0.75143,-1.51188],[-0.61382,0.82236,-0.63778],[-0.52739,0.87594,0.13998],[0.28087,0.77599,-0.09909]],"fit_prior_share":[0.869,0.99],"fit_refused":null}},"ShinR.Outer":{"plate":{"corners":["c0","c1","c2","c3","c4"]},"plane":{"point":[0.6,0.35,-1.5],"normal":[0.7,0.7,0]},"traces":[{"view":"hero","frame":"f4","from":"c0","to":"c1","side":1,"line":[[72.561,328.916],[88.561,316.916]]},{"view":"hero","frame":"f4","from":"c1","to":"c2","side":1,"line":[[88.561,316.916],[100.561,328.916]]},{"view":"hero","frame":"f4","from":"c2","to":"c3","side":1,"line":[[100.561,328.916],[100.561,383.916]]},{"view":"hero","frame":"f4","from":"c3","to":"c4","side":1,"line":[[100.561,383.916],[80.561,386.916]]},{"view":"hero","frame":"f4","from":"c4","to":"c0","side":1,"line":[[80.561,386.916],[72.561,328.916]]}],"reference":{"crown":[[0.72289,0.22711,-1.83415],[0.31158,0.63842,-1.46757],[0.53636,0.41364,-0.35818],[0.84834,0.10166,-0.27489],[1.15616,-0.20616,-0.75718]],"fit_prior_share":[0.849,0.999],"fit_refused":null}},"ShinR.Upper":{"plate":{"corners":["c0","c1","c2","c3","c4"]},"plane":{"point":[0,0.86,-0.1],"normal":[0.1,1,0.1]},"traces":[{"view":"hero","frame":"f4","from":"c0","to":"c1","side":1,"line":[[112.66,287.053],[143.66,291.053]]},{"view":"hero","frame":"f4","from":"c1","to":"c2","side":1,"line":[[143.66,291.053],[144.66,320.053]]},{"view":"hero","frame":"f4","from":"c2","to":"c3","side":1,"line":[[144.66,320.053],[121.66,325.053]]},{"view":"hero","frame":"f4","from":"c3","to":"c4","side":1,"line":[[121.66,325.053],[106.66,311.053]]},{"view":"hero","frame":"f4","from":"c4","to":"c0","side":1,"line":[[106.66,311.053],[112.66,287.053]]}],"reference":{"crown":[[0.50508,0.77741,0.22084],[0.11372,0.8384,0.00227],[-0.37595,0.86583,0.21762],[-0.23816,0.79185,0.8197],[0.4713,0.72747,0.754]],"fit_prior_share":[0.957,1.0],"fit_refused":null}},"ThighL.Inner":{"plate":{"corners":["c0","c1","c2","c3","c4"]},"plane":{"point":[0.74,0.25,-1.0],"normal":[1,0.55,0]},"traces":[{"view":"hero","frame":"f5","from":"c0","to":"c1","side":1,"line":[[243.338,250.068],[253.338,262.068]]},{"view":"hero","frame":"f5","from":"c1","to":"c2","side":1,"line":[[253.338,262.068],[263.338,292.068]]},{"view":"hero","frame":"f5","from":"c2","to":"c3","side":1,"line":[[263.338,292.068],[247.338,300.068]]},{"view":"hero","frame":"f5","from":"c3","to":"c4","side":1,"line":[[247.338,300.068],[233.338,268.068]]},{"view":"hero","frame":"f5","from":"c4","to":"c0","side":1,"line":[[233.338,268.068],[243.338,250.068]]}],"reference":{"crown":[[0.64942,0.41469,-0.92537],[0.50343,0.68012,-1.76754],[0.22347,1.18915,-1.76114],[0.29331,1.06216,-1.0278],[0.42366,0.82517,-0.6451]],"fit_prior_share":[0.869,0.913],"fit_refused":null}},"ThighL.Shield":{"plate":{"corners":["c0","c1","c2","c3","c4","c5","c6"]},"plane":{"point":[0,0.86,-0.9],"normal":[-0.12,1,0.08]},"traces":[{"view":"hero","frame":"f5","from":"c0","to":"c1","side":1,"line":[[252.338,243.068],[260.338,236.068]]},{"view":"hero","frame":"f5","from":"c1","to":"c2","side":1,"line":[[260.338,236.068],[273.338,238.068]]},{"view":"hero","frame":"f5","from":"c2","to":"c3","side":1,"line":[[273.338,238.068],[295.338,288.068]]},{"view":"hero","frame":"f5","from":"c3","to":"c4","side":1,"line":[[295.338,288.068],[291.338,296.068]]},{"view":"hero","frame":"f5","from":"c4","to":"c5","side":1,"line":[[291.338,296.068],[265.338,292.068]]},{"view":"hero","frame":"f5","from":"c5","to":"c6","side":1,"line":[[265.338,292.068],[253.338,262.068]]},{"view":"hero","frame":"f5","from":"c6","to":"c0","side":1,"line":[[253.338,262.068],[252.338,243.068]]}],"reference":{"crown":[[0.2485,0.89538,-0.96955],[0.10603,0.93559,-1.68579],[-0.51538,0.86882,-1.78331],[-0.6642,0.83615,-1.59821],[-0.40747,0.76773,-0.35786],[-0.07638,0.80346,-0.30779],[0.17235,0.84797,-0.4911]],"fit_prior_share":[0.887,0.964],"fit_refused":null}},"ThighR.Outer":{"plate":{"corners":["c0","c1","c2","c3","c4","c5"]},"plane":{"point":[0.62,0.5,-0.6],"normal":[0.7,0.7,0.1]},"traces":[{"view":"hero","frame":"f6","from":"c0","to":"c1","side":1,"line":[[111.702,188.513],[124.702,186.513]]},{"view":"hero","frame":"f6","from":"c1","to":"c2","side":1,"line":[[124.702,186.513],[120.702,217.513]]},{"view":"hero","frame":"f6","from":"c2","to":"c3","side":1,"line":[[120.702,217.513],[99.702,261.513]]},{"view":"hero","frame":"f6","from":"c3","to":"c4","side":1,"line":[[99.702,261.513],[87.702,261.513]]},{"view":"hero","frame":"f6","from":"c4","to":"c5","side":1,"line":[[87.702,261.513],[95.702,224.513]]},{"view":"hero","frame":"f6","from":"c5","to":"c0","side":1,"line":[[95.702,224.513],[111.702,188.513]]}],"reference":{"crown":[[1.05475,-0.01706,-0.02383],[1.09973,0.08158,-1.02911],[0.82099,0.36772,-1.08101],[0.48061,0.54859,0.03562],[0.48367,0.41439,0.95357],[0.79818,0.09537,0.98514]],"fit_prior_share":[0.823,0.98],"fit_refused":null}},"ThighR.Shield":{"plate":{"corners":["c0","c1","c2","c3","c4","c5","c6"]},"plane":{"point":[0,0.86,-0.9],"normal":[0.12,1,0.08]},"traces":[{"view":"hero","frame":"f6","from":"c0","to":"c1","side":1,"line":[[121.702,218.513],[150.702,221.513]]},{"view":"hero","frame":"f6","from":"c1","to":"c2","side":1,"line":[[150.702,221.513],[161.702,239.513]]},{"view":"hero","frame":"f6","from":"c2","to":"c3","side":1,"line":[[161.702,239.513],[161.702,273.513]]},{"view":"hero","frame":"f6","from":"c3","to":"c4","side":1,"line":[[161.702,273.513],[151.702,291.513]]},{"view":"hero","frame":"f6","from":"c4","to":"c5","side":1,"line":[[151.702,291.513],[113.702,280.513]]},{"view":"hero","frame":"f6","from":"c5","to":"c6","side":1,"line":[[113.702,280.513],[114.702,247.513]]},{"view":"hero","frame":"f6","from":"c6","to":"c0","side":1,"line":[[114.702,247.513],[121.702,218.513]]}],"reference":{"crown":[[0.53857,0.79075,-0.84226],[0.45475,0.86439,-1.63699],[-0.44412,0.98228,-1.76237],[-0.63795,0.96942,-1.31088],[-0.56905,0.8941,-0.47264],[-0.25844,0.82238,-0.04206],[0.46661,0.73756,-0.0694]],"fit_prior_share":[0.9,1.0],"fit_refused":null}},"ThighShield.partners":{"plate":{"corners":["c0","c1","c2","c3","c4","c5","c6"]},"traces":[{"view":"hero","frame":"f6","from":"c0","to":"c1","side":1,"line":[[121.702,218.513],[150.702,221.513]]},{"view":"hero","frame":"f6","from":"c1","to":"c2","side":1,"line":[[150.702,221.513],[161.702,239.513]]},{"view":"hero","frame":"f6","from":"c2","to":"c3","side":1,"line":[[161.702,239.513],[161.702,273.513]]},{"view":"hero","frame":"f6","from":"c3","to":"c4","side":1,"line":[[161.702,273.513],[151.702,291.513]]},{"view":"hero","frame":"f6","from":"c4","to":"c5","side":1,"line":[[151.702,291.513],[113.702,280.513]]},{"view":"hero","frame":"f6","from":"c5","to":"c6","side":1,"line":[[113.702,280.513],[114.702,247.513]]},{"view":"hero","frame":"f6","from":"c6","to":"c0","side":1,"line":[[114.702,247.513],[121.702,218.513]]},{"view":"hero","frame":"f5","from":"c0","to":"c1","side":-1,"line":[[295.338,288.068],[273.338,238.068]]},{"view":"hero","frame":"f5","from":"c1","to":"c2","side":-1,"line":[[273.338,238.068],[260.338,236.068]]},{"view":"hero","frame":"f5","from":"c2","to":"c3","side":-1,"line":[[260.338,236.068],[252.338,243.068]]},{"view":"hero","frame":"f5","from":"c3","to":"c4","side":-1,"line":[[252.338,243.068],[253.338,262.068]]},{"view":"hero","frame":"f5","from":"c4","to":"c5","side":-1,"line":[[253.338,262.068],[265.338,292.068]]},{"view":"hero","frame":"f5","from":"c5","to":"c6","side":-1,"line":[[265.338,292.068],[291.338,296.068]]},{"view":"hero","frame":"f5","from":"c6","to":"c0","side":-1,"line":[[291.338,296.068],[295.338,288.068]]}],"reference":{"crown":[[0.53857,0.79075,-0.84226],[0.45475,0.86439,-1.63699],[-0.44412,0.98228,-1.76237],[-0.63795,0.96942,-1.31088],[-0.56905,0.8941,-0.47264],[-0.25844,0.82238,-0.04206],[0.46661,0.73756,-0.0694]]}}}} \ No newline at end of file diff --git a/surfaces/blender/tests/fixtures/raptor_plates.json b/surfaces/blender/tests/fixtures/raptor_plates.json new file mode 100644 index 0000000..ebf9c13 --- /dev/null +++ b/surfaces/blender/tests/fixtures/raptor_plates.json @@ -0,0 +1 @@ +{"note":"RAPTOR (sheet 38): the hull plate that bears the 27, its four corners marked by eye in the hero (the right flank) and in the SIDE view (the left flank, so side -1), with the nose's front face and the two laser emitters. Coordinates are the hull's (raptor_form.SHEET at 3ced828: x right, y forward of the sheet's hip column, z up). side is raptor_form.SHEET.camera(), square-on at the sheet's 28.6 px a metre. world gives each mark's (y, z) off the SIDE view and its x from the hull's mass (the nose 0, the emitters +-0.56, a plate corner the flank's half-width at its station and height): hero is brokkr_reference.core.solve(world, pixels, box, model rolled, lens 50). The seven marks admit no camera under 21.8 px rms (left-out 44 px, lens not determined; 25.1 px at 50 mm): the sheet's two views do not draw one rigid hull, and four of the seven marks are the plate's own corners. What block_plate gives through these cameras is two views agreeing on a plate, not a measured accuracy: there is no truth for this plate.","cameras":{"hero":{"C":[11.303769012415719,10.50084330876064,1.6426541643628032],"R":[[-0.5899084170655855,0.7870428136060581,0.1804762284242304],[0.1745987487019839,-0.09389198835577137,0.9801528306719831],[0.7883675135537211,0.6097113284773865,-0.08202901620441301]],"f":944.4444444444445,"c":[400.0,320.0]},"side":{"C":[-400.0,0.0,0.0],"R":[[0.0,-1.0,0.0],[0.0,0.0,1.0],[-1.0,0.0,0.0]],"f":11441.176470588236,"c":[348.5,849.5]}},"box":[60,0,740,640],"world":{"nose":[0.0,5.681233933161954,4.038046272493573],"emitter_r":[0.56,4.96452442159383,3.7583547557840613],"emitter_l":[-0.56,4.96452442159383,3.7583547557840613],"p_ft":[0.6753672831185238,4.14293059125964,5.4365038560411305],"p_fb":[1.0477429305912596,4.317737789203084,4.632390745501285],"p_rb":[1.2748071979434448,3.0940874035989716,4.80719794344473],"p_rt":[1.282382176520994,3.0241645244215936,5.576349614395887]},"pixels":{"nose":[683,250],"emitter_r":[557,273],"emitter_l":[617,283],"p_ft":[500,120],"p_fb":[539,183],"p_rb":[461,184],"p_rt":[459,108]},"plate":{"corners":["p_ft","p_fb","p_rb","p_rt"]},"traces":[{"view":"hero","from":"p_ft","to":"p_fb","side":1,"line":[[500,120],[539,183]]},{"view":"side","from":"p_ft","to":"p_fb","side":-1,"line":[[230,694],[225,717]]},{"view":"hero","from":"p_fb","to":"p_rb","side":1,"line":[[539,183],[461,184]]},{"view":"side","from":"p_fb","to":"p_rb","side":-1,"line":[[225,717],[260,712]]},{"view":"hero","from":"p_rb","to":"p_rt","side":1,"line":[[461,184],[459,108]]},{"view":"side","from":"p_rb","to":"p_rt","side":-1,"line":[[260,712],[262,690]]},{"view":"hero","from":"p_rt","to":"p_ft","side":1,"line":[[459,108],[500,120]]},{"view":"side","from":"p_rt","to":"p_ft","side":-1,"line":[[262,690],[230,694]]}]} \ No newline at end of file diff --git a/surfaces/blender/tests/fixtures/spectre_plates.json b/surfaces/blender/tests/fixtures/spectre_plates.json new file mode 100644 index 0000000..75bbce6 --- /dev/null +++ b/surfaces/blender/tests/fixtures/spectre_plates.json @@ -0,0 +1 @@ +{"note":"SPECTRE's roof and cheek as plates. Cameras: spectre_skel.cameras() at nibu/fable-spectre-2 74fc241, solved by this repo's brokkr_reference.core; frames: the hull pitched about the waist by spectre_skel.PITCH (hero 3 degrees, side 0). Traces marked hand are spectre_skel.TRACES (roof brow and ridge, cheek chine); a trace marked fitted-edge is the straight edge between two vertices of spectre_fits.json's fitted cage drawn through the camera, standing in for a side nobody traced, so the outline closes. reference is spectre_fits.json's fitted cage along the traced runs: a fit from a hand blocking, not ground truth.","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":{"plate":{"corners":["ridge_rear","nose","brow_rear"],"mirror":true,"seam":["ridge_rear","nose"]},"traces":[{"view":"side","from":"ridge_rear","to":"nose","side":1,"line":[[883,400],[898,408],[930,426],[958,441]],"source":"hand"},{"view":"hero","from":"brow_rear","to":"nose","side":-1,"line":[[487,47],[443,92],[427,126],[400,128],[360,135],[325,142]],"source":"hand"},{"view":"side","from":"brow_rear","to":"nose","side":1,"line":[[883,404],[900.7,413.6],[919,423.6],[938.6,436.4],[958.6,443]],"source":"hand"},{"view":"hero","from":"brow_rear","to":"ridge_rear","side":-1,"line":[[487.1,47.1],[424.7,35.3]],"source":"fitted-edge"},{"view":"side","from":"brow_rear","to":"ridge_rear","side":1,"line":[[883.0,404.1],[883.0,399.9]],"source":"fitted-edge"}],"reference":{"ridge":[[0.0,1.173941,7.498167],[0.0,2.063931,7.015758],[0.0,2.624251,6.687296],[0.0,3.079302,6.461668],[0.0,3.280227,6.334663]],"brow":[[0.776479,1.177565,7.327593],[0.653669,2.30313,6.743599],[0.929821,2.609515,6.428508],[0.197231,2.908778,6.436474],[0.0,3.280227,6.334663]]}},"cheek":{"plate":{"corners":["chine_rear","jaw","chin"],"mirror":true,"seam":["jaw","chin"]},"traces":[{"view":"hero","from":"chine_rear","to":"jaw","side":-1,"line":[[472,169],[438,180],[390,170],[312,182]],"source":"hand"},{"view":"side","from":"chine_rear","to":"jaw","side":1,"line":[[919,447],[945,456.5],[961,459]],"source":"hand"},{"view":"side","from":"jaw","to":"chin","side":1,"line":[[965.6,456.7],[957.7,463.1]],"source":"fitted-edge"},{"view":"hero","from":"chin","to":"chine_rear","side":-1,"line":[[331.3,199.5],[472.1,167.8]],"source":"fitted-edge"},{"view":"side","from":"chin","to":"chine_rear","side":1,"line":[[957.7,463.1],[921.1,451.0]],"source":"fitted-edge"}],"reference":{"chine":[[1.097992,2.211844,6.0315],[0.924701,2.658187,5.897007],[0.340462,2.978516,6.057156],[0.0,3.458134,5.926945]]}}}} \ No newline at end of file diff --git a/surfaces/blender/tests/fixtures/spectre_truth.json b/surfaces/blender/tests/fixtures/spectre_truth.json new file mode 100644 index 0000000..590a4fd --- /dev/null +++ b/surfaces/blender/tests/fixtures/spectre_truth.json @@ -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). One plate, one pair of views. A stroke is an edge of the roof traced from a render by a search, not projected: along a seed polyline the drawn edge is the strongest brightness step within reach px across it, a straight stroke is laid through the steps found on each segment, and strokes meet where they cross. Every seed here is made from the truth's projection, so no trace here is a hand's. takes are that search from a seed that is not on the answer, twelve draws a family (families): offset_px moves the whole seed that far in a drawn direction, jitter_px moves each seed vertex by a normal draw of that many px, reach_px is the window. A take's lines are its strokes in the order of strokes. How far a take's points stand from the truth's projection is not stored: read it from truth and cameras. What takes read is read from takes; the bound is read with no search, from the truth's projection with every point moved as far (test_every_point_as_far_off_bounds_the_rendered_roof). strokes[].line is the same search seeded on the truth's projection itself with a 2.5 px window: every point stands within 2.5 px of the answer because the window ends there (off_projection_px), so it measures no accuracy; it is the base the fairness readings add noise to. drawn is the least share of a segment's length where a step was found. 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}],"families":{"offset 0.5":{"offset_px":0.5,"jitter_px":0.0,"reach_px":2.5},"offset 1":{"offset_px":1.0,"jitter_px":0.0,"reach_px":2.5},"offset 1.5":{"offset_px":1.5,"jitter_px":0.0,"reach_px":2.5},"jitter 1":{"offset_px":0.0,"jitter_px":1.0,"reach_px":3.5},"jitter 2":{"offset_px":0.0,"jitter_px":2.0,"reach_px":3.5},"jitter 3":{"offset_px":0.0,"jitter_px":3.0,"reach_px":6.0}},"takes":[{"family":"offset 0.5","lines":[[[772.2,383.42],[811.92,388.9],[876.83,399.81],[904.5,416.12],[941.9,427.27],[961.01,441.57]],[[325.38,142.38],[427.34,126.41]],[[961.4,440.48],[933.67,437.39]],[[427.13,125.47],[441.7,94.0],[487.6,47.66],[552.26,26.84],[587.98,18.69]],[[933.75,435.9],[907.77,423.92],[886.76,406.74],[810.85,394.02],[770.76,388.61]],[[587.72,18.19],[542.1,9.36]],[[769.97,386.53],[772.44,383.26]]]},{"family":"offset 0.5","lines":[[[772.44,383.47],[812.17,388.91],[876.72,399.75],[904.86,416.32],[941.65,427.12],[961.25,441.79]],[[325.56,142.4],[427.51,126.37]],[[961.82,439.84],[933.81,437.93]],[[427.74,125.91],[442.92,92.86],[487.36,47.76],[552.41,26.85],[588.09,18.5]],[[934.12,435.85],[909.12,424.03],[846.1,400.04],[811.15,393.65],[771.07,388.12]],[[587.95,18.37],[542.38,9.29]],[[769.95,386.71],[772.42,383.44]]]},{"family":"offset 0.5","lines":[[[772.32,383.47],[812.07,388.87],[876.79,399.78],[904.63,416.24],[942.07,427.3],[961.38,441.96]],[[325.27,142.42],[427.22,126.4]],[[960.78,443.98],[934.02,436.83]],[[427.91,126.68],[443.16,92.38],[487.75,47.59],[552.04,26.8],[587.79,18.66]],[[934.41,435.5],[908.74,424.97],[876.48,405.41],[811.05,393.6],[771.07,387.23]],[[587.88,18.31],[542.29,9.34]],[[770.14,387.44],[771.99,383.96]]]},{"family":"offset 0.5","lines":[[[771.89,383.3],[811.61,388.91],[876.95,399.87],[904.42,416.1],[942.18,427.41],[961.12,441.73]],[[324.82,142.53],[426.77,126.48]],[[961.4,439.48],[933.35,437.72]],[[426.07,126.07],[442.1,93.47],[487.78,47.57],[551.62,27.02],[587.32,18.64]],[[933.81,435.81],[908.63,424.33],[876.73,405.49],[810.58,393.7],[770.64,387.08]],[[587.45,18.21],[541.85,9.28]],[[770.15,387.64],[772.01,384.16]]]},{"family":"offset 0.5","lines":[[[772.21,383.42],[811.93,388.9],[876.98,399.83],[904.42,416.1],[941.91,427.28],[961.02,441.57]],[[325.39,142.37],[427.35,126.43]],[[961.41,440.49],[933.68,437.39]],[[426.58,125.21],[441.98,93.74],[487.53,47.69],[552.27,26.85],[587.99,18.69]],[[933.76,435.91],[907.78,423.92],[886.77,406.75],[810.86,394.02],[770.77,388.62]],[[587.73,18.21],[542.12,9.34]],[[769.98,386.54],[772.45,383.27]]]},{"family":"offset 0.5","lines":[[[771.65,383.25],[811.36,388.87],[876.64,399.62],[904.14,415.98],[942.73,427.49],[960.43,441.62]],[[324.82,142.51],[426.77,126.49]],[[960.88,440.26],[933.14,437.24]],[[426.31,125.41],[442.09,93.58],[487.52,47.7],[551.72,27.03],[587.38,18.65]],[[932.92,436.43],[908.62,423.23],[876.42,405.26],[810.29,393.97],[770.2,388.47]],[[587.15,18.2],[541.58,9.14]],[[769.87,386.74],[772.33,383.47]]]},{"family":"offset 0.5","lines":[[[772.49,383.45],[812.22,388.9],[876.83,399.77],[904.9,416.37],[942.01,427.24],[961.3,441.88]],[[325.57,142.42],[427.52,126.36]],[[961.99,439.4],[933.83,438.1]],[[427.84,126.06],[443.72,92.04],[487.52,47.65],[552.38,26.76],[588.13,18.66]],[[934.21,435.86],[909.1,424.23],[865.97,403.51],[811.19,393.71],[771.19,387.54]],[[588.0,18.41],[542.43,9.29]],[[769.98,386.83],[772.44,383.56]]]},{"family":"offset 0.5","lines":[[[771.68,383.23],[811.38,388.85],[876.76,399.69],[903.91,415.88],[942.71,427.54],[960.46,441.6]],[[324.84,142.49],[426.8,126.51]],[[960.91,440.24],[933.16,437.22]],[[426.38,125.4],[442.02,93.67],[487.56,47.66],[551.75,27.01],[587.42,18.7]],[[932.95,436.41],[908.63,423.23],[876.12,405.13],[810.32,393.9],[770.22,388.5]],[[587.17,18.19],[541.59,9.18]],[[769.9,386.72],[772.36,383.45]]]},{"family":"offset 0.5","lines":[[[772.25,383.46],[811.98,388.92],[876.91,399.83],[904.47,416.14],[941.69,427.2],[961.08,441.58]],[[325.43,142.4],[427.39,126.39]],[[961.41,440.69],[933.75,437.32]],[[428.93,126.33],[440.99,94.8],[487.38,47.73],[552.32,26.89],[587.99,18.52]],[[933.56,436.42],[901.54,418.82],[886.96,406.9],[810.91,394.03],[770.82,388.56]],[[587.76,18.29],[542.17,9.3]],[[770.03,386.57],[772.49,383.3]]]},{"family":"offset 0.5","lines":[[[771.53,383.24],[811.24,388.84],[876.58,399.58],[904.17,416.02],[942.85,427.52],[960.44,441.65]],[[324.62,142.52],[426.58,126.51]],[[960.9,439.76],[932.95,437.6]],[[426.45,125.79],[441.79,93.8],[487.6,47.65],[551.53,27.17],[587.16,18.59]],[[932.88,436.46],[908.59,423.25],[875.88,405.1],[810.15,394.08],[770.1,388.35]],[[587.06,18.11],[541.47,9.15]],[[769.95,387.07],[772.41,383.8]]]},{"family":"offset 0.5","lines":[[[772.42,383.43],[812.16,388.89],[876.93,399.84],[904.27,416.12],[942.08,427.28],[961.16,441.84]],[[325.55,142.39],[427.5,126.39]],[[961.81,439.81],[933.8,437.89]],[[427.99,126.0],[443.14,92.61],[487.44,47.72],[552.39,26.8],[588.14,18.74]],[[934.1,435.81],[909.17,423.85],[846.58,400.19],[811.09,393.93],[771.07,387.95]],[[587.93,18.35],[542.35,9.31]],[[769.94,386.67],[772.4,383.4]]]},{"family":"offset 0.5","lines":[[[772.33,383.51],[812.08,388.88],[876.82,399.78],[904.64,416.23],[942.09,427.29],[961.32,442.05]],[[325.28,142.4],[427.24,126.39]],[[960.8,443.97],[934.04,436.82]],[[427.93,126.67],[443.15,92.44],[487.67,47.63],[552.06,26.82],[587.8,18.6]],[[934.42,435.49],[908.75,424.96],[876.43,405.39],[811.06,393.59],[771.09,387.21]],[[587.89,18.32],[542.3,9.33]],[[770.16,387.43],[772.01,383.95]]]},{"family":"offset 1","lines":[[[772.38,383.52],[812.11,388.89],[876.84,399.81],[904.83,416.31],[942.18,427.33],[960.91,441.6]],[[325.71,142.43],[427.64,126.27]],[[961.44,440.94],[933.91,436.99]],[[428.47,125.55],[441.32,94.29],[487.61,47.67],[552.65,26.96],[588.05,17.44]],[[933.56,436.34],[910.35,421.18],[883.52,404.14],[811.37,391.86],[771.25,386.44]],[[587.86,18.35],[542.28,9.3]],[[770.86,386.31],[772.71,382.84]]]},{"family":"offset 1","lines":[[[772.88,383.51],[812.61,388.99],[876.65,399.68],[904.32,416.04],[942.18,427.32],[961.32,442.13]],[[326.04,142.31],[427.99,126.28]],[[962.04,440.73],[934.48,436.94]],[[428.18,125.72],[444.66,90.92],[487.59,47.69],[552.89,26.74],[588.51,18.1]],[[934.37,436.1],[907.56,423.63],[893.73,408.05],[811.51,394.23],[771.43,388.8]],[[588.36,18.49],[542.8,9.39]],[[770.34,386.51],[772.19,383.03]]]},{"family":"offset 1","lines":[[[772.65,383.46],[812.39,388.94],[876.82,399.73],[904.34,416.05],[942.59,427.45],[961.6,442.44]],[[325.47,142.41],[427.42,126.35]],[[961.0,444.6],[934.13,437.91]],[[427.59,126.83],[445.86,89.66],[487.8,47.56],[552.21,26.89],[587.94,18.52]],[[934.72,435.82],[909.21,425.01],[876.03,405.2],[811.39,393.52],[771.33,387.7]],[[588.2,18.5],[542.65,9.31]],[[769.78,387.65],[772.25,384.38]]]},{"family":"offset 1","lines":[[[771.77,383.24],[811.49,388.88],[876.89,399.84],[904.68,416.21],[942.07,427.36],[961.19,441.87]],[[324.56,142.56],[426.51,126.49]],[[959.98,445.09],[933.45,436.97]],[[426.3,126.73],[441.67,94.0],[487.55,47.72],[551.34,27.15],[587.03,18.65]],[[933.85,435.82],[908.65,424.4],[876.74,405.47],[810.48,393.57],[770.52,386.97]],[[587.34,18.23],[541.76,9.21]],[[770.27,388.2],[770.89,384.31]]]},{"family":"offset 1","lines":[[[772.4,383.5],[812.13,388.9],[876.76,399.76],[904.85,416.33],[942.01,427.29],[960.92,441.62]],[[325.72,142.4],[427.66,126.28]],[[961.46,440.95],[933.93,437.01]],[[428.01,125.33],[442.44,93.14],[487.66,47.67],[552.66,26.92],[588.11,17.62]],[[933.58,436.35],[910.33,421.26],[883.76,404.19],[811.39,391.87],[771.26,386.46]],[[587.88,18.34],[542.3,9.3]],[[770.87,386.32],[772.73,382.85]]]},{"family":"offset 1","lines":[[[771.27,383.3],[811.0,388.69],[876.81,399.69],[904.09,415.97],[942.56,427.46],[960.12,441.21]],[[324.56,142.57],[426.51,126.52]],[[960.58,439.78],[932.8,436.92]],[[426.52,125.27],[441.98,93.72],[487.52,47.66],[551.5,27.03],[587.16,18.71]],[[932.95,435.37],[907.74,423.91],[875.71,405.13],[810.04,392.94],[770.09,386.54]],[[586.76,18.15],[541.19,9.06]],[[770.02,386.52],[772.49,383.25]]]},{"family":"offset 1","lines":[[[772.97,383.51],[812.69,389.02],[876.68,399.67],[904.44,416.06],[942.77,427.5],[961.42,442.31]],[[326.06,142.3],[428.01,126.29]],[[962.46,439.42],[934.42,437.65]],[[428.37,126.02],[444.86,90.74],[487.7,47.65],[552.88,26.74],[588.51,18.09]],[[934.28,436.62],[909.84,423.7],[865.62,403.38],[811.61,394.21],[771.51,388.82]],[[588.46,18.51],[542.9,9.39]],[[770.0,386.61],[772.47,383.35]]]},{"family":"offset 1","lines":[[[771.32,383.28],[811.04,388.72],[876.68,399.65],[904.47,416.1],[942.73,427.49],[960.11,441.26]],[[324.61,142.54],[426.56,126.51]],[[960.5,440.31],[932.82,436.99]],[[426.55,125.22],[442.02,93.68],[487.58,47.65],[551.59,27.15],[587.15,18.42]],[[932.67,435.98],[908.29,422.93],[846.42,400.1],[810.09,392.9],[770.14,386.5]],[[586.81,18.11],[541.22,9.13]],[[770.07,386.48],[772.54,383.21]]]},{"family":"offset 1","lines":[[[772.51,383.46],[812.23,388.91],[876.74,399.77],[904.73,416.26],[941.61,427.14],[961.08,441.58]],[[325.8,142.4],[427.74,126.26]],[[961.72,440.29],[933.92,437.49]],[[428.2,125.45],[442.54,93.09],[487.55,47.71],[552.68,26.71],[588.39,18.56]],[[933.79,436.17],[910.34,421.48],[884.05,404.29],[811.47,391.93],[771.35,386.52]],[[587.97,18.39],[542.4,9.31]],[[770.96,386.39],[772.82,382.91]]]},{"family":"offset 1","lines":[[[771.02,383.27],[810.76,388.68],[876.86,399.74],[904.4,416.13],[942.65,427.42],[960.08,441.36]],[[324.18,142.65],[426.12,126.55]],[[960.37,439.85],[932.44,437.61]],[[426.31,125.81],[441.98,93.65],[487.56,47.71],[551.09,27.16],[586.76,18.83]],[[933.06,435.03],[907.48,424.33],[876.4,405.34],[809.73,393.46],[769.76,387.12]],[[586.56,18.08],[540.99,9.0]],[[769.94,387.09],[772.41,383.82]]]},{"family":"offset 1","lines":[[[772.84,383.49],[812.57,388.93],[876.79,399.72],[904.29,416.07],[942.26,427.34],[961.29,442.06]],[[326.02,142.33],[427.97,126.29]],[[961.99,440.73],[934.44,436.9]],[[428.18,125.66],[444.73,90.87],[487.62,47.63],[552.91,26.88],[588.47,17.98]],[[934.34,436.02],[907.53,423.56],[893.85,408.15],[811.5,394.0],[771.41,388.62]],[[588.32,18.48],[542.75,9.4]],[[770.54,386.51],[772.39,383.04]]]},{"family":"offset 1","lines":[[[772.68,383.48],[812.42,388.91],[876.78,399.73],[904.17,415.97],[942.84,427.54],[961.58,442.49]],[[325.51,142.42],[427.45,126.36]],[[961.07,444.43],[934.13,438.01]],[[427.49,126.74],[446.69,88.83],[487.73,47.61],[552.24,26.89],[587.99,18.58]],[[934.77,435.77],[909.21,425.05],[875.82,405.12],[811.44,393.35],[771.35,387.83]],[[588.22,18.51],[542.67,9.34]],[[769.81,387.63],[772.28,384.36]]]},{"family":"offset 1.5","lines":[[[772.59,383.45],[812.3,388.9],[876.74,399.75],[904.64,416.2],[942.2,427.33],[960.82,441.61]],[[326.01,142.31],[427.96,126.27]],[[962.0,439.23],[933.97,437.4]],[[427.07,124.34],[441.96,93.73],[487.53,47.7],[552.97,26.75],[588.54,18.06]],[[933.73,436.07],[910.55,420.86],[883.11,403.6],[811.77,390.32],[771.8,383.78]],[[588.01,18.42],[542.45,9.3]],[[770.96,385.83],[773.42,382.56]]]},{"family":"offset 1.5","lines":[[[773.33,383.49],[813.03,389.11],[876.97,399.84],[904.66,416.2],[942.31,427.31],[961.51,442.32]],[[326.53,142.28],[428.47,126.17]],[[962.46,440.77],[934.8,437.37]],[[428.39,125.43],[447.02,88.59],[487.6,47.66],[553.35,26.52],[589.05,18.22]],[[934.53,436.54],[911.04,421.91],[889.4,407.36],[812.1,393.19],[772.14,386.78]],[[588.76,18.65],[543.23,9.4]],[[770.8,386.33],[772.66,382.86]]]},{"family":"offset 1.5","lines":[[[772.97,383.5],[812.71,389.0],[876.73,399.67],[904.28,416.09],[942.16,427.27],[962.07,442.61]],[[325.67,142.41],[427.61,126.31]],[[961.31,444.86],[934.5,437.91]],[[427.38,127.02],[454.3,81.22],[487.71,47.61],[552.35,26.85],[588.14,18.66]],[[935.06,436.12],[909.68,425.04],[875.86,405.06],[811.7,393.66],[771.61,388.05]],[[588.54,18.55],[542.98,9.4]],[[770.27,388.15],[770.9,384.26]]]},{"family":"offset 1.5","lines":[[[771.63,383.3],[811.37,388.86],[876.51,399.68],[904.66,416.18],[941.93,427.28],[961.35,441.87]],[[324.31,142.65],[426.24,126.48]],[[959.87,445.24],[933.24,437.5]],[[425.74,127.02],[442.09,93.56],[487.6,47.67],[551.05,27.26],[586.78,18.87]],[[933.87,435.86],[908.75,424.32],[876.43,405.31],[810.3,394.0],[770.17,388.62]],[[587.25,18.2],[541.66,9.21]],[[770.47,388.79],[770.48,384.7]]]},{"family":"offset 1.5","lines":[[[772.61,383.47],[812.33,388.92],[876.75,399.76],[904.85,416.33],[942.11,427.26],[960.85,441.63]],[[326.04,142.32],[427.99,126.26]],[[961.99,439.39],[934.01,437.36]],[[427.11,124.36],[441.9,93.83],[487.44,47.73],[552.99,26.75],[588.56,18.02]],[[933.76,436.09],[910.56,420.9],[883.16,403.62],[811.8,390.33],[771.83,383.8]],[[588.04,18.42],[542.48,9.31]],[[770.59,385.72],[773.67,382.66]]]},{"family":"offset 1.5","lines":[[[770.9,383.26],[810.62,388.7],[876.71,399.71],[904.73,416.23],[941.66,427.18],[959.91,440.69]],[[324.3,142.61],[426.25,126.53]],[[960.31,439.19],[932.23,437.57]],[[426.48,125.02],[442.21,93.48],[487.53,47.69],[551.31,27.12],[586.96,18.88]],[[932.22,435.78],[908.35,421.82],[875.6,402.76],[809.89,391.58],[769.77,386.16]],[[586.39,18.01],[540.81,9.0]],[[770.56,386.43],[772.41,382.95]]]},{"family":"offset 1.5","lines":[[[773.45,383.55],[813.16,389.14],[877.01,399.88],[904.47,416.16],[942.92,427.55],[961.64,442.62]],[[326.56,142.29],[428.5,126.17]],[[962.73,440.33],[934.88,437.75]],[[426.47,124.84],[445.79,93.32],[487.63,47.63],[553.33,26.48],[589.02,18.1]],[[934.76,436.61],[905.93,422.03],[891.61,407.68],[812.1,394.21],[772.01,388.73]],[[588.92,18.65],[543.38,9.42]],[[770.42,386.53],[772.27,383.06]]]},{"family":"offset 1.5","lines":[[[770.96,383.31],[810.7,388.65],[876.9,399.77],[904.54,416.19],[941.96,427.26],[959.9,440.75]],[[324.38,142.52],[426.34,126.56]],[[960.48,438.72],[932.22,437.88]],[[426.54,124.96],[442.16,93.59],[487.56,47.63],[551.44,27.32],[586.77,17.63]],[[932.25,435.81],[908.44,421.72],[875.67,402.7],[809.96,391.52],[769.84,386.1]],[[586.45,18.02],[540.87,8.99]],[[771.03,386.5],[772.27,382.82]]]},{"family":"offset 1.5","lines":[[[772.76,383.46],[812.48,388.91],[876.73,399.75],[904.85,416.32],[941.56,427.1],[961.09,441.59]],[[326.15,142.28],[428.11,126.27]],[[962.11,439.54],[934.17,437.34]],[[427.21,124.44],[441.83,93.91],[487.53,47.7],[553.11,26.79],[588.64,17.91]],[[933.85,436.26],[910.69,421.0],[878.05,400.54],[812.12,389.32],[771.96,383.9]],[[588.18,18.49],[542.63,9.32]],[[770.88,385.86],[773.35,382.6]]]},{"family":"offset 1.5","lines":[[[770.54,383.13],[810.25,388.72],[876.65,399.75],[904.84,416.23],[942.11,427.34],[959.96,440.76]],[[323.74,142.75],[425.66,126.57]],[[960.12,438.76],[931.82,438.03]],[[426.23,125.87],[441.87,93.85],[487.61,47.62],[550.67,27.23],[586.36,19.05]],[[932.24,435.55],[907.49,423.24],[876.19,405.23],[809.18,393.83],[769.09,388.4]],[[586.06,18.0],[540.49,8.96]],[[769.93,387.11],[772.4,383.85]]]},{"family":"offset 1.5","lines":[[[773.27,383.46],[812.97,389.09],[877.14,399.86],[904.47,416.16],[942.4,427.35],[961.41,442.28]],[[326.5,142.25],[428.45,126.21]],[[962.4,440.72],[934.75,437.28]],[[428.19,125.24],[446.87,88.77],[487.56,47.65],[553.32,26.48],[589.0,18.11]],[[934.58,436.23],[910.75,422.28],[884.29,404.35],[812.22,392.09],[772.1,386.67]],[[588.7,18.61],[543.15,9.42]],[[770.99,386.3],[772.85,382.83]]]},{"family":"offset 1.5","lines":[[[773.01,383.49],[812.75,389.03],[876.71,399.68],[904.43,416.13],[942.34,427.39],[962.07,442.64]],[[325.73,142.43],[427.66,126.27]],[[961.35,444.86],[934.48,438.14]],[[425.82,126.24],[463.98,71.46],[487.68,47.63],[552.4,26.8],[588.22,18.74]],[[935.05,436.2],[909.79,424.89],[876.13,405.22],[811.71,393.9],[771.74,387.46]],[[588.58,18.56],[543.03,9.38]],[[770.17,388.06],[771.41,384.38]]]},{"family":"jitter 1","lines":[[[772.12,383.36],[812.38,388.95],[876.64,399.72],[904.88,416.31],[941.79,427.17],[960.67,441.38]],[[322.85,142.87],[425.92,126.58]],[[959.74,444.8],[934.1,438.03]],[[425.54,126.74],[461.82,73.68],[487.52,47.72],[551.49,27.31],[586.89,17.54]],[[933.07,434.97],[908.5,424.76],[876.66,405.06],[810.0,394.04],[771.52,388.76]],[[586.68,18.04],[543.4,9.59]],[[771.0,386.99],[773.43,385.58]]]},{"family":"jitter 1","lines":[[[772.4,383.5],[811.89,388.85],[877.17,399.89],[903.95,415.96],[942.28,427.37],[961.26,441.95]],[[324.38,142.63],[426.45,126.46]],[[961.25,440.31],[932.58,437.89]],[[425.77,125.03],[444.91,94.21],[487.53,47.7],[551.82,26.91],[587.78,18.62]],[[935.34,436.46],[909.28,424.33],[873.98,403.97],[810.81,388.11],[771.26,383.55]],[[586.22,18.0],[541.69,9.22]],[[769.81,387.13],[772.6,383.31]]]},{"family":"jitter 1","lines":[[[772.14,383.41],[810.97,388.79],[876.72,399.66],[904.18,416.03],[942.62,427.52],[961.38,442.16]],[[324.86,142.52],[427.48,126.37]],[[961.93,439.36],[933.26,438.01]],[[425.78,125.2],[445.07,94.15],[487.62,47.64],[554.44,26.95],[585.42,15.2]],[[934.72,435.73],[907.97,425.3],[892.02,407.68],[810.6,394.1],[769.39,388.19]],[[588.19,18.49],[540.98,8.97]],[[770.59,388.47],[770.49,384.36]]]},{"family":"jitter 1","lines":[[[773.53,383.55],[812.05,388.92],[877.11,399.85],[904.01,415.96],[943.04,427.59],[960.8,442.08]],[[324.9,142.53],[426.05,126.56]],[[960.69,444.57],[934.41,437.42]],[[425.84,126.96],[460.45,75.05],[487.63,47.61],[553.77,26.38],[587.21,18.87]],[[933.13,435.03],[906.32,424.87],[900.15,409.21],[808.47,391.64],[770.34,382.96]],[[587.95,18.41],[541.3,9.05]],[[769.84,386.41],[772.46,383.53]]]},{"family":"jitter 1","lines":[[[771.35,383.29],[813.47,389.1],[876.84,399.78],[904.57,416.14],[942.22,427.34],[961.92,442.37]],[[325.3,142.42],[425.24,126.69]],[[958.23,445.25],[932.92,436.75]],[[425.81,125.02],[445.39,93.95],[487.56,47.68],[552.2,27.06],[588.54,17.07]],[[933.69,435.48],[907.66,424.37],[879.64,407.18],[812.35,388.44],[770.32,383.68]],[[588.41,18.58],[541.16,9.01]],[[770.02,386.77],[772.36,383.84]]]},{"family":"jitter 1","lines":[[[771.0,383.3],[811.57,388.82],[877.26,399.89],[903.83,415.9],[941.6,427.14],[960.73,441.29]],[[323.88,142.64],[427.55,126.38]],[[961.4,438.02],[932.61,438.53]],[[427.66,127.16],[444.46,91.3],[487.38,47.77],[550.45,27.25],[586.72,18.86]],[[932.98,434.89],[909.33,422.55],[876.01,399.99],[810.2,388.64],[771.36,383.21]],[[588.78,18.61],[540.1,8.81]],[[769.7,387.37],[773.51,382.26]]]},{"family":"jitter 1","lines":[[[773.21,383.5],[809.22,388.45],[876.87,399.78],[904.24,416.06],[942.28,427.33],[960.57,441.47]],[[324.19,142.65],[426.27,126.51]],[[961.76,445.52],[933.49,438.74]],[[427.35,125.79],[446.24,89.36],[487.56,47.7],[552.42,26.76],[588.72,18.56]],[[934.36,435.46],[910.15,423.01],[877.33,400.12],[811.09,388.89],[771.72,384.11]],[[587.2,18.17],[541.58,9.18]],[[770.59,388.97],[770.49,384.13]]]},{"family":"jitter 1","lines":[[[772.04,383.34],[811.34,388.87],[876.73,399.66],[904.72,416.38],[942.56,427.22],[961.26,442.33]],[[325.29,142.41],[426.89,126.44]],[[959.01,443.53],[931.63,435.84]],[[425.93,126.1],[442.08,93.63],[487.53,47.65],[549.7,27.54],[587.54,18.64]],[[932.17,435.43],[908.81,421.43],[876.17,399.37],[810.68,394.6],[769.9,388.78]],[[587.65,18.31],[540.79,8.99]],[[772.1,385.76],[772.83,383.74]]]},{"family":"jitter 1","lines":[[[770.11,383.06],[810.35,388.69],[876.85,399.77],[904.0,415.92],[941.8,427.18],[961.53,441.96]],[[325.69,142.43],[426.28,126.47]],[[960.17,445.68],[932.68,436.68]],[[427.32,126.19],[443.61,92.07],[487.58,47.61],[551.72,27.04],[585.57,19.06]],[[932.38,435.14],[909.14,424.73],[881.48,408.27],[812.99,388.6],[768.67,383.05]],[[588.52,18.48],[540.26,8.84]],[[769.95,386.66],[772.06,383.99]]]},{"family":"jitter 1","lines":[[[771.26,383.25],[810.21,388.63],[876.87,399.85],[904.86,416.34],[942.57,427.36],[960.48,441.57]],[[324.61,142.51],[427.79,126.31]],[[959.87,444.94],[933.02,438.97]],[[427.23,126.44],[447.59,88.03],[487.54,47.67],[552.98,26.98],[588.33,17.23]],[[933.74,436.09],[907.13,423.09],[876.42,405.32],[810.81,393.6],[770.83,386.95]],[[587.8,18.34],[541.61,9.14]],[[769.77,387.08],[771.22,385.51]]]},{"family":"jitter 1","lines":[[[770.81,383.25],[811.02,388.74],[876.73,399.71],[904.47,416.12],[941.58,427.12],[960.24,440.88]],[[324.76,142.51],[426.27,126.58]],[[961.62,437.4],[933.39,438.69]],[[427.97,125.83],[443.16,92.64],[487.48,47.66],[551.28,27.16],[588.41,18.41]],[[933.06,435.04],[908.57,424.73],[876.26,405.37],[810.94,393.52],[771.34,387.05]],[[586.77,18.13],[542.78,9.42]],[[769.83,388.33],[772.77,382.47]]]},{"family":"jitter 1","lines":[[[772.14,383.44],[812.87,389.03],[876.8,399.68],[903.84,415.87],[942.52,427.37],[961.73,442.59]],[[325.76,142.4],[426.57,126.45]],[[961.16,444.61],[933.48,437.89]],[[428.02,125.43],[443.38,92.34],[487.45,47.74],[551.75,26.99],[586.17,18.97]],[[934.44,436.1],[907.18,423.82],[887.59,406.88],[811.3,394.38],[771.18,382.81]],[[587.92,18.35],[542.72,9.38]],[[770.07,386.47],[770.24,383.75]]]},{"family":"jitter 2","lines":[[[772.22,383.42],[813.02,389.08],[877.05,399.84],[904.59,416.26],[942.16,427.27],[960.3,441.17]],[[320.62,143.24],[424.82,126.72]],[[959.31,444.76],[934.64,438.68]],[[426.47,128.58],[445.5,90.14],[487.52,47.67],[550.97,27.19],[586.62,18.71]],[[931.81,435.27],[909.03,423.97],[873.61,404.68],[809.39,393.84],[772.46,387.55]],[[585.88,18.0],[544.92,9.76]],[[771.27,386.68],[774.89,387.54]]]},{"family":"jitter 2","lines":[[[772.72,383.37],[812.07,388.94],[877.14,399.89],[904.05,415.94],[942.85,427.53],[961.36,442.41]],[[323.68,142.77],[425.9,126.54]],[[961.86,437.41],[931.81,437.68]],[[426.35,125.02],[463.47,72.1],[488.69,46.85],[551.76,27.09],[587.92,18.48]],[[937.39,437.12],[909.61,424.84],[873.93,403.92],[810.16,387.65],[771.27,383.47]],[[584.89,17.78],[541.42,9.12]],[[769.89,387.3],[773.03,382.91]]]},{"family":"jitter 2","lines":[[[772.31,383.54],[810.24,388.48],[877.01,399.81],[904.31,416.06],[942.28,427.38],[961.88,442.5]],[[324.64,142.57],[427.93,126.25]],[[962.58,438.38],[933.2,437.76]],[[426.71,125.46],[460.97,74.53],[487.55,47.71],[556.85,26.25],[583.7,13.9]],[[935.48,436.03],[908.63,425.74],[895.16,408.38],[810.65,393.7],[767.91,389.45]],[[589.01,18.7],[539.9,8.76]],[[770.53,389.83],[770.44,385.59]]]},{"family":"jitter 2","lines":[[[774.77,383.51],[812.31,388.96],[877.02,399.78],[901.34,413.41],[942.05,437.68],[962.28,438.4]],[[324.71,142.49],[425.08,126.77]],[[962.98,436.86],[934.82,439.43]],[[426.15,128.65],[455.08,80.49],[487.61,47.64],[555.65,25.99],[586.77,18.7]],[[932.23,434.75],[910.29,425.63],[876.12,405.29],[805.46,393.48],[769.56,381.46]],[[588.39,18.55],[540.58,8.87]],[[770.27,386.2],[773.57,382.79]]]},{"family":"jitter 2","lines":[[[770.68,383.19],[815.2,389.36],[876.91,399.81],[904.7,416.23],[942.88,427.61],[962.59,443.37]],[[325.55,142.39],[423.53,127.01]],[[956.5,445.36],[932.21,436.18]],[[428.2,126.0],[452.64,82.95],[487.62,47.57],[552.56,27.33],[589.15,14.26]],[[933.16,436.14],[907.37,422.9],[880.16,407.51],[813.21,388.35],[769.47,383.23]],[[589.34,18.74],[540.34,8.82]],[[769.9,386.78],[772.26,384.01]]]},{"family":"jitter 2","lines":[[[769.91,383.09],[811.41,388.82],[876.96,399.75],[904.05,416.01],[941.79,427.22],[960.61,441.09]],[[322.61,142.91],[428.15,126.19]],[[960.99,438.23],[932.09,438.01]],[[425.78,127.16],[441.92,93.81],[487.64,47.62],[549.02,27.66],[585.82,19.09]],[[931.92,434.56],[909.13,422.39],[875.75,399.77],[808.94,388.44],[771.43,383.27]],[[590.05,18.79],[538.21,8.49]],[[769.15,387.65],[774.61,380.81]]]},{"family":"jitter 2","lines":[[[774.25,383.74],[806.7,388.03],[877.08,399.74],[903.84,415.85],[942.88,427.62],[960.24,441.35]],[[323.3,142.75],[425.54,126.67]],[[963.41,445.83],[933.72,439.06]],[[426.45,125.05],[441.76,93.76],[488.48,46.97],[552.92,26.83],[589.76,17.79]],[[934.72,435.58],[910.76,423.29],[876.55,399.7],[810.78,388.65],[772.3,383.83]],[[587.01,18.28],[541.21,9.04]],[[770.53,390.77],[770.68,385.0]]]},{"family":"jitter 2","lines":[[[772.04,383.35],[810.99,388.76],[876.67,399.69],[904.27,416.04],[942.07,427.31],[961.93,442.45]],[[325.48,142.42],[426.79,126.5]],[[958.02,441.66],[929.53,435.11]],[[425.72,126.74],[442.17,93.54],[487.53,47.71],[547.49,28.16],[587.48,18.74]],[[930.64,434.91],[907.72,420.86],[874.99,398.69],[810.91,393.88],[769.3,388.59]],[[587.77,18.31],[539.62,8.78]],[[773.45,384.21],[773.69,383.86]]]},{"family":"jitter 2","lines":[[[768.15,382.85],[808.98,388.41],[876.69,399.8],[904.71,416.2],[941.72,427.2],[962.03,442.35]],[[326.24,142.25],[425.56,126.69]],[[960.32,446.17],[931.69,436.58]],[[426.11,125.9],[442.3,93.29],[487.69,47.6],[551.52,27.14],[583.6,19.56]],[[931.32,435.1],[909.68,424.59],[883.45,409.45],[814.46,388.63],[766.09,382.63]],[[589.49,18.74],[538.56,8.47]],[[770.15,386.19],[772.58,383.54]]]},{"family":"jitter 2","lines":[[[770.52,383.19],[808.68,388.4],[877.07,399.89],[904.05,415.88],[942.03,427.3],[960.77,441.44]],[[324.08,142.73],[428.53,126.12]],[[959.55,444.87],[932.91,438.85]],[[427.32,126.84],[444.7,91.11],[487.49,47.63],[553.94,26.59],[589.34,17.06]],[[933.98,436.05],[905.41,422.34],[876.53,405.42],[810.8,394.29],[771.62,382.7]],[[588.12,18.47],[541.22,9.02]],[[768.8,386.86],[770.48,387.39]]]},{"family":"jitter 2","lines":[[[769.62,383.0],[810.3,388.67],[876.94,399.84],[904.47,416.13],[941.53,427.09],[959.33,440.25]],[[324.45,142.6],[425.53,126.64]],[[961.58,437.66],[933.45,439.23]],[[426.83,124.71],[441.87,93.83],[487.56,47.62],[550.65,27.23],[589.22,18.29]],[[932.17,435.12],[909.07,424.02],[876.09,405.26],[811.14,393.67],[771.95,386.79]],[[586.02,18.03],[543.61,9.53]],[[768.83,389.33],[773.87,381.4]]]},{"family":"jitter 2","lines":[[[772.16,383.35],[814.04,389.19],[876.79,399.72],[904.99,416.37],[941.48,427.02],[962.78,443.02]],[[326.44,142.28],[426.14,126.54]],[[962.08,444.53],[933.49,438.01]],[[427.13,124.01],[442.1,93.45],[488.28,47.22],[551.55,27.04],[584.71,19.31]],[[935.11,436.57],[903.98,421.78],[887.88,406.88],[811.89,394.99],[771.11,382.08]],[[588.3,18.5],[543.37,9.49]],[[769.41,385.63],[768.51,383.88]]]},{"family":"jitter 3","lines":[[[772.31,383.49],[813.67,389.13],[876.81,399.74],[904.94,416.36],[942.35,427.42],[959.91,441.02]],[[318.41,143.66],[423.72,126.86]],[[958.86,445.41],[935.2,438.92]],[[425.56,129.65],[444.03,98.8],[488.4,53.87],[550.24,27.28],[585.5,13.71]],[[930.85,434.97],[910.37,422.01],[876.12,399.69],[809.28,388.33],[773.2,384.35]],[[585.27,17.76],[546.41,10.16]],[[773.33,383.61],[780.24,383.54]]]},{"family":"jitter 3","lines":[[[772.95,383.45],[812.3,388.98],[877.36,399.89],[904.38,416.15],[945.16,428.12],[960.17,444.39]],[[322.96,142.82],[425.36,126.68]],[[959.95,446.06],[931.38,435.86]],[[427.94,125.75],[447.08,96.2],[481.18,49.65],[551.69,27.53],[587.39,14.17]],[[939.54,440.33],[900.17,418.37],[881.11,400.55],[809.23,388.5],[771.26,383.28]],[[583.58,17.4],[541.11,9.08]],[[769.75,387.38],[773.21,382.44]]]},{"family":"jitter 3","lines":[[[772.55,383.47],[809.52,388.44],[877.24,399.98],[904.14,416.03],[942.73,427.48],[962.27,443.03]],[[324.4,142.62],[428.38,126.18]],[[962.19,441.42],[934.64,431.68]],[[426.23,125.09],[446.62,96.02],[488.37,53.83],[558.24,22.24],[582.07,12.88]],[[936.24,436.35],[913.23,424.12],[875.44,399.4],[811.46,389.08],[768.07,382.68]],[[590.04,18.83],[538.72,8.56]],[[770.24,391.23],[770.72,387.13]]]},{"family":"jitter 3","lines":[[[775.58,383.68],[812.53,389.01],[876.51,399.61],[899.98,412.31],[942.17,441.76],[961.03,444.66]],[[324.54,142.58],[424.1,126.88]],[[961.94,442.84],[936.82,434.97]],[[423.84,129.18],[446.09,96.76],[489.62,52.55],[558.79,31.29],[586.41,18.58]],[[931.37,434.41],[912.33,424.01],[890.19,407.71],[804.05,390.46],[767.77,382.53]],[[588.88,18.66],[539.78,8.76]],[[770.34,385.16],[775.29,382.09]]]},{"family":"jitter 3","lines":[[[770.02,383.1],[816.92,389.68],[876.39,399.65],[904.85,416.22],[944.56,428.1],[958.57,450.52]],[[325.82,142.46],[421.86,127.14]],[[954.99,445.43],[931.2,435.94]],[[427.97,125.69],[444.15,98.81],[497.33,44.53],[552.89,27.42],[589.7,11.38]],[[933.08,435.69],[906.38,423.02],[863.44,397.56],[813.84,389.14],[768.6,382.91]],[[590.3,18.92],[539.47,8.73]],[[770.04,387.68],[771.79,383.89]]]},{"family":"jitter 3","lines":[[[768.75,382.84],[811.26,388.8],[876.91,399.72],[904.46,416.15],[942.91,427.51],[960.65,441.39]],[[321.36,143.53],[428.83,125.94]],[[960.87,437.12],[931.73,436.42]],[[426.49,128.4],[444.65,97.92],[486.8,55.51],[547.51,28.18],[584.03,15.02]],[[930.88,434.26],[908.84,422.34],[876.91,399.9],[807.66,388.22],[771.5,383.29]],[[591.32,19.0],[536.32,8.2]],[[768.81,388.07],[775.92,379.49]]]},{"family":"jitter 3","lines":[[[775.08,383.84],[804.15,387.73],[877.15,399.87],[904.49,416.14],[941.04,427.02],[960.32,440.76]],[[322.43,142.96],[424.82,126.72]],[[964.57,448.15],[934.39,437.63]],[[427.96,125.8],[445.87,95.78],[482.99,48.91],[553.36,26.84],[590.74,15.65]],[[932.76,439.56],[923.51,426.67],[876.24,399.74],[810.44,388.66],[772.87,383.48]],[[587.09,18.19],[540.82,8.99]],[[770.32,392.64],[770.5,385.79]]]},{"family":"jitter 3","lines":[[[772.03,383.41],[810.65,388.71],[876.89,399.76],[904.1,415.98],[942.77,427.47],[962.18,443.12]],[[325.65,142.41],[426.69,126.47]],[[955.4,445.22],[927.74,433.26]],[[425.49,127.45],[442.05,93.5],[487.75,47.61],[545.36,29.39],[586.77,14.23]],[[928.03,436.24],[917.62,423.8],[876.87,399.81],[811.68,388.97],[769.8,382.94]],[[587.89,18.34],[538.45,8.53]],[[774.81,382.66],[774.55,383.98]]]},{"family":"jitter 3","lines":[[[766.17,382.52],[807.57,388.26],[876.46,399.76],[904.94,416.19],[942.02,427.28],[962.54,442.86]],[[326.77,142.18],[424.8,126.76]],[[960.32,447.33],[931.05,435.56]],[[426.64,126.3],[448.42,87.22],[488.14,47.05],[552.57,32.63],[582.36,25.03]],[[931.95,420.86],[914.61,427.44],[874.37,404.19],[815.97,388.49],[763.51,382.27]],[[590.49,18.9],[536.82,8.27]],[[770.41,385.24],[773.95,382.68]]]},{"family":"jitter 3","lines":[[[769.78,383.13],[807.15,388.12],[876.86,399.84],[904.93,416.35],[942.52,427.42],[960.97,442.06]],[[323.39,142.65],[429.3,126.17]],[[958.78,446.76],[933.26,436.55]],[[425.52,126.39],[441.89,102.24],[497.39,44.48],[554.99,26.5],[589.53,13.53]],[[937.62,426.62],[906.11,415.8],[873.1,401.87],[811.96,388.86],[771.59,383.35]],[[588.54,18.5],[540.77,8.94]],[[771.29,384.14],[772.31,387.4]]]},{"family":"jitter 3","lines":[[[768.34,383.02],[809.62,388.44],[876.6,399.66],[904.61,416.22],[941.65,427.14],[958.44,439.58]],[[324.14,142.7],[424.82,126.71]],[[961.88,437.84],[933.52,440.08]],[[428.45,125.19],[453.91,81.73],[490.19,45.06],[551.18,32.7],[590.87,21.85]],[[934.82,425.1],[907.11,417.06],[899.61,413.06],[812.48,388.4],[773.09,383.53]],[[585.32,17.79],[544.4,9.73]],[[768.9,390.66],[774.21,380.09]]]},{"family":"jitter 3","lines":[[[772.06,383.54],[815.22,389.34],[876.79,399.75],[904.5,416.18],[942.54,427.38],[963.4,443.87]],[[327.12,142.16],[425.71,126.65]],[[962.85,445.63],[933.36,438.91]],[[428.59,124.08],[456.81,78.68],[487.74,47.67],[551.44,28.06],[582.39,13.41]],[[936.05,436.4],[908.73,421.99],[876.18,399.62],[813.71,389.19],[770.56,383.14]],[[588.7,18.64],[543.93,9.54]],[[768.75,384.79],[766.77,384.0]]]}]}}} \ No newline at end of file diff --git a/surfaces/blender/tests/live/reference_block.py b/surfaces/blender/tests/live/reference_block.py new file mode 100644 index 0000000..2cd1627 --- /dev/null +++ b/surfaces/blender/tests/live/reference_block.py @@ -0,0 +1,245 @@ +"""Live proof, in a background Blender, of brokkr_reference.block_plate through run_intent. + +A plate stands in a frame turned and moved in the world: an empty, "Frame". Its truth is a five-sided crown with +bowed sides, built by brokkr_kitbash.shell from core.plate_sheet, and two cameras 60 degrees apart look at it. Each +side is traced in both views where Blender's own projection draws the side as core.crease_run builds it. Then: + + block_plate from the frame, the corner names and the ten traces, no blocking: a sheet with every trace + explained, each corner decided by the views, nothing written to the scene + built brokkr_kitbash.shell takes the sheet without refusal, and at one level Blender builds each crown + side where core.crease_run says + fit_shell with the returned fit_traces on the built plate: accepted, every trace explained, and no point + moved over MOVED (fairness holds a bowed side in and fit_shell's own prior lets it out: + tests/test_reference.py test_the_blocking_goes_to_the_parser_and_to_fit_shell reads 74 mm of + it where a pixel is 27 mm; here a pixel is 5 mm). MOVED, GAP and GAP_MIRRORED each stand between + this scene's reading and a mutant's + mirrored a mirrored plate with two seam corners, traced the same way: the seam stays on x = 0, + brokkr_kitbash.shell builds both halves, and Blender builds the seam's side and a free side where + core.crease_run says + refusals a scaled frame, an unknown camera and a side nobody traced, each a failed receipt naming its cause + + blender --background --factory-startup --python-exit-code 1 --python surfaces/blender/tests/live/reference_block.py -- + +Run it with private BLENDER_USER_CONFIG, BLENDER_USER_EXTENSIONS and BLENDER_USER_SCRIPTS directories (it refuses +without them). is an absolute path: it writes .result.json and exits 1 when a check failed. Not part +of the unittest run: it needs Blender. +""" +import json +import math +import os +import sys +import tempfile +import time +import traceback +import types +from pathlib import Path + +import bpy +import numpy as np +from bpy_extras.object_utils import world_to_camera_view +from mathutils import Euler, Matrix, Vector + +SURFACE = Path(__file__).resolve().parents[2] +sys.path.insert(0, str(SURFACE / "tools")) +import private_dirs # noqa: E402 + +_refused = private_dirs.refusal(os.environ, os.path.expanduser("~"), lambda kind: bpy.utils.user_resource(kind)) +if _refused: + raise SystemExit(_refused) +OUT = sys.argv[sys.argv.index("--") + 1] +if not os.path.isabs(OUT): + raise SystemExit(f" must be an absolute path, not {OUT!r}: a relative one lands in Blender's start directory") +package = types.ModuleType("brokkr_bridge") +package.__path__ = [str(SURFACE / "brokkr_bridge")] +sys.modules["brokkr_bridge"] = package +from brokkr_bridge import blender_target as bt # noqa: E402 + +import addon_utils # noqa: E402 + +sys.path.append(str(SURFACE)) +bpy.ops.wm.read_factory_settings(use_empty=True) +for module in ("brokkr_mesh_polish", "brokkr_kitbash", "brokkr_reference"): + addon_utils.enable(module, default_set=True) +from brokkr_reference import core # noqa: E402 + +target = bt.BrokkrBlenderTarget(bpy) +target.configure_action_dirs("", tempfile.mkdtemp(prefix="brokkr-reference-block-live-")) +target.reload_host_actions() +R = {"blender": bpy.app.version_string, "checks": [], "hostErrors": target.host_actions()[1], + "hostRows": [row["name"] for row in target.host_actions()[0]]} +COUNT = [0] +T0 = time.time() +WIDTH, HEIGHT = 1000, 800 +MOVED, GAP, GAP_MIRRORED = 0.0165, 0.0088, 0.0273 # metres, each the geometric mean of this scene's reading and its least mutant's (lodur:ruling:deterministic-bound-margin), the mutants run through this script on a copy of the surface: fit_shell moves a point of the blocked plate 0.0048 (FAIR 0.05: 0.0565), the blocked crown stands 0.0027 from its truth (FAIR 0.05: 0.0288), the mirrored crown 0.0140 (FAIR 0.05: 0.0534; no end terms: 0.0646). Separations 3.4, 3.3 and 1.95 each side. A pixel is 5 mm here and the traces are exact, where weaker fairness reads nearer (FAIR 0.5: 0.0011, 0.0018, 0.0054): tests/test_reference.py test_fairness_is_set_by_the_rendered_roof says why 0.2 stands + + +def check(name, ok, detail=None): + R["checks"].append({"name": name, "ok": bool(ok), "detail": detail}) + + +def send(action, **fields): + COUNT[0] += 1 + receipt = target.run_intent(bpy.context, {"commandId": f"live-{COUNT[0]}", "requestedBy": "test/driver", "action": action, **fields}) + result = json.loads(receipt["hostResult"]) if receipt.get("hostResult") else None + print("SEND", f"{time.time() - T0:.1f}s", action, receipt["status"], str(receipt["message"])[:400], flush=True) + return receipt, result + + +def built(chain): + return core.crease_run(core.crease_run(np.asarray(chain, float))) + + +def pentagon(): + """Five sides as five-point cage chains: a plate 1.2 m across facing -y, its corners up to 0.15 m off the plane + y = 0, each side bowed 8% of its length toward -y and 35% outward in the plate.""" + angles = [2 * math.pi * i / 5 + 0.3 for i in range(5)] + P = np.array([[0.6 * math.cos(t), 0.15 * math.cos(2 * t), 0.6 * math.sin(t)] for t in angles]) + s, sides = np.linspace(0, 1, 5)[:, None], [] + for a, b in zip(P, np.roll(P, -1, axis=0)): + sides.append(a + s * (b - a) + np.sin(math.pi * s) * np.linalg.norm(b - a) * (0.08 * np.array([0, -1.0, 0]) + 0.35 * (a + b) / np.linalg.norm(a + b))) + return sides + + +def half(): + """A mirrored plate's authored half as chains: the seam's side on x = 0, bowed in the plane, and three free sides.""" + P = np.array([[0.0, 0.0, 0.5], [0.0, 0.0, -0.5], [0.5, 0.1, -0.4], [0.3, 0.1, 0.4]]) + s, sides = np.linspace(0, 1, 5)[:, None], [] + for i, (a, b) in enumerate(zip(P, np.roll(P, -1, axis=0))): + bow = np.array([0.0, -0.3, 0.0]) if i == 0 else np.array([0.25, -0.1, 0.0]) if i == 1 else np.zeros(3) + sides.append(a + s * (b - a) + np.sin(math.pi * s) * np.linalg.norm(b - a) * bow) + return sides + + +def pixels(camera, frame, points, side=1): + out = [] + for p in np.asarray(points, float) * [side, 1, 1]: + x, y, _ = world_to_camera_view(bpy.context.scene, camera, frame.matrix_world @ Vector(p)) + out.append([round(x * WIDTH, 3), round((1.0 - y) * HEIGHT, 3)]) + return out + + +def chains_of(out): + n, first, chains = sum(side["points"] - 1 for side in out["sides"]), 0, [] + for side in out["sides"]: + chains.append([(first + m) % n for m in range(side["points"])]) + first += side["points"] - 1 + return chains + + +def at_one_level(name, sheet, chains, mirror=False): + """The furthest a crown side as core.crease_run builds it at one level stands from a vertex Blender built.""" + send("brokkr_kitbash.shell", object_name=name, sheet=json.dumps(sheet), thickness=0.03, levels=1) + shell = bpy.data.objects[name] + wall = shell.modifiers["Kit Solidify"] + wall.show_viewport = False + mesh = np.array([v.co for v in shell.evaluated_get(bpy.context.evaluated_depsgraph_get()).to_mesh().vertices]) + wall.show_viewport = True + verts = np.array(sheet["verts"]) + return max(float(np.linalg.norm(mesh - p * [side, 1, 1], axis=1).min()) for chain in chains for side in ((1, -1) if mirror else (1,)) for p in core.crease_run(verts[chain])) + + +def snapshot(): + return sorted((o.name, o.type, tuple(round(c, 6) for row in o.matrix_world for c in row), o.get("kit_shell")) for o in bpy.data.objects) + + +try: + check("host files admitted with the block_plate row", not R["hostErrors"] and "brokkr_reference.block_plate" in R["hostRows"], R["hostErrors"] or R["hostRows"][-4:]) + scene = bpy.context.scene + scene.render.resolution_x, scene.render.resolution_y, scene.render.resolution_percentage = WIDTH, HEIGHT, 100 + frame = bpy.data.objects.new("Frame", None) + scene.collection.objects.link(frame) + frame.matrix_world = Matrix.Translation((0.3, -0.2, 1.0)) @ Euler((0.0, 0.0, math.radians(15.0))).to_matrix().to_4x4() + cameras = [] + for name, azimuth in (("A", 15.0), ("B", 75.0)): + camera = bpy.data.objects.new(name, bpy.data.cameras.new(name)) + scene.collection.objects.link(camera) + camera.data.lens, camera.data.sensor_fit = 50.0, "HORIZONTAL" + a = math.radians(azimuth) + camera.location = Vector((0.3, -0.2, 1.0)) + 7.0 * Vector((math.sin(a), -math.cos(a), 0.15)) + camera.rotation_euler = (Vector((0.3, -0.2, 1.0)) - camera.location).to_track_quat("-Z", "Y").to_euler() + cameras.append(camera) + bpy.context.view_layer.update() + + # --- the truth, built by brokkr_kitbash.shell, and its sides traced in both views ------------------------------- + names = [f"c{i}" for i in range(5)] + sides = pentagon() + crown = np.concatenate([side[:-1] for side in sides]) + truth = core.plate_sheet(crown, [0, 4, 8, 12, 16], facing=[0.0, -1.0, 0.0]) + made, _ = send("brokkr_kitbash.shell", object_name="Truth", sheet=json.dumps(truth), thickness=0.03, levels=2) + bpy.data.objects["Truth"].matrix_world = frame.matrix_world + bpy.context.view_layer.update() + traces = [{"camera": camera.name, "from": names[i], "to": names[(i + 1) % 5], "side": 1, "line": pixels(camera, frame, core.resampled(built(side), 24))} for i, side in enumerate(sides) for camera in cameras] + inside = all(0 <= u <= WIDTH and 0 <= v <= HEIGHT for trace in traces for u, v in trace["line"]) + check("brokkr_kitbash.shell builds the truth from core.plate_sheet, and both cameras frame every side", made["status"] == "accepted" and inside, made["message"]) + + # --- block_plate ------------------------------------------------------------------------------------------------------ + before = snapshot() + receipt, out = send("brokkr_reference.block_plate", frame_object="Frame", plate=json.dumps({"corners": names}), traces=json.dumps(traces, separators=(",", ":"))) + ok = receipt["status"] == "accepted" and out is not None + check(f"block_plate returns a sheet with every trace explained within {core.TOL:g} px and each corner decided by the views", + ok and max(row["unexplained_px"] for side in out["sides"] for row in side["traces"]) <= core.TOL and {corner["decided_by"] for corner in out["corners"]} == {"views"} + and len(receipt["hostResult"]) < 16000, + out and {"sides": [side["points"] for side in out["sides"]], "corners": [[corner["parallax_deg"], corner["m_per_px"], corner["prior_share"]] for corner in out["corners"]], + "rounds": out["rounds"], "seconds": out["seconds"], "chars": len(receipt["hostResult"])} or receipt["message"]) + check("block_plate wrote nothing: every object is as it was", snapshot() == before) + if ok: + chains = chains_of(out) + verts = np.array(out["sheet"]["verts"]) + gap = max(float(core._off(built(verts[chain]), core.resampled(built(side), 400)).max()) for chain, side in zip(chains, sides)) + check(f"the blocked crown as built stands within {GAP:g} m of the truth's", gap < GAP, gap) + worst = at_one_level("Blocked", out["sheet"], chains) + check("brokkr_kitbash.shell takes the blocked sheet, and at one level Blender builds every crown side where core.crease_run says, within 1e-4 m", + "Blocked" in bpy.data.objects and worst < 1e-4, worst) + applied, _ = send("brokkr_kitbash.shell", object_name="Blocked", sheet=json.dumps(out["sheet"]), thickness=0.03, levels=2) + bpy.data.objects["Blocked"].matrix_world = frame.matrix_world + bpy.context.view_layer.update() + receipt, fit = send("brokkr_reference.fit_shell", object_name="Blocked", traces=json.dumps(out["fit_traces"], separators=(",", ":"))) + moved = fit and max(point["moved_m"] for point in fit["points"]) + check(f"fit_shell takes the returned fit_traces on the built plate: accepted, every trace explained, no point moved over {MOVED:g} m", + applied["status"] == "accepted" and receipt["status"] == "accepted" and len(out["fit_traces"]) == 10 and out["left_out"] == [] and moved < MOVED + and max(row["unexplained_px"] for row in fit["traces"]) <= core.TOL, {"moved_m": moved} if fit else receipt["message"]) + + # --- a mirrored plate --------------------------------------------------------------------------------------------------- + names = ["top", "bottom", "low", "high"] + sides = half() + traces = [{"camera": camera.name, "from": names[i], "to": names[(i + 1) % 4], "side": side_, "line": pixels(camera, frame, core.resampled(built(side), 24), side_)} + for i, side in enumerate(sides) for camera, side_ in ((cameras[0], 1), (cameras[1], 1), (cameras[0], -1))] + traces = [trace for trace in traces if not (trace["from"] == "top" and trace["side"] == -1)] # the seam's side is its own reflection + receipt, out = send("brokkr_reference.block_plate", frame_object="Frame", plate=json.dumps({"corners": names, "mirror": True, "seam": ["top", "bottom"]}), + traces=json.dumps(traces, separators=(",", ":"))) + ok = receipt["status"] == "accepted" and out is not None + if ok: + chains = chains_of(out) + verts = np.array(out["sheet"]["verts"]) + gap = max(float(core._off(built(verts[chain]), core.resampled(built(side), 400)).max()) for chain, side in zip(chains, sides)) + check(f"a mirrored plate: the seam's corners are decided by the mirror plane, its side stays on x = 0, and the crown as built stands within {GAP_MIRRORED:g} m of the truth's", + [corner["decided_by"] for corner in out["corners"]][:2] == ["mirror", "mirror"] and float(np.abs(verts[chains[0], 0]).max()) == 0.0 and gap < GAP_MIRRORED, + {"gap": gap, "sides": [side["points"] for side in out["sides"]], "corners": [corner["decided_by"] for corner in out["corners"]], "poles": out["sheet"]["poles"]}) + worst = at_one_level("Mirrored", out["sheet"], chains, mirror=True) + check("brokkr_kitbash.shell builds both halves of the mirrored sheet, and at one level Blender builds the seam's side and the free sides, on both halves, where core.crease_run says, within 1e-4 m", + "Mirrored" in bpy.data.objects and worst < 1e-4, worst) + else: + check("block_plate blocks a mirrored plate", False, receipt["message"]) + + # --- refusals --------------------------------------------------------------------------------------------------------- + before = snapshot() + plate, text = json.dumps({"corners": names, "mirror": True, "seam": ["top", "bottom"]}), json.dumps(traces, separators=(",", ":")) + receipt, _ = send("brokkr_reference.block_plate", frame_object="Frame", plate=plate, traces=json.dumps([dict(traces[0], camera="Nobody")] + traces[1:], separators=(",", ":"))) + check("an unknown camera is refused naming the trace", receipt["status"] == "failed" and "traces[0]" in receipt["message"] and "Nobody" in receipt["message"], receipt["message"]) + receipt, _ = send("brokkr_reference.block_plate", frame_object="Frame", plate=plate, traces=json.dumps([trace for trace in traces if trace["from"] != "low"], separators=(",", ":"))) + check("a side nobody traced is refused by its corners' names", receipt["status"] == "failed" and "the side from 'low' to 'high' is traced in no view" in receipt["message"], receipt["message"]) + receipt, _ = send("brokkr_reference.block_plate", frame_object="Frame", plate=plate, traces=text, plane="0,0,0; 0,0") + check("a plane that is not a point and a normal is refused", receipt["status"] == "failed" and "plane" in receipt["message"], receipt["message"]) + check("no refusal changed the scene", snapshot() == before) + frame.scale = (2.0, 2.0, 2.0) + bpy.context.view_layer.update() + receipt, _ = send("brokkr_reference.block_plate", frame_object="Frame", plate=plate, traces=text) + check("a scaled frame is refused", receipt["status"] == "failed" and "scaled" in receipt["message"], receipt["message"]) +except Exception: # noqa: BLE001 whatever it was, it is a failed check with a name, printed and written, not a missing result file + check(f"no uncaught error after: {R['checks'][-1]['name'] if R['checks'] else 'the start'}", False, traceback.format_exc().splitlines()[-6:]) + +R["ok"] = all(c["ok"] for c in R["checks"]) +for c in R["checks"]: + print("CHECK", "ok " if c["ok"] else "FAIL", c["name"], "" if c["ok"] else c["detail"], flush=True) +Path(OUT + ".result.json").write_text(json.dumps(R, indent=1, default=str), encoding="utf-8") +sys.exit(0 if R["ok"] else 1) diff --git a/surfaces/blender/tests/live/reference_block.result.json b/surfaces/blender/tests/live/reference_block.result.json new file mode 100644 index 0000000..5af413c --- /dev/null +++ b/surfaces/blender/tests/live/reference_block.result.json @@ -0,0 +1,175 @@ +{ + "blender": "5.3.0", + "checks": [ + { + "name": "host files admitted with the block_plate row", + "ok": true, + "detail": [ + "brokkr_reference.solve_camera", + "brokkr_reference.flow_score", + "brokkr_reference.fit_shell", + "brokkr_reference.block_plate" + ] + }, + { + "name": "brokkr_kitbash.shell builds the truth from core.plate_sheet, and both cameras frame every side", + "ok": true, + "detail": "Operator brokkr_kitbash.shell finished." + }, + { + "name": "block_plate returns a sheet with every trace explained within 5.2 px and each corner decided by the views", + "ok": true, + "detail": { + "sides": [ + 3, + 3, + 3, + 3, + 3 + ], + "corners": [ + [ + 60.6, + 0.0031, + 0.019 + ], + [ + 61.0, + 0.0042, + 0.026 + ], + [ + 56.4, + 0.0035, + 0.022 + ], + [ + 57.3, + 0.0036, + 0.022 + ], + [ + 60.1, + 0.0037, + 0.023 + ] + ], + "rounds": 2, + "seconds": 0.137, + "chars": 7703 + } + }, + { + "name": "block_plate wrote nothing: every object is as it was", + "ok": true, + "detail": null + }, + { + "name": "the blocked crown as built stands within 0.0088 m of the truth's", + "ok": true, + "detail": 0.002711610846938251 + }, + { + "name": "brokkr_kitbash.shell takes the blocked sheet, and at one level Blender builds every crown side where core.crease_run says, within 1e-4 m", + "ok": true, + "detail": 1.1421151381392388e-07 + }, + { + "name": "fit_shell takes the returned fit_traces on the built plate: accepted, every trace explained, no point moved over 0.0165 m", + "ok": true, + "detail": { + "moved_m": 0.0048 + } + }, + { + "name": "a mirrored plate: the seam's corners are decided by the mirror plane, its side stays on x = 0, and the crown as built stands within 0.0273 m of the truth's", + "ok": true, + "detail": { + "gap": 0.013972102623404082, + "sides": [ + 3, + 3, + 2, + 2 + ], + "corners": [ + "mirror", + "mirror", + "views", + "views" + ], + "poles": [ + 0, + 2, + 11 + ] + } + }, + { + "name": "brokkr_kitbash.shell builds both halves of the mirrored sheet, and at one level Blender builds the seam's side and the free sides, on both halves, where core.crease_run says, within 1e-4 m", + "ok": true, + "detail": 8.42242114374928e-08 + }, + { + "name": "an unknown camera is refused naming the trace", + "ok": true, + "detail": "Error: traces[0]: 'Nobody' is not a camera object." + }, + { + "name": "a side nobody traced is refused by its corners' names", + "ok": true, + "detail": "Error: the side from 'low' to 'high' is traced in no view: every side of the outline is traced, or the plate is given fewer corners. Nothing changed." + }, + { + "name": "a plane that is not a point and a normal is refused", + "ok": true, + "detail": "Error: plane's normal '0,0' is not 3 finite numbers with commas between." + }, + { + "name": "no refusal changed the scene", + "ok": true, + "detail": null + }, + { + "name": "a scaled frame is refused", + "ok": true, + "detail": "Error: frame_object 'Frame' is scaled (2.0, 2.0, 2.0): a plate is in metres of its frame. Apply or clear the scale." + } + ], + "hostErrors": [], + "hostRows": [ + "brokkr_mesh_polish.audit", + "brokkr_mesh_polish.repair", + "brokkr_mesh_polish.orient", + "brokkr_mesh_polish.delight", + "brokkr_mesh_polish.scrub_markings", + "brokkr_mesh_polish.cut_parts", + "brokkr_mesh_polish.pick", + "brokkr_kitbash.place_part", + "brokkr_kitbash.set_params", + "brokkr_kitbash.describe", + "brokkr_kitbash.report", + "brokkr_kitbash.attach", + "brokkr_kitbash.detach", + "brokkr_kitbash.roll", + "brokkr_kitbash.aim", + "brokkr_kitbash.reach", + "brokkr_kitbash.joint", + "brokkr_kitbash.slide", + "brokkr_kitbash.joints", + "brokkr_kitbash.close", + "brokkr_kitbash.boolean", + "brokkr_kitbash.cut", + "brokkr_kitbash.cut_many", + "brokkr_kitbash.freeze", + "brokkr_kitbash.thaw", + "brokkr_kitbash.ribs", + "brokkr_kitbash.shell", + "brokkr_kitbash.hose", + "brokkr_reference.solve_camera", + "brokkr_reference.flow_score", + "brokkr_reference.fit_shell", + "brokkr_reference.block_plate" + ], + "ok": true +} \ No newline at end of file diff --git a/surfaces/blender/tests/test_reference.py b/surfaces/blender/tests/test_reference.py index db8af73..db7fcf5 100644 --- a/surfaces/blender/tests/test_reference.py +++ b/surfaces/blender/tests/test_reference.py @@ -717,6 +717,538 @@ class FitTests(unittest.TestCase): core.fit_sheet(sheet_, kit.sheet(sheet_), FIT_FRAME, traces, cams) +EYE = [[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]] +PLATE = [f"c{i}" for i in range(5)] +ON_Y = {"point": [0, 0, 0], "normal": [0, 1, 0]} + + +def plate_camera(azimuth, distance=17.6, f=663.0): + """A camera `distance` off the origin, level, turned `azimuth` degrees from looking along +y: Paladin's hero's + lens and range (663 px, 17.6 m).""" + a = math.radians(azimuth) + C = distance * np.array([math.sin(a), -math.cos(a), 0.0]) + right = np.cross(-C / distance, [0, 0, 1.0]) + right /= np.linalg.norm(right) + return {"C": C.tolist(), "R": np.stack([right, np.cross(right, -C / distance), C / distance]).tolist(), "f": f, "c": [500.0, 500.0]} + + +def pentagon(bow, lateral=0.0, twist=0.15): + """The sides of a pentagon plate 1.2 m across facing -y, as five-point cage chains: its corners `twist` metres + off the plane y = 0 (a twisted plate), each side bowed `bow` of its length toward -y, which a view from there + sees end on, and `lateral` of it outward in the plate.""" + angles = [2 * math.pi * i / 5 + 0.3 for i in range(5)] + P = np.array([[0.6 * math.cos(t), twist * math.cos(2 * t), 0.6 * math.sin(t)] for t in angles]) + s, sides = np.linspace(0, 1, 5)[:, None], [] + for a, b in zip(P, np.roll(P, -1, axis=0)): + sides.append(a + s * (b - a) + np.sin(math.pi * s) * np.linalg.norm(b - a) * (bow * np.array([0, -1.0, 0]) + lateral * (a + b) / np.linalg.norm(a + b))) + return sides + + +def plate_traces(cams, sides, sigma=0.0, seed=7): + """(views, traces) of a plate's sides as built, drawn through each camera in 12 points, `sigma` px of noise.""" + rng, views, traces = np.random.default_rng(seed), [], [] + for i, side in enumerate(sides): + for k, cam in enumerate(cams): + u = core.resampled(core.project(cam, core.crease_run(core.crease_run(side))), 12) + traces.append({"camera": f"View{k}", "from": PLATE[i], "to": PLATE[(i + 1) % 5], "side": 1, "line": (u + rng.normal(0, sigma, u.shape)).tolist()}) + views.append((cam, EYE)) + return views, traces + + +def crown_chains(out): + """Per side of a block_plate report, its crown vertices in the sheet.""" + n, first, chains = sum(side["points"] - 1 for side in out["sides"]), 0, [] + for side in out["sides"]: + chains.append([(first + m) % n for m in range(side["points"])]) + first += side["points"] - 1 + return chains + + +def off_run(out, chain, truth): + """The furthest a blocked side as built stands from a true cage chain as built, metres.""" + built = core.crease_run(core.crease_run(np.array(out["sheet"]["verts"])[chain])) + return core._off(built, core.resampled(core.crease_run(core.crease_run(np.asarray(truth, float))), 400)) + + +def off_plate(out, sides): + return max(float(off_run(out, chain, side).max()) for chain, side in zip(crown_chains(out), sides)) + + +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, take=None, off=None): + """(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. The strokes are the fixture's + own, searched from the truth's projection, or those of its `take`, searched from a seed off it, or with + `off` (d, degrees) no search at all: the truth's projection, each point of each stroke in turn moved d px + in its own direction.""" + 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), [], [] + turns = iter(np.radians(off[1])) if off else None + for k, stroke in enumerate(plate["strokes"]): + line = np.array(stroke["line"] if take is None else plate["takes"][take]["lines"][k]) + if off: + line = core.seen(fixture["cameras"][stroke["view"]], fixture["frames"][stroke["view"]], np.array([plate["truth"][corner] for corner in stroke["through"]]) * [stroke["side"], 1, 1]) + line = line + off[0] * np.array([[math.cos(turn), math.sin(turn)] for _, turn in zip(line, turns)]) + line = line + (rng.normal(0, sigma, line.shape) 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_projection(fixture, plate, take): + """The furthest a point of a take's strokes stands from the truth's projection, px.""" + worst = 0.0 + for stroke, line in zip(plate["strokes"], plate["takes"][take]["lines"]): + drawn = core.seen(fixture["cameras"][stroke["view"]], fixture["frames"][stroke["view"]], np.array([plate["truth"][corner] for corner in stroke["through"]]) * [stroke["side"], 1, 1]) + worst = max(worst, float(np.linalg.norm(np.array(line) - drawn, axis=1).max())) + return worst + + +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, test_every_point_as_far_off_bounds_the_rendered_roof + 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 + 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, T08, T2, T26, T3 START 0.6, 0.8, 2.0, 2.6, 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 + + 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: 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)) + self.assertLess(off_plate(out, sides), most, (apart, sigma)) + 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, T06, T3, T08, T2, T26 (Soul s2, start-unpinned-and-comment-stale). 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; with no plane a plate blocks when three corners start. START is 1, the prior's own + unit: it is not derived from a measurement, it is pinned between two. At Paladin's lens and range the + pentagon's third corner starts at START 0.724 with the views 19 degrees apart, 0.831 at 16.5 and 2.729 at 5; + at 11 this test's plate (0.5 px, seed 7) turns from refused to blocked between START 1.22 and 1.23. So + at 16.5 degrees it blocks with no plane (73.0 mm from the truth) and at 11 it is refused naming its + corners: 1 stands 1.20 over the one reading and 1.22 under the other, the two's geometric mean within + 1%. START 0.6 and 0.8 refuse the 16.5 degrees; 2.0, 2.6 and 3.3 block the 11 (104.4 + mm off; the line switches blocking and refusal and is no cliff in accuracy). At 5 degrees the corners + triangulate 0.25 to 1.5 m off: with a plane every corner is decided by it (prior_share 0.795 to 0.838), + with none the plate is refused. The line is metres a pixel, not degrees: through a lens three times as + long the same plate 7 degrees apart starts at 0.648 and blocks from its views, 60.5 mm from the truth + (65.0 at 19 degrees through the short lens).""" + sides = pentagon(0.08) + self.assertEqual(blocked_plate(*plate_traces([plate_camera(0), plate_camera(16.5)], sides, 0.5))["plane"]["from"], "corners") + with self.assertRaisesRegex(core.ReferenceFitError, r"^plane: none was given, and 'c0', 'c1', 'c2', 'c3', 'c4' are decided by no view"): + blocked_plate(*plate_traces([plate_camera(0), plate_camera(11)], sides, 0.5)) + 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 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 + draws its twisted corners in). Sides bowed 35% of their length in the plate grow to three points and every + trace reads under 1 px; M6 refuses the plate, its first side not explained at two points. The grown crown + ends 41.6 mm off: fairness holds the bow in while the traces stay explained (M4, in the class's notes).""" + cams = [plate_camera(0), plate_camera(60)] + out = blocked_plate(*plate_traces(cams, pentagon(0.0))) + self.assertEqual(([side["points"] for side in out["sides"]], out["rounds"], len(out["sheet"]["verts"])), ([2] * 5, 1, 11)) + self.assertLess(off_plate(out, pentagon(0.0)), 0.004) + sides = pentagon(0.08, 0.35) + out = blocked_plate(*plate_traces(cams, sides)) + self.assertEqual(([side["points"] for side in out["sides"]], out["rounds"], len(out["sheet"]["verts"])), ([3] * 5, 2, 21)) + 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 + crown ends 85.1 mm off the truth. M2, which holds each point where it was started instead of to the plane, + ends 109.7 mm off: the bound is their geometric mean, separation 1.14 each side (1.29 across), the least + the ruling takes.""" + sides = pentagon(0.0, 0.35, twist=0.0) + out = blocked_plate(*plate_traces([plate_camera(30)], sides), plane=ON_Y) + self.assertEqual([corner["decided_by"] for corner in out["corners"]], ["plane"] * 5) + self.assertEqual([corner["parallax_deg"] for corner in out["corners"]], [0.0] * 5) + self.assertEqual([side["points"] for side in out["sides"]], [3] * 5) + self.assertLess(off_plate(out, sides), 0.0966) + + def test_a_plane_far_off_square_on_to_its_one_view_is_refused(self): + """M5: the guard promoted from the Paladin harness (paladin_limbs.plate, the 8 m pauldron). One view 64 + degrees off the plane's normal blocks the plate on it; at 68 degrees (cosine 0.375, under core.SQUARE) the + plate is refused naming the corner, the trace and the angle. M5 blocks it.""" + sides = pentagon(0.0, twist=0.0) + out = blocked_plate(*plate_traces([plate_camera(64)], sides), plane=ON_Y) + self.assertLess(off_plate(out, sides), 1e-4) + with self.assertRaisesRegex(core.ReferenceFitError, r"^plate\.corners\[0\] 'c0': the plane stands 67 degrees off square-on to the view of traces\[0\]"): + blocked_plate(*plate_traces([plate_camera(68)], sides), plane=ON_Y) + + def spectre(self, name): + fixture = json.loads((Path(__file__).resolve().parent / "fixtures" / "spectre_plates.json").read_text(encoding="utf-8")) + plate = fixture["plates"][name] + traces = [{"camera": trace["view"], **{key: trace[key] for key in ("from", "to", "side", "line")}, **({"frame": fixture["frames"]["hero"]} if trace["view"] == "hero" else {})} for trace in plate["traces"]] + return fixture, plate, core.block_plate([(fixture["cameras"][trace["view"]], fixture["frames"][trace["view"]]) for trace in plate["traces"]], plate["plate"], traces, kit.sheet) + + def test_spectre_roof_and_cheek(self): + """block-spectre, M1, M3, M6. SPECTRE's roof and cheek from no blocking (tests/fixtures/spectre_plates.json: + the brow, ridge and chine are hand traces, the sides nobody traced are edges of the fitted cage). Roof: the + brow's free corner is decided by the views (62.8 degrees, prior_share 0.054), the ridge's two by the mirror + plane; the ridge, traced in the side view alone, is built 7.3 mm at most from the fitted ridge and the brow + a median of 8.4 mm from the fitted brow (78.6 at most), in four points. M1 reads 27.7 and 18.9 (M4 19.8 on the brow): the bounds + are the geometric means, separations 1.95 and 1.50 each side. Cheek: the jaw, where the two hand traces + disagree by 0.27 m, stays on x = 0. M3 lands the roof's nose at x = -0.049 and the jaw at -0.140 and the + cage's parser refuses both; M1 puts the cheek's skirt across the plane and it is refused; M6 refuses both + at two points a side.""" + fixture, plate, out = self.spectre("roof") + self.assertEqual([(corner["name"], corner["decided_by"]) for corner in out["corners"]], [("ridge_rear", "mirror"), ("nose", "mirror"), ("brow_rear", "views")]) + self.assertLess(out["corners"][2]["prior_share"], core.VIEWS / 1.2) + self.assertGreater(out["corners"][2]["parallax_deg"], 60) + ridge, brow, rear = crown_chains(out) + self.assertEqual([side["points"] for side in out["sides"]], [2, 4, 2]) + self.assertLess(float(off_run(out, ridge, plate["reference"]["ridge"]).max()), 0.0142) + self.assertLess(float(np.median(off_run(out, brow, plate["reference"]["brow"]))), 0.0126) + verts = np.array(out["sheet"]["verts"]) + self.assertEqual(float(np.abs(verts[ridge, 0]).max()), 0.0) + self.assertEqual(out["left_out"], [1, 3]) # the hero poses the hull 3 degrees down: fit_shell has one frame + self.assertEqual([trace["run"] for trace in out["fit_traces"]], [{"verts": ridge}, {"verts": brow[::-1]}, {"verts": rear}]) + fixture, plate, out = self.spectre("cheek") + self.assertEqual([(corner["name"], corner["decided_by"]) for corner in out["corners"]], [("chine_rear", "views"), ("jaw", "mirror"), ("chin", "mirror")]) + chine, seam, _ = crown_chains(out) + self.assertEqual([float(x) for x in np.array(out["sheet"]["verts"])[seam, 0]], [0.0, 0.0]) + 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; Soul s2, bound-premise-seeded-by-truth), 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: one plate, + one pair of views. 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. + + The traces are the fixture's takes (tests/fixtures/spectre_truth.json says how): a search for the + strongest brightness step across each edge, from a seed that is not on the answer. Six families of twelve + draws: the truth's projection moved as one by 0.5, 1 and 1.5 px in a drawn direction (a 2.5 px window), + and each of its vertices moved by a normal draw of 1 and 2 px (3.5 px) and of 3 px (6 px). Such a take's + points stand 2.1 to 30.7 px from the truth's projection, 6.8 at the median: a stroke ends where it + crosses its neighbours, and two that run nearly along each other cross far off. 62 of the 72 block (12, + 12, 11, 10, 10, 7 by family; nine are refused at a side not explained at six points, one at the cage's + parser), every one with the ridge's six corners decided by the mirror plane and the outer edge's five by + the views (prior_share 0.037 at most). + + What the takes read: a blocked plate's worst corner over its take's worst point x the coarser view's + pixel is 1.18 at most (1.12, 1.16, 1.18, 1.04, 1.06, 1.11 by family), 33 to 929 mm, 142 at the median; + the three draws that grow a side stand at 0.51, 0.75 and 1.08. That is no bound: a take's worst point is + one far crossing, and it inflates the denominator (Soul s3, bound-is-the-takes-outliers). The bound is + BOUND, set by test_every_point_as_far_off_bounds_the_rendered_roof, and the takes are held to it. M3 + lands the ridge off x = 0 and every take is refused. No bound is stated in the takes' rms: against the + rms the same readings reach 5.3. A search seeded on the truth's projection itself is no reading: its + 2.5 px window ends its strokes 2.5 px off and its plate 39 mm off.""" + 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) + self.assertEqual(len(record["takes"]), 72) + blocked = 0 + for take in range(len(record["takes"])): + views, plate, traces, sides, _ = rendered("roof", corners, take=take) + try: + out = core.block_plate(views, plate, traces, kit.sheet) + except core.ReferenceFitError: + continue + blocked += 1 + self.assertEqual([corner["decided_by"] for corner in out["corners"]], ["mirror"] * 6 + ["views"] * 5, take) + self.assertLess(max(corner["prior_share"] for corner in out["corners"]), core.VIEWS / 1.2, take) + self.assertGreater(min(corner["parallax_deg"] for corner in out["corners"][6:]), 59, take) + self.assertEqual(max(abs(float(np.array(out["sheet"]["verts"])[chain[0], 0])) for chain in crown_chains(out)[:6]), 0.0, take) + self.assertLess(off_rendered(out, sides)[0], self.BOUND * off_projection(fixture, record, take) * pixel, take) + self.assertGreaterEqual(blocked, 52) + + BOUND = 2.08 # a blocked plate's worst corner, in its worst traced point x the coarser view's pixel: one plate, one pair of views + FAR = [0, 107, 45, 33, 216, 300, 270, 165, 99, 150, 45, 30, 90, 270, 180, 285, 345, 270, 90, 240, 125, 184, 321, 279] # degrees, a point: the worst a search found + + def test_every_point_as_far_off_bounds_the_rendered_roof(self): + """block-bound (Soul s3, bound-is-the-takes-outliers, bound-families-left-out), M1. The worst a trace + does for its worst point is to have no outlier: every point of every stroke the same d px off the + truth's projection. No search, no renders: the rendered roof's truth drawn through its two cameras and + moved. Each view moved as one, 12 directions by 12 at 1 px: all 144 block and the worst corner stands + 1.005 to 1.505 x d x the coarser view's pixel off (1.096 at the median; 1.504 and 1.502 at 2 and 3 px). + M1 reads 2.865 there: BOUND, 2.08, is the geometric mean, separation 1.38 each side. Each stroke its own + direction reaches 1.582 (a coordinate ascent over 12 and 36 directions, six starts) and each point its + own 1.666 at 1 px and 1.659 at 3: FAR, a coordinate ascent over 8 directions from nine starts, which + end at 1.57 to 1.65, the best refined over 24. FAR is the worst found, not the worst there is; BOUND + stands 1.25 over it and claims no mutant there (M1 reads 1.994). The eight families of searched takes, + 40 fresh draws each, read 1.11 to 1.33 (docs/reference.md), every one under the 1.505.""" + corners = ["ridge_rear", "r4", "r3", "r2", "r1", "nose", "a", "b", "c", "d", "e"] + _, _, _, _, (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()) + + def reads(d, degrees): + views, plate, traces, sides, _ = rendered("roof", corners, off=(d, degrees)) + return off_rendered(core.block_plate(views, plate, traces, kit.sheet), sides)[0] / (d * pixel) + + moved = [reads(1.0, [side if stroke["view"] == "side" else hero for stroke in record["strokes"] for _ in stroke["through"]]) + for hero in range(0, 360, 30) for side in range(0, 360, 30)] + self.assertLess(max(moved), self.BOUND) + for d in (1.0, 3.0): + self.assertLess(1.6, reads(d, self.FAR), d) # still the far draw + self.assertLess(reads(d, self.FAR), self.BOUND, d) + + 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, over the draws that blocked: 19, 20, 23, 24, 24, 25, + 26, 27 of the 168 are refused and counted in neither. FAIR is flat from 0.1 to 0.3: 0.2 and 0.25 + tie here, and on Soul's seeds (verdict cut-trace-block.s3) 0.1, 0.15 and 0.2 read 196, 196, 195. 0.2 is + kept as a point on that plateau, not a resolved lowest (docs/reference.md has all three sets). The roof's strokes here are the fixture's + own, searched from the truth's projection, with the noise added on top. 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_raptor_plate_from_two_views(self): + """block-raptor (tests/fixtures/raptor_plates.json): the hull plate bearing RAPTOR's 27, its corners marked + by eye in the hero (right flank) and in the SIDE view (left flank, side -1). The hero camera is solved + from hull marks alone (the nose, both emitters, the plate's corners): the seven admit none under 25.1 px + rms at 50 mm (the sheet's hero and SIDE view do not draw one rigid hull), where the first hero, solved + from leg joints, stood 18.5 degrees from the SIDE view and drew the hull tens of pixels off. Through it + the plate blocks from its two views: sight lines 33.9 to 40.1 degrees apart, every trace explained + within 3.2 px, the corners on the right flank at x 0.87 to 1.72 m. The prior has 0.173 to 0.197 of each + corner, under core.VIEWS by less than the margin, so the label is not asserted: on this sheet two views + decide a flank corner only just. No truth exists for the plate and four of the camera's seven marks are + its corners: this is two views agreeing, pinned as it read, not an accuracy.""" + fixture = json.loads((Path(__file__).resolve().parent / "fixtures" / "raptor_plates.json").read_text(encoding="utf-8")) + solved = core.solve(fixture["world"], fixture["pixels"], fixture["box"], model="rolled", lens=50) + self.assertGreater(solved["rms"], 20) + self.assertLess(float(np.abs(np.array(solved["C"]) - fixture["cameras"]["hero"]["C"]).max()), 1e-6) + traces = [{key: trace[key] for key in ("from", "to", "side", "line")} for trace in fixture["traces"]] + out = core.block_plate([(fixture["cameras"][trace["view"]], EYE) for trace in fixture["traces"]], fixture["plate"], traces, kit.sheet) + self.assertGreater(min(corner["parallax_deg"] for corner in out["corners"]), 30) + self.assertLess(max(corner["prior_share"] for corner in out["corners"]), 1.2 * core.VIEWS) + self.assertLess(max(trace["unexplained_px"] for side in out["sides"] for trace in side["traces"]), core.TOL / 1.2) + self.assertEqual((out["plane"]["from"], [side["points"] for side in out["sides"]]), ("corners", [2] * 4)) + crown = np.array(out["sheet"]["verts"])[:4] + self.assertTrue((crown[:, 0] > 0.8).all() and (crown[:, 0] < 1.8).all(), crown[:, 0]) + + 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: + over 1 where the sight line leans on the plane), every side stays two points, and the crown is the one the + harness lifted onto that plane, within 1 mm (its fit_shell read 0.65 to 1.0 on the same plates). None of + the 16 planes stands over 66 degrees off its view at e688951 (ForearmL.Outer, 61.6, is the furthest): the + guard is claimed by test_a_plane_far_off_square_on_to_its_one_view_is_refused. The thigh shields as + partners, the left's polygon seen as the right's reflection in the left thigh's frame, are refused, a side + 19.0 px unexplained at six points: the sheet's two polygons are not one plate mirrored (their lifted corners + stand 0.16 to 0.77 m apart), so no Paladin plate has a corner decided by a partner view here.""" + fixture = json.loads((Path(__file__).resolve().parent / "fixtures" / "paladin_plates.json").read_text(encoding="utf-8")) + + def block(name): + plate = fixture["plates"][name] + views = [(fixture["cameras"][trace["view"]], fixture["frames"][trace["frame"]]) for trace in plate["traces"]] + return plate, core.block_plate(views, plate["plate"], [{key: trace[key] for key in ("from", "to", "side", "line")} for trace in plate["traces"]], kit.sheet, plane=plate.get("plane")) + + single = sorted(name for name in fixture["plates"] if name != "ThighShield.partners") + self.assertEqual(len(single), 16) + for name in single: + plate, out = block(name) + n = len(plate["plate"]["corners"]) + self.assertEqual(({corner["decided_by"] for corner in out["corners"]}, [side["points"] for side in out["sides"]], out["plane"]["from"]), ({"plane"}, [2] * n, "given"), name) + self.assertGreater(min(corner["prior_share"] for corner in out["corners"]), 0.9, name) + crown, lifted = np.array(out["sheet"]["verts"])[:n], np.array(plate["reference"]["crown"]) # the harness turned some crowns to face out: the same ring from another corner, or the other way round + self.assertLess(min(float(np.abs(crown - np.roll(lifted[::way], turn, axis=0)).max()) for way in (1, -1) for turn in range(n)), 0.001, name) + with self.assertRaisesRegex(core.ReferenceFitError, r"^the side from 'c0' to 'c1' is not explained at 6 points, the most a side is given: traces\[0\] is not explained"): + block("ThighShield.partners") + + def test_the_blocking_goes_to_the_parser_and_to_fit_shell(self): + """block-then-fit without Blender (tests/live/reference_block.py builds it): the sheet is one the cage's + parser takes, fit_traces name each side as a run of authored vertices, and fit_sheet takes both. On the + straight plate fit_shell's own prior moves no point 5 mm (2.2 at most: the plane had drawn the twisted + corners in); on the bowed plate it moves the grown points up to 74 mm, back toward the bow fairness held in.""" + cams = [plate_camera(0), plate_camera(60)] + for sides, most in ((pentagon(0.0), 0.005), (pentagon(0.08, 0.35), 0.09)): + views, traces = plate_traces(cams, sides) + out = blocked_plate(views, traces) + self.assertEqual((len(out["fit_traces"]), out["left_out"]), (10, [])) + self.assertEqual(set(out["fit_traces"][0]), {"camera", "run", "side", "line"}) + fit = core.fit_sheet(out["sheet"], kit.sheet(out["sheet"]), EYE, out["fit_traces"], [cam for cam, _ in views]) + self.assertLess(max(point["moved_m"] for point in fit["points"]), most) + self.assertLess(len(json.dumps(out, separators=(",", ":"))), core.RESULT_LIMIT) + + def test_block_refusals_name_their_field(self): + """block-refusals.""" + cams = [plate_camera(0), plate_camera(60)] + views, traces = plate_traces(cams, pentagon(0.0)) + + def refused(pattern, views_=views, traces_=traces, plate=None, parse=None, **more): + with self.assertRaisesRegex(core.ReferenceFitError, pattern): + core.block_plate(views_, plate or {"corners": PLATE}, traces_, parse or kit.sheet, **more) + + keep = [k for k, trace in enumerate(traces) if trace["from"] != "c2"] + refused(r"^the side from 'c2' to 'c3' is traced in no view", [views[k] for k in keep], [traces[k] for k in keep]) + keep = [k for k, trace in enumerate(traces) if trace["from"] not in ("c1", "c2")] + refused(r"^plate\.corners\[2\] 'c2': no trace ends at it", [views[k] for k in keep], [traces[k] for k in keep]) + refused(r"^traces\[0\]\.from 'c0' and \.to 'c2' are not consecutive corners", traces_=[{**traces[0], "to": "c2"}] + traces[1:]) + refused(r"^traces\[0\]\.from and \.to must name corners", traces_=[{**traces[0], "to": "c9"}] + traces[1:]) + refused(r"^traces\[3\]\.camera 'View1' is no camera of this plate", views[:3] + [(None, EYE)] + views[4:]) + refused(r"^traces\[1\]\.frame must be a 4 x 4 that only turns and moves", views[:1] + [(cams[1], (2 * np.eye(4)).tolist())] + views[2:]) + refused(r"^traces\[2\]\.side must be 1, or -1", traces_=traces[:2] + [{**traces[2], "side": 2}] + traces[3:]) + refused(r"^traces\[2\]\.line must be two or more", traces_=traces[:2] + [{**traces[2], "line": [[1, 2]]}] + traces[3:]) + refused(r"^traces\[2\] must be \{camera, box, frame, from, to, side, line\}", traces_=traces[:2] + [{**traces[2], "run": {}}] + traces[3:]) + refused(r"^plate\.corners must be three or more different names", plate={"corners": ["a", "b"]}) + refused(r"^plate\.seam must name two or more corners next to each other", plate={"corners": PLATE, "mirror": True, "seam": ["c0"]}) + refused(r"^plate\.seam must name two or more corners next to each other", plate={"corners": PLATE, "seam": ["c0", "c1"]}) + refused(r"^plane must be \{point: \[x, y, z\], normal: \[x, y, z\]\}", plane={"point": [0, 0, 0], "normal": [0, 0, 0]}) + + def no(document): + raise kit.KitError("sheet.verts[0] is not to its taste") + + refused(r"^sheet: the cage's parser does not take the plate as blocked \(sheet\.verts\[0\] is not to its taste\)", parse=no) + long = [{**trace, "line": core.resampled(np.array(trace["line"]), 160).round(1).tolist()} for trace in traces] + refused(r"^traces: the sheet and its report could be about \d+ characters, over the 16000", traces_=long) + # a mirrored plate's corner drawn across the mirror plane from the others + P, names = np.array([[0, 0, 0.5], [0, 0, -0.5], [0.5, 0.1, -0.4], [-0.05, 0.1, 0.4]]), ["a", "b", "c", "d"] + mirrored = [{"from": names[i], "to": names[(i + 1) % 4], "side": 1, "line": core.project(cam, P[[i, (i + 1) % 4]]).tolist()} for i in range(4) for cam in cams] + refused(r"^plate\.corners\[3\] 'd' starts at x = -0\.050, across the mirror plane", [(cam, EYE) for _ in range(4) for cam in cams], mirrored, {"corners": names, "mirror": True, "seam": ["a", "b"]}) + + @unittest.skipIf(np is None, "numpy") class CameraTests(unittest.TestCase): CAM = {"C": [3.0, -7.0, 2.5], "f": 1400.0, "c": [640.0, 395.0], "box": BOX} @@ -780,8 +1312,8 @@ class HostFileTests(unittest.TestCase): def test_the_row_names_the_operator_and_properties_the_add_on_defines(self): source = (SURFACE / "brokkr_reference" / "__init__.py").read_text(encoding="utf-8") - self.assertEqual([row["name"] for row in self.document["actions"]], ["brokkr_reference.solve_camera", "brokkr_reference.flow_score", "brokkr_reference.fit_shell"]) - self.assertEqual(source.count("bl_idname = "), 3) + self.assertEqual([row["name"] for row in self.document["actions"]], ["brokkr_reference.solve_camera", "brokkr_reference.flow_score", "brokkr_reference.fit_shell", "brokkr_reference.block_plate"]) + self.assertEqual(source.count("bl_idname = "), 4) for row in self.document["actions"]: self.assertIn(f'bl_idname = "{row["name"]}"', source) self.assertEqual(row.get("result"), "brokkr_mesh_polish_result") @@ -807,6 +1339,11 @@ class HostFileTests(unittest.TestCase): for bad in ({"tol": 0}, {"share": 11}, {"traces": ""}, {"object_name": "x" * 64}): with self.assertRaises(at.IntentInvalid): at.validate({**fit, **bad}, self.host) + block = {**self.envelope, "action": "brokkr_reference.block_plate", "frame_object": "Frame", "plate": "{}", "traces": "[{}]"} + self.assertEqual((at.validate(block, self.host)["share"], at.validate(block, self.host)["tol"], at.validate(block, self.host)["plane"]), (0.1, core.TOL, "")) + for bad in ({"tol": 0}, {"share": 11}, {"traces": ""}, {"plate": ""}, {"frame_object": "x" * 64}, {"plane": "x" * 201}): + with self.assertRaises(at.IntentInvalid): + at.validate({**block, **bad}, self.host) class OwnershipTests(unittest.TestCase): @@ -827,7 +1364,7 @@ class OwnershipTests(unittest.TestCase): decided by matching trace points to each other.""" for path in (SURFACE / "brokkr_reference").glob("*.py"): text = path.read_text(encoding="utf-8") - self.assertIsNone(re.search(r"def pair|_smoothest|cage_through|on_plane", text), path.name) + self.assertIsNone(re.search(r"def pair|_smoothest|cage_through|on_plane|epipolar", text), path.name) self.assertIsNone(re.search(r"SHELL\] *=|kit_shell\"\] *=|\.data\.vertices|foreach_set|from_pydata", text), path.name) def test_no_other_package_names_this_one(self):