"""Ramp-A교 마크별 대조 이미지: 도면(DXF 교각(3).dxf) 철근상세 그림 ↔ 모델 형상 ↔ 표 L/모델 L. 입력: 검토파일/Ramp-A교P1/도면_철근상세_DXF렌더.png (render_dxf.py, 6000x8406), c1_shape_audit2.json""" import json from pathlib import Path import numpy as np import matplotlib matplotlib.use("Agg") import matplotlib.pyplot as plt from matplotlib import font_manager from PIL import Image Image.MAX_IMAGE_PIXELS = None font_manager.fontManager.addfont(r"C:\Windows\Fonts\malgun.ttf") plt.rcParams["font.family"] = "Malgun Gothic" ROOT = Path(r"D:\★Pier 자료\프로그램\Pier_T") SRC = Image.open(ROOT / "검토파일" / "Ramp-A교P1" / "도면_철근상세_DXF렌더.png").convert("RGB") D = json.load(open(r"C:\Users\User\AppData\Local\PierApp\jobs\c1_work\c1_shape_audit2.json", encoding="utf-8-sig"))["RampA"] OUT = ROOT / "검토파일" / "수정후_캡처" K = 2.4235 # 첫 렌더(4800폭) 표시좌표 → 6000폭 렌더 픽셀 def d1(x0, y0, x1, y1): return tuple(int(v * K) for v in (x0, y0, x1, y1)) def r1(x0, y0, x1, y1): return (int(3300 + x0 * 2.1), int(y0 * 2.1), int(3300 + x1 * 2.1), int(y1 * 2.1)) def l2(x0, y0, x1, y1): return (int(x0 * 2.1), int(4203 + y0 * 2.1), int(x1 * 2.1), int(4203 + y1 * 2.1)) FIG = {"I": d1(230, 220, 570, 325), "U": d1(190, 625, 615, 770), "rect": d1(255, 1340, 550, 1520), "pent": d1(1050, 110, 1400, 420), "hook": d1(980, 950, 1460, 1180), "hoop": d1(1090, 1450, 1350, 1720), "rect13": r1(580, 200, 990, 520), "rectj": r1(580, 670, 990, 990), "coupler": r1(570, 1210, 920, 1360), "diag": l2(290, 250, 640, 560), "soffit": l2(160, 1400, 760, 1610)} MAP = {"C1": "diag", "C2": "diag", "C3": "diag", "C4": "diag", "C5": "diag", "C6": "soffit", "C7": "rect", "C9": "rect", "C11": "rect", "C8": "pent", "C10": "pent", "C12": "pent", "C13": "rect13", "C14": "rectj", "C15": "U", "C16": "U", "S1": "U", "S2": "U", "S3": "I", "S4": "I", "P1": "coupler", "P2": "hoop", "P3": "hook", "P1-1": "I", "P1-2": "I", "P2-1": "hoop", "P3-1": "hook", "P3-2": "U"} EST = {"P1-1", "P1-2", "P3-2"} made = [] for part, hosts in {"코핑": ("P1-CP",), "기둥·말뚝": ("P1-CL", "P1-PL01", "P1-PL02")}.items(): seen, its = set(), [] for x in D: if x["host"] in hosts and (x["mark"], x["host"]) not in seen: seen.add((x["mark"], x["host"])); its.append(x) rows = (len(its) + 1) // 2 fig, axs = plt.subplots(rows, 4, figsize=(17, rows * 2.6)); axs = np.atleast_2d(axs) for ax in axs.ravel(): ax.axis("off") for i, x in enumerate(its): r, c = divmod(i, 2) a1, a2 = axs[r][c * 2], axs[r][c * 2 + 1] a1.axis("on"); a1.set_xticks([]); a1.set_yticks([]); a1.imshow(SRC.crop(FIG[MAP[x["mark"]]])) a1.set_title("도면 %s%s" % (x["mark"], " (그림 추정)" if x["mark"] in EST else ""), fontsize=9.5, fontweight="bold", color="#8a5a00") P = np.array(x["pts"]); C = P - P.mean(0) _, _, vt = np.linalg.svd(C, full_matrices=False); Q = C @ vt[:2].T a2.axis("on"); a2.set_xticks([]); a2.set_yticks([]) a2.plot(Q[:, 0], Q[:, 1], "-", color="#1f77b4", lw=2); a2.plot(*Q[0], "o", color="green", ms=5); a2.plot(*Q[-1], "s", color="red", ms=5) w, h = np.ptp(Q[:, 0]), np.ptp(Q[:, 1]) if h < 0.2 * w or w < 0.2 * h: a2.set_aspect("auto"); a2.margins(0.08) else: a2.set_aspect("equal") a2.set_title("모델 %s %s N=%d (%s)" % (x["mark"], x["dia"], x["n_obj"], x["host"][3:]), fontsize=9.5, fontweight="bold") a2.set_xlabel("표 L=%s / 모델 %s (가로세로 비율 왜곡 가능)" % ((x["design_len"] or "-").split(".")[0], x["len"]), fontsize=8) fig.suptitle("Ramp-A교 %s 철근 — 도면(DXF) 철근상세 그림 ↔ 모델 형상" % part, fontsize=15, fontweight="bold") fig.tight_layout(rect=(0, 0, 1, 0.97)) p = OUT / ("도면대조_RampA_%s.png" % part.replace("·", "")); fig.savefig(p, dpi=75); plt.close(fig); made.append(p.name) print(made)