Files
ViewDesignEngine/docs/reference/api-reference-brep.md
T
hm fef4ca22ab
pr-quality / static-gate (workflows + docs claims + coverage profile) (push) Canceled after 0s
pr-quality / fast-gate (build + core-pr tests + determinism) (push) Canceled after 0s
feat(brep/cae): face-level midsurface/offset and surface shell mesh; region table (VDE-1623/1618)
VDE-1623 (P1) - face-level midsurface and shell mesh:
  include/vde/brep/face_midsurface.h + src/brep/face_midsurface.cpp
    FaceTrimmedSurface (3D loops + per-segment source faces + thickness)
    offset_face_surface (plane/cylinder exact; sphere/cone/torus/spline reject)
    mid_surface_face (thickness min/mean/max, loop pairing, e_* diagnostics)
  include/vde/cae/surface_shell_mesh.h + src/cae/surface_shell_mesh.cpp
    surface_shell_mesh: quads/tris + thickness + element_source_face +
    boundary_nodes(node, source face)
  deviations documented: cae namespace (avoids brep<->mesh cycle), face-level
  3D loops instead of parametric brep::TrimmedSurface, new function name.
  test_vde1623_face_midsurface 15/15: plate thickness 2 / area 5000 / all quads /
  boundary sources; holed plate keeps 1 inner loop with hole-wall tags;
  wedge e_nonuniform_thickness; loop mismatch e_face_count_mismatch.

VDE-1618 (P2) - body region semantics:
  include/vde/cae/region_table.h + src/cae/region_table.cpp (namespace vde::mesh)
    RegionRole/MeshRegion/RegionTable + build_region_table
    connected-component regions by shared nodes; FNV-1a geometric-signature
    region_id independent of material/element count/order; boundary face tags.
  test_vde1618_region_table 13/13: single box 1 Solid region/6 tags; stable ids
  across remesh; material-independent ids; thin-wall shell 1 Solid/12 planes;
  shell+cavity merged mesh -> Solid+Cavity 2 regions.

Integration fixes:
  surface_shell_mesh.cpp undefined surface_index (blocked A7 builds) -> input_index
  loop_source_faces was all -1: BrepModel::edge_faces takes edge array index while
  sampling stored TopoEdge::id (vertex ids 0..7 shift edge ids 8..19 vs index 0..11)
  -> whole chain now stores indices; source-face tags verified.

Verification: full Release build OK; 20 integration suites all green
(test_vde1623 15/15, test_vde1618 13/13, test_vde1346 15/15, test_vde1360 12/12,
test_fea_mesh 68+1 skip, test_brep 96/96, test_trimmed_surface 34/34, ...);
PR gate 930/930 passed, 0 failed, 76.58 s.
2026-11-20 01:56:43 +08:00

38 KiB
Raw Blame History

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 装配级特征
body_access.h 体稳定身份、逐体枚举/提取、体解析(VDE-1622)
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 验证
selfint_seeds.h 自交手术种子库与验收口径(Phase 2.1/2.3)
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;
    std::uint64_t stable_id = 0;   // 几何指纹派生的稳定身份(VDE-1622)
    std::uint64_t revision = 0;    // 几何修订号(重建递增)
};
// 访问器:body_stable_id / set_body_stable_id / body_revision / set_body_revision
// 逐体访问见 body_access.h(list_bodies / extract_body / list_assembly_bodies / resolve_body)

// 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

body_access.h — 体访问契约(VDE-1622)

namespace vde::brep {

struct BodyId { std::uint64_t value = 0; bool valid() const; };
struct BodyRevision { std::uint64_t value = 0; };
struct BodyInfo {
    BodyId id; int index; std::string name, source;
    int shell_count, face_count, edge_count; bool closed; double volume;
    core::Point3D bbox_min, bbox_max; BodyRevision revision;
};
[[nodiscard]] std::vector<BodyInfo> list_bodies(const BrepModel& model);

struct BodyExtraction { std::optional<BrepModel> body; std::string error; };
[[nodiscard]] BodyExtraction extract_body(const BrepModel& model, BodyId id);
[[nodiscard]] BodyExtraction extract_body_at(const BrepModel& model, int body_index);

struct PartBodyRef { std::string part_path; int part_index = -1; std::optional<BrepModel> body; };
[[nodiscard]] std::vector<PartBodyRef> list_assembly_bodies(const Assembly& assembly);

enum class BodyMatch { Resolved, Missing, Ambiguous, Split, Merged };
struct BodyResolution { BodyMatch status; int index; std::vector<int> candidates; std::string reason; };
[[nodiscard]] BodyResolution resolve_body(const BrepModel& model, BodyId id);

}  // namespace vde::brep

语义要点:

  • BodyId 由体几何指纹生成(与 bodies_ 顺序无关),stable_id 持久化在 .vde additive 段 BODY_IDENTITY(段 17);旧文件读回 stable_id=0;
  • extract_body 返回单 BrepModel(num_bodies()==1),源模型不变;开放体 volume=-1;
  • resolve_body 只返回确定结果:唯一命中 Resolved,多个 Ambiguous(附候选),无命中按进程内快照判 Merged/Split,否则 Missing;
  • 装配路径 part_path 为 "/asm/cell/p1" 形式,与 Assembly::assign_part_indices() 一致;
  • 阵列/镜像重复体需宿主 set_body_stable_id 按特征实例路径补写。

step_import.h / step_export.h — 装配读写(VDE-900)

// step_import.h
[[nodiscard]] Assembly import_step_assembly(const std::string& filepath,
                                            const StepImportOptions& options = {});
// StepImportReport 追加:assembly_products / assembly_instances / assembly_roots

// step_export.h 装配导出:每个实例写 CONTEXT_DEPENDENT_SHAPE_REPRESENTATION(#rel, #pds)
  • 导入:PRODUCT/NAUO/CDSR/ITEM_DEFINED_TRANSFORMATION → Assembly 树 + 实例 local_transform;失败返回空树 + 结构化诊断;
  • 导出:装配路径每实例补 CDSR,同时修正 PRODUCT 名称写回;扁平零件不写 CDSR。

face_midsurface.h — 面级中面 / 偏移裁剪曲面(VDE-1623)

namespace vde::brep {

struct FaceTrimmedSurface {
    std::shared_ptr<curves::NurbsSurface> surface;   // 独立曲面(平面/圆柱的 NURBS 表示;中面=拟合平面)
    std::vector<std::vector<core::Point3D>> loops;   // 外环 + 内环,3D 折线,已定向;loops[0]=外环
    std::vector<std::vector<int>> loop_source_faces; // 每段边界背后相邻 B-Rep 面 id(孔壁面标记;-1=未知)
    int source_face = -1;                            // 偏移结果=被偏移面;中面结果=face_a
    double average_offset = 0.0;                     // 中面结果 = thickness/2
    bool reversed = false;                           // 结果解析法向与源面外法向相反
    double thickness = 0.0;                          // 中面结果:配对厚度均值
    std::vector<int> source_faces;                   // 中面结果:配对的两面
};

struct MidSurfacePairResult {
    FaceTrimmedSurface mid;
    double thickness_mean = 0.0, thickness_min = 0.0, thickness_max = 0.0;
    int face_a = -1, face_b = -1;
    bool ok = false;
    std::string code, message;   // ok=true 时为空
};

[[nodiscard]] std::optional<FaceTrimmedSurface> offset_face_surface(
    const BrepModel& body, int face_id, double offset_distance,
    std::string* diagnostic = nullptr);

[[nodiscard]] MidSurfacePairResult mid_surface_face(
    const BrepModel& body, int face_a, int face_b, double tolerance = 0.02);

}  // namespace vde::brep

语义要点:

  • offset_face_surface:平面 → 平行平面 + 环整体平移(average_offset=offset_distance、面积不变); 圆柱面(含内孔壁)→ 同心圆柱,半径 r ± offset(内孔面 reversed=true)。球/锥/环/样条返回 e_unsupported_offset;半径塌陷/环退化返回 e_offset_topology_failure;两类前缀可区分; 越界/空体返回 e_invalid_face / e_empty,均不抛异常。
  • mid_surface_face:两面法向点积 ≤ -0.99 → 环数一致 → 逐环顶点配对(方向/移位/重采样最小代价)→ 厚度 min/mean/max;(max-min)/mean > tolerance 返回 e_nonuniform_thickness 且不输出中面。 成功时 mid.loops 为配对点中点、mid.surface 为法向与 face_a 同侧的拟合平面、 average_offset=thickness_mean/2、thickness=thickness_mean、source_faces={face_a,face_b}。
  • 失败码:e_invalid_face / e_empty / e_not_parallel / e_face_count_mismatch / e_nonuniform_thickness / e_unsupported_offset / e_offset_topology_failure。
  • 只读、无全局状态、可并发调用;不要求输入体封闭。

surface_shell_mesh.h(vde::cae)— 面级壳网格(VDE-1623)

namespace vde::cae {

struct SurfaceShellMeshParams {
    double target_edge_length = 0.0;   // <=0 时取面尺寸的 5%
    double thickness = 0.0;            // 面级曲面未带厚度时的默认壳厚
    bool quad_dominant = true;         // true=四边形优先(允许三角形回退)
};

struct SurfaceShellMeshResult {
    std::vector<core::Point3D> nodes;
    std::vector<std::array<int,4>> quads;             // 4 节点;三角形不进 quads
    std::vector<std::array<int,3>> tris;
    std::vector<double> thickness;                    // 每单元厚度
    std::vector<int> element_source_face;             // 每单元来源 B-Rep 面
    std::vector<std::pair<int,int>> boundary_nodes;   // (node, source_face),同一节点可多条
    bool ok = false;
    std::string code, message;   // 失败码:e_empty / e_mesh_failure
};

[[nodiscard]] SurfaceShellMeshResult surface_shell_mesh(
    const std::vector<brep::FaceTrimmedSurface>& surfaces,
    const SurfaceShellMeshParams& params = {});

}  // namespace vde::cae

语义要点:

  • 输入一组面级裁剪曲面(偏移结果或中面结果),输出壳网格;相邻面的共享边节点按坐标量化容差 (1e-9·包围盒对角线)焊接合并。
  • quad_dominant=true 时矩形面全四边形(quads 非空、tris 可含少量回退三角形); false 时输出三角形(全进 tris,quads 为空)。输出顺序:全部 quads 在前、tris 在后, thickness / element_source_face 与单元同序。
  • 内环保留(孔不填平):孔环上的边界节点来源面优先取 loop_source_faces 的孔壁面 id, 否则回退 surface.source_face;外边界节点同理带侧壁面来源。
  • 命名空间选 vde::cae 而非工单草图的 vde::mesh:brep 依赖 mesh,反向会形成循环依赖; 且既有壳网格 API(cae::shell_mesh,VDE-1360)即属 vde::cae。
  • 只支持近似平面面级曲面(平面性检查 1e-9·包围盒对角线),非平面 → e_mesh_failure; 空输入 → e_empty。

其余模块 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);

// selfint_seeds.h — 自交手术种子库与验收口径(Phase 2.1/2.3)
enum class SelfIntCategory { Clean, BoundaryTouch, AssemblyInterference, AreaPenetration };
struct SelfIntEvidence { SelfIntCategory category; bool valid; double watertightness;
    size_t intra_penetration_pairs, inter_penetration_pairs, boundary_touch_pairs, reported_pairs; };
struct SelfIntAcceptance { bool require_valid; double min_watertightness;
    size_t max_intra_penetration_pairs, max_inter_penetration_pairs; };
struct SelfIntSeed { std::string id, model, note; SelfIntCategory expected; SelfIntAcceptance accept; };
[[nodiscard]] SelfIntEvidence classify_self_intersection(const ValidationResult& r);
[[nodiscard]] SelfIntEvidence diagnose_self_intersection(const BrepModel& body,
    std::vector<std::array<int, 2>>* intra_penetration_faces_out = nullptr);
[[nodiscard]] SelfIntAcceptance strict_acceptance();            // valid && wt>0.99 && 壳内穿透=0
[[nodiscard]] SelfIntAcceptance assembly_tolerant_acceptance(); // 放宽壳间干涉
[[nodiscard]] bool meets_acceptance(const SelfIntAcceptance& a, const SelfIntEvidence& e);
[[nodiscard]] const std::vector<SelfIntSeed>& builtin_selfint_seeds();
[[nodiscard]] std::vector<const SelfIntSeed*> seeds_for_category(SelfIntCategory c);
[[nodiscard]] const SelfIntSeed* find_seed(const std::string& id);

// 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);