Productize site machinery + config automation (session-proven -> scripts/)

- register_site_outlines.py: point-to-edge ICP registration CLI (footprint
  union vs site outline / DIM_COOR corners), manifest-ready output, loud
  warning above 2 m residual
- massing_from_outline.py: honest massing spec CLI (outline x storeys x
  height, labeled 总图轮廓体量), manifest anchors on stdout
- detect_sheet_frames: multi-floor titles (四、六、八 / 十一至十四) expand to
  per-storey config entries sharing clip/offset — the 13号 b2 silent-floor-
  loss class is now prevented at the source; compound CN numerals parsed
  (十一/二十一 no longer collapse to F0 keys); per-frame DIM_ELEV ladders +
  uniform-step storey suggestion in the report (evidence, not auto-filled z)
- 27号 2# real data: 19-storey enumerated title auto-expands, step 3.0 x 11
  suggestion correct; regression suite +11 checks

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-03 08:28:05 +08:00
parent 9729857549
commit fc05464749
6 changed files with 536 additions and 15 deletions

View File

@@ -13,6 +13,7 @@ Run: python3 tests/test_extraction_pipeline.py
from __future__ import annotations
import json
import math
import shutil
import subprocess
import sys
@@ -375,6 +376,45 @@ def make_titleblock_dxf(path: Path) -> None:
doc.saveas(path)
def make_ladder_dxf(path: Path) -> None:
"""Storey-table automation: a multi-floor title (三、五层平面图) must expand
into per-floor config entries, and the 剖面图 frame's DIM_ELEV ladder must
yield per-frame ladders + a uniform-step storey suggestion."""
doc = ezdxf.new("R2010", setup=True)
for layer in ("WALL", "DOTE", "PUB_TEXT", "DIM_ELEV"):
doc.layers.add(layer)
msp = doc.modelspace()
pitch = 98100.0
def draw_frame(oy: float, title: str) -> None:
outline = [((0, 0), (40000, 0)), ((40000, 0), (40000, 20000)),
((40000, 20000), (0, 20000)), ((0, 20000), (0, 0))]
interior = [((8000 * i, 0), (8000 * i, 20000)) for i in range(1, 5)]
interior += [((0, 10000), (40000, 10000))]
for (sx, sy), (ex, ey) in outline + interior:
msp.add_line((sx, sy + oy), (ex, ey + oy), dxfattribs={"layer": "WALL"})
for x in (0, 8000, 19000, 26000, 37000, 40000):
msp.add_line((x, -3000 + oy), (x, 26000 + oy), dxfattribs={"layer": "DOTE"})
for y in (0, 6000, 10000, 20000):
msp.add_line((-3000, y + oy), (46000, y + oy), dxfattribs={"layer": "DOTE"})
msp.add_text(title, height=800, dxfattribs={"layer": "PUB_TEXT"}).set_placement((18000, oy - 6000))
draw_frame(0.0, "一层平面图")
draw_frame(-pitch, "三、五层平面图")
draw_frame(-2 * pitch, "十一至十四层平面图")
# section frame with an elevation ladder: 0..21 step 3.0 + noise values
sx0 = 120000.0
msp.add_text("1-1剖面图", height=800, dxfattribs={"layer": "PUB_TEXT"}).set_placement((sx0 + 8000, -6000))
for k in range(8):
v = 3.0 * k
msp.add_text(f"{v:.3f}", height=350,
dxfattribs={"layer": "DIM_ELEV"}).set_placement((sx0 + 2000, 1000 + k * 3000))
for noise in ("0.150", "22.500"):
msp.add_text(noise, height=350,
dxfattribs={"layer": "DIM_ELEV"}).set_placement((sx0 + 6000, 2000))
doc.saveas(path)
def make_mixedrow_dxf(path: Path) -> None:
"""27号 1#B pattern: main plans stack in a COLUMN, but a couple of stray
same-row detail titles fabricate a bogus (much smaller) x-pitch. clip_w
@@ -980,6 +1020,77 @@ def main() -> int:
rc_good, md_good = cd_audit("good", -100000.0) # correct slot
check("correct slot PASSes cross-floor datum", rc_good == 0, md_good[-400:] if rc_good != 0 else "")
# --- multi-floor titles expand; per-frame ladders + storey suggestion (27号/13号 config 手写之痛) ---
ld_dir = WORK / "dxf_ladder"
ld_dir.mkdir(parents=True, exist_ok=True)
make_ladder_dxf(ld_dir / "ladder.dxf")
proc = run([
sys.executable, "scripts/detect_sheet_frames.py",
"--dxf", str(ld_dir / "ladder.dxf"), "--out-config", str(WORK / "frames_ld.json"),
"--out-report", str(WORK / "frames_ld.md"), "--vendor-dir", str(VENDOR),
])
check("detect handles ladder/multi-floor sheet", proc.returncode == 0, proc.stderr[-500:])
if proc.returncode == 0:
frames_ld = json.loads((WORK / "frames_ld.json").read_text(encoding="utf-8"))
ld = {f["key"]: f for f in frames_ld["drawings"][0]["floors"]}
check("enumerated title expands (三、五层)", "F3" in ld and "F5" in ld
and ld["F3"]["clip"] == ld["F5"]["clip"], str(sorted(ld)))
check("range title expands (十一至十四层)", all(f"F{n}" in ld for n in (11, 12, 13, 14)),
str(sorted(ld)))
check("compound CN numerals parsed (no F0 keys)", not any(k.startswith("F0") for k in ld),
str(sorted(ld)))
ld_md = (WORK / "frames_ld.md").read_text(encoding="utf-8")
check("per-frame elevation ladder reported", "1-1剖面图" in ld_md and "ladder:" in ld_md, ld_md[-500:])
check("uniform storey step suggested", "suggested storey table: uniform step 3.0" in ld_md, ld_md[-600:])
# --- register_site_outlines.py: ICP registration recovers rotation+translation ---
reg_dir = WORK / "register"
reg_dir.mkdir(parents=True, exist_ok=True)
# model footprint: 30x12 rect with an asymmetric notch (pins the 180° flip)
model_poly = [[0, 0], [30, 0], [30, 12], [8, 12], [8, 9], [0, 9]]
reg_spec = {
"project": "reg", "units": {"scale": 0.001}, "categories": {},
"source": {"config": {}},
"floors": {"F1": {"name": "F1", "z": 0.0, "height": 3.0,
"bounds": [0, 0, 30, 12],
"segments": {"walls": []},
"footprint": {"polygons": [model_poly]}, "caps": []}},
}
(reg_dir / "spec.json").write_text(json.dumps(reg_spec), encoding="utf-8")
th = math.radians(30.0)
site_pts = [[round(x * math.cos(th) - y * math.sin(th) + 500.0, 3),
round(x * math.sin(th) + y * math.cos(th) + 200.0, 3)] for x, y in model_poly]
(reg_dir / "pts.json").write_text(json.dumps(site_pts), encoding="utf-8")
proc = run([
sys.executable, "scripts/register_site_outlines.py",
"--spec", str(reg_dir / "spec.json"), "--floors", "F1",
"--site-points", str(reg_dir / "pts.json"), "--out", str(reg_dir / "reg.json"),
])
check("register_site_outlines runs", proc.returncode == 0, proc.stderr[-500:])
if proc.returncode == 0:
reg = json.loads((reg_dir / "reg.json").read_text(encoding="utf-8"))
d_rot = abs((reg["rotation_deg"] - 30.0 + 180) % 360 - 180)
check("registration recovers rotation", d_rot <= 0.5, str(reg))
check("registration residual small", reg["residual_m"] <= 0.15, str(reg))
check("manifest fragment emitted", "model_anchor_m" in reg.get("manifest_entry", {}), str(reg.keys()))
# --- massing_from_outline.py: honest massing spec from site outline ---
proc = run([
sys.executable, "scripts/massing_from_outline.py",
"--outline", str(reg_dir / "pts.json"), "--storeys", "5", "--height", "3.0",
"--name", "test_massing", "--out", str(reg_dir / "massing.json"),
])
check("massing_from_outline runs", proc.returncode == 0, proc.stderr[-500:])
if proc.returncode == 0:
ms = json.loads((reg_dir / "massing.json").read_text(encoding="utf-8"))
fl = ms["floors"]
top = fl[max(fl, key=lambda k: fl[k]["z"])]
check("massing has N floors with walls+footprint",
len(fl) == 5 and all(f["segments"]["walls"] and f["footprint"]["polygons"] for f in fl.values()),
str({k: len(v['segments']['walls']) for k, v in fl.items()}))
check("massing top floor capped", bool(top["caps"]), str(top.get("caps")))
check("massing marked as outline volume", "体量" in ms.get("description", ""), ms.get("description", ""))
# --- bogus x-pitch from stray same-row titles must not shrink clips (27号 1#B) ---
mx_dir = WORK / "dxf_mixedrow"
mx_dir.mkdir(parents=True, exist_ok=True)