### 宿主复测闭环
- VDE-1249/VDE-1250 标记 Fixed(宿主 1.0.68 复测记录:0 error、13,030/0 ctest、n42 82s、n49/n50/n60、save-load match=1);
- VDE-1251(dense pattern,1.0.72 修复)待宿主复测;
### P3-15c ui/pdm bridge TU 迁移
- geometric_snap/snap_ext→vde_ui、structural_profiles→vde_pdm;规范头 + 旧 brep 兼容转发头(不进 kernel SDK);
- check_kernel_boundary allowlist 清零;默认 build 0 error、定向 170/170、kernel-only 971 步 0 undefined;
### P3-15d/e 模块包
- 新增 vde-cam/vde-cae/vde-ui/vde-pdm 包(共 8 个模块包);独立 consumer:
CAM_CONSUMER_PASS segments=1006 gcode=1011、CAE_CONSUMER_PASS tet=384 patches=6、
UI_CONSUMER_PASS layouts=4 picked=1、PDM_CONSUMER_PASS materials=21 profiles=32 bom=1;
- 默认构建/聚合不变;docs module-packaging-split §7.1/§7.2;剩余 assembly/PMI/钣金;
### P3-14c 外部服务容器运行时抽象
- sandbox.container{runtime auto|docker|podman,image,network,read_only};argv 构造 docker/podman run(仅挂载 workdir、
--network none、--read-only/tmpfs、env 白名单、超时/失败清理);无 runtime 默认 unsupported_sandbox,allow_unsandboxed 降级;
- fake runtime 测试 5/5;docs §7.3/§12.9;真实 docker e2e 需环境;
### P3-16c largeMesh O(F²) 修复
- display_conforming_patch 每体一次统计 sphere 面数;8192 面球 >600s→~2s(261k tris、deg/open/zeroArea=0);
- degenerate_triangles 语义澄清 + 回退场景用 B-Rep wireframe 的宿主指引;test_vde1250_large_mesh 3/3;
### P3-17 插件 SDK scaffold + 远程索引
- tool scaffold 四类模板(独立 build/--check/--list PASS)+ --fetch-index(本地/http WinHTTP,签名/路径/ABI/哈希校验);
### 工程
- 版本 1.0.74;全量构建 0 error(375 targets);全量 ctest 7540 注册、7445/7445 PASS(0 failed,25 skipped,224.07s)。
245 lines
8.4 KiB
C++
245 lines
8.4 KiB
C++
#pragma once
|
||
/**
|
||
* @file geometric_snap.h
|
||
* @brief 几何捕捉/查询 API(VDE-175)
|
||
*
|
||
* 提供交互式建模中所需的几何吸附点和查询功能:
|
||
* - 吸附到几何实体上的特殊点(中点、端点、圆心等)
|
||
* - 最近点查询
|
||
* - 面/边的几何中心计算
|
||
*
|
||
* 这些功能是 Gizmo 定位、智能标注、草图原点设定和装配配合的基础。
|
||
*
|
||
* @ingroup brep
|
||
*/
|
||
#include "vde/brep/brep.h"
|
||
#include "vde/core/point.h"
|
||
#include "vde/curves/nurbs_curve.h"
|
||
#include <vector>
|
||
#include <functional>
|
||
|
||
namespace vde::brep {
|
||
|
||
// ═══════════════════════════════════════════════
|
||
// 吸附类型枚举
|
||
// ═══════════════════════════════════════════════
|
||
|
||
/**
|
||
* @brief 吸附点类型位掩码
|
||
*
|
||
* 支持按位组合,例如 SnapType::Midpoint | SnapType::Endpoint。
|
||
*/
|
||
enum class SnapType : uint32_t {
|
||
None = 0,
|
||
/// 边/线段的中点
|
||
Midpoint = 1 << 0,
|
||
/// 边/曲线的端点
|
||
Endpoint = 1 << 1,
|
||
/// 面/边的几何中心
|
||
Center = 1 << 2,
|
||
/// 圆/圆弧的四分点(0°/90°/180°/270°)
|
||
Quadrant = 1 << 3,
|
||
/// 两条边的交点
|
||
Intersection = 1 << 4,
|
||
/// 几何体上最近点
|
||
Nearest = 1 << 5,
|
||
/// 切点(面/曲线上的切点)
|
||
Tangent = 1 << 6,
|
||
/// 所有类型
|
||
All = 0xFFFFFFFF
|
||
};
|
||
|
||
/// 按位 OR 组合吸附类型
|
||
inline SnapType operator|(SnapType a, SnapType b) {
|
||
return static_cast<SnapType>(static_cast<uint32_t>(a) | static_cast<uint32_t>(b));
|
||
}
|
||
inline SnapType operator&(SnapType a, SnapType b) {
|
||
return static_cast<SnapType>(static_cast<uint32_t>(a) & static_cast<uint32_t>(b));
|
||
}
|
||
inline bool operator!(SnapType a) {
|
||
return static_cast<uint32_t>(a) == 0;
|
||
}
|
||
|
||
// ═══════════════════════════════════════════════
|
||
// 吸附结果
|
||
// ═══════════════════════════════════════════════
|
||
|
||
/**
|
||
* @brief 几何吸附结果
|
||
*
|
||
* 包含吸附点的世界坐标、所在实体信息以及距离。
|
||
*/
|
||
struct SnapResult {
|
||
/// 吸附点的世界坐标
|
||
core::Point3D world_point{0, 0, 0};
|
||
|
||
/// 吸附到哪个面(-1 = 不在面上)
|
||
int face_id = -1;
|
||
|
||
/// 吸附到哪条边(-1 = 不在边上)
|
||
int edge_id = -1;
|
||
|
||
/// 吸附到哪个顶点(-1 = 不在顶点上)
|
||
int vertex_id = -1;
|
||
|
||
/// 吸附类型
|
||
SnapType snap_type = SnapType::None;
|
||
|
||
/// 吸附点到查询点的距离
|
||
double distance = 0.0;
|
||
};
|
||
|
||
// ═══════════════════════════════════════════════
|
||
// 吸附函数
|
||
// ═══════════════════════════════════════════════
|
||
|
||
/**
|
||
* @brief 将查询点吸附到几何体的特殊点上
|
||
*
|
||
* 根据 snap_types 指定的吸附类型,遍历体的所有面/边/顶点,
|
||
* 找出最近的吸附候选点。
|
||
*
|
||
* 算法:
|
||
* 1. 若 snap_types 包含 Nearest: 在所有面上找最近点
|
||
* 2. 若 snap_types 包含 Midpoint: 计算所有边的中点
|
||
* 3. 若 snap_types 包含 Endpoint: 收集所有边的端点
|
||
* 4. 若 snap_types 包含 Center: 计算所有面和边的几何中心
|
||
* 5. 若 snap_types 包含 Quadrant: 对圆/圆弧边计算四分点
|
||
* 6. 若 snap_types 包含 Intersection: 检查边的交点
|
||
* 7. 若 snap_types 包含 Tangent: 计算切点
|
||
* 8. 返回距离 query_point 最近的候选点
|
||
*
|
||
* @param body B-Rep 模型
|
||
* @param near_point 查询点(世界坐标)
|
||
* @param snap_types 吸附类型掩码(按位 OR 组合)
|
||
* @param tolerance 吸附容差,只返回距离 ≤ tolerance 的结果
|
||
* @return 吸附结果(若 tolerance 内无候选点,snap_type == SnapType::None)
|
||
*/
|
||
[[nodiscard]] SnapResult snap_to_geometry(
|
||
const BrepModel& body,
|
||
const core::Point3D& near_point,
|
||
SnapType snap_types,
|
||
double tolerance = 1.0);
|
||
|
||
/**
|
||
* @brief 枚举容差内的全部吸附候选(VDE-333)
|
||
*
|
||
* 与 `snap_to_geometry` 使用同一套候选生成逻辑,但返回容差内的**所有**
|
||
* 候选点(而非仅最近的一个),供多候选 UI(batch_snap)使用。
|
||
*
|
||
* @param body B-Rep 模型
|
||
* @param near_point 查询点(世界坐标)
|
||
* @param snap_types 吸附类型掩码(按位 OR 组合)
|
||
* @param tolerance 吸附容差,只返回距离 ≤ tolerance 的候选
|
||
* @return 候选列表(未排序;每个候选的 distance 已按 near_point 计算)
|
||
*/
|
||
[[nodiscard]] std::vector<SnapResult> collect_snap_candidates(
|
||
const BrepModel& body,
|
||
const core::Point3D& near_point,
|
||
SnapType snap_types,
|
||
double tolerance = 1.0);
|
||
|
||
/**
|
||
* @brief 计算边的中点
|
||
*
|
||
* 取边曲线的参数中点 evaluate(0.5 * (t_min + t_max))。
|
||
* 若边无曲线(直线边),则取两端点线性插值的中点。
|
||
*
|
||
* @param body B-Rep 模型
|
||
* @param edge_id 边 ID(数组索引)
|
||
* @return 边中点世界坐标
|
||
*
|
||
* @pre edge_id 有效(0 ≤ edge_id < num_edges())
|
||
*/
|
||
[[nodiscard]] core::Point3D midpoint(const BrepModel& body, int edge_id);
|
||
|
||
/**
|
||
* @brief 计算面或边的几何中心
|
||
*
|
||
* 面:使用 face_bounds() 的包围盒中心(近似几何中心)
|
||
* 边:使用 midpoint() 等效
|
||
*
|
||
* @param body B-Rep 模型
|
||
* @param face_or_edge_id 面或边 ID(数组索引)
|
||
* @return 几何中心世界坐标
|
||
*
|
||
* @note 对于圆形边(圆弧/圆),返回真正的圆心,而非中点
|
||
* @note 当前实现使用包围盒中心作为近似,完整实现需曲面参数域中心投影
|
||
*/
|
||
[[nodiscard]] core::Point3D center_point(const BrepModel& body, int face_or_edge_id);
|
||
|
||
/**
|
||
* @brief 计算圆形边的四分点
|
||
*
|
||
* 四分点为圆/圆弧在 0°、90°、180°、270° 位置的点。
|
||
* 仅对 Circle 类型的曲线边有效。
|
||
*
|
||
* @param body B-Rep 模型
|
||
* @param circular_edge_id 圆形边 ID(数组索引)
|
||
* @return 四分点坐标列表(4 个点)
|
||
*
|
||
* @pre 边为圆形边(CurveType::Circle)
|
||
* @note 若边为非圆形边,返回空向量
|
||
*/
|
||
[[nodiscard]] std::vector<core::Point3D> quadrant_points(
|
||
const BrepModel& body, int circular_edge_id);
|
||
|
||
/**
|
||
* @brief 查询几何体上最近点
|
||
*
|
||
* 遍历所有面的所有边,取顶点和边中点中距离 near_point 最近的点。
|
||
* 完整实现需要 NURBS 曲面/曲线上的最近点投影(Newton 迭代),
|
||
* 当前实现使用离散采样近似。
|
||
*
|
||
* @param body B-Rep 模型
|
||
* @param near_point 查询点(世界坐标)
|
||
* @return 几何体上最近点坐标
|
||
*/
|
||
[[nodiscard]] core::Point3D nearest_point_on_geometry(
|
||
const BrepModel& body,
|
||
const core::Point3D& near_point);
|
||
|
||
// ═══════════════════════════════════════════════
|
||
// VDE-333: 新增动态捕捉函数
|
||
// ═══════════════════════════════════════════════
|
||
|
||
// 注:live_cursor_snap() / GeometryQueryFn / aperture 等"交互式捕捉"包装
|
||
// 已迁移至 vde_ui/geometric_snap_ui.h(namespace vde::ui)。
|
||
// SnapResult 为交互代码与内核几何查询共用,仍保留在本头文件中。
|
||
|
||
/**
|
||
* @brief 两点中点捕捉(VDE-333)
|
||
*
|
||
* 计算两点的线性中点。
|
||
*
|
||
* @param p1 第一个点
|
||
* @param p2 第二个点
|
||
* @return 中点坐标
|
||
*/
|
||
[[nodiscard]] inline core::Point3D snap_to_midpoint(
|
||
const core::Point3D& p1, const core::Point3D& p2) {
|
||
return core::Point3D(
|
||
(p1.x() + p2.x()) * 0.5,
|
||
(p1.y() + p2.y()) * 0.5,
|
||
(p1.z() + p2.z()) * 0.5);
|
||
}
|
||
|
||
/**
|
||
* @brief 两曲线交点捕捉(VDE-333)
|
||
*
|
||
* 计算两条 NURBS 曲线的交点。
|
||
* 使用参数域采样 + 最近点逼近方法。
|
||
* 若存在多个交点,返回距 curve1 起点最近的那个。
|
||
*
|
||
* @param curve1 第一条 NURBS 曲线
|
||
* @param curve2 第二条 NURBS 曲线
|
||
* @param tolerance 交点容差
|
||
* @return 交点坐标;若未找到交点,返回 (0,0,0) 且设置 SnapResult.snap_type=None
|
||
*/
|
||
[[nodiscard]] SnapResult snap_to_intersection(
|
||
const curves::NurbsCurve& curve1,
|
||
const curves::NurbsCurve& curve2,
|
||
double tolerance = 1e-6);
|
||
|
||
} // namespace vde::brep
|