From be5744d388c8de3a15f3741c71aeb61707fdd4b0 Mon Sep 17 00:00:00 2001 From: hm-thinkbook14p Date: Wed, 26 Aug 2026 20:27:04 +0800 Subject: [PATCH] =?UTF-8?q?feat(brep):=20corner=5Fblend=20=E7=BB=93?= =?UTF-8?q?=E6=9E=9C=E6=97=A0=E6=95=88=E6=97=B6=E8=87=AA=E5=8A=A8=E6=89=A9?= =?UTF-8?q?=E5=B1=95=E4=B8=A4=E7=AB=AF=E7=82=B9=E9=82=BB=E8=BE=B9=E5=BD=A2?= =?UTF-8?q?=E6=88=90=E5=9C=86=E8=A7=92=E7=BD=91=E7=BB=9C(=E6=95=91?= =?UTF-8?q?=E7=81=AB=E5=BC=8F)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 单边 blend 在薄壁双壁墙角的结构性自交(strip 端部嵌入邻墙)仅靠半径钳制 不可救。新增:blend 结果 validate 无效时,对每个目标边端点取最长 2-面 邻边(未在集合中)扩展 edge 集合,递归调用 corner_blend_impl 形成多边 共享角点网络(allow_expand=false 防递归),网络结果有效则采用。 语料基准(corpus/real 3809 文件 814 calls): - 单边钳制后: ok=562 invalid=0 fail=252 (pass 69.0%) - +网络救火: ok=610 invalid=0 fail=204 (pass 74.9%, +5.9pp) - 网络救回 48/252 例(19%),耗时仅 +5% (1325s vs 1257s,网络只对失败案例跑) - banana-M3 body1 e40 由"回退原体"转为"网络救回 54 面 valid" 回归测试全通过(step_import 39 / brep_blend 12 / advanced_blend 32 / brep 27 / brep_validate 16)。 --- src/brep/blend_corner.cpp | 62 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 3 deletions(-) diff --git a/src/brep/blend_corner.cpp b/src/brep/blend_corner.cpp index 6cf77411d..85fc8de11 100644 --- a/src/brep/blend_corner.cpp +++ b/src/brep/blend_corner.cpp @@ -259,9 +259,11 @@ NurbsSurface make_blend_patch_oriented( } /// 圆角网络核心实现(变半径版本,radii 与 edge_ids 一一对应) +/// allow_expand:结果无效时是否允许自动扩展两端点邻边形成网络再试 BrepModel corner_blend_impl(const BrepModel& body, const std::vector& edge_ids, - const std::vector& radii) { + const std::vector& radii, + bool allow_expand = true) { #define DBG_STEP(fmt, ...) \ do { if (getenv("VDE_CB_DEBUG")) fprintf(stderr, "[corner_blend] " fmt "\n", ##__VA_ARGS__); } while (0) const int E = static_cast(body.num_edges()); @@ -779,10 +781,64 @@ BrepModel corner_blend_impl(const BrepModel& body, finish_model(result, "corner_blend"); // ── 结果有效性回退:blend 导致自交/水密性下降时(薄壁墙角的结构性 - // 嵌入等单边 blend 无法避免的情形),返回原体,绝不输出无效模型。 - // 与半径钳制互补:钳制让可救的变小半径继续 blend;回退兜底其余。── + // 嵌入等单边 blend 无法避免的情形),先尝试扩展两端点邻边形成网络 + // (共享角点的多边协同重建可消除 strip 端部嵌入邻墙),仍无效才返回 + // 原体,绝不输出无效模型。与半径钳制互补:钳制让可救的变小半径继续 + // blend;网络扩展救回结构性自交;回退兜底其余。── try { auto vr = validate(result); + if (!vr.valid && allow_expand) { + // 扩展网络:每个目标边端点上找 1 条最长 2-面邻边(未在集合中) + std::set nset = edge_set; + for (int e : edge_set) { + const auto& ed = body.edge(e); + int vs[2] = {ed.v_start, ed.v_end}; + for (int v : vs) { + int pick = -1; + double bl = 0.0; + for (int ei = 0; ei < E; ++ei) { + if (nset.count(ei)) continue; + const auto& e2 = body.edge(ei); + if (e2.v_start != v && e2.v_end != v) continue; + if (body.edge_faces(ei).size() != 2) continue; + double len = (body.vertex(e2.v_end).point - + body.vertex(e2.v_start).point).norm(); + if (len > bl) { bl = len; pick = ei; } + } + if (pick >= 0) nset.insert(pick); + } + } + if (nset.size() > edge_set.size()) { + std::vector nids; + std::vector nrs; + for (int e : nset) { + nids.push_back(e); + auto it = edge_r.find(e); + if (it != edge_r.end()) { nrs.push_back(it->second); continue; } + // 扩展边半径:取与其共享端点的目标边半径 + const auto& ee = body.edge(e); + double r0 = radii.empty() ? 0.01 : radii[0]; + for (int t : edge_set) { + const auto& ed = body.edge(t); + if (ed.v_start == ee.v_start || ed.v_end == ee.v_start || + ed.v_start == ee.v_end || ed.v_end == ee.v_end) + r0 = edge_r[t]; + } + nrs.push_back(r0); + } + BrepModel net = corner_blend_impl(body, nids, nrs, false); + auto vn = validate(net); + if (vn.valid && net.num_faces() > body.num_faces()) { + DBG_STEP("single invalid (%s) -> network expand rescued (%zu faces)", + vr.errors.empty() ? "?" : vr.errors[0].c_str(), + net.num_faces()); + return net; + } + } + DBG_STEP("blend result invalid (%s) -> fallback to original body", + vr.errors.empty() ? "?" : vr.errors[0].c_str()); + return body; + } if (!vr.valid) { DBG_STEP("blend result invalid (%s) -> fallback to original body", vr.errors.empty() ? "?" : vr.errors[0].c_str());