Merge branch 'feat/h1-blend-network'
This commit is contained in:
@@ -259,9 +259,11 @@ NurbsSurface make_blend_patch_oriented(
|
||||
}
|
||||
|
||||
/// 圆角网络核心实现(变半径版本,radii 与 edge_ids 一一对应)
|
||||
/// allow_expand:结果无效时是否允许自动扩展两端点邻边形成网络再试
|
||||
BrepModel corner_blend_impl(const BrepModel& body,
|
||||
const std::vector<int>& edge_ids,
|
||||
const std::vector<double>& radii) {
|
||||
const std::vector<double>& 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<int>(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<int> 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<int> nids;
|
||||
std::vector<double> 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());
|
||||
|
||||
Reference in New Issue
Block a user