Land the two deferred gaps: title-block frame clips + cross-floor datum gate

- detect_sheet_frames: title-block INSERTs (A0_V1/A0+0.5_V1/*图框*) define the
  clip window when they contain the title — pitch windows halved elongated
  sheets (13号 加长A0, one frame holding both towers); wall refine is clamped
  inside the frame rect; 13号 b1 real data: all 45 frames rect-clipped
- audit floors_aligned: cross-floor wall-profile datum check catches
  "self-consistent but misplaced" floors (13号 F3 错槽 85.8m that envelope
  centers PASSed); zero-shift guard kills the dense-podium false positive
  (27号 1#A PH matched "better" 1.5m off while already fitting in place)
- 门卫 size mismatch root-caused as representation granularity (gate compound
  vs kiosk symbol), not an extraction bug — closed in the log
- regression suite +6 checks (titleblock / crossdatum bad+good), all three
  projects re-audited with no false positives

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-03 08:05:57 +08:00
parent 1e11d38fa9
commit 9729857549
5 changed files with 239 additions and 13 deletions

View File

@@ -401,10 +401,68 @@ def floors_alignment_gate(spec: dict[str, Any], config: dict[str, Any]) -> dict[
"detail": worst[1] + ". Floors are not stacked — per-frame offsets are missing or wrong; "
"run detect_sheet_frames.py and use its clip/offset config.",
}
# Cross-floor datum: envelope centers are blind to "self-consistent but
# misplaced" floors (13号 F3 sat one tower-slot off — 85.8 m — and PASSed:
# the merged twin-tower envelope hid it). Correlate each floor's wall
# profile against the group's reference floor: a strong off-zero peak
# means the whole floor sits N meters from the shared wall datum.
try:
sys.path.insert(0, str(Path(__file__).resolve().parent))
from detect_sheet_frames import correlate_shift, wall_profile
except Exception:
correlate_shift = wall_profile = None # type: ignore
if correlate_shift is not None:
wall_segs: dict[str, list[tuple[float, float, float, float]]] = {}
for fk, floor in spec.get("floors", {}).items():
segs = floor.get("segments", {}).get("walls") or []
if len(segs) >= 10:
wall_segs[fk] = [(s["start"][0], s["start"][1], s["end"][0], s["end"][1]) for s in segs]
by_group: dict[str, list[str]] = defaultdict(list)
for fk in wall_segs:
by_group[derive._cap_floor_group(fk, config)].append(fk)
for grp, keys in by_group.items():
if len(keys) < 2:
continue
ref_key = max(keys, key=lambda k: sum(
math.hypot(s[2] - s[0], s[3] - s[1]) for s in wall_segs[k]))
ref_x = wall_profile(wall_segs[ref_key], 0, axis_tol=0.02, min_len=0.4)
ref_y = wall_profile(wall_segs[ref_key], 1, axis_tol=0.02, min_len=0.4)
def zero_cov(ref_prof, prof, tol: float = 0.25) -> float:
total = sum(w for _, w in prof)
if total <= 0:
return 0.0
matched = sum(w for p, w in prof
if any(abs(p - rp) <= tol for rp, _ in ref_prof))
return matched / total
for fk in keys:
if fk == ref_key:
continue
for axis, ref_prof in ((0, ref_x), (1, ref_y)):
prof = wall_profile(wall_segs[fk], axis, axis_tol=0.02, min_len=0.4)
shift, cov, ratio = correlate_shift(ref_prof, prof, coarse=0.5, fine=0.05)
# a floor already matching IN PLACE is not misplaced, however
# attractive some shifted peak looks (dense podium references
# let any small profile "match" somewhere: 27号 1#A PH)
if shift is not None and zero_cov(ref_prof, prof) >= 0.7 * cov:
continue
if (shift is not None and cov >= 0.45 and ratio >= 1.5
and abs(shift) > 1.0):
return {
"name": "floors_aligned",
"status": "FAIL",
"detail": (
f"cross_floor_datum {grp}: {fk} wall profile matches {ref_key} "
f"only when shifted {round(shift, 1)} m in {'xy'[axis]} "
f"(coverage {cov:.2f}, peak ratio {min(ratio, 99):.1f}) — the floor is "
"self-consistent but misplaced (wrong frame offset / wrong tower slot, "
"13号 F3 错槽 pattern). Re-check that frame's offset against the shared datum."
),
}
return {
"name": "floors_aligned",
"status": "PASS",
"detail": "Wall-bbox centers of same-stack floors coincide.",
"detail": "Wall-bbox centers of same-stack floors coincide; cross-floor wall-profile datum consistent.",
}

View File

@@ -205,7 +205,7 @@ def title_qualifier(name: str) -> str:
return name if m is None else name[: m.start()]
def wall_profile(segs, axis: int):
def wall_profile(segs, axis: int, axis_tol: float = 2.0, min_len: float = 400.0):
"""Length-weighted axis positions of straight walls.
axis=0: vertical segments -> x positions; axis=1: horizontal -> y.
@@ -213,13 +213,14 @@ def wall_profile(segs, axis: int):
in the frame (13号 tower / 27号 2#): correlating profiles between
frames recovers the true translation where clip-corner anchoring is
off by whole bays (wall bbox min-corner varies with balconies).
Defaults are mm-scale; pass axis_tol/min_len in meters for spec-space use.
"""
out = []
for sx, sy, ex, ey in segs:
dx, dy = abs(ex - sx), abs(ey - sy)
if axis == 0 and dx < 2.0 and dy > 400:
if axis == 0 and dx < axis_tol and dy > min_len:
out.append(((sx + ex) / 2, dy))
elif axis == 1 and dy < 2.0 and dx > 400:
elif axis == 1 and dy < axis_tol and dx > min_len:
out.append(((sy + ey) / 2, dx))
return out
@@ -368,6 +369,34 @@ def main() -> int:
elif OTHER_TITLE.search(content) and not match_any(layer, title_excludes):
others.append({"name": content, "x": x, "y": y, "h": height})
# Title-block frame INSERTs (A0_V1 / A0+0.5_V1 / *图框* …) carry the TRUE
# sheet rect. Pitch-sized windows halve elongated sheets (13号 加长A0 held
# both towers in one frame and F1 lost a tower) — prefer the block rect.
frame_block_re = re.compile(r"(?i)(^A[0-4](\+[0-9.]+)?([_\-]|$))|图框|图签|(^TK([_\-]|$))")
frame_rects: list[tuple[float, float, float, float]] = []
for entity in msp.query("INSERT"):
name = str(entity.dxf.name)
if not frame_block_re.search(name):
continue
xs_fb: list[float] = []
ys_fb: list[float] = []
try:
for ve in entity.virtual_entities():
vk = ve.dxftype()
if vk == "LINE":
for p in (ve.dxf.start, ve.dxf.end):
xs_fb.append(float(p.x)); ys_fb.append(float(p.y))
elif vk == "LWPOLYLINE":
for px, py in ve.get_points("xy"):
xs_fb.append(float(px)); ys_fb.append(float(py))
except Exception:
continue
if not xs_fb:
continue
w, h = max(xs_fb) - min(xs_fb), max(ys_fb) - min(ys_fb)
if w >= 20000 and h >= 15000 and 0.3 <= (w / h) <= 4.0: # plausible sheet
frame_rects.append((min(xs_fb), min(ys_fb), max(xs_fb), max(ys_fb)))
for entity in msp:
kind = entity.dxftype()
if kind == "INSERT":
@@ -439,6 +468,13 @@ def main() -> int:
if pitch_x and not pitch_y:
# row layout: title x may sit anywhere under its frame; centre on it
rough = [t["x"] - clip_w * 0.6, t["y"] - clip_h * 0.04, t["x"] + clip_w * 0.6, t["y"] + clip_h]
frame_rect = next((r for r in frame_rects
if r[0] <= t["x"] <= r[2] and r[1] <= t["y"] <= r[3]), None)
if frame_rect is not None:
fw, fh = frame_rect[2] - frame_rect[0], frame_rect[3] - frame_rect[1]
rough = [frame_rect[0] + fw * 0.01, frame_rect[1] + fh * 0.01,
frame_rect[2] - fw * 0.01, frame_rect[3] - fh * 0.01]
notes.append(f"{t['name']}: frame-block rect used for clip window ({fw / 1000:.1f}x{fh / 1000:.1f} m)")
clip = None
for group in refine_groups:
found = segments_in(lines, rough, group)
@@ -447,10 +483,14 @@ def main() -> int:
ys_ = [v for s in found for v in (s[1], s[3])]
margin = pitch * 0.06
clip = [min(xs) - margin, min(ys_) - margin, max(xs) + margin, max(ys_) + margin]
if frame_rect is not None: # never swallow the neighbour sheet
clip = [max(clip[0], rough[0]), max(clip[1], rough[1]),
min(clip[2], rough[2]), min(clip[3], rough[3])]
break
if clip is None:
clip = rough
notes.append(f"{t['name']}: no wall/roof geometry in rough clip; using pitch-based clip")
if frame_rect is None:
notes.append(f"{t['name']}: no wall/roof geometry in rough clip; using pitch-based clip")
# Axis geometry lives OUTSIDE the wall-tight clip (axis-number stubs sit
# beyond the facade), so collect grid candidates in an expanded window.
axis_margin = pitch * 0.16