// 语料重建工具:为 SAT/XT/IGES 生成完整、可导入的测试文件 // // 背景:tests/data/corpus/ 下原有的 SAT/XT/IGES 生成文件是旧外部脚本 // 产出的残缺占位符(只有拓扑骨架、无几何记录 / P 段被截断),无法导入。 // 本工具用当前仓库内导出器(export_acis_sat / export_parasolid_xt / // export_iges_file)重新生成完整语料,并对每个文件立即回读验证, // 只保留「导出成功且导入非空」的组合,保证语料质量。 // // 用法: // gen_corpus // // 注意:会覆盖目标目录下与输出同名的文件;旧残缺文件由脚本手动删除。 #include "vde/brep/brep.h" #include "vde/brep/iges_export.h" #include "vde/brep/iges_import.h" #include "vde/brep/modeling.h" #include "vde/core/transform.h" #include "vde/foundation/industrial_formats.h" #include #include #include using namespace vde::brep; using namespace vde::core; using namespace vde::io; namespace { struct Spec { const char* shape; // 基元名(用于文件名) int index; // 同基元不同参数编号 const char* xform; // 变换名 BrepModel body; // 已应用变换的模型 }; const char* kXforms[] = {"none", "mirror", "rotate", "scale", "translate"}; BrepModel apply_xform(BrepModel body, int xi) { switch (xi) { case 0: return body; // none case 1: return body.transformed(mirror(Vector3D(0.3, 1.0, 0.7))); case 2: return body.transformed(rotate(Vector3D(1.0, 1.0, 1.0), 0.7)); case 3: return body.transformed(scale(1.5, 0.8, 1.2)); default: return body.transformed(translate(3.0, -2.0, 1.5)); } } // 构造 5 基元 × 每组参数 × 5 变换 std::vector build_specs() { std::vector out; auto push = [&](const char* shape, int idx, BrepModel base) { for (int xi = 0; xi < 5; ++xi) out.push_back({shape, idx, kXforms[xi], apply_xform(base, xi)}); }; // box: 4 组尺寸 push("box", 0, make_box(2.0, 3.0, 4.0)); push("box", 1, make_box(5.0, 1.0, 2.0)); push("box", 2, make_box(0.5, 0.5, 0.5)); push("box", 3, make_box(10.0, 2.0, 6.0)); // cylinder: 4 组半径/高度 push("cylinder", 0, make_cylinder(1.0, 3.0, 24)); push("cylinder", 1, make_cylinder(2.5, 1.0, 24)); push("cylinder", 2, make_cylinder(0.75, 4.0, 24)); push("cylinder", 3, make_cylinder(1.5, 2.5, 24)); // sphere: 4 组半径(降分段控制文件大小) push("sphere", 0, make_sphere(1.0, 16, 8)); push("sphere", 1, make_sphere(2.0, 16, 8)); push("sphere", 2, make_sphere(0.5, 16, 8)); push("sphere", 3, make_sphere(1.5, 16, 8)); // cone: 4 组底部/顶部半径/高度 push("cone", 0, make_cone(1.0, 0.5, 2.0, 24)); push("cone", 1, make_cone(2.0, 0.0, 3.0, 24)); push("cone", 2, make_cone(1.5, 1.0, 1.0, 24)); push("cone", 3, make_cone(0.75, 0.25, 2.5, 24)); // torus: 4 组主/管半径 push("torus", 0, make_torus(3.0, 1.0, 24, 12)); push("torus", 1, make_torus(2.0, 0.5, 24, 12)); push("torus", 2, make_torus(4.0, 1.5, 24, 12)); push("torus", 3, make_torus(2.5, 0.75, 24, 12)); return out; } std::string filename(const Spec& s, const char* ext) { char buf[128]; std::snprintf(buf, sizeof(buf), "%s_%03d_%s.%s", s.shape, s.index, s.xform, ext); return buf; } } // namespace int main(int argc, char** argv) { if (argc < 4) { std::fprintf(stderr, "usage: %s \n", argv[0]); return 1; } const std::string sat_dir = argv[1]; const std::string xt_dir = argv[2]; const std::string iges_dir = argv[3]; auto specs = build_specs(); int total = 0, sat_ok = 0, xt_ok = 0, iges_ok = 0; for (const auto& s : specs) { const std::string base = std::string(s.shape) + "_" + std::to_string(s.index) + "_" + s.xform; // SAT { const std::string p = sat_dir + "/" + filename(s, "sat"); bool wrote = false, read_ok = false; try { export_acis_sat(s.body, p); wrote = true; auto m = import_acis_sat(p); read_ok = m.num_faces() > 0; } catch (const std::exception& e) { std::fprintf(stderr, " [SAT] %s EXC: %s\n", base.c_str(), e.what()); } ++total; if (wrote && read_ok) ++sat_ok; else std::fprintf(stderr, " [SAT] %s -> %s\n", base.c_str(), wrote ? "import empty" : "export failed"); } // XT { const std::string p = xt_dir + "/" + filename(s, "xt"); bool wrote = false, read_ok = false; try { export_parasolid_xt(s.body, p); wrote = true; auto m = import_parasolid_xt(p); read_ok = m.num_faces() > 0; } catch (const std::exception& e) { std::fprintf(stderr, " [XT] %s EXC: %s\n", base.c_str(), e.what()); } ++total; if (wrote && read_ok) ++xt_ok; else std::fprintf(stderr, " [XT] %s -> %s\n", base.c_str(), wrote ? "import empty" : "export failed"); } // IGES { const std::string p = iges_dir + "/" + filename(s, "igs"); bool wrote = false, read_ok = false; try { wrote = export_iges_file(p, {s.body}); auto models = import_iges(p); read_ok = !models.empty(); } catch (const std::exception& e) { std::fprintf(stderr, " [IGES] %s EXC: %s\n", base.c_str(), e.what()); } ++total; if (wrote && read_ok) ++iges_ok; else std::fprintf(stderr, " [IGES] %s -> %s\n", base.c_str(), wrote ? "import empty" : "export failed"); } } std::printf("\ncorpus generation summary:\n"); std::printf(" specs total : %d\n", static_cast(specs.size())); std::printf(" SAT : %d/%d roundtrip ok\n", sat_ok, total); std::printf(" XT : %d/%d roundtrip ok\n", xt_ok, total); std::printf(" IGES : %d/%d roundtrip ok\n", iges_ok, total); return 0; }