Files
ViewDesignEngine/bench/bench_boolean.cpp
T
hm b378b191da
Build & Test / build-and-test (push) Canceled after 0s
VDE Build & Test / build-and-test (push) Canceled after 0s
Build & Test / python-bindings (push) Canceled after 0s
build(io/brep): VDE-006/013/067 依赖环解除 + 模块开关接线 + 裸 mesh:: 清理
VDE-006:新增集成层 vde_io 归集跨层 TU,依赖图变严格单向
io→brep→{sdf,mesh}→{curves,collision}→spatial→core→foundation,删除
-Wl,--start-group;BrepModel 桥接(brep_to_mesh/mesh_bridge)归 vde_brep。
移除兜底后暴露并修复两处反向依赖:core/icp.cpp→vde_spatial,
brep/parallel_boolean.cpp→vde::boolean(VDE_DEPS_brep 增 boolean)。

VDE-013:顶层解析 VDE_BUILD_*→VDE_ENABLE_*,VDE_DEPS_* 级联关闭,
src/ 与 tests/ 按 VDE_ENABLE_* 门控,使模块开关真正生效。

VDE-067:全仓裸 mesh:: 清理为完全限定名 vde::mesh::(正则命中 0)。

回归:全量构建 EXIT 0;test_icp/test_parallel_boolean/test_geometry_completion
全绿。既有缺陷(FEA 球面网格挂起、CAM in_range 哨兵、3MF 装配、时序竞态)
经取证与本批无关,记入 docs/reference/audit-feedback.md §5。
2026-10-07 06:39:07 +08:00

93 lines
3.4 KiB
C++
Raw 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.
/// bench_boolean.cpp — 3D mesh boolean operation benchmarks
///
/// Metrics:
/// MeshBoolean_Union/N{faces} — sphere ∪ sphere
/// MeshBoolean_Intersection/N{faces} — sphere ∩ sphere
///
/// Two spheres (radius 1.0, separated by 0.5 along X) are generated via BrepModel,
/// discretized to HalfedgeMesh with controlled segment counts, then passed to
/// mesh_boolean().
#include <benchmark/benchmark.h>
#include <vde/brep/brep.h>
#include <vde/brep/modeling.h>
#include <vde/mesh/mesh_boolean.h>
#include <vde/mesh/halfedge_mesh.h>
#include <cmath>
using namespace vde;
namespace {
struct SpherePair {
vde::mesh::HalfedgeMesh a;
vde::mesh::HalfedgeMesh b;
};
/// Create two intersecting spheres with approximately `face_count` faces each.
/// sphere_a at origin, sphere_b translated by +1.0 along X (overlap ~0.5)
SpherePair make_sphere_pair(int face_count) {
// make_sphere produces ~ 2 * seg_u * seg_v faces → solve for seg
int seg = std::max(static_cast<int>(std::ceil(std::sqrt(face_count / 2.0))), 3);
// Use deflection to control tessellation density per face
// Each NURBS face tessellates res×res quads where res = max(4, 1/deflection)
// For benchmark we want coarse tessellation: deflection = 0.5 → res=4
double deflection = 0.5;
auto sphere_a = brep::make_sphere(1.0, seg, seg).to_mesh(deflection);
auto sphere_b = brep::make_sphere(1.0, seg, seg).to_mesh(deflection);
// Translate sphere_b by +1.0 along X so they overlap by ~0.5
// Rebuild from triangles with translated vertices
vde::mesh::HalfedgeMesh b_moved;
std::vector<core::Point3D> all_verts;
std::vector<std::array<int, 3>> all_tris;
for (size_t fi = 0; fi < sphere_b.num_faces(); ++fi) {
auto fv = sphere_b.face_vertices(static_cast<int>(fi));
if (fv.size() < 3) continue;
int base = static_cast<int>(all_verts.size());
for (int vi : fv) {
auto p = sphere_b.vertex(vi);
all_verts.push_back(core::Point3D(p.x() + 1.0, p.y(), p.z()));
}
// triangulate if > 3
for (size_t j = 1; j + 1 < fv.size(); ++j)
all_tris.push_back({base, base + static_cast<int>(j), base + static_cast<int>(j + 1)});
}
b_moved.build_from_triangles(all_verts, all_tris);
return {sphere_a, b_moved};
}
} // namespace
class MeshBooleanFixture : public benchmark::Fixture {
public:
void SetUp(const benchmark::State& state) override {
auto pair = make_sphere_pair(state.range(0));
mesh_a = std::move(pair.a);
mesh_b = std::move(pair.b);
}
vde::mesh::HalfedgeMesh mesh_a;
vde::mesh::HalfedgeMesh mesh_b;
};
BENCHMARK_DEFINE_F(MeshBooleanFixture, Union)(benchmark::State& state) {
for (auto _ : state) {
auto result = vde::mesh::mesh_boolean(mesh_a, mesh_b, vde::mesh::BooleanOp::Union);
benchmark::DoNotOptimize(result.num_faces());
}
state.SetItemsProcessed(state.iterations());
}
BENCHMARK_REGISTER_F(MeshBooleanFixture, Union)->Arg(100)->Arg(500);
BENCHMARK_DEFINE_F(MeshBooleanFixture, Intersection)(benchmark::State& state) {
for (auto _ : state) {
auto result = vde::mesh::mesh_boolean(mesh_a, mesh_b, vde::mesh::BooleanOp::Intersection);
benchmark::DoNotOptimize(result.num_faces());
}
state.SetItemsProcessed(state.iterations());
}
BENCHMARK_REGISTER_F(MeshBooleanFixture, Intersection)->Arg(100)->Arg(500);