// 探针:G2 脏数据 healing 诊断 — 打印边引用分布/悬空边/gap_fill 行为 #include "vde/brep/step_import.h" #include "vde/brep/brep_heal.h" #include "vde/brep/brep_validate.h" #include "vde/brep/advanced_healing.h" #include #include #include using namespace vde::brep; static void dump(const BrepModel& m, const char* tag) { std::printf("[%s] V=%zu E=%zu F=%zu\n", tag, m.num_vertices(), m.num_edges(), m.num_faces()); std::map refs; for (size_t fi = 0; fi < m.num_faces(); ++fi) for (int ei : m.face_edges(static_cast(fi))) refs[ei]++; int d0 = 0, d1 = 0, d2 = 0, d3 = 0; for (size_t ei = 0; ei < m.num_edges(); ++ei) { auto it = refs.find(static_cast(ei)); int c = it == refs.end() ? 0 : it->second; if (c == 0) d0++; else if (c == 1) d1++; else if (c == 2) d2++; else d3++; } std::printf("[%s] edge refs: 0-face=%d 1-face=%d 2-face=%d 3+-face=%d\n", tag, d0, d1, d2, d3); for (size_t ei = 0; ei < m.num_edges(); ++ei) { auto it = refs.find(static_cast(ei)); int c = it == refs.end() ? 0 : it->second; if (c != 2) { const auto& e = m.edge(static_cast(ei)); auto p1 = m.vertex(e.v_start).point; auto p2 = m.vertex(e.v_end).point; std::printf(" e%zu refs=%d v%d(%.6f,%.6f,%.6f)-v%d(%.6f,%.6f,%.6f) len=%.6f\n", ei, c, e.v_start, p1.x(), p1.y(), p1.z(), e.v_end, p2.x(), p2.y(), p2.z(), (p2 - p1).norm()); } } } int main(int argc, char** argv) { setvbuf(stdout, nullptr, _IONBF, 0); if (argc < 2) { std::printf("usage: dbg_g2_diag [tol_gapfill]\n"); return 1; } double gf_tol = argc > 2 ? std::atof(argv[2]) : 1e-6; auto models = import_step(argv[1]); std::printf("imported bodies=%zu\n", models.size()); for (auto& m : models) { { const auto& shells = m.all_shells(); std::printf("[shells] count=%zu\n", shells.size()); for (size_t si = 0; si < shells.size(); ++si) std::printf(" shell%zu faces=%zu\n", si, shells[si].faces.size()); std::map ftype; for (size_t fi = 0; fi < m.num_faces(); ++fi) ftype[static_cast(m.face_type(static_cast(fi)))]++; for (auto& [t, c] : ftype) std::printf(" face_type %d (0=Plane 1=Cyl 2=Cone 3=Sphere 4=Torus 5=Spline 6=Other): %d\n", t, c); } dump(m, "import"); { auto vri = validate(m); std::printf("[validate-import] valid=%d wt=%.4f\n", vri.valid ? 1 : 0, vri.watertightness); for (const auto& e : vri.errors) std::printf(" [vderr] %s\n", e.c_str()); for (const auto& w : vri.warnings) std::printf(" [vdwarn] %s\n", w.c_str()); } // 单独跑 gap_fill 看行为 GapFillReport gf = gap_fill(m, gf_tol); std::printf("[gap_fill tol=%.0e] before=%d found=%d filled=%d after=%d wt=%d\n", gf_tol, gf.boundary_edges_before, gf.holes_found, gf.holes_filled, gf.boundary_edges_after, gf.is_watertight_after ? 1 : 0); for (const auto& w : gf.warnings) std::printf(" [gfwarn] %s\n", w.c_str()); if (gf.holes_filled > 0) dump(m, "after-gap_fill"); // automatic_heal 完整流水线 auto rep = automatic_heal(m); std::printf("[auto_heal] fill=%d simplify=%d regularize=%d orient=%d check=%d score=%d\n", rep.fill.items_fixed, rep.simplify.items_fixed, rep.regularize.items_fixed, rep.orient.items_fixed, rep.check.items_fixed, rep.overall_score); for (const auto& w : rep.warnings) std::printf(" [warn] %s\n", w.c_str()); dump(m, "healed"); { // 打印指定面 ID 的类型与顶点(诊断自交面) std::vector ids = {2,4,5,16,30,37,394,356,357,361,371}; for (int fid : ids) { if (fid >= static_cast(m.num_faces())) continue; std::printf(" face %d type=%d edges=[", fid, static_cast(m.face_type(fid))); for (int ei : m.face_edges(fid)) std::printf("%d ", ei); std::printf("]\n"); } } auto vr = validate(m); std::printf("[validate] valid=%d wt=%.4f\n", vr.valid ? 1 : 0, vr.watertightness); for (const auto& e : vr.errors) std::printf(" [vderr] %s\n", e.c_str()); for (const auto& w : vr.warnings) std::printf(" [vdwarn] %s\n", w.c_str()); // heal 之后补跑 gap_fill GapFillReport gf2 = gap_fill(m, gf_tol); std::printf("[gap_fill-after-heal tol=%.0e] before=%d found=%d filled=%d after=%d wt=%d\n", gf_tol, gf2.boundary_edges_before, gf2.holes_found, gf2.holes_filled, gf2.boundary_edges_after, gf2.is_watertight_after ? 1 : 0); for (const auto& w : gf2.warnings) std::printf(" [gf2warn] %s\n", w.c_str()); if (gf2.holes_filled > 0) { dump(m, "healed+fill"); auto vr2 = validate(m); std::printf("[validate-after-fill] valid=%d wt=%.4f\n", vr2.valid ? 1 : 0, vr2.watertightness); for (const auto& e : vr2.errors) std::printf(" [vderr] %s\n", e.c_str()); for (const auto& w : vr2.warnings) std::printf(" [vdwarn] %s\n", w.c_str()); } } return 0; }