fix(measure): VDE-1269 multiply-connected volume/mass (1.0.125)
This commit is contained in:
@@ -9,6 +9,20 @@
|
||||
> 与 `origin/main` 同期新增的 1.0.45..1.0.61(格式/语料工作)合并后按时间顺序重编号为 **1.0.62..1.0.65**
|
||||
> (本文件中旧编号 1.0.45..1.0.48 的引用即指这四批;历史验证报告 55-58 中的版本号为验证当时编号)。
|
||||
|
||||
## [1.0.125] — 2026-11-02
|
||||
|
||||
### VDE-1269 多连通体测量
|
||||
|
||||
- analytic_measure/mass_properties 按 closed component + 嵌套树(solid-angle winding)分组;不相交 abs 相加、嵌套按深度符号;
|
||||
- VDE-1269 场景 volume=4000、area=2000、centroid=(0,0,5);嵌套腔体 7000;单连通不变;
|
||||
- test_measure 40/40、test_brep_boolean 39/39;
|
||||
|
||||
### 验证与工程(1.0.125)
|
||||
|
||||
- 版本 1.0.125 全链路同步;构建 0 error;
|
||||
- 全量 ctest **7962 注册、7962 PASS、0 failed**(681.93s);
|
||||
- 自验证报告:[129-VDE1.0.125-VDE1269多连通体测量修复自验证报告.md](docs/reference/129-VDE1.0.125-VDE1269多连通体测量修复自验证报告.md);
|
||||
|
||||
## [1.0.124] — 2026-11-02
|
||||
|
||||
### FMT-11 DWFx 图像/二进制 W2D 诊断
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
project(ViewDesignEngine VERSION 1.0.124 LANGUAGES C CXX)
|
||||
project(ViewDesignEngine VERSION 1.0.125 LANGUAGES C CXX)
|
||||
|
||||
# MSVC: expose M_PI from <cmath> (GCC/MinGW define it by default).
|
||||
if(MSVC)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
C++20 全栈 B-Rep 几何内核。对标 Parasolid/ACIS,覆盖曲面建模、网格处理、格式交换、CAM 制造、工程图、装配体。
|
||||
|
||||
[](CHANGELOG.md)
|
||||
[](CHANGELOG.md)
|
||||
[](CMakeLists.txt)
|
||||
[](LICENSE)
|
||||
[]()
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
| **日期** | 2026-11-02 |
|
||||
| **模块** | `vde::brep` — `src/brep/measure.cpp`(`analytic_measure` / `mass_properties`)、`src/brep/brep.cpp`(`BrepModel::body_volume`) |
|
||||
| **严重度** | P2(不崩溃;多体 volume/mass 错误) |
|
||||
| **状态** | **Open**(host 侧已加 workaround;VDE 侧建议修) |
|
||||
| **状态** | **Fixed(1.0.125)**:component 分组 + 嵌套树;VDE-1269 场景 volume=4000/area=2000/centroid(0,0,5);嵌套腔体 7000;单连通不变 | |
|
||||
| **宿主环境** | ViewDesign `main`(VDE pin `e98f50c5` v1.0.0-2156);Windows x64 Release |
|
||||
|
||||
## 现象
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# 模块功能说明书
|
||||
|
||||
> ViewDesignEngine v1.0.124 · **30 个 CMake 模块**(11 几何内核 + 2 集成层 + 17 官方/应用模块)+ 分层聚合 `vde::kernel` / `vde::io` / `vde::app`;插件 ABI **1.9**,管理器见 `include/vde/plugin/`。当前状态总览见 [106-VDE工程现状总览](../reference/106-VDE工程现状总览(1.0.107).md)。
|
||||
> ViewDesignEngine v1.0.125 · **30 个 CMake 模块**(11 几何内核 + 2 集成层 + 17 官方/应用模块)+ 分层聚合 `vde::kernel` / `vde::io` / `vde::app`;插件 ABI **1.9**,管理器见 `include/vde/plugin/`。当前状态总览见 [106-VDE工程现状总览](../reference/106-VDE工程现状总览(1.0.107).md)。
|
||||
|
||||
## foundation — 基础设施 + 格式 IO
|
||||
|
||||
|
||||
+2
-1
@@ -1,6 +1,6 @@
|
||||
# ViewDesignEngine 文档
|
||||
|
||||
> v1.0.124 · C++20 B-Rep 几何引擎 + 微内核插件架构(ABI 1.9 / 30 模块 / 7822 测试) · Apache 2.0
|
||||
> v1.0.125 · C++20 B-Rep 几何引擎 + 微内核插件架构(ABI 1.9 / 30 模块 / 7822 测试) · Apache 2.0
|
||||
|
||||
## 快速导航
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
| CAE 工程立项 | [VDCAE 独立 CAE 工程设计与需求规格](design/cae-project-design.md) |
|
||||
| 插件生态团队交接 | [插件生态交接与规划](design/plugin-ecosystem-handoff.md) |
|
||||
| 查看功能缺口/缺陷 | [107-VDE功能与缺陷审计(1.0.107)](reference/107-VDE功能与缺陷审计(1.0.107).md) |
|
||||
| 查看 1.0.125 VDE-1269 | [129 VDE-1269 自验证报告](reference/129-VDE1.0.125-VDE1269多连通体测量修复自验证报告.md) |
|
||||
| 查看 1.0.124 FMT-11 DWFx | [128 DWFx 自验证报告](reference/128-VDE1.0.124-FMT11-DWFx图像与二进制W2D自验证报告.md) |
|
||||
| 查看 1.0.123 FMT-11 COLLADA | [127 FMT-11 自验证报告](reference/127-VDE1.0.123-FMT11-COLLADA材质自验证报告.md) |
|
||||
| 查看 1.0.122 FMT-10 glTF | [126 FMT-10 自验证报告](reference/126-VDE1.0.122-FMT10-glTF-PBR材质自验证报告.md) |
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
# VDE 1.0.125 VDE-1269 多连通体测量修复自验证报告
|
||||
|
||||
> 版本 **1.0.125** · 日期 2026-11-02 · 性质:Lead 自验证(独立 verifier 待)
|
||||
> 反馈:[VDE-1269](../feedback/VDE-1269.md) 多连通 BrepModel analytic_measure/mass_properties 符号相消
|
||||
> 基线:1.0.124 全量 7959/7959 PASS
|
||||
|
||||
## 1. 结论
|
||||
|
||||
一个 BrepModel 含多个不连通闭合壳时,volume/mass 不再全局符号相消为 0;VDE-1269 场景 volume=4000、area=2000、centroid=(0,0,5)。
|
||||
**Release 全量 CTest 7962/7962 PASS,0 failed。**
|
||||
|
||||
## 2. 实现
|
||||
|
||||
- 按几何共享边把面分成 closed component(DSU,兼容 boolean 未完全缝合的重复顶点);
|
||||
- AABB + solid-angle winding number 建立嵌套树(避免 ray parity 在重复共面三角形上的偶偶误判);
|
||||
- analytic_measure:每个 component signed triple 先 abs,再按嵌套深度奇偶组合(root +、腔体 −、岛中岛 +);不嵌套 root 各自 abs 相加;
|
||||
- mass_properties:多分量按同一嵌套树计算体积/一阶矩/二阶矩,嵌套按深度符号,root 质心/惯量正体积加权;
|
||||
- 单连通仍走原实现;area/centroid 口径不变;
|
||||
- `analytic_volume`/`BrepModel::body_volume`/`volume` 同步。
|
||||
|
||||
## 3. 测试与结果
|
||||
|
||||
- VDE1269Measure.DisjointComponentsVolumeMass:volume=4000、area=2000、centroid=(0,0,5)、mass volume 4000;
|
||||
- VDE1269Measure.NestedCavityKeepsSign:20³−10³ volume=7000、area=3000;
|
||||
- VDE1269Measure.SingleConnectedUnchanged:480/376/centroid(1,2,3);
|
||||
- test_measure 40/40、test_brep_boolean 39/39;定向 Measure/BrepBoolean 51/51。
|
||||
|
||||
## 4. 验证
|
||||
|
||||
- 构建 0 error;全量 ctest **7962 注册 / 7962 PASS / 0 failed**(681.93s,20 skip);
|
||||
- release 门禁提交前复跑(目标 14/14)。
|
||||
|
||||
## 5. 限制
|
||||
|
||||
- mesh-only 三角汤 fast path(VDE-1262)在多分量时仍走全局 signed/abs,未纳入本次分组;host 精确 Boolean 路径已覆盖;
|
||||
- 嵌套关系依赖 component 可三角化;极薄/不水密 shell 会退回各自 abs;
|
||||
- 1.0.125 尚未独立 verifier。
|
||||
@@ -1,6 +1,6 @@
|
||||
# ViewDesignEngine API 参考文档
|
||||
|
||||
> **版本**: 1.0.124 · **分支**: main · **语言**: C++20 · **插件 ABI**: 1.9
|
||||
> **版本**: 1.0.125 · **分支**: main · **语言**: C++20 · **插件 ABI**: 1.9
|
||||
|
||||
## 📚 文档索引
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
| **1.0.108 计划** | [108-VDE1.0.108改进计划与执行看板](108-VDE1.0.108改进计划与执行看板.md) | 本轮 WP-108-01..10 范围/验收/执行记录 |
|
||||
| **格式专项立项** | [109-格式互操作专项分批计划](../reference/109-格式互操作专项分批计划.md) | F1 STEP/IGES、F2 压缩/网格、F3 DWG/Rhino/PRC、F4 插件化 |
|
||||
| **1.0.108 验证** | [108 自验证报告](108-VDE1.0.108改进批次自验证报告.md) | 7850/7850、定向、Debug ICP/fuzz、覆盖率基线 |
|
||||
| **1.0.125 VDE-1269** | [129 VDE-1269 自验证报告](129-VDE1.0.125-VDE1269多连通体测量修复自验证报告.md) | 多连通体积/质量;7962/7962 |
|
||||
| **1.0.124 FMT-11 DWFx** | [128 DWFx 自验证报告](128-VDE1.0.124-FMT11-DWFx图像与二进制W2D自验证报告.md) | 图像元数据/W2D 诊断;7959/7959 |
|
||||
| **1.0.123 FMT-11** | [127 FMT-11 自验证报告](127-VDE1.0.123-FMT11-COLLADA材质自验证报告.md) | COLLADA 材质/多 primitive;7955/7955 |
|
||||
| **1.0.122 FMT-10** | [126 FMT-10 自验证报告](126-VDE1.0.122-FMT10-glTF-PBR材质自验证报告.md) | glTF PBR/动画元数据;7952/7952 |
|
||||
|
||||
@@ -1160,7 +1160,7 @@ public:
|
||||
// VDE-181: 包围盒 + 体属性
|
||||
// ═══════════════════════════════════════════════
|
||||
|
||||
/** @brief 模型体积近似 (VDE-181) — AABB 体积 */
|
||||
/** @brief 体体积(解析质量度量;多连通按 closed component 分组,嵌套腔体相减;VDE-1269) */
|
||||
[[nodiscard]] double body_volume() const;
|
||||
|
||||
/** @brief 模型表面积近似 (VDE-181) — AABB 表面积 */
|
||||
|
||||
@@ -93,7 +93,7 @@ struct BomEntry;
|
||||
* @return 解析体积(正数)与面积,与 SolidWorks MassProperty 同口径
|
||||
*/
|
||||
struct AnalyticMeasure {
|
||||
double volume = 0.0; ///< ∫S·(Su×Sv)/3,封闭整壳
|
||||
double volume = 0.0; ///< 多 closed component 分组后的正体积(嵌套腔体相减)
|
||||
double surface_area = 0.0; ///< ∫|Su×Sv|
|
||||
long long evals = 0; ///< [diag] 全件曲面求值次数(= 解析档实际开销)
|
||||
int capped_faces = 0; ///< [diag] 命中求值上限而降级为粗积的面数(>0 表示
|
||||
|
||||
@@ -28,11 +28,11 @@
|
||||
#define VDE_VERSION_MINOR 0
|
||||
|
||||
/// 修订版本号(向后兼容的问题修复)
|
||||
#define VDE_VERSION_PATCH 124
|
||||
#define VDE_VERSION_PATCH 125
|
||||
|
||||
/// 版本字符串(与 CHANGELOG / CMake project VERSION 保持同步;
|
||||
/// 1.0.1 之前的漂移已在本版修正)
|
||||
#define VDE_VERSION_STRING "1.0.124"
|
||||
#define VDE_VERSION_STRING "1.0.125"
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════
|
||||
// D11: API 版本化 + 稳定性声明
|
||||
@@ -90,7 +90,7 @@
|
||||
|
||||
/// 当前版本号整型编码(1.0.83 → 10083;与 VDE_VERSION_MAJOR/MINOR/PATCH 及
|
||||
/// CHANGELOG / CMake project VERSION 同步)
|
||||
#define VDE_VERSION_NUM VDE_VERSION_CODE(1, 0, 124)
|
||||
#define VDE_VERSION_NUM VDE_VERSION_CODE(1, 0, 125)
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════
|
||||
// 构建信息(由 CMake configure_file 注入)
|
||||
|
||||
+349
-5
@@ -16,6 +16,8 @@
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <numeric>
|
||||
|
||||
using vde::core::AABB3D;
|
||||
using vde::core::Point2D;
|
||||
@@ -745,6 +747,287 @@ FaceMeasure face_measure(const BrepModel& body, int face_index, double deflectio
|
||||
return out;
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
// ── VDE-1269:多连通/多体 B-Rep 的 closed component 分组 ──────────
|
||||
// analytic_measure/mass_properties 的 volume 不能对全部面做一次 signed 求和
|
||||
// 后统一 abs:同一 BrepModel 内两个绕向相反的独立闭合壳会抵消为 0。
|
||||
// 这里按共享边把面分成连通分量(closed component),再按 AABB+射线包含
|
||||
// 关系还原嵌套树:同层不嵌套分量取 abs 后相加,嵌套分量保留符号相减。
|
||||
|
||||
struct MeasureComponentInfo {
|
||||
std::vector<int> faces;
|
||||
AABB3D bounds;
|
||||
};
|
||||
|
||||
struct MeasurePartition {
|
||||
std::vector<int> face_component; // face index -> component index
|
||||
std::vector<MeasureComponentInfo> components;
|
||||
};
|
||||
|
||||
MeasurePartition partition_measure_components(const BrepModel& body) {
|
||||
MeasurePartition out;
|
||||
const int n = static_cast<int>(body.num_faces());
|
||||
if (n <= 0) return out;
|
||||
out.face_component.assign(static_cast<size_t>(n), -1);
|
||||
std::vector<int> uf(static_cast<size_t>(n));
|
||||
std::iota(uf.begin(), uf.end(), 0);
|
||||
std::function<int(int)> find = [&](int x) -> int {
|
||||
return uf[static_cast<size_t>(x)] == x
|
||||
? x
|
||||
: (uf[static_cast<size_t>(x)] = find(uf[static_cast<size_t>(x)]));
|
||||
};
|
||||
auto unite = [&](int a, int b) {
|
||||
a = find(a); b = find(b);
|
||||
if (a != b) uf[static_cast<size_t>(b)] = a;
|
||||
};
|
||||
auto vkey = [&](int vid) -> std::array<long long, 3> {
|
||||
const auto& p = body.vertex(vid).point;
|
||||
return {std::llround(p.x() * 1e9), std::llround(p.y() * 1e9),
|
||||
std::llround(p.z() * 1e9)};
|
||||
};
|
||||
using EdgeKey = std::pair<std::array<long long, 3>, std::array<long long, 3>>;
|
||||
auto ekey = [&](int eid) -> EdgeKey {
|
||||
const auto& e = body.edge(eid);
|
||||
auto a = vkey(e.v_start), b = vkey(e.v_end);
|
||||
if (a > b) std::swap(a, b);
|
||||
return {a, b};
|
||||
};
|
||||
std::map<EdgeKey, int> edge_owner;
|
||||
for (int fi = 0; fi < n; ++fi) {
|
||||
for (int eid : body.face_edges(fi)) {
|
||||
const EdgeKey k = ekey(eid);
|
||||
auto it = edge_owner.find(k);
|
||||
if (it == edge_owner.end()) edge_owner.emplace(k, fi);
|
||||
else unite(fi, it->second);
|
||||
}
|
||||
}
|
||||
std::map<int, int> root_comp;
|
||||
for (int fi = 0; fi < n; ++fi) {
|
||||
const int r = find(fi);
|
||||
auto it = root_comp.find(r);
|
||||
int ci;
|
||||
if (it == root_comp.end()) {
|
||||
ci = static_cast<int>(out.components.size());
|
||||
root_comp.emplace(r, ci);
|
||||
out.components.push_back({});
|
||||
} else {
|
||||
ci = it->second;
|
||||
}
|
||||
out.face_component[static_cast<size_t>(fi)] = ci;
|
||||
auto& comp = out.components[static_cast<size_t>(ci)];
|
||||
comp.faces.push_back(fi);
|
||||
comp.bounds.expand(body.face_bounds(fi));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
struct ComponentMeshData {
|
||||
std::vector<Point3D> verts;
|
||||
std::vector<std::array<int, 3>> tris;
|
||||
std::vector<int> tri_face;
|
||||
std::vector<std::vector<std::array<int, 3>>> comp_tris;
|
||||
};
|
||||
|
||||
void build_component_mesh(const BrepModel& body, const MeasurePartition& part,
|
||||
double deflection, ComponentMeshData& out) {
|
||||
out = ComponentMeshData{};
|
||||
body.to_mesh_tagged(deflection, out.verts, out.tris, out.tri_face);
|
||||
out.comp_tris.assign(part.components.size(), {});
|
||||
if (out.tri_face.size() != out.tris.size()) return;
|
||||
for (size_t ti = 0; ti < out.tris.size(); ++ti) {
|
||||
const int f = out.tri_face[ti];
|
||||
if (f < 0 || f >= static_cast<int>(part.face_component.size())) continue;
|
||||
const int c = part.face_component[static_cast<size_t>(f)];
|
||||
if (c < 0 || c >= static_cast<int>(out.comp_tris.size())) continue;
|
||||
out.comp_tris[static_cast<size_t>(c)].push_back(out.tris[ti]);
|
||||
}
|
||||
}
|
||||
|
||||
bool bounds_contain(const AABB3D& outer, const AABB3D& inner) {
|
||||
const double scale = std::max(1.0, outer.extent().norm());
|
||||
const double tol = 1e-9 * scale;
|
||||
const Point3D& omin = outer.min();
|
||||
const Point3D& omax = outer.max();
|
||||
const Point3D& imin = inner.min();
|
||||
const Point3D& imax = inner.max();
|
||||
return imin.x() >= omin.x() - tol && imax.x() <= omax.x() + tol &&
|
||||
imin.y() >= omin.y() - tol && imax.y() <= omax.y() + tol &&
|
||||
imin.z() >= omin.z() - tol && imax.z() <= omax.z() + tol;
|
||||
}
|
||||
|
||||
bool point_inside_component(const std::vector<Point3D>& verts,
|
||||
const std::vector<std::array<int, 3>>& tris,
|
||||
const Point3D& p) {
|
||||
if (tris.empty()) return false;
|
||||
// Solid-angle winding number:比 ray parity 更能容忍 boolean 结果里
|
||||
// 共面重复/重叠三角形(parity 会被重复面翻成偶数而误判)。
|
||||
double angle = 0.0;
|
||||
for (const auto& t : tris) {
|
||||
const Vector3D a = verts[static_cast<size_t>(t[0])] - p;
|
||||
const Vector3D b = verts[static_cast<size_t>(t[1])] - p;
|
||||
const Vector3D c = verts[static_cast<size_t>(t[2])] - p;
|
||||
const double la = a.norm(), lb = b.norm(), lc = c.norm();
|
||||
if (la < 1e-15 || lb < 1e-15 || lc < 1e-15) continue;
|
||||
const double num = a.dot(b.cross(c));
|
||||
const double den = la * lb * lc + a.dot(b) * lc + b.dot(c) * la +
|
||||
c.dot(a) * lb;
|
||||
angle += 2.0 * std::atan2(num, den);
|
||||
}
|
||||
return std::abs(angle) > 2.0 * 3.14159265358979323846;
|
||||
}
|
||||
|
||||
std::vector<int> component_parents(const MeasurePartition& part,
|
||||
const ComponentMeshData& mesh) {
|
||||
const int nc = static_cast<int>(part.components.size());
|
||||
std::vector<int> parents(static_cast<size_t>(nc), -1);
|
||||
for (int i = 0; i < nc; ++i) {
|
||||
const auto& ci = part.components[static_cast<size_t>(i)];
|
||||
if (ci.faces.empty()) continue;
|
||||
Point3D rep = ci.bounds.center();
|
||||
if (!mesh.comp_tris[static_cast<size_t>(i)].empty()) {
|
||||
const auto& tri = mesh.comp_tris[static_cast<size_t>(i)][0];
|
||||
rep = mesh.verts[static_cast<size_t>(tri[0])];
|
||||
}
|
||||
const double ivol = ci.bounds.volume();
|
||||
double best_vol = std::numeric_limits<double>::max();
|
||||
int best = -1;
|
||||
for (int j = 0; j < nc; ++j) {
|
||||
if (j == i) continue;
|
||||
const auto& cj = part.components[static_cast<size_t>(j)];
|
||||
if (cj.faces.empty()) continue;
|
||||
const double jvol = cj.bounds.volume();
|
||||
if (!(jvol > ivol * (1.0 + 1e-12))) continue; // 防 parent 环
|
||||
if (!bounds_contain(cj.bounds, ci.bounds)) continue;
|
||||
if (!point_inside_component(
|
||||
mesh.verts, mesh.comp_tris[static_cast<size_t>(j)], rep))
|
||||
continue;
|
||||
if (jvol < best_vol) { best_vol = jvol; best = j; }
|
||||
}
|
||||
parents[static_cast<size_t>(i)] = best;
|
||||
}
|
||||
return parents;
|
||||
}
|
||||
|
||||
std::vector<int> component_roots(const std::vector<int>& parents) {
|
||||
std::vector<int> roots(parents.size(), -1);
|
||||
for (size_t i = 0; i < parents.size(); ++i) {
|
||||
int x = static_cast<int>(i);
|
||||
while (x >= 0 && parents[static_cast<size_t>(x)] >= 0)
|
||||
x = parents[static_cast<size_t>(x)];
|
||||
roots[i] = x;
|
||||
}
|
||||
return roots;
|
||||
}
|
||||
|
||||
MassProperties mass_properties_multi_component(const BrepModel& body,
|
||||
const MeasurePartition& part) {
|
||||
ComponentMeshData mesh;
|
||||
build_component_mesh(body, part, 0.05, mesh);
|
||||
const auto parents = component_parents(part, mesh);
|
||||
const auto roots = component_roots(parents);
|
||||
const size_t nc = part.components.size();
|
||||
std::vector<double> comp_vol(nc, 0.0);
|
||||
std::vector<Point3D> comp_first(nc, Point3D(0, 0, 0));
|
||||
std::vector<Eigen::Matrix3d> comp_second(nc, Eigen::Matrix3d::Zero());
|
||||
|
||||
auto comp = [](const Point3D& p, int i) -> double {
|
||||
return i == 0 ? p.x() : (i == 1 ? p.y() : p.z());
|
||||
};
|
||||
for (size_t ti = 0; ti < mesh.tris.size(); ++ti) {
|
||||
const int f = mesh.tri_face[ti];
|
||||
if (f < 0 || f >= static_cast<int>(part.face_component.size())) continue;
|
||||
const int ci = part.face_component[static_cast<size_t>(f)];
|
||||
if (ci < 0 || ci >= static_cast<int>(nc)) continue;
|
||||
const auto& tri = mesh.tris[ti];
|
||||
const Point3D& v0 = mesh.verts[static_cast<size_t>(tri[0])];
|
||||
const Point3D& v1 = mesh.verts[static_cast<size_t>(tri[1])];
|
||||
const Point3D& v2 = mesh.verts[static_cast<size_t>(tri[2])];
|
||||
const double tet_vol = (v0.cross(v1)).dot(v2) / 6.0;
|
||||
if (std::abs(tet_vol) < 1e-15) continue;
|
||||
comp_vol[static_cast<size_t>(ci)] += tet_vol;
|
||||
comp_first[static_cast<size_t>(ci)] +=
|
||||
(v0 + v1 + v2) * (0.25 * tet_vol);
|
||||
const Point3D* vs[3] = {&v0, &v1, &v2};
|
||||
for (int p = 0; p < 3; ++p) {
|
||||
for (int q = 0; q < 3; ++q) {
|
||||
const double w = tet_vol * (p == q ? 0.1 : 0.05);
|
||||
for (int i = 0; i < 3; ++i)
|
||||
for (int j = 0; j < 3; ++j)
|
||||
comp_second[static_cast<size_t>(ci)](i, j) +=
|
||||
w * comp(*vs[p], i) * comp(*vs[q], j);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<int> depth(nc, 0);
|
||||
for (size_t i = 0; i < nc; ++i) {
|
||||
int x = static_cast<int>(i);
|
||||
while (x >= 0 && parents[static_cast<size_t>(x)] >= 0) {
|
||||
++depth[i];
|
||||
x = parents[static_cast<size_t>(x)];
|
||||
}
|
||||
}
|
||||
std::vector<double> root_vol(nc, 0.0);
|
||||
std::vector<Point3D> root_first(nc, Point3D(0, 0, 0));
|
||||
std::vector<Eigen::Matrix3d> root_second(nc, Eigen::Matrix3d::Zero());
|
||||
for (size_t i = 0; i < nc; ++i) {
|
||||
const int r = roots[i];
|
||||
if (r < 0) continue;
|
||||
// 分量自身绕向归一为正值,再按嵌套深度奇偶加/减。
|
||||
double V = comp_vol[i];
|
||||
Point3D M = comp_first[i];
|
||||
Eigen::Matrix3d S = comp_second[i];
|
||||
if (V < 0.0) { V = -V; M = M * -1.0; S = -S; }
|
||||
const double sign = (depth[i] % 2 == 1) ? -1.0 : 1.0;
|
||||
root_vol[static_cast<size_t>(r)] += sign * V;
|
||||
root_first[static_cast<size_t>(r)] += M * sign;
|
||||
root_second[static_cast<size_t>(r)] += S * sign;
|
||||
}
|
||||
|
||||
double total_vol = 0.0;
|
||||
Point3D weighted_centroid(0, 0, 0);
|
||||
Eigen::Matrix3d second_moment = Eigen::Matrix3d::Zero();
|
||||
for (size_t i = 0; i < nc; ++i) {
|
||||
if (parents[i] >= 0) continue; // 只看树根
|
||||
double V = root_vol[i];
|
||||
if (std::abs(V) < 1e-15) continue;
|
||||
Point3D M = root_first[i];
|
||||
Eigen::Matrix3d S = root_second[i];
|
||||
if (V < 0.0) { V = -V; M = M * -1.0; S = -S; }
|
||||
total_vol += V;
|
||||
weighted_centroid += M;
|
||||
second_moment += S;
|
||||
}
|
||||
MassProperties mp;
|
||||
if (total_vol < 1e-15) return mp;
|
||||
mp.volume = total_vol;
|
||||
mp.centroid = weighted_centroid / total_vol;
|
||||
const double trace_sm = second_moment(0,0) + second_moment(1,1) + second_moment(2,2);
|
||||
Eigen::Matrix3d I_ref = -second_moment;
|
||||
I_ref(0,0) += trace_sm;
|
||||
I_ref(1,1) += trace_sm;
|
||||
I_ref(2,2) += trace_sm;
|
||||
const double m = total_vol;
|
||||
const double cx = mp.centroid.x(), cy = mp.centroid.y(), cz = mp.centroid.z();
|
||||
Eigen::Matrix3d shift;
|
||||
shift(0,0) = m * (cy*cy + cz*cz);
|
||||
shift(1,1) = m * (cx*cx + cz*cz);
|
||||
shift(2,2) = m * (cx*cx + cy*cy);
|
||||
shift(0,1) = shift(1,0) = -m * cx * cy;
|
||||
shift(0,2) = shift(2,0) = -m * cx * cz;
|
||||
shift(1,2) = shift(2,1) = -m * cy * cz;
|
||||
mp.inertia = I_ref - shift;
|
||||
auto gyrate = [&](int i) -> double {
|
||||
const double val = mp.inertia(i,i) / m;
|
||||
return val > 0 ? std::sqrt(val) : 0.0;
|
||||
};
|
||||
mp.gyration_radii = core::Vector3D(gyrate(0), gyrate(1), gyrate(2));
|
||||
return mp;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
double analytic_surface_area(const BrepModel& body, double deflection) {
|
||||
return analytic_measure(body, deflection).surface_area;
|
||||
}
|
||||
@@ -772,6 +1055,11 @@ AnalyticMeasure analytic_measure(const BrepModel& body, double deflection) {
|
||||
return fast;
|
||||
}
|
||||
|
||||
// VDE-1269:先按共享边把面分成 closed component;volume 分量化后再按
|
||||
// 嵌套树组合,避免多个独立壳的 signed triple 全局抵消。
|
||||
const MeasurePartition measure_part = partition_measure_components(body);
|
||||
std::vector<double> comp_triple(measure_part.components.size(), 0.0);
|
||||
|
||||
// 单趟:对每个面只调一次 mass_integral(同一遍 Gauss 同时给面积与
|
||||
// 带符号体积系数),area 直接累加;triple 按面法向反转取带符号,
|
||||
// 封闭整壳 /3 得到体积(同 analytic_volume 语义)。
|
||||
@@ -812,12 +1100,63 @@ AnalyticMeasure analytic_measure(const BrepModel& body, double deflection) {
|
||||
faces[i].reversed ? 1 : 0, ms);
|
||||
}
|
||||
m.surface_area += fm.area;
|
||||
if (fm.triple_is_outward)
|
||||
tri_sum += fm.triple; // 已是外法向口径(平面精确积分/三角化回退)
|
||||
else
|
||||
tri_sum += faces[i].reversed ? -fm.triple : fm.triple;
|
||||
const double signed_triple =
|
||||
fm.triple_is_outward ? fm.triple
|
||||
: (faces[i].reversed ? -fm.triple : fm.triple);
|
||||
tri_sum += signed_triple;
|
||||
if (i < measure_part.face_component.size()) {
|
||||
const int ci = measure_part.face_component[i];
|
||||
if (ci >= 0 && ci < static_cast<int>(comp_triple.size()))
|
||||
comp_triple[static_cast<size_t>(ci)] += signed_triple;
|
||||
}
|
||||
}
|
||||
if (measure_part.components.size() <= 1) {
|
||||
m.volume = std::abs(tri_sum) / 3.0; // 单连通:保持原口径
|
||||
} else {
|
||||
// 多分量:每个 closed component 内部 signed 求和;仅在有 AABB 包含
|
||||
// 候选时才建网格做精确包含判定(不嵌套的并排/多体件无额外开销)。
|
||||
bool need_nesting = false;
|
||||
for (size_t i = 0; i < measure_part.components.size() && !need_nesting; ++i) {
|
||||
for (size_t j = 0; j < measure_part.components.size(); ++j) {
|
||||
if (i == j) continue;
|
||||
if (bounds_contain(measure_part.components[j].bounds,
|
||||
measure_part.components[i].bounds)) {
|
||||
need_nesting = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
std::vector<int> parents(measure_part.components.size(), -1);
|
||||
if (need_nesting) {
|
||||
ComponentMeshData mesh;
|
||||
build_component_mesh(body, measure_part, deflection, mesh);
|
||||
parents = component_parents(measure_part, mesh);
|
||||
}
|
||||
const auto roots = component_roots(parents);
|
||||
// 嵌套深度奇偶决定加减:root=+,腔体深度1=-,岛中岛深度2=+。
|
||||
// 分量自身 triple 先取 abs(忽略单一壳整体绕向),再按深度带符号,
|
||||
// 与“不相交分量 abs 相加”一致,且不依赖 boolean 是否保留腔体绕向。
|
||||
std::vector<int> depth(measure_part.components.size(), 0);
|
||||
for (size_t ci = 0; ci < measure_part.components.size(); ++ci) {
|
||||
int x = static_cast<int>(ci);
|
||||
while (x >= 0 && parents[static_cast<size_t>(x)] >= 0) {
|
||||
++depth[ci];
|
||||
x = parents[static_cast<size_t>(x)];
|
||||
}
|
||||
}
|
||||
std::vector<double> root_triple(measure_part.components.size(), 0.0);
|
||||
for (size_t ci = 0; ci < comp_triple.size(); ++ci) {
|
||||
const int r = roots[ci];
|
||||
if (r < 0) continue;
|
||||
const double sign = (depth[ci] % 2 == 1) ? -1.0 : 1.0;
|
||||
root_triple[static_cast<size_t>(r)] += sign * std::abs(comp_triple[ci]);
|
||||
}
|
||||
double total = 0.0;
|
||||
for (size_t ci = 0; ci < root_triple.size(); ++ci) {
|
||||
if (parents[ci] < 0) total += std::abs(root_triple[ci]) / 3.0;
|
||||
}
|
||||
m.volume = total;
|
||||
}
|
||||
m.volume = std::abs(tri_sum) / 3.0;
|
||||
m.num_faces = static_cast<int>(faces.size());
|
||||
if (m.capped_faces > 0 || m.nonfinite_faces > 0 || m.tessellated_faces > 0 ||
|
||||
m.num_faces > AnalyticMeasure::kFaceCountLimit) {
|
||||
@@ -881,6 +1220,11 @@ Point3D centroid(const BrepModel& body) {
|
||||
// ── mass_properties ─────────────────────────────────────────
|
||||
|
||||
MassProperties mass_properties(const BrepModel& body) {
|
||||
// VDE-1269:多连通/多体按 closed component 分组求体积/质心/惯性;
|
||||
// 单连通保持原实现(单分量走下方原路径,数值口径不变)。
|
||||
const MeasurePartition measure_part = partition_measure_components(body);
|
||||
if (measure_part.components.size() > 1)
|
||||
return mass_properties_multi_component(body, measure_part);
|
||||
auto mesh = body.to_mesh(0.05);
|
||||
MassProperties mp;
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "vde/brep/modeling.h"
|
||||
#include "vde/brep/measure.h"
|
||||
#include "vde/brep/assembly.h"
|
||||
#include "vde/brep/brep_boolean.h"
|
||||
#include "vde/curves/nurbs_surface.h"
|
||||
#include <cmath>
|
||||
#include <algorithm>
|
||||
@@ -511,3 +512,64 @@ TEST(AnalyticMeasureTest, MeshOnlyTriangleSoupFastPath) {
|
||||
EXPECT_LE(m.evals, 1000) << "快速路径不应做自适应 Gauss 曲面求值";
|
||||
EXPECT_LE(ms, 100.0) << "mesh-only 三角汤度量应 <100ms(Release)";
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════
|
||||
// VDE-1269:多连通/多体 BrepModel 的 volume / mass 符号分组
|
||||
// ═══════════════════════════════════════════════════════════
|
||||
|
||||
TEST(VDE1269Measure, DisjointComponentsVolumeMass) {
|
||||
// 30×20×10 外盒减去贯穿中部的 10×20×10 内盒 → 两个不相交 10×20×10 盒。
|
||||
// 两壳 winding 相反时旧实现全局 signed 求和后 abs → 0。
|
||||
const Point3D center(0, 0, 5);
|
||||
BrepModel outer = make_box(30, 20, 10, center);
|
||||
BrepModel inner = make_box(10, 20, 10, center);
|
||||
BrepModel cut = brep_difference(outer, inner);
|
||||
ASSERT_GT(cut.num_faces(), 0u);
|
||||
EXPECT_GE(cut.all_shells().size(), 1u);
|
||||
const AnalyticMeasure m = analytic_measure(cut);
|
||||
EXPECT_NEAR(m.volume, 4000.0, 1e-4) << "两个不连通分量应 abs 后相加";
|
||||
EXPECT_NEAR(m.surface_area, 2000.0, 1e-4) << "面积口径不应改变";
|
||||
const double v = analytic_volume(cut);
|
||||
EXPECT_NEAR(v, 4000.0, 1e-4);
|
||||
EXPECT_NEAR(cut.body_volume(), 4000.0, 1e-4);
|
||||
const MassProperties mp = mass_properties(cut);
|
||||
EXPECT_NEAR(mp.volume, 4000.0, 1e-3);
|
||||
EXPECT_NEAR(mp.centroid.x(), 0.0, 1e-5);
|
||||
EXPECT_NEAR(mp.centroid.y(), 0.0, 1e-5);
|
||||
EXPECT_NEAR(mp.centroid.z(), 5.0, 1e-5);
|
||||
EXPECT_GT(mp.inertia(0, 0), 0.0);
|
||||
EXPECT_GT(mp.inertia(1, 1), 0.0);
|
||||
EXPECT_GT(mp.inertia(2, 2), 0.0);
|
||||
}
|
||||
|
||||
TEST(VDE1269Measure, NestedCavityKeepsSign) {
|
||||
// 20³ 外盒内挖 10³ 腔体:一个 closed component 的两个嵌套壳,腔体应减。
|
||||
const Point3D center(0, 0, 5);
|
||||
BrepModel outer = make_box(20, 20, 20, center);
|
||||
BrepModel inner = make_box(10, 10, 10, center);
|
||||
BrepModel cut = brep_difference(outer, inner);
|
||||
ASSERT_GT(cut.num_faces(), 0u);
|
||||
const AnalyticMeasure m = analytic_measure(cut);
|
||||
EXPECT_NEAR(m.volume, 7000.0, 1e-4) << "嵌套腔体应保留负号相减";
|
||||
EXPECT_NEAR(m.surface_area, 3000.0, 1e-4);
|
||||
const MassProperties mp = mass_properties(cut);
|
||||
EXPECT_NEAR(mp.volume, 7000.0, 1e-3);
|
||||
EXPECT_NEAR(mp.centroid.x(), 0.0, 1e-5);
|
||||
EXPECT_NEAR(mp.centroid.y(), 0.0, 1e-5);
|
||||
EXPECT_NEAR(mp.centroid.z(), 5.0, 1e-5);
|
||||
EXPECT_GT(mp.inertia(0, 0), 0.0);
|
||||
EXPECT_GT(mp.inertia(1, 1), 0.0);
|
||||
EXPECT_GT(mp.inertia(2, 2), 0.0);
|
||||
}
|
||||
|
||||
TEST(VDE1269Measure, SingleConnectedUnchanged) {
|
||||
BrepModel box = make_box(10, 8, 6, Point3D(1, 2, 3));
|
||||
const AnalyticMeasure m = analytic_measure(box);
|
||||
EXPECT_NEAR(m.volume, 480.0, 1e-6);
|
||||
EXPECT_NEAR(m.surface_area, 2.0 * (10*8 + 10*6 + 8*6), 1e-6);
|
||||
const MassProperties mp = mass_properties(box);
|
||||
EXPECT_NEAR(mp.volume, 480.0, 1e-3);
|
||||
EXPECT_NEAR(mp.centroid.x(), 1.0, 1e-5);
|
||||
EXPECT_NEAR(mp.centroid.y(), 2.0, 1e-5);
|
||||
EXPECT_NEAR(mp.centroid.z(), 3.0, 1e-5);
|
||||
}
|
||||
|
||||
@@ -22,15 +22,15 @@ TEST(VersionMacro, MinorVersion) {
|
||||
}
|
||||
|
||||
TEST(VersionMacro, PatchVersion) {
|
||||
EXPECT_EQ(VDE_VERSION_PATCH, 124);
|
||||
EXPECT_EQ(VDE_VERSION_PATCH, 125);
|
||||
}
|
||||
|
||||
TEST(VersionMacro, VersionString) {
|
||||
EXPECT_STREQ(VDE_VERSION_STRING, "1.0.124");
|
||||
EXPECT_STREQ(VDE_VERSION_STRING, "1.0.125");
|
||||
}
|
||||
|
||||
TEST(VersionMacro, VersionNum) {
|
||||
EXPECT_EQ(VDE_VERSION_NUM, 10124); // 1*10000 + 0*100 + 83
|
||||
EXPECT_EQ(VDE_VERSION_NUM, 10125); // 1*10000 + 0*100 + 83
|
||||
}
|
||||
|
||||
// 版本口径一致性:字符串 / 整型校验值 / 分量必须互相对齐(防止再次出现
|
||||
@@ -79,8 +79,8 @@ TEST(VersionInfo, DefaultConstruction) {
|
||||
VersionInfo info = vde_version();
|
||||
EXPECT_EQ(info.major, 1);
|
||||
EXPECT_EQ(info.minor, 0);
|
||||
EXPECT_EQ(info.patch, 124);
|
||||
EXPECT_EQ(info.version_string, "1.0.124");
|
||||
EXPECT_EQ(info.patch, 125);
|
||||
EXPECT_EQ(info.version_string, "1.0.125");
|
||||
EXPECT_FALSE(info.build_type.empty());
|
||||
EXPECT_FALSE(info.compiler_info.empty());
|
||||
EXPECT_EQ(info.cpp_standard, "C++20");
|
||||
@@ -98,8 +98,8 @@ TEST(VersionInfo, BuildTimestamp) {
|
||||
|
||||
TEST(VersionString, Format) {
|
||||
std::string vs = vde_version_string();
|
||||
// 格式:ViewDesignEngine v1.0.124 (C++20, GCC x.x)
|
||||
EXPECT_TRUE(vs.find("ViewDesignEngine v1.0.124") != std::string::npos);
|
||||
// 格式:ViewDesignEngine v1.0.125 (C++20, GCC x.x)
|
||||
EXPECT_TRUE(vs.find("ViewDesignEngine v1.0.125") != std::string::npos);
|
||||
EXPECT_TRUE(vs.find("C++20") != std::string::npos);
|
||||
EXPECT_TRUE(vs.find("(") != std::string::npos);
|
||||
EXPECT_TRUE(vs.find(")") != std::string::npos);
|
||||
|
||||
Reference in New Issue
Block a user