fix(cae): reject same-area non-prismatic sweep and validate star mesh
This commit is contained in:
@@ -1614,3 +1614,59 @@ CorpusProbe.LBracketTetraRejected
|
||||
~~~text
|
||||
test_fea_mesh: 40/40 PASS
|
||||
~~~
|
||||
|
||||
|
||||
## 进展(2026-11-14 第三十三轮)
|
||||
|
||||
### 语料批量扫描发现两个真实缺陷
|
||||
|
||||
扫描 corpus/real/step 小文件:
|
||||
|
||||
~~~text
|
||||
occ__bug33638__2.stp
|
||||
V=36 F=12
|
||||
原先 prism 路径输出 12 tets
|
||||
closed=true,但体积误差 50%
|
||||
~~~
|
||||
|
||||
根因:
|
||||
|
||||
~~~text
|
||||
棱柱快速路径只比较两端盖环“面积相同”;
|
||||
不同形状但同面积时被误判为拉伸体。
|
||||
~~~
|
||||
|
||||
修复:
|
||||
|
||||
~~~text
|
||||
两端盖环点数必须一致;
|
||||
投影后逐点距离 <= max(1e-7, target_size*1e-6);
|
||||
否则拒绝 prism 路径。
|
||||
~~~
|
||||
|
||||
扫描还发现:
|
||||
|
||||
~~~text
|
||||
star 路径可能返回 boundary 不闭合的网格。
|
||||
~~~
|
||||
|
||||
修复:
|
||||
|
||||
~~~text
|
||||
star 路径返回前调用 validate_volume_mesh;
|
||||
closed/体积误差不通过则回退。
|
||||
~~~
|
||||
|
||||
### 新增语料回归
|
||||
|
||||
~~~text
|
||||
CorpusProbe.NonPrismaticSameAreaIsNotExtruded
|
||||
occ__bug33638__2.stp
|
||||
若输出网格非空,必须 validate.ok
|
||||
~~~
|
||||
|
||||
全部:
|
||||
|
||||
~~~text
|
||||
test_fea_mesh: 42 tests,41 passed,1 skipped(批量扫描)
|
||||
~~~
|
||||
|
||||
@@ -1050,9 +1050,15 @@ bool make_extruded_prism_tet_mesh(const brep::BrepModel& body,
|
||||
if (!build_prism_loops(body, cap_b, ex, ey, origin, target_size, top_loops))
|
||||
return false;
|
||||
if (top_loops.size() != loops.size()) return false;
|
||||
const double cap_tol = std::max(1e-7, target_size * 1e-6);
|
||||
for (size_t li = 0; li < loops.size(); ++li) {
|
||||
if (loops[li].pts.size() != top_loops[li].pts.size()) return false;
|
||||
const double a0 = loops[li].area, a1 = top_loops[li].area;
|
||||
if (std::abs(a0 - a1) > 1e-3 * std::max(a0, a1)) return false;
|
||||
// 面积相同不代表同形;端点必须在投影后逐点重合。
|
||||
for (size_t k = 0; k < loops[li].pts.size(); ++k)
|
||||
if ((loops[li].pts[k] - top_loops[li].pts[k]).norm() > cap_tol)
|
||||
return false;
|
||||
}
|
||||
// 最大面积为外环,其余为孔
|
||||
size_t outer = 0;
|
||||
@@ -1203,6 +1209,8 @@ bool make_star_tet_mesh(const brep::BrepModel& body, double target_size,
|
||||
if (std::abs(volume - body_volume) > 0.02 * body_volume) return false;
|
||||
mesh.material_ids.assign(mesh.elements.size(), 0);
|
||||
mesh.diagnostic = "tetrahedral_mesh: star-shaped centroid path";
|
||||
const auto check = validate_volume_mesh(body, mesh, 0.02);
|
||||
if (!check.ok) return false;
|
||||
out = std::move(mesh);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <cmath>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <set>
|
||||
|
||||
@@ -718,3 +719,80 @@ TEST(CorpusProbe, LBracketTetraRejected) {
|
||||
EXPECT_NE(tet.diagnostic.find("rejected"), std::string::npos)
|
||||
<< tet.diagnostic;
|
||||
}
|
||||
|
||||
|
||||
TEST(CorpusProbe, BatchSweep) {
|
||||
if (!std::getenv("VDE_CORPUS_SWEEP")) GTEST_SKIP() << "set VDE_CORPUS_SWEEP=1";
|
||||
const char* src_root = std::getenv("VDE_SOURCE_DIR");
|
||||
const std::string dir = std::string(src_root ? src_root : "D:/20_AI/ViewDesignEngine") +
|
||||
"/corpus/real/step";
|
||||
namespace fs = std::filesystem;
|
||||
std::vector<fs::path> files;
|
||||
std::error_code ec;
|
||||
for (const auto& e : fs::directory_iterator(dir, ec)) {
|
||||
if (!e.is_regular_file()) continue;
|
||||
const auto ext = e.path().extension().string();
|
||||
if (ext != ".stp" && ext != ".step" && ext != ".STP" && ext != ".STEP") continue;
|
||||
const auto sz = e.file_size();
|
||||
if (sz > 2 * 1024 * 1024) continue;
|
||||
files.push_back(e.path());
|
||||
}
|
||||
ASSERT_FALSE(files.empty()) << dir;
|
||||
std::sort(files.begin(), files.end(), [](const fs::path& a, const fs::path& b) {
|
||||
return fs::file_size(a) < fs::file_size(b);
|
||||
});
|
||||
int limit = 20;
|
||||
if (const char* l = std::getenv("VDE_CORPUS_LIMIT")) limit = std::max(1, std::atoi(l));
|
||||
int imported = 0, mids_ok = 0, tet_ok = 0, rejected = 0;
|
||||
for (int i = 0; i < static_cast<int>(files.size()) && i < limit; ++i) {
|
||||
auto r = vde::brep::import_cad(files[i].string());
|
||||
if (!r.ok || r.bodies.empty()) {
|
||||
std::fprintf(stderr, "SWEEP import FAIL %s\n", files[i].filename().string().c_str());
|
||||
continue;
|
||||
}
|
||||
++imported;
|
||||
const auto& b = r.bodies.front();
|
||||
const auto mids = vde::cae::extract_midsurface(b, 0.2);
|
||||
if (!mids.empty()) ++mids_ok;
|
||||
TetMeshParams tp;
|
||||
tp.max_size = 5.0;
|
||||
tp.quality_iterations = 0;
|
||||
auto tet = tetrahedral_mesh(b, tp);
|
||||
if (!tet.elements.empty()) {
|
||||
const auto v = validate_volume_mesh(b, tet, 0.02);
|
||||
std::fprintf(stderr, " VAL closed=%d err=%g ok=%d\n",
|
||||
v.closed ? 1 : 0, v.relative_error, v.ok ? 1 : 0);
|
||||
if (v.ok) ++tet_ok;
|
||||
} else if (tet.diagnostic.find("rejected") != std::string::npos) {
|
||||
++rejected;
|
||||
}
|
||||
std::fprintf(stderr, "SWEEP %s V=%u F=%u mids=%zu tet=%zu %s\n",
|
||||
files[i].filename().string().c_str(), b.num_vertices(),
|
||||
b.num_faces(), mids.size(), tet.elements.size(),
|
||||
tet.diagnostic.c_str());
|
||||
}
|
||||
std::fprintf(stderr, "SWEEP summary imported=%d mids=%d tet_ok=%d rejected=%d\n",
|
||||
imported, mids_ok, tet_ok, rejected);
|
||||
}
|
||||
|
||||
|
||||
TEST(CorpusProbe, NonPrismaticSameAreaIsNotExtruded) {
|
||||
const char* src_root = std::getenv("VDE_SOURCE_DIR");
|
||||
const std::string path =
|
||||
std::string(src_root ? src_root : "D:/20_AI/ViewDesignEngine") +
|
||||
"/corpus/real/step/occ__bug33638__2.stp";
|
||||
std::ifstream in(path);
|
||||
if (!in.good()) GTEST_SKIP() << "corpus file missing";
|
||||
auto r = vde::brep::import_cad(path);
|
||||
ASSERT_TRUE(r.ok) << r.diagnostic.summary();
|
||||
TetMeshParams tp;
|
||||
tp.max_size = 5.0;
|
||||
tp.quality_iterations = 0;
|
||||
auto tet = tetrahedral_mesh(r.bodies.front(), tp);
|
||||
if (tet.elements.empty()) {
|
||||
EXPECT_FALSE(tet.diagnostic.empty());
|
||||
} else {
|
||||
const auto v = validate_volume_mesh(r.bodies.front(), tet, 0.02);
|
||||
EXPECT_TRUE(v.ok) << v.diagnostic;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user