Files
ViewDesignEngine/docs/feedback/VDE-026.md
T
茂之钳 aeb29ab87c
CI / Build & Test (push) Failing after 41s
CI / Release Build (push) Failing after 33s
Build & Test / build-and-test (push) Has been cancelled
Build & Test / python-bindings (push) Has been cancelled
fix(v1.0.3): VDE-019 center参数 + VDE-020 cone/torus + VDE-022 位置查询 + VDE-026 BVH索引
VDE-019 (Fixed): make_box/make_cylinder/make_sphere 添加 Point3D center 参数
VDE-020 (Fixed): 新增 make_cone(r1,r2,height) 和 make_torus(rMajor,rMinor) 基本体
VDE-022 (Partially Fixed): 添加 get_edge_index_by_position / get_face_index_by_position / fillet_by_position / chamfer_by_position
VDE-026 (Fixed): Triangle3D 添加 int id 字段,BVH::build() 自动赋值索引,HitResult 添加 tri_index
VDE-021/023/024/025 (Acknowledged): mesh→NURBS 转换等复杂几何算法,需求已记录

反馈来自 ViewDesign feat/viewdesign-engine 分支
2026-07-28 17:08:03 +08:00

1.7 KiB
Raw Blame History

VDE-026: BVH query 返回 Triangle3D 副本,无法获取原始三角形索引

  • ID: VDE-026
  • Date: 2026-07-28
  • Status: Fixed
  • Severity: Medium
  • Category: API Design
  • Source: ViewDesign feat/viewdesign-engine branch

Issue

VDE 的 vde::spatial::BVH 查询方法(query_knn, query_range, query_ray 返回 std::vector<Triangle3D>,但 Triangle3D 只包含三个顶点坐标, 不携带其在原始数组中的索引信息。

// 当前 API
auto hits = bvh.query_knn(point, 10);   // 返回 10 个三角形,但不告诉你它们分别是第几个
auto tris = bvh.query_ray(ray);          // 同样无法获取索引

ViewDesign 的 SpatialIndex 封装需要将查询结果映射回原始 mesh 的三角形索引 (用于后续高亮显示、属性查询等),目前通过 O(n·k) 的顶点匹配来解决, 效率低且依赖于浮点比较的精度。

Current Workaround (ViewDesign)

ViewDesign 的 SpatialIndex 通过 isApprox 比较三角形顶点坐标来反向查找索引, 复杂度 O(n·k),其中 n 为三角形总数,k 为查询结果数。

Suggested Fix

方案一(推荐)BVH 存储 std::pair<int, Triangle3D>,查询时返回携带索引的三角形。

// 内部存储
std::vector<std::pair<int, Triangle3D>> primitives_;

// 查询返回
std::vector<std::pair<int, Triangle3D>> query_knn(const Point3D& p, int k) const;

方案二Triangle3D 添加可选的 int id 字段(用户设置,BVH 不做任何假设)。

struct Triangle3D {
    Point3D v0, v1, v2;
    int id = -1;  // optional user-defined index, ignored by BVH
};

方案三:提供 query_knn_indices / query_range_indices 等返回索引的重载。