Files

16 KiB
Raw Permalink Blame History

API 总览

ViewDesignEngine 提供 C++20 头文件 API,所有公开接口位于 include/vde/ 目录下。

模块 API 概览

foundation — 基础设施 (vde::foundation)

// 数学类型(定义于 foundation,经 core 重新导出)
#include <vde/foundation/math_types.h>   // Point2D, Point3D, Vector2D, Vector3D
#include <vde/core/point.h>              // vde::core 重新导出的点/向量类型
#include <vde/core/aabb.h>               // AABB2D, AABB3D
#include <vde/core/matrix4d.h>           // Matrix4x4, Transform3D

// 公差与精确谓词
#include <vde/foundation/tolerance.h>    // Tolerance, is_zero(), is_equal()
#include <vde/foundation/exact_predicates.h> // orient2d, orient3d, incircle

// 格式 I/O
#include <vde/foundation/io_obj.h>       // read_obj(), write_obj()
#include <vde/foundation/io_stl.h>       // read_stl(), write_stl()
#include <vde/foundation/io_ply.h>       // read_ply(), write_ply()
#include <vde/foundation/io_gltf.h>      // write_gltf(), import_gltf()
#include <vde/foundation/io_3mf.h>       // read_3mf(), write_3mf()
#include <vde/foundation/io_dxf.h>       // import_dxf(), export_dxf_string()
#include <vde/foundation/io_dwg_plugin.h>// import_dwg_plugin()
#include <vde/foundation/industrial_formats.h> // Parasolid XT/SAT/JT/IFC/PDF3D(命名空间 vde::io)

STEP AP203/214/242 与 IGES 5.3 的导入导出位于 brep 模块(见下)。

core — 几何核心 (vde::core)

#include <vde/core/polygon.h>            // Polygon2D, triangulate(), simplify()
#include <vde/core/voronoi.h>            // VoronoiDiagram2D
#include <vde/core/convex_hull.h>        // convex_hull_2d(), convex_hull_3d()
#include <vde/core/distance.h>           // distance()(点/线/面/三角/AABB 重载)
#include <vde/core/icp.h>                // icp_register()
#include <vde/core/object_pool.h>        // ObjectPool<T> 内存池
#include <vde/core/transaction.h>        // Transaction (begin/commit/rollback)

compute — 高性能计算 (vde::compute)

#include <vde/compute/compute_backend.h> // CPU SIMD 后端;VDE_USE_CUDA 启用真实 CUDA kernel(无设备时诚实回退)

cam — 数控加工 (vde::cam,独立模块)

#include <vde_cam/cam_toolpath.h>        // ToolPath, GCode, CLData
#include <vde_cam/cam_strategies.h>      // roughing_toolpath, finishing_toolpath, drilling_toolpath
#include <vde_cam/cam_5axis.h>           // 5轴联动: swarf_machining, multi_axis_roughing
#include <vde_cam/cam_advanced.h>        // 自适应/摆线/残料/清根/HSM
#include <vde_cam/cam_optimization.h>    // 切屑减薄/恒接触/进给优化

curves — 曲线曲面 (vde::curves)

#include <vde/curves/bezier_curve.h>      // BezierCurve
#include <vde/curves/bspline_curve.h>     // BSplineCurve
#include <vde/curves/nurbs_curve.h>       // NurbsCurve
#include <vde/curves/bezier_surface.h>    // BezierSurface
#include <vde/curves/bspline_surface.h>   // BSplineSurface
#include <vde/curves/nurbs_surface.h>     // NurbsSurface
#include <vde/curves/nurbs_operations.h>  // offset_surface, trim_surface, blend_surfaces, ruled_surface, coons_patch, extrude_curve
#include <vde/curves/tessellation.h>      // adaptive_tessellate()
#include <vde/curves/surface_intersection.h>  // intersect_surfaces()
#include <vde/curves/surface_analysis.h>  // curvature_map(), zebra_stripe()
#include <vde/curves/surface_continuity.h>// G0/G1/G2 continuity check
#include <vde/curves/surface_fairing.h>   // fair_surface()
#include <vde/curves/exact_offset.h>      // exact_offset()
#include <vde/curves/surface_extension.h> // extend_surface()
#include <vde/curves/parallel_intersection.h> // parallel_surface_intersection()

mesh — 网格处理 (vde::mesh)

#include <vde/mesh/halfedge_mesh.h>       // HalfedgeMesh
#include <vde/mesh/delaunay_2d.h>         // delaunay_2d()
#include <vde/mesh/delaunay_3d.h>         // delaunay_3d()
#include <vde/mesh/mesh_simplify.h>       // simplify_mesh()
#include <vde/mesh/mesh_smooth.h>         // smooth_mesh(), smooth_laplacian(), smooth_taubin()
#include <vde/mesh/mesh_boolean.h>        // mesh_boolean()
#include <vde/mesh/mesh_quality.h>        // mesh_quality_report()
#include <vde/mesh/mesh_repair.h>         // non_manifold_repair(), automatic_hole_filling()
#include <vde/mesh/alpha_shapes.h>        // alpha_shapes()
#include <vde/mesh/mesh_parameterize.h>   // tutte_parameterization(), lscm_parameterization()
#include <vde/mesh/geodesic.h>            // geodesic_distance()
#include <vde/mesh/mesh_curvature.h>      // compute_curvature()
#include <vde/mesh/marching_cubes.h>      // marching_cubes()
#include <vde/mesh/parallel_mc.h>         // parallel_marching_cubes()
#include <vde/mesh/mesh_lod.h>            // generate_lod()
#include <vde/mesh/reverse_engineering.h> // reverse engineering pipeline
#include <vde/mesh/point_cloud.h>         // PointCloud processing
#include <vde/mesh/fea_mesh.h>            // FEA mesh generation

spatial — 空间索引 (vde::spatial)

#include <vde/spatial/bvh.h>             // BVH<Triangle>
#include <vde/spatial/octree.h>          // Octree<Point3D>
#include <vde/spatial/kd_tree.h>         // KDTree<Point3D>
#include <vde/spatial/r_tree.h>          // RTree<AABB3D>
#include <vde/spatial/incremental_bvh.h> // IncrementalBVH

boolean — 布尔运算 (vde::boolean)

#include <vde/boolean/boolean_2d.h>       // boolean_2d()
#include <vde/boolean/boolean_mesh.h>     // mesh_union(), mesh_difference(), mesh_intersection(), mesh_boolean()
#include <vde/boolean/polygon_offset.h>   // polygon_offset()

collision — 碰撞检测 (vde::collision)

#include <vde/collision/gjk.h>           // gjk_distance(), gjk_intersect()
#include <vde/collision/sat.h>           // sat_intersect()
#include <vde/collision/ray_intersect.h>  // ray_triangle_intersect(), ray_aabb_intersect(), ray_mesh_intersect()
#include <vde/collision/tri_intersect.h>  // tri_tri_intersect()

brep — B-Rep 建模 (vde::brep)

#include <vde/brep/brep.h>              // BrepModel, TopoVertex, TopoEdge, TopoFace
#include <vde/brep/modeling.h>          // make_box, make_sphere, fillet, chamfer, shell
#include <vde/brep/brep_boolean.h>      // brep_union, brep_intersection, brep_difference
#include <vde/brep/brep_validate.h>     // validate()
#include <vde/brep/brep_heal.h>         // heal_topology(), heal_gaps(), heal_orientation()
#include <vde/brep/step_import.h / step_export.h> // STEP AP203/214/242 导入导出
#include <vde/brep/iges_import.h / iges_export.h> // IGES 5.3 导入导出
#include <vde/brep/tolerance.h>         // Tolerance settings
#include <vde/brep/trimmed_surface.h>   // TrimmedSurface
#include <vde/brep/ssi_boolean.h>       // Surface-surface intersection boolean
#include <vde/brep/format_io.h>         // 格式 I/O 聚合
#include <vde/brep/measure.h>           // distance, surface_area, volume, centroid
#include <vde/brep/brep_drawing.h>      // Drawing generation
#include <vde/brep/auto_dimensioning.h> // Automatic dimensioning
#include <vde/brep/pmi_mbd.h>           // PMI/MBD annotations
#include <vde/brep/gdt.h>               // GD&T annotations
#include <vde/brep/euler_op.h>          // Euler operators
#include <vde/brep/draft_analysis.h>    // Draft angle analysis
#include <vde/brep/feature_recognition.h> // Feature recognition
#include <vde/brep/defeature.h>         // Defeaturing
#include <vde/brep/advanced_blend.h>    // Advanced blending
#include <vde/brep/ffd_deformation.h>   // Free-form deformation
#include <vde/brep/constraint_solver.h> // 3D constraint solving
#include <vde/brep/assembly_constraints.h> // apply_constraint()
#include <vde/brep/direct_modeling.h>   // Direct modeling
#include <vde/brep/fastener_library.h>  // Fastener library

sdf — 隐式建模 (vde::sdf)

#include <vde/sdf/sdf_primitives.h>     // sphere, box, cylinder, torus, cone, etc.
#include <vde/sdf/sdf_operations.h>     // op_union, op_intersection, op_difference, op_smooth_union
#include <vde/sdf/sdf_tree.h>           // SdfNode, evaluate()
#include <vde/sdf/sdf_to_mesh.h>        // sdf_to_mesh()
#include <vde/sdf/sdf_gradient.h>       // gradient()
#include <vde/sdf/sdf_optimize.h>       // fit_to_point_cloud(), fit_surface_to_points()

sketch — 草图约束 (vde::sketch)

已移出公共 API 面(VDE-1201):原 #include <vde/sketch/constraint_solver.h> 的 2D 约束求解器现为 VDE 内部实现(src/sketch/),不经 C ABI 导出、不并入聚合目标 vde。 约束求解统一由宿主侧 VDCS(ViewDesignConstraintSolver)承担。

模块间依赖关系

ViewDesignEngine 采用分层架构,内核模块间依赖严格单向;foundation 聚合 I/O 依赖 (链接 vde_mesh / vde_brep 以支持格式转换),GCC 下以 --start-group 解决环链。

                            ┌─────────────────────────────────┐
                            │          vde (聚合接口库)         │
                            └──────────────┬──────────────────┘
                  ┌────────────────────────┼────────────────────────┐
                  │                        │                        │
         ┌────────┴────────┐     ┌────────┴────────┐     ┌────────┴────────┐
         │    vde_capi     │     │    vde_brep     │     │  vde_compute    │
         │   (C ABI 出口)   │     │  (B-Rep 建模)   │     │   (CPU/CUDA)    │
         └────────┬────────┘     └────────┬────────┘     └────────┬────────┘
                  │                       │                       │
        ┌─────────┼───────────────┬───────┼───────┬───────────────┘
        │         │               │       │       │
        ▼         ▼               ▼       ▼       ▼
  ┌──────────┐┌──────────┐┌──────────┐┌──────────┐┌──────────┐
  │ vde_sdf  ││vde_sketch││vde_curves││vde_mesh  ││vde_      │
  │隐式建模  ││草图约束   ││曲线曲面   ││网格处理   ││collision │
  └────┬─────┘└────┬─────┘└────┬─────┘└────┬─────┘└────┬─────┘
       │           │           │           │           │
       └───────────┴───────────┼───────────┴───────────┘
                               │
                     ┌─────────┴──────────┐
                     │                    │
               ┌─────┴─────┐        ┌─────┴─────┐
               │ vde_core  │        │vde_spatial│
               │ 几何核心   │        │ 空间索引   │
               └─────┬─────┘        └─────┬─────┘
                     │                    │
                     └──────────┬─────────┘
                                │
                     ┌──────────┴──────────┐
                     │   vde_foundation    │
                     │    基础设施层        │
                     └──────────┬──────────┘
                                │
                     ┌──────────┴──────────┐
                     │   Eigen3 (外部依赖)  │
                     └─────────────────────┘

其余独立业务模块(vde_expression / vde_param / vde_event / vde_drafting / vde_infra / vde_mechanism / vde_pdm / vde_license / vde_platform / vde_ui / vde_cam / vde_render) 通过聚合库 vde 统一暴露。

依赖矩阵

模块 foundation core spatial curves mesh collision boolean brep sdf sketch
foundation — — — — ✅¹ — — ✅¹ — —
core ✅ — — — ✅ — — ✅ — —
compute — ✅ — — — — — — — —
spatial — ✅ — — — — — — — —
curves — ✅ — — — — — — — —
mesh — ✅ — ✅ — — — ✅ — —
collision — ✅ ✅ — — — — — — —
boolean — — ✅ — ✅ — — — — —
brep — — — ✅ ✅ ✅ — — ✅ —
sdf — ✅ — — ✅ — — — — —
sketch — ✅ — — — — — — — —
capi ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅

¹ foundation 为支持网格/B-Rep 格式转换而链接 vde_mesh / vde_brep(聚合 I/O 依赖), GCC 下由 --start-group 处理环链;core → mesh/brep 的链接同理。

层次说明

层 模块 职责 上游依赖数
L0 基础 foundation 数学类型、I/O、公差、精确谓词 0 (仅 Eigen)
L1 核心 core, spatial, compute 几何算法 + 空间索引 + 高性能计算 1
L2 曲面 curves 曲线曲面计算 1
L3 网格 mesh 网格处理与重建 2
L4 检测 collision, boolean 碰撞检测、布尔运算 2–3
L5 领域 brep, sdf, sketch 高层建模 3–4
L6 出口 capi, compute 跨语言接口、计算加速 0–10
L7 业务 expression, param, event, drafting, infra, mechanism, pdm, license, platform, ui, cam, render 业务扩展模块 1–4

核心类型速查

类型 命名空间 说明
Point2D / Point3D vde::core 2D/3D 点
Vector2D / Vector3D vde::core 2D/3D 向量
AABB2D / AABB3D vde::core 轴对齐包围盒
Matrix3x3 / Matrix4x4 vde::core 3x3 / 4x4 变换矩阵
Triangle vde::core 三角形
HalfedgeMesh vde::mesh 半边网格数据结构
BrepModel vde::brep B-Rep 实体模型
SdfNode vde::sdf SDF 场景图节点
BezierCurve vde::curves Bézier 曲线
NurbsSurface vde::curves NURBS 曲面

使用约定

头文件包含

// 推荐:只包含需要的头文件
#include <vde/mesh/halfedge_mesh.h>
#include <vde/core/point.h>

// C 语言 API(外部语言绑定):vde/vde.h 是 C ABI 入口
#include <vde/vde.h>  // vde_create / vde_load_mesh / vde_destroy ...

命名空间使用

// .cpp 文件中可以使用 using
using namespace vde::core;
using namespace vde::mesh;

// .h 文件中禁止 using namespace
// 使用完整限定名或在作用域内声明
namespace vde::my_module {
    using vde::core::Point3D;
}

错误处理

VDE 采用以下错误处理策略:

  • 返回值: 大部分函数返回 std::optional<T> 或错误码
  • 断言: 内部不变量使用 assert()
  • 异常: 仅在构造函数/资源分配失败时使用(RAII 保证)
  • 日志: 通过 VDE_LOG_WARNING / VDE_LOG_ERROR 宏

线程安全

  • 所有 const 方法可并发调用
  • 非 const 方法需要外部同步
  • vde::infra 提供并发容器(concurrent_data.h:LockFreeQueue 无锁(VDE-1307 起 Vyukov 有界 MPMC)、LockFreeStack 自旋锁同步、ConcurrentHashMap 分段锁)与并行任务图(performance_tuning.h)