Files
ViewDesignEngine/dbg_filelist_health.cpp
hm 5a4bec3e3e fix(validate): 验证口径对齐 OCCT——边界接触降级,仅面积穿透判失效
faces_self_intersect 由 bool 改三值接触类别(0 无/1 边界相触/2 面积穿透):
check1 真实边界曲线相触(T-接触/叠边/分缝,源级合法)降为 warnings,
不再 errors/valid=false;check2 顶点/边严格穿面仍判致命。
ValidationResult 新增 penetration_face_pairs/boundary_touch_face_pairs。
复诊 occt_abc_fail3.txt:143 尾差过验证 108→136/143,仍阻断 7 全为真穿透,
五率投影 ≈99.81%(3,742/3,749);口径单调无回归面。
2026-09-04 01:07:14 +08:00

140 lines
5.8 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 探针:失败清单逐文件复诊(Phase 1 归类用,链接最新内核)
// 读取 VDE_REAL_FAIL_LIST 落盘的失败清单(每行 [import]/[heal]/[valid] <path>,
// 前缀自动剥离,也容忍裸路径),对每个 STEP 文件的每个 body 输出
// raw(导入即) validate → automatic_heal → post validate 一行摘要:
// valid / watertightness / errors 计数与原因关键字 / 拓扑(V/E/F/硬边)。
// 归类口径与 test_model_corpus harness 一致:PASS = valid && wt > 0.99。
// 用法:dbg_filelist_health.exe <fail_list.txt>
#include "vde/brep/step_import.h"
#include "vde/brep/brep_heal.h"
#include "vde/brep/brep_validate.h"
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#ifdef _WIN32
#include <windows.h>
#endif
using namespace vde::brep;
static std::string ext_lower(const std::string& f) {
auto dot = f.find_last_of('.');
if (dot == std::string::npos) return "";
std::string e;
for (size_t i = dot; i < f.size(); ++i)
e += static_cast<char>(std::tolower(static_cast<unsigned char>(f[i])));
return e;
}
static Vector3D face_n_in(const BrepModel& m, int f) {
const auto& surf = m.face_surface(f);
const auto& ku = surf.knots_u();
const auto& kv = surf.knots_v();
double uc = ku.empty() ? 0.5 : 0.5 * (ku.front() + ku.back());
double vc = kv.empty() ? 0.5 : 0.5 * (kv.front() + kv.back());
Vector3D n = surf.normal(uc, vc);
if (m.face(f).reversed) n = -n;
double l = n.norm();
if (l < 1e-12) return Vector3D::UnitZ();
return n / l;
}
static int count_hard(const BrepModel& m) {
int hard = 0;
for (int ei = 0; ei < static_cast<int>(m.num_edges()); ++ei) {
auto efs = m.edge_faces(ei);
if (static_cast<int>(efs.size()) >= 2) {
Vector3D na = face_n_in(m, efs[0]), nb = face_n_in(m, efs[1]);
if (na.dot(nb) <= 0.995) ++hard;
}
}
return hard;
}
static void print_stat(const char* tag, const ValidationResult& v) {
std::printf("%s:%s wt=%.4f nm=%zu dgl=%zu ori=%zu eul=%d err=%zu pene=%zu touch=%zu",
tag, v.valid ? "V" : "I", v.watertightness, v.non_manifold_edges,
v.dangling_edges, v.inconsistent_orientations, v.euler_characteristic,
v.errors.size(), v.penetration_face_pairs, v.boundary_touch_face_pairs);
if (!v.errors.empty()) {
std::printf(" [");
for (size_t i = 0; i < v.errors.size() && i < 3; ++i) {
if (i) std::printf(" | ");
std::printf("%s", v.errors[i].c_str());
}
if (v.errors.size() > 3) std::printf(" | +%zu more", v.errors.size() - 3);
std::printf("]");
}
}
int main(int argc, char** argv) {
setvbuf(stdout, nullptr, _IONBF, 0);
if (argc < 2) { std::printf("usage: dbg_filelist_health.exe <fail_list.txt>\n"); return 1; }
std::ifstream in(argv[1]);
if (!in) { std::printf("[open error] %s\n", argv[1]); return 1; }
std::string line;
int nfiles = 0, nbodies = 0;
int n_import_fail = 0, n_heal_exc = 0;
int ok_after_heal = 0, heal_break = 0, still_invalid = 0, wt_low = 0, degenerate = 0;
while (std::getline(in, line)) {
// 剥离 [import]/[heal]/[valid] 前缀
auto tab = line.find('\t');
std::string f = (tab == std::string::npos) ? line : line.substr(tab + 1);
if (f.empty()) continue;
if (f.front() == '\r' || f.front() == '\n') continue;
std::string tag = (tab == std::string::npos) ? "[file]" : line.substr(0, tab);
std::string ext = ext_lower(f);
if (ext != ".step" && ext != ".stp" && ext != ".p21") {
std::printf("%s NONSTEP %s\n", tag.c_str(), f.c_str());
continue;
}
std::vector<BrepModel> imported;
try { imported = import_step(f); }
catch (const std::exception& e) {
std::printf("%s IMPORT-EXC %s (what=%s)\n", tag.c_str(), f.c_str(), e.what());
++n_import_fail;
continue;
}
if (imported.empty()) {
std::printf("%s IMPORT-EMPTY %s\n", tag.c_str(), f.c_str());
++n_import_fail;
continue;
}
++nfiles;
for (size_t bi = 0; bi < imported.size(); ++bi) {
BrepModel& m = imported[bi];
if (m.num_faces() == 0) { continue; } // 空 body 跳过(占位)
++nbodies;
auto vraw = validate(m);
try { (void)automatic_heal(m); }
catch (...) { std::printf("%s b%zu HEAL-EXC %s\n", tag.c_str(), bi, f.c_str()); ++n_heal_exc; continue; }
auto vpost = validate(m);
auto bb = m.bounds();
double scale = (bb.max() - bb.min()).norm();
int hard = count_hard(m);
std::printf("%s b%zu V=%zu E=%zu F=%zu hard=%d scale=%.4g ",
tag.c_str(), bi, m.num_vertices(), m.num_edges(),
m.num_faces(), hard, scale);
print_stat("raw", vraw);
std::printf(" ");
print_stat("post", vpost);
std::printf(" %s\n", f.c_str());
// 汇总口径(与 harness 一致:PASS = post.valid && post.wt > 0.99)
if (vpost.valid && vpost.watertightness > 0.99) ++ok_after_heal;
else if (vraw.valid && (!vpost.valid || vpost.watertightness <= 0.99)) ++heal_break;
else if (!vpost.valid) ++still_invalid;
else ++wt_low;
}
}
std::printf("[summary] files=%d bodies=%d import_fail=%d heal_exc=%d\n", nfiles, nbodies,
n_import_fail, n_heal_exc);
std::printf("[summary] post-heal ok(valid&&wt>0.99)=%d heal_break(B)=%d still_invalid(C)=%d wt_low=%d\n",
ok_after_heal, heal_break, still_invalid, wt_low);
return 0;
}