feat(brep): add bad sheet detection; treat empty model check as pass

This commit is contained in:
hm
2026-11-07 18:13:14 +08:00
parent babae801a2
commit f0fdc40657
3 changed files with 38 additions and 1 deletions
+3
View File
@@ -282,6 +282,9 @@ bool heal_topology(BrepModel& body, double tolerance = 1e-6);
*/
[[nodiscard]] bool heal_face_quality_ok(size_t faces_before, size_t faces_after);
/// 坏面片检测:空曲面/空环/非法边引用;返回面索引。
[[nodiscard]] std::vector<int> find_bad_sheets(const BrepModel& body);
// ── 旧版兼容 ──
/**
+29 -1
View File
@@ -3339,7 +3339,7 @@ StepResult step_check(const BrepModel& body) {
result.items_fixed++; // 欧拉验证通过
}
} else {
result.success = false;
// 空模型没有可校验实体:按“无缺陷”处理,而不是失败。
result.warnings.push_back("Check: 模型为空,跳过欧拉验证");
}
@@ -3678,6 +3678,34 @@ bool heal_face_quality_ok(size_t faces_before, size_t faces_after) {
return faces_after <= heal_face_quality_bound(faces_before);
}
std::vector<int> find_bad_sheets(const BrepModel& body) {
std::vector<int> bad;
for (int fi = 0; fi < static_cast<int>(body.num_faces()); ++fi) {
const auto& f = body.face(fi);
if (f.surface_id < 0 ||
f.surface_id >= static_cast<int>(body.num_surfaces()) ||
body.surface(f.surface_id).control_points().empty() ||
f.loops.empty()) {
bad.push_back(fi);
continue;
}
bool broken = false;
for (int lid : f.loops) {
const auto& loop = body.loop_by_id(lid);
if (loop.edges.empty()) { broken = true; break; }
for (int eid : loop.edges)
if (eid < 0 || eid >= static_cast<int>(body.num_edges())) {
broken = true;
break;
}
if (broken) break;
}
if (broken) bad.push_back(fi);
}
return bad;
}
// ═══════════════════════════════════════════════════════════
// VDE-337: Model Healing Enhancements
// ═══════════════════════════════════════════════════════════
+6
View File
@@ -935,3 +935,9 @@ TEST(BrepHealRulesWave3Test, DiagnosticsReport_ContainsRuleCounts) {
EXPECT_NE(rep.find("split_nonmanifold_faces"), std::string::npos);
EXPECT_NE(rep.find("tolerance_used"), std::string::npos);
}
TEST(BrepHealTest, FindBadSheetsOnBoxIsEmpty) {
auto box = make_box(10, 10, 10);
EXPECT_TRUE(find_bad_sheets(box).empty());
}