# B-Rep 模块 API 参考 > 边界表示(B-Rep)模块 — 实体建模、阵列、约束、剖面、视口、标注、捕捉、型材 ## 模块概述 brep 模块是 ViewDesignEngine 的核心建模引擎,提供完整的 B-Rep 实体创建、编辑、分析和渲染能力。包含 60+ 头文件,涵盖从基本体创建到高级装配约束、结构型材焊接、齿轮/弹簧生成等工业级功能。 --- ## 头文件列表 | 头文件 | 说明 | |--------|------| | `brep.h` | B-Rep 核心数据结构(BrepModel、拓扑实体) | | `modeling.h` | 高层建模 API(基本体/扫掠/编辑/齿轮/弹簧) | | `brep_boolean.h` | 布尔运算(并集/交集/差集) | | `ssi_boolean.h` | 曲面-曲面求交布尔运算 | | `boolean_fallback.h` | 布尔运算降级回退策略 | | `section_view.h` | 截面/裁剪 API(VDE-173) | | `gizmo_api.h` | Gizmo 坐标变换 + 智能标注引擎(VDE-194) | | `dimension_api.h` | PMI/标注尺寸 API(VDE-176) | | `hlr_api.h` | 消隐线 API(VDE-183/VDE-195) | | `viewport_api.h` | 视口/投影矩阵 API(VDE-185/197/200/202) | | `geometric_snap.h` | 几何捕捉查询 API(VDE-175) | | `pattern_ops.h` | B-Rep 阵列/镜像/装配布尔(VDE-070) | | `brep_position.h` | 基于位置查找边/面 | | `structural_profiles.h` | 结构型材 + 焊道生成 | | `constraint_solver.h` | 二维约束求解器 | | `constraint_types.h` | 约束类型定义 | | `assembly_constraints.h` | 装配约束(配合/对齐/等距等) | | `assembly.h` | 装配体树结构 | | `assembly_instance.h` | 装配体实例化 | | `assembly_feature.h` | 装配级特征 | | `assembly_patterns.h` | 装配阵列 | | `assembly_lod.h` | 装配体 LOD | | `flexible_assembly.h` | 柔性装配体 | | `fastener_library.h` | 紧固件库 | | `kinematic_chain.h` | 运动链约束 | | `auto_dimensioning.h` | 自动标注 | | `brep_drawing.h` | 工程图生成 | | `drawing_standards.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` | 高级融合曲面 | | `direct_modeling.h` | 直接建模 | | `euler_op.h` | 欧拉操作(拓扑编辑) | | `brep_face_split.h` | 面分割 | | `trimmed_surface.h` | 修剪曲面 | | `sheet_metal.h` | 钣金设计 | | `ffd_deformation.h` | 自由变形(FFD) | | `gdt.h` | 几何尺寸与公差(GD&T) | | `draft_analysis.h` | 拔模分析 | | `quality_feedback.h` | 质量反馈 | | `step_import.h` | STEP 导入 | | `step_export.h` | STEP 导出 | | `iges_import.h` | IGES 导入 | | `iges_export.h` | IGES 导出 | | `dxf_import.h` | DXF 导入 | | `format_io.h` | 统一格式 IO 调度 | | `explode_view.h` | 爆炸视图 | | `interference_check.h` | 干涉检查 | | `motion_simulation.h` | 运动仿真 | | `update_notifier.h` | 更新通知 | | `incremental_update.h` | 增量更新 | | `incremental_mesh.h` | 增量网格 | | `parallel_boolean.h` | 并行布尔运算 | | `large_assembly.h` | 大型装配体优化 | --- ## 详细 API ### `brep.h` — 核心数据结构 ```cpp 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 }; // 拓扑实体 struct TopoVertex { int id; Point3D point; double tolerance; }; struct TopoEdge { int id; int v0, v1; CurveType curve_type; int curve_id; /* ... */ }; struct TopoFace { int id; int surface_id; std::vector loop_ids; bool reversed; /* ... */ }; struct TopoShell { int id; std::vector face_ids; bool closed; }; struct TopoBody { int id; std::string name; std::vector shell_ids; }; // BrepModel 主要 API class BrepModel { public: // 构建 int add_vertex(const Point3D& p); int add_edge(int v0, int v1); int add_curve(const curves::NurbsCurve& curve); int add_surface(const curves::NurbsSurface& surf); int add_loop(const std::vector& edge_ids); int add_face(int surface_id, const std::vector& loop_ids); int add_shell(const std::vector& face_ids); int add_body(const std::vector& shell_ids, const std::string& name = ""); // 查询 [[nodiscard]] size_t num_vertices() const; [[nodiscard]] size_t num_edges() const; [[nodiscard]] size_t num_faces() const; [[nodiscard]] size_t num_shells() const; [[nodiscard]] size_t num_bodies() const; [[nodiscard]] size_t num_curves() const; [[nodiscard]] size_t num_surfaces() const; [[nodiscard]] bool empty() 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 TopoBody& body(int id) const; // 新增几何查询(VDE-179/VDE-180) [[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]] double face_curvature(int face_id) const; // 面曲率 [[nodiscard]] double body_volume(int body_id) const; // 体体积 [[nodiscard]] std::vector face_adjacency(int face_id) const; // 面的相邻面 // 几何访问 [[nodiscard]] const curves::NurbsCurve& curve(int id) const; [[nodiscard]] const curves::NurbsSurface& surface(int id) const; // 包围盒 [[nodiscard]] AABB3D bounds() const; // B-Rep → Mesh [[nodiscard]] mesh::HalfedgeMesh to_mesh(double deflection = 0.1) const; // STEP/IGES IO static BrepModel import_step(const std::string& path); static std::vector import_step_multi(const std::string& path); bool export_step(const std::string& path) const; static BrepModel import_iges(const std::string& path); bool export_iges(const std::string& path) const; }; } // namespace vde::brep ``` ### `modeling.h` — 高层建模 API ```cpp 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& 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& 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& profile, const Vector3D& direction, double thickness); } // namespace vde::brep ``` ### `section_view.h` — 截面/裁剪(VDE-173) ```cpp namespace vde::brep { [[nodiscard]] std::vector 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 cross_section_extents( const BrepModel& body, const core::Vector3D& axis, int num_slices); // 沿轴等距截面面积序列 } // namespace vde::brep ``` ### `gizmo_api.h` — Gizmo 与智能标注(VDE-194) ```cpp namespace vde::brep { enum class GizmoAxisType { TranslateX, TranslateY, TranslateZ, RotateX, RotateY, RotateZ, ScaleX, ScaleY, ScaleZ, ScaleUniform }; struct Transform3D { core::Matrix4D matrix; GizmoAxisType axis; double value; core::Point3D pivot; }; struct DimensionData { int face_id; core::Point3D start, end, text_pos; double length; std::string orientation; int priority; }; [[nodiscard]] Transform3D gizmo_transform( const BrepModel& body, const core::Point3D& point, GizmoAxisType axis_type); // Gizmo 交互变换 [[nodiscard]] std::vector smart_dimension( const BrepModel& body, const std::vector& face_ids); // 智能标注 } // namespace vde::brep ``` ### `dimension_api.h` — 标注尺寸(VDE-176) ```cpp 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) ```cpp namespace vde::brep { struct EdgeSegment { core::Point3D p0, p1; int edge_id; bool visible; double depth; }; [[nodiscard]] std::vector hlr_edges(const BrepModel& body, const core::Vector3D& view_dir); // 消隐线 [[nodiscard]] std::vector silhouette_edges(const BrepModel& body, const core::Vector3D& view_dir); // 轮廓边 [[nodiscard]] std::vector shaded_edges(const BrepModel& body, const core::Vector3D& view_dir); // 着色模式可见边 } // namespace vde::brep ``` ### `viewport_api.h` — 视口/投影矩阵(VDE-185/197/200/202) ```cpp namespace vde::brep { struct BoundingSphere { core::Point3D center; double radius; }; [[nodiscard]] BoundingSphere bounding_sphere(const BrepModel& body); // 最小包围球 [[nodiscard]] bool view_frustum_cull(const BrepModel& body, const core::Matrix4D& view_matrix, const core::Matrix4D& proj_matrix); // 视锥体裁剪 [[nodiscard]] core::Matrix4D camera_matrix(const BrepModel& body, const core::Point3D& camera_pos, const core::Point3D& target, const core::Vector3D& up = {0,0,1}); // look-at 视图矩阵 [[nodiscard]] std::string orientation_cube_face(const core::Vector3D& dir); // 方向立方体面 struct CameraPose { core::Point3D position, target; core::Vector3D up; }; [[nodiscard]] CameraPose camera_interpolate(const core::Point3D& from_pos, const core::Point3D& from_target, const core::Point3D& to_pos, const core::Point3D& to_target, double t); // 相机插值 struct GridLine { core::Point3D start, end; }; struct GridData { std::vector lines; Color grid_color, axis_color; double extent_x, extent_y; }; [[nodiscard]] GridData scene_grid(double extents, double spacing); // 场景网格 struct PlaneData { core::Point3D origin; core::Vector3D normal; double offset; }; [[nodiscard]] PlaneData ground_plane(const std::vector& bodies); // 地平面 } // namespace vde::brep ``` ### `geometric_snap.h` — 几何捕捉(VDE-175) ```cpp 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 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) ```cpp 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` — 基于位置查找 ```cpp 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` — 结构型材 ```cpp 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` — 布尔运算 ```cpp namespace vde::brep { enum class BooleanOp { Union, Intersection, Difference }; [[nodiscard]] BrepModel brep_union(const BrepModel& a, const BrepModel& b); [[nodiscard]] BrepModel brep_intersect(const BrepModel& a, const BrepModel& b); [[nodiscard]] BrepModel brep_subtract(const BrepModel& a, const BrepModel& b); } // namespace vde::brep ``` ### `constraint_solver.h` — 二维约束求解器 ```cpp namespace vde::brep { class ConstraintSolver { public: int add_point(double x, double y, bool fixed = false); int add_line(int p0, int p1); void add_distance_constraint(int p0, int p1, double d); void add_horizontal(int line_id); void add_vertical(int line_id); void add_parallel(int l0, int l1); void add_perpendicular(int l0, int l1); void add_coincident(int p0, int p1); bool solve(int max_iter = 100, double tol = 1e-6); Point2D get_point(int idx) const; }; } // namespace vde::brep ``` ### `assembly_constraints.h` — 装配约束 ```cpp namespace vde::brep { enum class AssemblyConstraintType { Mate, Align, Distance, Angle, Concentric, Parallel, Perpendicular, Tangent, Gear }; void add_assembly_constraint(const std::string& name, AssemblyConstraintType type, const BrepModel& body_a, int face_a, const BrepModel& body_b, int face_b, double value = 0.0); bool solve_assembly_constraints(const std::vector& bodies, int max_iter = 50, double tol = 1e-6); } // namespace vde::brep ``` ### 其余模块 API 摘要 ```cpp // brep_validate.h — B-Rep 验证 struct ValidationResult { bool valid; std::vector errors, warnings; }; [[nodiscard]] ValidationResult validate_brep(const BrepModel& body); // brep_heal.h — B-Rep 修复 [[nodiscard]] BrepModel heal_brep(const BrepModel& body, double tolerance = 1e-6); // measure.h — 测量 [[nodiscard]] double measure_distance(const BrepModel& body_a, const BrepModel& body_b); [[nodiscard]] double measure_angle(const BrepModel& body, int face1, int face2); [[nodiscard]] double measure_radius(const BrepModel& body, int circular_face_id); // pmi_mbd.h — PMI/MBD 标注 void add_pmi_dimension(BrepModel& body, int face_id, double value, const std::string& type); void add_pmi_tolerance(BrepModel& body, double upper, double lower); void add_pmi_datum(BrepModel& body, int face_id, const std::string& label); // direct_modeling.h — 直接建模 [[nodiscard]] BrepModel move_face(const BrepModel& body, int face_id, const Vector3D& offset); [[nodiscard]] BrepModel offset_face(const BrepModel& body, int face_id, double distance); [[nodiscard]] BrepModel remove_face(const BrepModel& body, int face_id); // sheet_metal.h — 钣金 struct SheetMetalParams { double thickness, bend_radius, k_factor; }; [[nodiscard]] BrepModel sheet_metal_flange(const BrepModel& body, int edge_id, double length, double angle_deg, const SheetMetalParams& params); [[nodiscard]] BrepModel sheet_metal_unfold(const BrepModel& body); // ffd_deformation.h — 自由变形 struct FFDParams { int nu, nv, nw; std::vector lattice; }; [[nodiscard]] BrepModel ffd_deform(const BrepModel& body, const FFDParams& params); // interference_check.h — 干涉检查 struct InterferenceResult { bool has_interference; std::vector> interfering_pairs; double max_penetration; }; [[nodiscard]] InterferenceResult check_interference(const std::vector& bodies); // step_import.h / step_export.h — STEP IO [[nodiscard]] BrepModel import_step(const std::string& path); bool export_step(const BrepModel& body, const std::string& path); // iges_import.h / iges_export.h — IGES IO [[nodiscard]] BrepModel import_iges(const std::string& path); bool export_iges(const BrepModel& body, const std::string& path); ``` --- ## 代码示例 ### 示例 1: 齿轮轴建模 ```cpp #include #include #include 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: 结构型材焊接 ```cpp #include #include #include 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); ```