新增扫掠体能力(对标 Parasolid PK_TOPOL_sweep / 机器人数控仿真 swept volume): - sample_path:关键位姿路径 → 采样位姿(平移线性插值 + 旋转四元数 slerp) - swept_volume:采样位姿 SSI 布尔并集构建真实扫掠体 B-Rep + 保守 AABB 包络, 布尔失败自动降级仅返回包络(恒可用) - motion_envelope:保守运动包络(恒成功、快速,用于装配级干涉校核预筛选) - swept_collision:运动体 vs 静态障碍扫掠碰撞,逐采样 AABB 快速拒绝 + 顶点包含精确判定(classify_point_adaptive)+ SSI 布尔交集兜底, 返回归一化首次碰撞时间(机床/装配仿真运动干涉校核) 顺带修复两处库级 bug(由扫掠碰撞测试暴露): - ssi_boolean.cpp ray_hits_grid:射线穿过细分网格顶点/边时多三角形重复计数 导致奇偶分类错误(内部点误判 OUT),按射线参数去重,一个表面穿越记一次命中 - brep.cpp BrepModel::transform:未变换 trimmed_surfaces_,导致变换体 to_mesh 网格仍在原始位置(分类/碰撞全部失效),补齐裁剪面基础 NURBS 变换 test_swept_volume 12/12 通过;ssi_boolean/brep_boolean/boolean_fallback/ boolean_robustness/parallel_boolean/tolerant_modeling/brep/brep_modeling/ trimmed_surface/assembly/interference_check 回归全绿
29 KiB
29 KiB
B-Rep 模块 API 参考
边界表示(B-Rep)模块 — 实体建模、阵列、约束、剖面、标注、捕捉、型材
模块概述
brep 模块是 ViewDesignEngine 的核心建模引擎,提供完整的 B-Rep 实体创建、编辑、分析和渲染能力。包含 60+ 头文件,涵盖从基本体创建到高级装配约束、结构型材焊接、齿轮/弹簧生成等工业级功能。
头文件列表
| 头文件 | 说明 |
|---|---|
brep.h |
B-Rep 核心数据结构(BrepModel、拓扑实体) |
topo_naming.h |
拓扑命名(面/边持久标识与跨重建解析) |
modeling.h |
高层建模 API(基本体/扫掠/编辑/齿轮/弹簧) |
brep_boolean.h |
布尔运算(并集/交集/差集) |
ssi_boolean.h |
曲面-曲面求交布尔运算 |
boolean_fallback.h |
布尔运算降级回退策略 |
swept_volume.h |
扫掠体/运动包络/扫掠碰撞(P2-2) |
section_view.h |
截面/裁剪 API(VDE-173) |
dimension_api.h |
PMI/标注尺寸 API(VDE-176) |
hlr_api.h |
消隐线 API(VDE-183/VDE-195) |
geometric_snap.h |
几何捕捉查询 API(VDE-175) |
pattern_ops.h |
B-Rep 阵列/镜像/装配布尔(VDE-070) |
brep_position.h |
基于位置查找边/面 |
structural_profiles.h |
结构型材 + 焊道生成 |
constraint_solver.h |
三维装配约束求解器(约束图/Newton-Raphson/DOF 分析) |
constraint_types.h |
约束类型定义 |
assembly_constraints.h |
装配约束(配合/对齐/等距等) |
assembly.h |
装配体树结构 |
assembly_instance.h |
装配体实例化 |
assembly_feature.h |
装配级特征 |
assembly_patterns.h |
装配阵列 |
flexible_assembly.h |
柔性装配体 |
fastener_library.h |
紧固件库 |
fastener_engine.h |
智能紧固件引擎(孔检测 + 标准件选择) |
auto_dimensioning.h |
自动标注 |
brep_drawing.h |
工程图生成 |
measure.h |
测量工具 |
pmi_types.h |
PMI 类型定义 |
pmi_mbd.h |
PMI/MBD 产品制造信息 |
feature_tree.h |
特征树 |
feature_recognition.h |
特征识别 |
defeature.h |
去特征化 |
tolerance.h |
公差分析 |
tolerant_modeling.h |
容差建模 |
brep_validate.h |
B-Rep 验证 |
brep_heal.h |
B-Rep 修复 |
advanced_healing.h |
高级修复 |
advanced_blend.h |
高级融合曲面 |
solid_features.h |
基础实体特征(Dome/Thicken/Indent/Split/Move/Scale 等) |
direct_modeling.h |
直接建模 |
euler_op.h |
欧拉操作(拓扑编辑) |
brep_face_split.h |
面分割 |
trimmed_surface.h |
修剪曲面 |
sheet_metal.h |
钣金设计 |
ffd_deformation.h |
自由变形(FFD) |
gdt.h |
几何尺寸与公差(GD&T) |
gdt_stackup.h |
公差堆叠分析(Worst-Case/RSS/Monte Carlo) |
draft_analysis.h |
拔模分析 |
step_import.h |
STEP 导入 |
step_export.h |
STEP 导出 |
iges_import.h |
IGES 导入 |
iges_export.h |
IGES 导出 |
nurbs_to_brep.h |
NURBS 曲面 → B-Rep 直接转换 |
dxf_import.h |
DXF 导入 |
dfm_rules.h |
DFM/DFA 规则引擎(可配置制造可行性检查) |
format_io.h |
统一格式 IO 调度 |
explode_view.h |
爆炸视图 |
interference_check.h |
干涉检查 |
incremental_update.h |
增量更新 |
incremental_mesh.h |
增量网格 |
parallel_boolean.h |
并行布尔运算 |
large_assembly.h |
大型装配体优化 |
详细 API
brep.h — 核心数据结构
namespace vde::brep {
// 枚举
enum class CurveType { Line, Circle, Bezier, BSpline, Nurbs };
enum class FaceType { Plane, Cylinder, Cone, Sphere, Torus, Spline, Other };
enum class EdgeType { Line, Circle, Ellipse, Spline, Other };
enum class EntityType { Vertex, Edge, Face };
// 拓扑实体
struct TopoVertex { int id; Point3D point; double tolerance = 1e-6; };
struct TopoEdge { int id; int v_start, v_end; std::shared_ptr<curves::NurbsCurve> curve; bool reversed = false; };
struct TopoLoop { int id; std::vector<int> edges; bool is_outer = true; };
struct TopoFace { int id; int surface_id; int trimmed_surface_id = -1; std::vector<int> loops; bool reversed = false; bool visible = true; };
struct TopoShell { int id; std::vector<int> faces; bool closed = true; };
struct TopoBody { int id; std::vector<int> shells; std::string name; };
// BrepModel 主要 API
class BrepModel {
public:
// 构建
int add_vertex(const Point3D& p);
int add_vertex_unique(const Point3D& p, double tolerance = 1e-9); // 自动去重
int add_edge(int v0, int v1);
int add_edge(int v0, int v1, const curves::NurbsCurve& curve); // 曲线边
int add_edge_unique(int v0, int v1, double tolerance = 1e-9);
int add_loop(const std::vector<int>& edges, bool outer = true);
int add_face(int surface_id, const std::vector<int>& loops);
int add_shell(const std::vector<int>& faces, bool closed = true);
int add_body(const std::vector<int>& shells, const std::string& name = "");
int add_surface(const curves::NurbsSurface& surf);
int add_trimmed_surface(const TrimmedSurface& ts);
// 查询
[[nodiscard]] size_t num_vertices() const;
[[nodiscard]] size_t num_edges() const;
[[nodiscard]] size_t num_faces() const;
[[nodiscard]] size_t num_bodies() const;
[[nodiscard]] size_t num_surfaces() const;
[[nodiscard]] size_t num_trimmed_surfaces() const;
// 拓扑查询(按数组索引)
[[nodiscard]] const TopoVertex& vertex(int id) const;
[[nodiscard]] const TopoEdge& edge(int id) const;
[[nodiscard]] const TopoFace& face(int id) const;
[[nodiscard]] const TopoShell& shell(int id) const;
[[nodiscard]] const curves::NurbsSurface& surface(int id) const;
[[nodiscard]] const TopoLoop& loop_by_id(int id) const;
[[nodiscard]] const std::vector<TopoFace>& all_faces() const; // 其余 all_* 同理
// 几何/拓扑查询(VDE-179/VDE-180/VDE-191 等)
[[nodiscard]] FaceType face_type(int face_id) const; // 面类型识别
[[nodiscard]] EdgeType edge_type(int edge_id) const; // 边类型识别
[[nodiscard]] double face_area(int face_id) const; // 面面积
[[nodiscard]] CurvatureInfo face_curvature(int face_id) const; // 面曲率(min/max 主曲率)
[[nodiscard]] core::Vector3D face_normal(int face_id) const; // 面近似法向
[[nodiscard]] double edge_length(int edge_id) const; // 边长度
[[nodiscard]] double body_volume() const; // 模型体积(AABB 近似)
[[nodiscard]] std::vector<int> getAdjacentFaces(int face_id) const;// 共边相邻面(VDE-178)
[[nodiscard]] AdjacencyGraph adjacency_graph() const; // 面邻接图(VDE-191)
// 包围盒
[[nodiscard]] AABB3D bounds() const;
// B-Rep → Mesh
[[nodiscard]] mesh::HalfedgeMesh to_mesh(double deflection = 0.01) const;
[[nodiscard]] mesh::HalfedgeMesh to_mesh_adaptive(double curvature_tolerance) const;
[[nodiscard]] mesh::HalfedgeMesh to_mesh_parallel(int num_threads) const;
// 保拓扑仿射变换(VDE-171)
[[nodiscard]] BrepModel transformed(const core::Transform3D& tf) const;
void transform(const core::Transform3D& tf);
// STEP/IGES IO(位于独立头文件,见 step_import.h / iges_import.h 自由函数)
};
} // namespace vde::brep
modeling.h — 高层建模 API
namespace vde::brep {
// === 扫掠特征(NURBS 轮廓) ===
[[nodiscard]] BrepModel extrude(const curves::NurbsCurve& profile, const Vector3D& dir);
[[nodiscard]] BrepModel revolve(const curves::NurbsCurve& profile, const Point3D& axis_origin, const Vector3D& axis_dir, double angle_rad = 2*M_PI);
[[nodiscard]] BrepModel sweep(const curves::NurbsCurve& profile, const curves::NurbsCurve& path);
[[nodiscard]] BrepModel loft(const std::vector<curves::NurbsCurve>& profiles);
// === 扫掠特征(Mesh 轮廓) ===
[[nodiscard]] BrepModel extrude(const mesh::HalfedgeMesh& profileMesh, const Vector3D& dir);
[[nodiscard]] BrepModel revolve(const mesh::HalfedgeMesh& profileMesh, const Point3D& origin, const Vector3D& axis, double angle = 2*M_PI);
[[nodiscard]] BrepModel sweep(const mesh::HalfedgeMesh& profileMesh, const curves::NurbsCurve& path);
[[nodiscard]] BrepModel sweep(const mesh::HalfedgeMesh& profileMesh, const mesh::HalfedgeMesh& pathMesh);
[[nodiscard]] BrepModel revolve(const mesh::HalfedgeMesh& profileMesh, const mesh::HalfedgeMesh& axis_wire, double angle = 2*M_PI);
[[nodiscard]] BrepModel loft(const std::vector<mesh::HalfedgeMesh>& profiles);
// === 基本体 ===
[[nodiscard]] BrepModel make_box(double w, double h, double d, const Point3D& center = Point3D(0,0,0));
[[nodiscard]] BrepModel make_cylinder(double radius, double height, int segments = 32, const Point3D& center = Point3D(0,0,0));
[[nodiscard]] BrepModel make_sphere(double radius, int segments_u = 32, int segments_v = 16, const Point3D& center = Point3D(0,0,0));
[[nodiscard]] BrepModel make_cone(double r1, double r2, double height, int segments = 32, const Point3D& center = Point3D(0,0,0));
[[nodiscard]] BrepModel make_torus(double rMajor, double rMinor, int segments_u = 32, int segments_v = 16, const Point3D& center = Point3D(0,0,0));
// === 编辑操作 ===
[[nodiscard]] BrepModel fillet(const BrepModel& body, int edge_id, double radius);
[[nodiscard]] BrepModel fillet_variable(const BrepModel& body, int edge_id, double r_start, double r_end, int samples = 8);
[[nodiscard]] BrepModel chamfer(const BrepModel& body, int edge_id, double distance);
[[nodiscard]] BrepModel shell(const BrepModel& body, int face_id, double thickness);
// === 基于位置的操作 ===
[[nodiscard]] int get_edge_index_by_position(const BrepModel& body, const Point3D& nearPoint);
[[nodiscard]] int get_face_index_by_position(const BrepModel& body, const Point3D& nearPoint);
[[nodiscard]] BrepModel fillet_by_position(const BrepModel& body, const Point3D& nearPoint, double radius, double tolerance = 1e-6);
[[nodiscard]] BrepModel chamfer_by_position(const BrepModel& body, const Point3D& nearPoint, double distance, double tolerance = 1e-6);
[[nodiscard]] BrepModel shell_by_position(const BrepModel& body, const Point3D& nearPoint, double thickness, double tolerance = 1e-6);
// === 齿轮生成 ===
[[nodiscard]] BrepModel make_spur_gear(double module, int teeth, double width, double pressure_angle = 20.0);
[[nodiscard]] BrepModel make_helical_gear(double module, int teeth, double width, double pressure_angle = 20.0, double helix_angle = 15.0);
// === 弹簧生成 ===
enum class SpringType { Compression, Extension, Torsion };
[[nodiscard]] BrepModel make_spring(double coil_diameter, double wire_diameter, double coils, double free_length, SpringType type = SpringType::Compression);
// === 加强筋 ===
[[nodiscard]] BrepModel make_rib(const BrepModel& body, const std::vector<Point3D>& profile, const Vector3D& direction, double thickness);
} // namespace vde::brep
swept_volume.h — 扫掠体/运动包络/扫掠碰撞(P2-2)
namespace vde::brep {
struct SweptVolumeOptions {
int samples_per_segment = 12; // 每段关键位姿间的采样数
bool merge_union = true; // true=布尔并集构建真实扫掠体;false=仅包络
};
struct SweptVolumeResult {
BrepModel volume; // 扫掠体 B-Rep(布尔并集成功时)
AABB3D envelope; // 保守运动包络(采样位姿包围盒并集)
bool valid = false; // 扫掠体构建是否成功
int samples_used = 0; // 实际采样位姿数
std::string issue; // 失败/降级原因
};
struct SweptCollision {
bool hit = false; // 路径上是否发生碰撞
double time = -1.0; // 归一化首次碰撞时间 ∈ [0,1]
int sample_index = -1;
AABB3D contact_box; // 碰撞时运动体包围盒
};
// 关键位姿路径 → 采样位姿序列(平移线性插值 + 旋转 slerp)
[[nodiscard]] std::vector<Transform3D> sample_path(
const std::vector<Transform3D>& key_poses, int samples_per_segment = 12);
// 构建运动扫掠体积(采样位姿布尔并集 + 保守包络)
[[nodiscard]] SweptVolumeResult swept_volume(
const BrepModel& body,
const std::vector<Transform3D>& key_poses,
const SweptVolumeOptions& opts = {});
// 保守运动包络(AABB 并集,恒成功)
[[nodiscard]] AABB3D motion_envelope(
const BrepModel& body,
const std::vector<Transform3D>& key_poses,
int samples_per_segment = 12);
// 运动体 vs 静态障碍扫掠碰撞(AABB 快速拒绝 + 顶点包含 + SSI 布尔交集)
[[nodiscard]] SweptCollision swept_collision(
const BrepModel& body,
const std::vector<Transform3D>& key_poses,
const BrepModel& obstacle,
int samples_per_segment = 12);
} // namespace vde::brep
section_view.h — 截面/裁剪(VDE-173)
namespace vde::brep {
[[nodiscard]] std::vector<curves::NurbsCurve> section_plane(
const BrepModel& body,
const core::Point3D& plane_point,
const core::Vector3D& plane_normal); // B-Rep 与平面求交 → 截面曲线
[[nodiscard]] BrepModel clip_body(
const BrepModel& body,
const core::Point3D& plane_point,
const core::Vector3D& plane_normal,
bool keep_positive = true); // 半空间体裁剪
[[nodiscard]] std::vector<double> cross_section_extents(
const BrepModel& body,
const core::Vector3D& axis,
int num_slices); // 沿轴等距截面面积序列
} // namespace vde::brep
gizmo_api.h / viewport_api.h — 已移至 vde_ui 模块
模块拆分后,Gizmo 变换(
gizmo_transform/smart_dimension等,VDE-194)与 视口/投影(bounding_sphere/view_frustum_cull/scene_grid等,VDE-185/197/200/202) 已随 UI 能力迁移至独立模块,见include/vde_ui/gizmo_api.h与include/vde_ui/viewport_api.h(命名空间vde::ui),不再属于 vde::brep。
dimension_api.h — 标注尺寸(VDE-176)
namespace vde::brep {
struct DimensionData {
core::Point3D start, end;
double value;
core::Vector3D direction;
bool valid;
};
[[nodiscard]] DimensionData linear_dimension(const BrepModel& body, int face_id, const core::Vector3D& dir); // 线性标注
[[nodiscard]] DimensionData angular_dimension(const BrepModel& body, int face1, int face2); // 角度标注
[[nodiscard]] DimensionData radial_dimension(const BrepModel& body, int circular_face); // 径向标注
} // namespace vde::brep
hlr_api.h — 消隐线(VDE-183/VDE-195)
namespace vde::brep {
struct EdgeSegment {
core::Point3D p0, p1;
int edge_id;
bool visible;
double depth;
};
[[nodiscard]] std::vector<EdgeSegment> hlr_edges(const BrepModel& body, const core::Vector3D& view_dir); // 消隐线
[[nodiscard]] std::vector<EdgeSegment> silhouette_edges(const BrepModel& body, const core::Vector3D& view_dir); // 轮廓边
[[nodiscard]] std::vector<EdgeSegment> shaded_edges(const BrepModel& body, const core::Vector3D& view_dir); // 着色模式可见边
} // namespace vde::brep
viewport_api.h — 已移至 vde_ui 模块
视口/投影相关 API(
bounding_sphere/view_frustum_cull/camera_matrix/scene_grid等, VDE-185/197/200/202)已随模块拆分迁移至include/vde_ui/viewport_api.h(命名空间vde::ui),不再属于 vde::brep。
geometric_snap.h — 几何捕捉(VDE-175)
namespace vde::brep {
enum class SnapType : uint32_t {
None=0, Midpoint=1<<0, Endpoint=1<<1, Center=1<<2, Quadrant=1<<3,
Intersection=1<<4, Nearest=1<<5, Tangent=1<<6, All=0xFFFFFFFF
};
// 支持按位 OR 组合:SnapType::Midpoint | SnapType::Endpoint
struct SnapResult {
core::Point3D world_point;
int face_id, edge_id, vertex_id;
SnapType snap_type;
double distance;
};
[[nodiscard]] SnapResult snap_to_geometry(const BrepModel& body, const core::Point3D& near_point, SnapType snap_types, double tolerance = 1.0);
[[nodiscard]] core::Point3D midpoint(const BrepModel& body, int edge_id); // 边中点
[[nodiscard]] core::Point3D center_point(const BrepModel& body, int face_or_edge_id); // 面/边几何中心
[[nodiscard]] std::vector<core::Point3D> quadrant_points(const BrepModel& body, int circular_edge_id); // 圆形边四分点
[[nodiscard]] core::Point3D nearest_point_on_geometry(const BrepModel& body, const core::Point3D& near_point); // 几何最近点
} // namespace vde::brep
pattern_ops.h — 阵列/镜像/装配布尔(VDE-070)
namespace vde::brep {
enum class AssemblyBoolOp { Union = 0, Intersection = 1, Difference = 2 };
[[nodiscard]] BrepModel linear_pattern(const BrepModel& body, const Vector3D& direction, int count, double spacing);
[[nodiscard]] BrepModel circular_pattern(const BrepModel& body, const Point3D& center, const Vector3D& axis, int count, double total_angle_deg = 360.0);
[[nodiscard]] BrepModel mirror_body_pattern(const BrepModel& body, const Point3D& plane_point, const Vector3D& plane_normal);
[[nodiscard]] BrepModel assembly_boolean(const Assembly& assembly, AssemblyBoolOp op = AssemblyBoolOp::Union);
} // namespace vde::brep
brep_position.h — 基于位置查找
namespace vde::brep {
int get_edge_by_position(const BrepModel& body, const Point3D& nearPoint, double tolerance = 1e-6);
int get_face_by_position(const BrepModel& body, const Point3D& nearPoint, double tolerance = 1e-6);
} // namespace vde::brep
structural_profiles.h — 结构型材
namespace vde::brep {
[[nodiscard]] BrepModel make_i_beam(double height, double width, double web_thk, double flange_thk, double length); // 工字钢
[[nodiscard]] BrepModel make_c_channel(double height, double width, double web_thk, double flange_thk, double length); // 槽钢
[[nodiscard]] BrepModel make_angle(double width, double height, double thickness, double length); // 角钢
[[nodiscard]] BrepModel make_rectangular_tube(double width, double height, double wall_thk, double length); // 方管
[[nodiscard]] BrepModel make_round_tube(double outer_diameter, double wall_thk, double length); // 圆管
[[nodiscard]] BrepModel make_weld_bead(const BrepModel& body_a, const BrepModel& body_b, int edge_a, int edge_b, double bead_size); // 焊道
} // namespace vde::brep
brep_boolean.h — 布尔运算
namespace vde::brep {
[[nodiscard]] BrepModel brep_union(const BrepModel& a, const BrepModel& b); // 并集 A ∪ B
[[nodiscard]] BrepModel brep_intersection(const BrepModel& a, const BrepModel& b); // 交集 A ∩ B
[[nodiscard]] BrepModel brep_difference(const BrepModel& a, const BrepModel& b); // 差集 A \ B
} // namespace vde::brep
constraint_solver.h — 三维装配约束求解器
namespace vde::brep {
// 约束类型(constraint_types.h)
enum class ConstraintType { Coincident, Concentric, Tangent, Distance, Angle, Parallel, Perpendicular };
// 单个约束描述
struct Constraint {
int node_a, node_b; // 约束的零件 A/B 索引
ConstraintType type;
double value = 0.0; // 约束值(Distance=distance, Angle=radians)
double weight = 1.0;
std::string name;
};
// 自由度分析结果
struct DOFInfo {
int total_dof = 6; // 空间刚体 6 DOF(3 平移 + 3 旋转)
int eliminated_dof = 0; // 已消除的 DOF
int remaining_dof = 6;
bool is_fixed = false; // 是否完全约束
};
// 3D 约束图:节点 = 装配零件,边 = 约束
class ConstraintGraph {
public:
explicit ConstraintGraph(Assembly& assembly); // 从装配体树构造
int add_node(const std::string& name, AssemblyNode* node);
int add_constraint(const Constraint& c);
[[nodiscard]] std::vector<DOFInfo> analyze_dof() const; // DOF 分析
[[nodiscard]] bool is_fully_constrained() const; // 是否完全约束
[[nodiscard]] std::vector<OverConstraintInfo> detect_over_constraints() const; // 过度约束检测
[[nodiscard]] std::vector<Constraint>& constraints();
void clear();
};
// Newton-Raphson 求解器
struct NRSolverConfig { int max_iterations = 100; double tolerance = 1e-6; double step_size = 0.5; double damping = 0.5; bool check_over_constrained = true; };
struct SolveResult { bool converged; int iterations; double final_error; std::vector<double> error_history; std::string message; };
class NewtonRaphsonSolver {
public:
[[nodiscard]] SolveResult solve(ConstraintGraph& graph, Assembly& assembly,
const NRSolverConfig& config = NRSolverConfig{});
[[nodiscard]] SolveResult incremental_solve(ConstraintGraph& graph, Assembly& assembly,
int constraint_idx, double new_value,
const NRSolverConfig& config = NRSolverConfig{});
};
// 其余分析器:DOFAnalyzer(自由度分解)、RedundancyDetector(冗余检测)、
// ConstraintPropagator(约束传播)、KinematicChainSolver(闭环运动学)
} // namespace vde::brep
assembly_constraints.h — 装配约束
namespace vde::brep {
// 在两个装配节点之间施加约束(node_b 移动以满足约束)
[[nodiscard]] bool apply_constraint(
Assembly& assembly,
AssemblyNode* node_a,
AssemblyNode* node_b,
ConstraintType type, // Coincident/Concentric/Tangent/Distance/Angle/Parallel/Perpendicular
double value = 0.0); // Distance/Angle 约束的可选值
} // namespace vde::brep
其余模块 API 摘要
// brep_validate.h — B-Rep 验证
struct ValidationResult {
bool valid; // 是否通过所有必要检查
std::vector<std::string> errors, warnings; // 错误/警告列表
double watertightness; // 水密性比率(1.0 = 完美水密)
double self_intersection_free; // 无自交比率
double min_edge_length, max_edge_length; // 最短/最长边
size_t non_manifold_edges, dangling_edges; // 非流形边/悬挂边计数
int euler_characteristic; // 欧拉示性数 V - E + F
};
[[nodiscard]] ValidationResult validate(const BrepModel& body);
// brep_heal.h — B-Rep 拓扑修复(原地修改,返回操作计数)
int heal_gaps(BrepModel& body, double tolerance = 1e-6); // BFS 合并近距顶点
int heal_slivers(BrepModel& body); // 移除退化面
int heal_orientation(BrepModel& body); // 统一面方向(欧拉验证)
bool heal_topology(BrepModel& body, double tolerance = 1e-6); // 一站式流水线
int heal_step_import(BrepModel& body); // STEP 导入后自动修复
// 旧版兼容:heal_merge_vertices / heal_merge_edges / heal_close_gaps
// measure.h — 测量
[[nodiscard]] double distance(const BrepModel& a, const BrepModel& b); // 两实体最小距离
[[nodiscard]] double surface_area(const BrepModel& body); // 表面积
[[nodiscard]] double volume(const BrepModel& body); // 体积(散度定理)
[[nodiscard]] core::Point3D centroid(const BrepModel& body); // 质心
[[nodiscard]] MassProperties mass_properties(const BrepModel& body); // 质量属性(惯性张量等)
[[nodiscard]] double clearance(const BrepModel& a, const BrepModel& b); // 间隙分析
[[nodiscard]] WallThicknessResult analyze_wall_thickness(const BrepModel& body, int samples_per_face = 5);
[[nodiscard]] CircleFitResult fit_circle_3_points(const core::Point3D& p1, const core::Point3D& p2, const core::Point3D& p3);
// pmi_mbd.h — PMI/MBD 标注(pmi_types.h 定义 PMIType/PMIAnnotation)
[[nodiscard]] PMIAnnotation make_pmi_dimension(PMIType type, double value,
const core::Point3D& position, const std::vector<int>& face_ids);
[[nodiscard]] PMIAnnotation make_pmi_gdt(const GDTCallout& callout, const core::Point3D& position);
[[nodiscard]] PMIAnnotation make_pmi_surface_finish(double roughness_ra, int face_id, const core::Point3D& position);
[[nodiscard]] PMIAnnotation make_pmi_datum_target(const std::string& label, int face_id, const core::Point3D& position);
[[nodiscard]] std::vector<PMIAnnotation> filter_annotations(const std::vector<PMIAnnotation>& annotations, uint32_t type_filter);
// direct_modeling.h — 直接建模(返回 DirectModelingResult)
struct DirectModelingResult { bool success; BrepModel body; std::vector<std::string> errors, warnings; };
[[nodiscard]] DirectModelingResult move_face(const BrepModel& body, int face_id, const Vector3D& offset);
[[nodiscard]] DirectModelingResult offset_face(const BrepModel& body, int face_id, double distance);
[[nodiscard]] DirectModelingResult tweak_face(const BrepModel& body, int face_id, const Vector3D& translation);
[[nodiscard]] DirectModelingResult scale_body(const BrepModel& body, double factor, const Point3D& center);
[[nodiscard]] DirectModelingResult mirror_body(const BrepModel& body, const Point3D& plane_point, const Vector3D& plane_normal);
[[nodiscard]] DirectModelingResult fill_hole(const BrepModel& body, int face_id);
// sheet_metal.h — 钣金
struct SheetMetalMaterial { /* 材料定义(用于 K-factor) */ };
struct UnfoldResult { bool success; BrepModel flat; std::vector<std::string> errors, warnings; };
struct FlangeResult { bool success; BrepModel body; std::vector<int> new_face_ids, new_edge_ids; std::vector<std::string> errors, warnings; };
[[nodiscard]] UnfoldResult unfold_sheet_metal(const BrepModel& body, int face_id,
const SheetMetalMaterial& material = SheetMetalMaterial{}, double thickness = 0.0);
[[nodiscard]] FlangeResult create_flange(const BrepModel& body, int edge_id,
double angle_deg, double length,
const SheetMetalMaterial& material = SheetMetalMaterial{}, double thickness = 0.0);
[[nodiscard]] FlangeResult flange_feature(const BrepModel& body, int face_id,
double bend_angle, double bend_radius, const SheetMetalMaterial& material = SheetMetalMaterial{});
[[nodiscard]] BrepModel joggle_feature(const BrepModel& body, int face_id, double offset, const core::Vector3D& direction);
// ffd_deformation.h — 自由变形
struct FFDLattice { int nx, ny, nz; std::vector<Point3D> control_points; AABB3D bbox; };
[[nodiscard]] FFDLattice create_lattice(const AABB3D& bbox, int nx, int ny, int nz);
[[nodiscard]] BrepModel deform_brep(const BrepModel& body,
const FFDLattice& lattice, const std::vector<Vector3D>& displacements); // 位移量 [nx*ny*nz]
[[nodiscard]] BrepModel lattice_ffd(const BrepModel& body, const FFDLattice& lattice, /* 控制点偏移 */);
// interference_check.h — 干涉检查(输入为装配体)
struct InterferencePair { /* 零件对 + 穿透深度 */ };
struct InterferenceResult {
bool has_interference;
int total_pairs_checked, interfering_pairs;
std::vector<InterferencePair> pairs; // 所有检查对
std::vector<InterferencePair> conflicts; // 仅干涉对
[[nodiscard]] std::string summary() const;
};
[[nodiscard]] InterferenceResult check_interference(const Assembly& assembly, bool coarse_only = false);
[[nodiscard]] InterferencePair check_pair(const BrepModel& a, const BrepModel& b,
const core::Transform3D& ta, const core::Transform3D& tb);
// step_import.h / step_export.h — STEP IO(多体返回)
[[nodiscard]] std::vector<BrepModel> import_step(const std::string& filepath);
bool export_step_file(const std::string& filepath, const std::vector<BrepModel>& bodies);
// iges_import.h / iges_export.h — IGES IO(多体返回)
[[nodiscard]] std::vector<BrepModel> import_iges(const std::string& filepath);
bool export_iges_file(const std::string& filepath, const std::vector<BrepModel>& bodies);
代码示例
示例 1: 齿轮轴建模
#include <vde/brep/modeling.h>
#include <vde/brep/brep_boolean.h>
#include <vde/core/matrix4d.h>
using namespace vde::brep;
using namespace vde::core;
// 齿轮
auto gear = make_spur_gear(2.5, 20, 25, 20.0);
// 轴(圆柱体)
auto shaft = make_cylinder(15, 100, 64, Point3D(0, 0, -37.5));
// 合并齿轮和轴
auto assembly = brep_union(gear, shaft);
// 倒角
auto result = chamfer(assembly, 0, 1.0);
示例 2: 结构型材焊接
#include <vde/brep/structural_profiles.h>
#include <vde/brep/pattern_ops.h>
#include <vde/core/transform.h>
using namespace vde::brep;
using namespace vde::core;
// 创建工字钢梁
auto beam = make_i_beam(200, 100, 8, 12, 3000);
// 创建 4 根角钢立柱
auto column = make_angle(50, 50, 6, 500);
auto columns = linear_pattern(column, Vector3D::UnitX(), 4, 800);
// 焊道
auto bead = make_weld_bead(beam, column, 0, 0, 5.0);