fix(brep): SW 口径对齐 - sheet/曲面体来源降级为警告 + heal 非流形守护

STEP SHELL_BASED_SURFACE_MODEL/FBSM/GBSR/曲面集导入为曲面实体(BrepModel BodySource::SurfaceSheet),诊断中开放外壳(水密性<90%)从 error(k3) 降级为警告(kind8):对标 SW 曲面导入不报错,如需实体化/CAM 先曲面缝合或加厚。

heal 增加回退条件 4(非流形守护):heal 不得引入/增加 >=3 面共享边。修复 wgehaeuse 曲面体 heal 后 6 body 退化为 k2 非流形的回归(42-file heal 扫:err body 94->63,heal 修复 31、0 回归;A 类单面 sheet 573 body 清零)。
This commit is contained in:
hm
2026-09-09 16:32:56 +08:00
parent c669fb3c63
commit 6fdee0ef19
4 changed files with 64 additions and 7 deletions
+18
View File
@@ -384,6 +384,17 @@ struct EdgeStyle {
// B-Rep 模型类
// ═══════════════════════════════════════════════
/// 体来源类别(SW 口径:区分实体 vs 曲面体/sheet)
/// Solid = 源为实体语义(MANIFOLD_SOLID_BREP / CLOSED_SHELL / CSG / 镶嵌体),
/// 开放/水密性不足 = 真实实体缺陷(缺面/破壳)。
/// SurfaceSheet = 源为曲面模型语义(SHELL_BASED_SURFACE_MODEL / FBSM /
/// GEOMETRIC_SET / GBSR / CBS 曲面集),开放外壳 = 曲面体合法形态
/// (对标 SW:STEP 曲面模型导入为曲面实体,不判导入错误)。
enum class BodySource : int {
Solid = 0,
SurfaceSheet = 1,
};
/**
* @brief B-Rep 模型
*
@@ -412,6 +423,12 @@ class BrepModel {
public:
BrepModel() = default;
/** @brief 查询体来源类别(Solid / SurfaceSheet,SW 口径) */
[[nodiscard]] BodySource source_class() const { return source_class_; }
/** @brief 设置体来源类别(导入端标记源 STEP 语义) */
void set_source_class(BodySource s) { source_class_ = s; }
/**
* @brief 添加顶点
* @param p 顶点坐标
@@ -1166,6 +1183,7 @@ private:
std::vector<curves::NurbsSurface> surfaces_;
std::vector<TrimmedSurface> trimmed_surfaces_;
RenderMaterial material_; ///< VDE-196: 渲染材质信息
BodySource source_class_ = BodySource::Solid; ///< 体来源类别(导入端 SW 口径)
///< 环 ID → loops_ 数组下标的索引(由 add_loop 维护),避免 loop_by_id /
///< face_edges / edge_faces 在稠密模型上做 O(L) 线性扫描。
mutable std::unordered_map<int, int> loop_index_;
+15
View File
@@ -1653,12 +1653,27 @@ AutoHealReport automatic_heal(BrepModel& body, const AutoHealOptions& opts) {
if (wiped_faces) {
degraded = true;
}
// 回退条件 4(非流形守护,2026-09 wgehaeuse 曲面体回归):heal 缝合/
// 合并共享边链可能把原本无 ≥3 面共享边的体(含 SW 口径下合法的开放壳
// sheet/曲面体)合并出非流形边(k2),属 heal 劣化输入。任何情况下
// heal 都不应引入/增加非流形边;触发则回退原始体。
bool nm_introduced =
vnew.non_manifold_edges > vraw.non_manifold_edges;
if (!degraded && nm_introduced) {
degraded = true;
}
if (degraded) {
body = std::move(backup);
if (wiped_faces) {
report.warnings.push_back(
"Heal: 修复将把该体全部 " + std::to_string(before_f) +
" 个面删空(空体),回退到原始体(防御:错误面保留为可定位降级报告)");
} else if (nm_introduced) {
report.warnings.push_back(
"Heal: 修复引入非流形边(" +
std::to_string(vraw.non_manifold_edges) + " → " +
std::to_string(vnew.non_manifold_edges) +
" 条 ≥3 面共享边),回退到原始体(防御:heal 不得制造非流形缺陷)");
} else {
report.warnings.push_back(vraw.valid
? "Heal: 原始模型有效但修复后无效/水密性跌破 0.99,回退到原始体(防御性保护)"
+22 -7
View File
@@ -856,11 +856,24 @@ BodyDiagnostics diagnose_body(const BrepModel& body) {
d.error_count++;
}
if (vr.watertightness < 0.9 && vr.total_edges > 0) {
push_diag(d.errors, DiagSeverity::Error, 3,
"水密性低于 90%(" + std::to_string(
static_cast<int>((1.0 - vr.watertightness) * vr.total_edges)) +
" 条边缺少相邻面)");
d.error_count++;
const bool is_sheet = body.source_class() == BodySource::SurfaceSheet;
std::string n_edges = std::to_string(
static_cast<int>((1.0 - vr.watertightness) * vr.total_edges));
if (is_sheet) {
// SW 口径:SHELL_BASED_SURFACE_MODEL / FBSM / 曲面集导入为曲面实体,
// 开放外壳(水密性 <90%)是曲面体合法形态,不构成导入错误。
// 降级为警告(kind 8):实体化/后续 CAM 前需曲面缝合或加厚。
push_diag(d.warnings, DiagSeverity::Warning, 8,
"曲面体(sheet/曲面模型,非实体):未闭合,水密性低于 90%(" +
n_edges + " 条边缺少相邻面)——开放外壳为曲面体语义合法形态,"
"如需实体化/后续 CAM 请先曲面缝合或加厚");
d.warning_count++;
} else {
push_diag(d.errors, DiagSeverity::Error, 3,
"水密性低于 90%(" + n_edges +
" 条边缺少相邻面)——实体模型存在缺面/破壳");
d.error_count++;
}
}
if (vr.untrimmed_faces > 0) {
// 无边界环面 = 整域未裁剪曲面:无实体边界、无法序列化导出为 STEP 实面。
@@ -873,8 +886,10 @@ BodyDiagnostics diagnose_body(const BrepModel& body) {
if (body.face_edges(fi).empty()) it.faces.push_back(fi);
d.error_count++;
}
if (d.errors.empty() && !vr.valid) {
// 兜底:validate 标记失效但上面未归类的错误(防御)
if (d.errors.empty() && !vr.valid &&
body.source_class() != BodySource::SurfaceSheet) {
// 兜底:validate 标记失效但上面未归类的错误(防御)。
// 曲面体在 wt 降级为警告后 errors 为空属预期(开放外壳合法),不兜底判错。
push_diag(d.errors, DiagSeverity::Error, 5, "模型未通过完整性验证");
d.error_count++;
}
+9
View File
@@ -1308,6 +1308,8 @@ public:
if (fids.empty()) { ++conv_done_; continue; }
int sh = model.add_shell(fids, false);
model.add_body({sh}, find_product_name(fbsm_id));
// FBSM = 钣金中面/曲面蒙皮:开放薄壳合法(曲面体语义)
model.set_source_class(BodySource::SurfaceSheet);
result.push_back(std::move(model));
++conv_done_;
report_convert(static_cast<int>(conv_done_ * 100 / conv_total_), {});
@@ -1371,6 +1373,8 @@ public:
if (cancelled()) {
result.clear(); // 整体丢弃部分结果(与上通道取消语义一致)
}
// GBSR/GEOMETRIC_SET/CBS 曲面集:整域/裁剪面片均为曲面体语义
for (auto& b : result) b.set_source_class(BodySource::SurfaceSheet);
}
}
@@ -2464,6 +2468,11 @@ private:
BrepModel model;
const auto& solid_ent = entities_.at(solid_id);
// SW 口径来源类别:SHELL_BASED_SURFACE_MODEL = 曲面模型(开放外壳属
// 合法曲面体形态,诊断不判"水密性"实体错误);MANIFOLD_SOLID_BREP 等
// 实体语义保持 Solid(开放/破壳才是真实缺陷)。
if (solid_ent.type == "SHELL_BASED_SURFACE_MODEL")
model.set_source_class(BodySource::SurfaceSheet);
// MANIFOLD_SOLID_BREP args: name, outer (CLOSED_SHELL ref)
// SHELL_BASED_SURFACE_MODEL args: name, sbsm_boundary (SET of SHELL refs)
if (solid_ent.args.size() < 2) return model;