Page:
api reference core
Pages
01 quickstart
02 sdf modeling
03 brep modeling
27 竞品分析
30 严谨差距分析
API REFERENCE
API使用手册
Home
README
VERSIONING
api overview
api reference brep
api reference capi
api reference core
api reference curves
api reference foundation
api reference mesh
api reference spatial
api usage
architecture
benchmark report
building
changelog
contributing
format support
module manual
testing
严谨差距分析
几何引擎全景调研
向ACIS学习
向Parasolid学习
布尔算法调研
快速入门
改进路线图
更新日志
构建指南
架构概览
模块说明书
测试指南
版本管理规范
竞品分析
贡献指南
项目概述
Clone
Table of Contents
- Core 模块 API 参考
- 模块概述
- 头文件列表
- 详细 API
- matrix4d.h — 4×4 变换矩阵
- platform.h — 平台抽象层
- expression_eval.h — 表达式求解器
- transform.h — 仿射变换
- point.h — 点/向量类型
- aabb.h — 轴对齐包围盒
- triangle.h — 三角形
- polygon.h — 二维多边形
- plane.h — 平面
- line.h — 直线/线段/射线
- distance.h — 距离计算与最近点
- convex_hull.h — 凸包
- voronoi.h — Voronoi 图
- icp.h — 迭代最近点配准
- cam_toolpath.h — CAM 刀路基础
- cam_mesh.h — Mesh 轮廓提取
- cam_strategies.h — 加工策略
- cam_5axis.h — 5 轴联动 CAM
- cam_advanced.h — 高级 CAM 策略
- cam_optimization.h — CAM 综合优化
- gcode_import.h — G-code 导入
- version.h — 版本信息
- 代码示例
This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
Core 模块 API 参考
核心几何模块 — 矩阵变换、基础图元、表达式求解、CAM 加工、平台抽象
模块概述
core 模块是 ViewDesignEngine 的基础层,提供所有上层模块依赖的几何类型、数学运算、表达式求解器和 CAM 加工策略。包含 20+ 头文件,覆盖从基础点/向量到 5 轴联动 CAM 的完整功能栈。
头文件列表
| 头文件 | 说明 |
|---|---|
matrix4d.h |
4×4 变换矩阵(平移/旋转/缩放/镜像) |
platform.h |
平台抽象层(动态库、临时文件、M_PI) |
expression_eval.h |
数学表达式求解器(参数化设计) |
transform.h |
Eigen::Transform3D 封装(translate/rotate/scale/mirror) |
point.h |
点/向量类型重新导出 |
aabb.h |
轴对齐包围盒 |
triangle.h |
三维三角形(面积/法线/包含测试) |
polygon.h |
二维多边形(面积/三角剖分/凸包) |
plane.h |
三维平面(Hessian 形式) |
line.h |
三维直线/线段/射线 |
distance.h |
几何距离计算 + 最近点查询 |
convex_hull.h |
2D/3D 凸包(Graham Scan / QuickHull) |
voronoi.h |
二维 Voronoi 图 |
icp.h |
迭代最近点(ICP)点云配准 |
version.h |
版本信息(编译时/运行时) |
cam_toolpath.h |
CAM 刀路基础(路径段/轮廓/口袋/钻孔/G-code) |
cam_mesh.h |
Mesh 轮廓提取 + 刀路生成 |
cam_strategies.h |
完整 CAM 加工策略(粗加工/精加工/钻孔/后处理) |
cam_5axis.h |
5 轴联动 CAM(侧刃/多轴/运动学) |
cam_advanced.h |
CAM 高级策略(自适应清除/摆线/残料/清根) |
cam_optimization.h |
CAM 综合优化(切屑减薄/HSM/恒接触角/刀具寿命) |
gcode_import.h |
G-code 文件导入 |
performance_tuning.h |
性能调优参数 |
concurrent_data.h |
并发数据结构 |
simd_vector.h |
SIMD 向量加速 |
exact_predicates.h |
精确几何谓词 |
object_pool.h |
对象池(内存管理) |
topology_compression.h |
拓扑压缩 |
transaction.h |
事务管理 |
详细 API
matrix4d.h — 4×4 变换矩阵
namespace vde::core {
struct Matrix4D {
double m00=1, m01=0, m02=0, m03=0;
double m10=0, m11=1, m12=0, m13=0;
double m20=0, m21=0, m22=1, m23=0;
double m30=0, m31=0, m32=0, m33=1;
static Matrix4D Identity(); // 单位矩阵
static Matrix4D Translation(double x, double y, double z); // 平移变换
static Matrix4D Translation(const Vector3D& v); // 平移变换(向量)
static Matrix4D RotationX(double angle_rad); // 绕 X 轴旋转
static Matrix4D RotationY(double angle_rad); // 绕 Y 轴旋转
static Matrix4D RotationZ(double angle_rad); // 绕 Z 轴旋转
static Matrix4D Scale(double sx, double sy, double sz); // 非均匀缩放
static Matrix4D Mirror(const Point3D& plane_point, // 镜面反射
const Vector3D& plane_normal);
double& at(int row, int col); // 元素访问(读写)
double at(int row, int col) const; // 元素访问(只读)
double* data(); // 原始数据指针
const double* data() const; // 原始数据指针(只读)
Matrix4D operator*(const Matrix4D& rhs) const; // 矩阵乘法
Point3D transform_point(const Point3D& p) const; // 变换点(含平移)
Vector3D transform_vector(const Vector3D& v) const; // 变换向量(仅旋转缩放)
Matrix4D inverse() const; // 逆矩阵
};
} // namespace vde::core
platform.h — 平台抽象层
namespace vde::platform {
// 宏定义
#define M_PI 3.14159265358979323846 // π 常量(MSVC 补丁)
using LibHandle = void*; // 动态库句柄
LibHandle load_library(const std::string& path); // 加载动态库
void unload_library(LibHandle h); // 卸载动态库
void* find_symbol(LibHandle h, const std::string& name); // 查找符号
std::string last_error(); // 最后错误信息
bool make_temp_file(const std::string& prefix, // 创建临时文件
const std::string& suffix, std::string& path);
bool delete_file(const std::string& path); // 删除文件
int run_command(const std::string& cmd); // 执行系统命令
} // namespace vde::platform
expression_eval.h — 表达式求解器
namespace vde::core {
using ExpressionVars = std::map<std::string, double>; // 变量映射表
// 解析并求值数学表达式
// 支持的运算: + - * / ^ ( )
// 支持的函数: sin cos tan sqrt abs pow log exp min max
// 内置常量: pi, e
[[nodiscard]] double evaluate_expression(
const std::string& expr,
const ExpressionVars& variables = {});
} // namespace vde::core
transform.h — 仿射变换
namespace vde::core {
using Transform3D = Eigen::Transform<double, 3, Eigen::Affine>; // 3D 仿射变换类型
Transform3D translate(const Vector3D& v); // 平移变换(向量)
Transform3D translate(double x, double y, double z);// 平移变换(分量)
Transform3D rotate(const Vector3D& axis, double angle_rad); // 轴-角旋转
Transform3D rotate_x(double rad); // 绕 X 轴旋转
Transform3D rotate_y(double rad); // 绕 Y 轴旋转
Transform3D rotate_z(double rad); // 绕 Z 轴旋转
Transform3D scale(double sx, double sy, double sz); // 非均匀缩放
Transform3D scale(double s); // 均匀缩放
Transform3D mirror(const Vector3D& normal); // 过原点平面反射
Transform3D mirror_about_plane(const Plane3D& plane);// 任意平面反射
} // namespace vde::core
point.h — 点/向量类型
namespace vde::core {
template <typename T, size_t Dim>
using Point = foundation::Point<T, Dim>; // 通用 N 维点
using Point2D = foundation::Point2D; // double 二维点
using Point3D = foundation::Point3D; // double 三维点
using Point2f = foundation::Point2f; // float 二维点
using Point3f = foundation::Point3f; // float 三维点
template <typename T, size_t Dim>
using Vector = foundation::Vector<T, Dim>; // 通用 N 维向量
using Vector2D = foundation::Vector2D; // double 二维向量
using Vector3D = foundation::Vector3D; // double 三维向量
} // namespace vde::core
aabb.h — 轴对齐包围盒
namespace vde::core {
template <typename T>
class AABB {
public:
AABB(); // 空包围盒
AABB(const Point3D& min, const Point3D& max); // 从角点构造
void expand(const Point3D& p); // 扩展包含点
void expand(const AABB& other); // 扩展包含另一包围盒
[[nodiscard]] Point3D center() const; // 中心点
[[nodiscard]] Vector3D extent() const; // 对角线向量
[[nodiscard]] T surface_area() const; // 表面积
[[nodiscard]] T volume() const; // 体积
[[nodiscard]] bool contains(const Point3D& p) const; // 点包含测试
[[nodiscard]] bool intersects(const AABB& other) const; // 相交测试
[[nodiscard]] const Point3D& min() const; // 最小角点
[[nodiscard]] const Point3D& max() const; // 最大角点
};
using AABB3D = AABB<double>; // 双精度 AABB
using AABB3f = AABB<float>; // 单精度 AABB
} // namespace vde::core
triangle.h — 三角形
namespace vde::core {
template <typename T>
class Triangle {
public:
Triangle(); // 默认构造(退化)
Triangle(const Point3D& v0, const Point3D& v1, const Point3D& v2);
[[nodiscard]] const Point3D& v(int i) const; // 第 i 个顶点
[[nodiscard]] const std::array<Point3D, 3>& vertices() const;
[[nodiscard]] Vector3D normal() const; // 单位法向量
[[nodiscard]] T area() const; // 面积
[[nodiscard]] Point3D centroid() const; // 质心
[[nodiscard]] bool contains(const Point3D& p) const; // 包含测试(投影到平面)
int id = -1; // 用户索引
};
using Triangle3D = Triangle<double>;
using Triangle3f = Triangle<float>;
} // namespace vde::core
polygon.h — 二维多边形
namespace vde::core {
class Polygon2D {
public:
Polygon2D();
explicit Polygon2D(std::vector<Point2D> vertices);
[[nodiscard]] const std::vector<Point2D>& vertices() const;
[[nodiscard]] size_t size() const;
[[nodiscard]] bool empty() const;
[[nodiscard]] double signed_area() const; // 有向面积(CCW > 0)
[[nodiscard]] double area() const; // 绝对面积
[[nodiscard]] double perimeter() const; // 周长
[[nodiscard]] Point2D centroid() const; // 质心
[[nodiscard]] AABB<double> bounding_box() const;// 包围盒
[[nodiscard]] bool contains(const Point2D& p) const; // 射线法包含测试
[[nodiscard]] bool is_ccw() const; // 是否逆时针
[[nodiscard]] bool is_convex() const; // 是否凸多边形
[[nodiscard]] Polygon2D offset(double distance) const; // 边界偏移
[[nodiscard]] Polygon2D simplify(double tolerance) const; // Douglas-Peucker 简化
[[nodiscard]] std::vector<std::array<int, 3>> triangulate() const; // 耳切法三角剖分
static Polygon2D convex_hull_2d(const std::vector<Point2D>& points); // Andrew 凸包
};
} // namespace vde::core
plane.h — 平面
namespace vde::core {
template <typename T>
class Plane {
public:
Plane(); // 默认 XY 平面
Plane(const Point3D& point, const Vector3D& normal); // 点和法线
Plane(const Point3D& a, const Point3D& b, const Point3D& c); // 三点
[[nodiscard]] const Vector3D& normal() const; // 单位法向量
[[nodiscard]] T d() const; // 平面方程常数
[[nodiscard]] T signed_distance(const Point3D& p) const; // 有向距离
[[nodiscard]] T distance(const Point3D& p) const; // 绝对距离
[[nodiscard]] Point3D project(const Point3D& p) const; // 正交投影
};
using Plane3D = Plane<double>;
} // namespace vde::core
line.h — 直线/线段/射线
namespace vde::core {
template <typename T>
class Line3D { // 无限直线
public:
Line3D();
Line3D(const Point3D& origin, const Vector3D& direction);
[[nodiscard]] const Point3D& origin() const;
[[nodiscard]] const Vector3D& direction() const;
[[nodiscard]] Point3D point_at(T t) const; // 参数求点
};
template <typename T>
class Segment3D { // 线段
public:
Segment3D();
Segment3D(const Point3D& p0, const Point3D& p1);
[[nodiscard]] const Point3D& p0() const;
[[nodiscard]] const Point3D& p1() const;
[[nodiscard]] Vector3D direction() const; // 方向向量
[[nodiscard]] T length() const; // 长度
};
template <typename T>
class Ray3D { // 射线 (t ≥ 0)
public:
Ray3D();
Ray3D(const Point3D& origin, const Vector3D& direction);
[[nodiscard]] const Point3D& origin() const;
[[nodiscard]] const Vector3D& direction() const;
[[nodiscard]] Point3D point_at(T t) const;
};
using Line3Dd = Line3D<double>;
using Segment3Dd = Segment3D<double>;
using Ray3Dd = Ray3D<double>;
} // namespace vde::core
distance.h — 距离计算与最近点
namespace vde::core {
// 点到几何体的距离
double distance(const Point3D& a, const Point3D& b); // 点-点
double distance(const Point3D& p, const Line3D<double>& line); // 点-直线
double distance(const Point3D& p, const Segment3D<double>& seg); // 点-线段
double distance(const Point3D& p, const Plane<double>& plane); // 点-平面
double distance(const Point3D& p, const Triangle<double>& tri); // 点-三角形
double distance(const Point3D& p, const AABB<double>& box); // 点-AABB
// 几何体之间的最短距离
double distance(const Segment3D<double>& a, const Segment3D<double>& b); // 线段-线段
double distance(const Line3D<double>& a, const Line3D<double>& b); // 直线-直线
double distance(const AABB<double>& a, const AABB<double>& b); // AABB-AABB
double distance(const Triangle<double>& a, const Triangle<double>& b); // 三角形-三角形
// 最近点查询
Point3D closest_point(const Point3D& p, const Triangle<double>& tri);
Point3D closest_point(const Point3D& p, const Segment3D<double>& seg);
Point3D closest_point(const Point3D& p, const AABB<double>& box);
Point3D closest_point(const Point3D& p, const Plane<double>& plane);
} // namespace vde::core
convex_hull.h — 凸包
namespace vde::core {
std::vector<Point2D> convex_hull_2d(const std::vector<Point2D>& points); // Graham Scan
std::vector<std::array<Point3D, 3>> convex_hull_3d(const std::vector<Point3D>& points); // QuickHull
} // namespace vde::core
voronoi.h — Voronoi 图
namespace vde::core {
struct VoronoiCell {
Point2D site;
std::vector<Point2D> vertices;
std::vector<std::array<int, 2>> edges;
};
std::vector<VoronoiCell> voronoi_2d(const std::vector<Point2D>& points); // Delaunay 对偶
} // namespace vde::core
icp.h — 迭代最近点配准
namespace vde::core {
struct ICPResult {
Transform3D transform; // 对齐变换
double rms_error; // 均方根误差
int iterations; // 实际迭代次数
bool converged; // 是否收敛
};
[[nodiscard]] ICPResult icp_register(
const std::vector<Point3D>& source,
const std::vector<Point3D>& target,
int max_iter = 50,
double tolerance = 1e-6);
} // namespace vde::core
cam_toolpath.h — CAM 刀路基础
namespace vde::core {
enum class PathSegmentType { Rapid, Linear, ArcCW, ArcCCW };
struct PathSegment {
Point3D start, end, center;
PathSegmentType type;
double feed_rate, z_depth;
};
struct Toolpath {
std::string name;
std::vector<PathSegment> segments;
double safe_z, cut_z, step_down;
};
[[nodiscard]] curves::NurbsCurve offset_contour(const curves::NurbsCurve& curve, double distance);
[[nodiscard]] Toolpath contour_toolpath(const curves::NurbsCurve& curve, double cut_depth, double safe_z, double step_down);
[[nodiscard]] Toolpath pocket_toolpath(const curves::NurbsCurve& boundary, const std::vector<curves::NurbsCurve>& islands, double cut_depth, double step_over, double angle);
[[nodiscard]] std::string export_gcode(const Toolpath& tp); // 导出 G-code
} // namespace vde::core
cam_mesh.h — Mesh 轮廓提取
namespace vde::core {
struct ContourParams { double safe_z, step_down, feed_rate, stock_to_leave; };
struct PocketParams { double step_over, safe_z, step_down, feed_rate, cut_angle; };
[[nodiscard]] std::vector<curves::NurbsCurve> extract_contour_from_mesh(const mesh::HalfedgeMesh& mesh, double z_height);
[[nodiscard]] std::vector<curves::NurbsCurve> extract_slice_contour(const mesh::HalfedgeMesh& mesh, double z_height);
[[nodiscard]] Toolpath contour_toolpath(const mesh::HalfedgeMesh& mesh, double z_height, const Tool& tool, const ContourParams& params);
[[nodiscard]] Toolpath pocket_toolpath(const mesh::HalfedgeMesh& mesh, const std::vector<mesh::HalfedgeMesh>& islands, double z_height, const Tool& tool, const PocketParams& params);
} // namespace vde::core
cam_strategies.h — 加工策略
namespace vde::core {
// 刀具系统
enum class ToolType { ENDMILL, BALLNOSE, DRILL, FACEMILL, TAP };
struct Tool {
int id; std::string name; ToolType type;
double diameter, flutes, length, overall_length, shank_diameter;
[[nodiscard]] double spindle_rpm(double cutting_speed_m_per_min) const;
[[nodiscard]] double feed_rate_mm_per_min(double feed_per_tooth) const;
};
class ToolLibrary {
int add_tool(const Tool& tool);
[[nodiscard]] std::optional<Tool> find_tool(int id) const;
[[nodiscard]] std::optional<Tool> find_tool(const std::string& name) const;
[[nodiscard]] const std::vector<Tool>& list_tools() const;
[[nodiscard]] size_t size() const;
};
// 加工参数
struct RoughingParams { double step_down, step_over, stock_to_leave, feed_rate, safe_z; };
struct FinishingParams { double step_over, feed_rate, safe_z, depth_of_cut; };
enum class FinishingStrategy { PARALLEL, SPIRAL };
enum class DrillingCycle { G81, G83, G84 };
struct DrillPoint { Point3D position; double depth, peck_depth; };
// 后处理器
class PostProcessor {
public:
[[nodiscard]] virtual std::string prologue(const Toolpath& tp) const = 0;
[[nodiscard]] virtual std::string epilogue(const Toolpath& tp) const = 0;
[[nodiscard]] virtual std::string format_gcode(const PathSegment& seg) const = 0;
[[nodiscard]] std::string post_process(const Toolpath& tp) const;
};
class FanucPost : public PostProcessor { /* ... */ };
class SiemensPost : public PostProcessor { /* ... */ };
class HeidenhainPost : public PostProcessor { /* ... */ };
// 加工策略
[[nodiscard]] Toolpath roughing_toolpath(const brep::BrepModel& body, const Tool& tool, const RoughingParams& params);
[[nodiscard]] Toolpath finishing_toolpath(const brep::BrepModel& body, const Tool& tool, const FinishingParams& params, FinishingStrategy strategy = FinishingStrategy::PARALLEL);
[[nodiscard]] Toolpath drilling_toolpath(const std::vector<DrillPoint>& points, const Tool& tool, DrillingCycle cycle = DrillingCycle::G81, double safe_z = 10.0, double feed_rate = 200.0);
// 仿真
struct SimulationResult { mesh::HalfedgeMesh remaining_mesh, removed_mesh; double volume_removed, volume_remaining; int steps; };
[[nodiscard]] SimulationResult material_removal_simulation(const brep::BrepModel& body, const Toolpath& toolpath, const Tool& tool);
} // namespace vde::core
cam_5axis.h — 5 轴联动 CAM
namespace vde::core {
struct CLData { Point3D position; Vector3D tool_axis; double feed_rate; };
struct AxisToolpath5 { std::string name; std::vector<CLData> points; double safe_height; };
enum class ToolAxisStrategy { FixedAngle, LeadLag, Tilted, NormalToSurface };
enum class MachineType { HeadHead, TableTable, HeadTable };
enum class MachineAxisConfig { AC, BC, AB };
struct MachineConfig {
MachineType machine_type; MachineAxisConfig axis_config;
double a_min, a_max, b_min, b_max, c_min, c_max;
Vector3D pivot_offset; double tool_length;
[[nodiscard]] bool in_range(double a, double b, double c) const;
[[nodiscard]] std::optional<std::tuple<double,double,double>> axis_to_angles(const Vector3D& tool_axis) const;
};
struct SwarfParams { double step_down, step_over, feed_rate, safe_height, tilt_angle; };
struct MultiAxisRoughingParams { double step_down, step_over, stock_to_leave, feed_rate, safe_height, tilt_angle, lead_angle; };
struct MultiAxisFinishingParams { double step_over, feed_rate, safe_height; ToolAxisStrategy axis_strategy; double max_tilt, lead_angle; bool collision_check; double shank_clearance, holder_clearance; };
[[nodiscard]] AxisToolpath5 swarf_machining(const curves::NurbsSurface& surface, const Tool& tool, const SwarfParams& params);
[[nodiscard]] AxisToolpath5 multi_axis_roughing(const brep::BrepModel& body, const Tool& tool, const MultiAxisRoughingParams& params, const MachineConfig& config = {});
[[nodiscard]] AxisToolpath5 multi_axis_finishing(const curves::NurbsSurface& surface, const brep::BrepModel& body, const Tool& tool, const MultiAxisFinishingParams& params, const MachineConfig& config = {});
[[nodiscard]] AxisToolpath5 inverse_kinematics(const AxisToolpath5& toolpath, const MachineConfig& config);
[[nodiscard]] bool check_collision(const Point3D& position, const Vector3D& tool_axis, const brep::BrepModel& body, const Tool& tool, double shank_clearance, double holder_clearance);
[[nodiscard]] Vector3D optimize_tool_axis(const std::vector<Vector3D>& candidates, const MachineConfig& config);
} // namespace vde::core
cam_advanced.h — 高级 CAM 策略
namespace vde::core {
struct AdaptiveClearingParams { double step_down, min_step_over, max_step_over, engagement_angle, feed_rate, safe_z, stock_to_leave; };
struct TrochoidalParams { double step_down, trochoid_radius, step_forward, feed_rate, safe_z; };
struct RestMachiningParams { double step_down, step_over, feed_rate, safe_z, stock_threshold; };
struct PencilTracingParams { double step_along, feed_rate, safe_z, corner_angle_min, corner_angle_max; };
struct ToolHolder { double diameter, length, clearance; std::string name; };
struct CollisionResult { bool has_collision; int collision_index; Point3D collision_point; double penetration_depth; std::string description; };
struct ToolpathOptimizationParams { bool reorder_segments, merge_collinear, remove_duplicates, smooth_corners; double merge_tolerance, duplicate_tolerance, corner_radius; };
struct Material { std::string name; double hardness_brinell, specific_cutting_force, max_chip_thickness, max_feed_per_tooth; };
[[nodiscard]] Toolpath adaptive_clearing(const brep::BrepModel& body, const Tool& tool, const AdaptiveClearingParams& params);
[[nodiscard]] Toolpath trochoidal_milling(const std::vector<Point3D>& slot, const Tool& tool, const TrochoidalParams& params);
[[nodiscard]] Toolpath rest_machining(const brep::BrepModel& body, const Tool& prev_tool, const Tool& next_tool, const RestMachiningParams& params = {});
[[nodiscard]] Toolpath pencil_tracing(const brep::BrepModel& body, const Tool& tool, const PencilTracingParams& params = {});
[[nodiscard]] std::vector<CollisionResult> tool_holder_collision_check(const Toolpath& toolpath, const ToolHolder& holder, const brep::BrepModel& body);
[[nodiscard]] Toolpath toolpath_optimization(const Toolpath& toolpath, const ToolpathOptimizationParams& params = {});
[[nodiscard]] Toolpath feed_rate_optimization(const Toolpath& toolpath, const Material& material);
// 后处理器扩展
class MazakPost : public PostProcessor { /* ... */ };
class OkumaPost : public PostProcessor { /* ... */ };
class HaasPost : public PostProcessor { /* ... */ };
class DMGPost : public PostProcessor { /* ... */ };
// 探测 + 螺纹
enum class ProbingCycleType { SingleSurface, Boss, Pocket, Corner, Angle };
struct ProbingParams { ProbingCycleType cycle_type; Point3D approach_position, target_position; Vector3D probe_direction; double overtravel, feed_rate, retract_distance, safe_z; };
struct ProbingResult { Point3D contact_point; bool contact_made; double deviation; std::string message; };
struct ThreadMillParams { double thread_diameter, thread_pitch, thread_depth, major_diameter, minor_diameter; int num_passes; double feed_rate, safe_z; bool right_hand, internal_thread; Point3D hole_center; };
[[nodiscard]] Toolpath probing_cycle(const Tool& tool, const ProbingParams& params);
[[nodiscard]] ProbingResult probing_cycle_with_result(const Tool& tool, const ProbingParams& params, const brep::BrepModel& body);
[[nodiscard]] Toolpath thread_milling(const Tool& tool, const ThreadMillParams& params);
} // namespace vde::core
cam_optimization.h — CAM 综合优化
namespace vde::core {
struct HSMParams { double step_down, step_over, feed_rate, spindle_rpm, safe_z, stock_to_leave, corner_radius; bool trochoidal_corners; };
struct ConstantEngagementParams { double target_engagement, step_down, feed_rate, safe_z, min_step_over, max_step_over, engagement_tolerance; };
struct ToolLifeParams { double max_cutting_time_min, max_cutting_length_m, wear_coefficient, critical_flank_wear, spindle_speed_factor; bool enable_adaptive_feed; };
struct ToolLifeResult { double estimated_life_min, accumulated_wear_mm, material_removed_mm3, current_flank_wear, recommended_feed_scale; bool needs_replacement; std::string warning_message; };
struct TurnMillParams { double stock_diameter, step_down, trochoid_radius, step_forward, feed_rate, spindle_rpm, turning_rpm, safe_z; bool sync_axes; };
[[nodiscard]] Toolpath chip_thinning_optimization(const Toolpath& toolpath, const Tool& tool);
[[nodiscard]] Toolpath trochoidal_turn_milling(const brep::BrepModel& body, const Tool& tool, const TurnMillParams& params = {});
[[nodiscard]] Toolpath high_speed_machining(const Toolpath& toolpath, const HSMParams& params);
[[nodiscard]] Toolpath constant_engagement_milling(const brep::BrepModel& body, const Tool& tool, const ConstantEngagementParams& params = {});
[[nodiscard]] ToolLifeResult tool_life_management(const Tool& tool, const Material& material, const ToolLifeParams& params = {});
} // namespace vde::core
gcode_import.h — G-code 导入
namespace vde::core {
struct GcodeImportState { Point3D position, arc_center; bool absolute, metric; int plane; double feed_rate; int spindle_speed; bool spindle_on, spindle_cw; int tool_number; int canned_cycle; double retract_plane, peck_depth, dwell_time, drill_target_z, unit_factor; };
[[nodiscard]] Toolpath import_gcode(const std::string& path); // 从文件导入
[[nodiscard]] Toolpath import_gcode_from_string(const std::string& gcode_text); // 从字符串导入
} // namespace vde::core
version.h — 版本信息
namespace vde::core {
#define VDE_VERSION_MAJOR 1
#define VDE_VERSION_MINOR 0
#define VDE_VERSION_PATCH 1
#define VDE_VERSION_STRING "1.0.1"
struct VersionInfo {
int major, minor, patch;
std::string version_string, build_type, build_timestamp, compiler_info, cpp_standard;
};
VersionInfo vde_version();
std::string vde_version_string();
int vde_version_compare(int lhs_major, int lhs_minor, int lhs_patch,
int rhs_major, int rhs_minor, int rhs_patch);
} // namespace vde::core
代码示例
示例 1: 矩阵链式变换
#include <vde/core/matrix4d.h>
#include <vde/core/transform.h>
using namespace vde::core;
// 先平移再旋转
auto T = Matrix4D::Translation(10, 0, 0); // 沿 X 平移 10
auto R = Matrix4D::RotationZ(M_PI / 4); // 绕 Z 旋转 45°
auto M = T * R; // 复合变换
Point3D p(1, 2, 3);
Point3D result = M.transform_point(p); // 变换后的点
// 逆变换
Matrix4D inv = M.inverse();
Point3D back = inv.transform_point(result); // 回到原始位置
示例 2: CAM 刀路生成
#include <vde/core/cam_toolpath.h>
#include <vde/core/cam_strategies.h>
#include <vde/brep/modeling.h>
using namespace vde;
// 创建工件
auto body = brep::make_box(100, 50, 20);
// 定义刀具
core::Tool tool;
tool.type = core::ToolType::ENDMILL;
tool.diameter = 10.0;
tool.name = "D10";
// 粗加工
core::RoughingParams rough;
rough.step_down = 2.0;
rough.step_over = 6.0;
rough.stock_to_leave = 0.5;
auto rough_tp = core::roughing_toolpath(body, tool, rough);
// 精加工
core::FinishingParams finish;
finish.step_over = 0.3;
auto finish_tp = core::finishing_toolpath(body, tool, finish, core::FinishingStrategy::SPIRAL);
// 导出 G-code
std::string gcode = core::export_gcode(finish_tp);