按反馈文档审计逐项实现并全量验证: - VDE-1193 §B: fillet/fillet_variable 依边凸凹修正切点几何(凸边球心内向偏移、 凹边外向进入凹槽),modeling.cpp 的 face_centroid 改内部链接消除与 ssi_boolean 的同名符号多重定义。test_brep_modeling 73/73、test_defeature 9/9、 test_feature_recognition 16/16、test_advanced_blend 32/32 - VDE-432: 任意草图轮廓 Wrap(Emboss/Deboss/Scribe) - VDE-1185: export_step_ap242 几何改走 brep::export_step——原内置写盘器把每个 ADVANCED_FACE 的 PLANE 都写在原点、不写圆柱/样条面,致 AP242 往返体积/面积为 0; 改后 FILE_SCHEMA 换 AP242,PMI/材料/校验以高位 id 追加进 DATA 段,删除无用几何写盘器。 test_industrial_formats 74/74(含 IndustrialRtGeometry 6 例、IndustrialStepAP242 17 例) - VDE-475: extrude_rect_profile/make_weld_bead 改整体 transformed 变换,修复手工 复制拓扑导致的 loop id 失配(I 型钢崩溃 / WeldBead is_valid=false); extrude_annular_profile 轴向由 Z 对齐到 X。test_structural_profiles 25/25 - VDE-495: routing_ext 柔性软管/电气线束/等轴测出图。test_routing_ext 15/15 - docs: 同步 VDE-475/VDE-1185/VDE-1193 §B 状态
22 KiB
22 KiB
Curves 模块 API 参考
曲线曲面模块 — NURBS 曲线/曲面、曲面工具、连续性、偏移、编辑
模块概述
curves 模块提供完整的参数曲线曲面数学库,包括 Bézier、B-Spline、NURBS 的创建/求值/编辑,以及曲面加厚、缝合、边界填充、直纹面等工业曲面建模工具。
头文件列表
| 头文件 | 说明 |
|---|---|
nurbs_curve.h |
NURBS 曲线(静态工厂:line/circle/arc/helix) |
nurbs_surface.h |
NURBS 曲面(静态工厂:plane/box/cylinder/sphere/cone) |
bezier_curve.h |
Bézier 曲线 |
bezier_surface.h |
Bézier 曲面 |
bspline_curve.h |
B-Spline 曲线 |
bspline_surface.h |
B-Spline 曲面 |
surface_tools.h |
曲面核心工具(加厚/缝合/边界/填充) |
nurbs_operations.h |
NURBS 操作(直纹面/偏移/融合等) |
curve_tools.h |
曲线工具集 |
surface_intersection.h |
曲面-曲面求交 |
surface_continuity.h |
曲面连续性分析 |
surface_extension.h |
曲面延伸 |
surface_editing.h |
曲面编辑 |
surface_analysis.h |
曲面分析(曲率/斑马线等) |
surface_fairing.h |
曲面光顺 |
control_point_edit.h |
控制点编辑 |
curve_surface_projection.h |
曲线-曲面投影 |
continuity_types.h |
连续性类型定义 |
exact_offset.h |
精确偏移 |
parallel_intersection.h |
并行求交加速 |
tessellation.h |
曲面离散化 |
generative_surfaces.h |
生成式曲面 |
class_a_surfacing.h |
A 级曲面 |
advanced_intersection.h |
高级求交(鲁棒 SSI/自交检测) |
iga_prep.h |
IGA (等几何分析) 准备 |
parameterization.h |
参数化特征与表达式求值 |
reconstruction.h |
曲线/曲面重建 |
subdivision.h |
细分曲面(Catmull-Clark) |
详细 API
nurbs_curve.h — NURBS 曲线
namespace vde::curves {
class NurbsCurve {
public:
NurbsCurve(); // 空曲线
NurbsCurve(std::vector<Point3D> control_points, std::vector<double> knots,
std::vector<double> weights, int degree);
[[nodiscard]] Point3D evaluate(double t) const; // 求点 C(t)
[[nodiscard]] Vector3D derivative(double t, int order = 1) const; // 求导
[[nodiscard]] int degree() const; // 阶次
[[nodiscard]] std::pair<double, double> domain() const; // 参数域
[[nodiscard]] const std::vector<Point3D>& control_points() const; // 控制点
[[nodiscard]] const std::vector<double>& weights() const; // 权重
[[nodiscard]] const std::vector<double>& knots() const; // 节点向量
// 静态工厂方法
[[nodiscard]] static NurbsCurve line(const Point3D& from, const Point3D& to); // 直线段
[[nodiscard]] static NurbsCurve circle(const Point3D& center, double radius, // 完整圆
const Vector3D& normal = Vector3D::UnitZ());
[[nodiscard]] static NurbsCurve arc(const Point3D& center, double radius, // 圆弧
double start_angle, double end_angle,
const Vector3D& normal = Vector3D::UnitZ());
[[nodiscard]] static NurbsCurve helix(double radius, double pitch, // 螺旋线
double height, double turns);
[[nodiscard]] static NurbsCurve interpolate(const std::vector<Point3D>& points, int degree = 3); // 点集插值
// 便捷工厂(VDE-493)
[[nodiscard]] static NurbsCurve rectangle(const Point3D& corner1, const Point3D& corner2); // 矩形
[[nodiscard]] static NurbsCurve regular_polygon(const Point3D& center, double radius,
int sides, const Vector3D& normal = Vector3D::UnitZ()); // 正多边形
[[nodiscard]] static NurbsCurve slot(const Point3D& center, double length, double width); // 腰孔/键槽
[[nodiscard]] static NurbsCurve ellipse(const Point3D& center, double rx, double ry,
const Vector3D& normal = Vector3D::UnitZ()); // 椭圆
[[nodiscard]] static NurbsCurve arc_3point(const Point3D& start, const Point3D& mid,
const Point3D& end); // 三点圆弧
[[nodiscard]] static NurbsCurve closed_from_points(const std::vector<Point3D>& points); // 闭合折线
[[nodiscard]] static NurbsCurve equation_driven_curve( // 参数方程曲线(VDE-493)
const std::string& expr_x, const std::string& expr_y, const std::string& expr_z,
double t_min, double t_max, int samples = 64, int degree = 3);
};
} // namespace vde::curves
nurbs_surface.h — NURBS 曲面
namespace vde::curves {
class NurbsSurface {
public:
NurbsSurface(); // 空曲面
NurbsSurface(std::vector<std::vector<Point3D>> control_grid,
std::vector<double> knots_u, std::vector<double> knots_v,
std::vector<std::vector<double>> weights,
int degree_u, int degree_v);
[[nodiscard]] Point3D evaluate(double u, double v) const; // 求点 S(u,v)
[[nodiscard]] Vector3D derivative_u(double u, double v) const; // ∂S/∂u
[[nodiscard]] Vector3D derivative_v(double u, double v) const; // ∂S/∂v
[[nodiscard]] Vector3D normal(double u, double v) const; // 单位法向量
[[nodiscard]] int degree_u() const; // u 向阶次
[[nodiscard]] int degree_v() const; // v 向阶次
[[nodiscard]] std::array<int, 2> num_control_points() const; // 控制点数量
[[nodiscard]] const std::vector<double>& knots_u() const;
[[nodiscard]] const std::vector<double>& knots_v() const;
[[nodiscard]] const std::vector<std::vector<Point3D>>& control_points() const;
[[nodiscard]] const std::vector<std::vector<double>>& weights() const;
static NurbsSurface ruled(const NurbsCurve& c1, const NurbsCurve& c2); // 直纹面
static NurbsSurface revolve(const NurbsCurve& profile, const Point3D& axis_origin, // 旋转面
const Vector3D& axis_dir, double angle_rad);
// 静态工厂方法(VDE-075)
[[nodiscard]] static NurbsSurface plane(const Point3D& origin, // 矩形平面
const Vector3D& u_dir, const Vector3D& v_dir,
double width, double height);
[[nodiscard]] static std::array<NurbsSurface, 6> box(double width, double height, // 立方体 6 面
double depth,
const Point3D& center = Point3D::Zero());
// 基本体素曲面(VDE-076)
[[nodiscard]] static NurbsSurface cylinder(double cx, double cy, double cz, // 圆柱面
double radius, double height,
double axisX=0, double axisY=0, double axisZ=1);
[[nodiscard]] static NurbsSurface sphere(double cx, double cy, double cz, // 球面
double radius);
[[nodiscard]] static NurbsSurface cone(double cx, double cy, double cz, // 圆锥面
double baseRadius, double topRadius, double height,
double axisX=0, double axisY=0, double axisZ=1);
[[nodiscard]] static NurbsSurface torus(double cx, double cy, double cz, // 环面
double majorRadius, double minorRadius,
double axisX=0, double axisY=0, double axisZ=1);
[[nodiscard]] std::pair<std::vector<Point3D>, std::vector<std::array<int,3>>>
tessellate(int res_u, int res_v) const; // 三角化
[[nodiscard]] core::AABB3D bbox() const; // 控制点凸包 AABB
[[nodiscard]] Point3D closest_point(const Point3D& p) const; // 最近点投影
[[nodiscard]] double distance_to(const Point3D& p) const; // 点到曲面距离
};
} // namespace vde::curves
surface_tools.h — 曲面核心工具
namespace vde::curves {
[[nodiscard]] brep::BrepModel thicken_surface(
const NurbsSurface& surface, double thickness,
bool both_sides = false, bool cap_ends = true); // 曲面加厚为实体
[[nodiscard]] brep::BrepModel sew_surfaces(
const std::vector<NurbsSurface>& surfaces,
double tolerance = 1e-6); // 多曲面缝合为壳体
[[nodiscard]] NurbsSurface boundary_surface(
const std::vector<NurbsCurve>& curves_3d); // 边界网格生成曲面(Coons patch)
[[nodiscard]] NurbsSurface fill_surface(
const std::vector<NurbsCurve>& boundary_curves); // N 边填充曲面
} // namespace vde::curves
bezier_curve.h / bspline_curve.h
namespace vde::curves {
class BezierCurve {
public:
explicit BezierCurve(std::vector<Point3D> control_points);
[[nodiscard]] Point3D evaluate(double t) const;
[[nodiscard]] Vector3D derivative(double t, int order = 1) const;
[[nodiscard]] int degree() const; // = 控制点数 - 1
[[nodiscard]] std::pair<double, double> domain() const; // 固定 [0,1]
[[nodiscard]] const std::vector<Point3D>& control_points() const;
[[nodiscard]] std::pair<BezierCurve, BezierCurve> split(double t) const; // de Casteljau 分割
[[nodiscard]] BezierCurve degree_elevate(int times = 1) const; // 升阶
};
class BSplineCurve {
public:
BSplineCurve(std::vector<Point3D> control_points,
std::vector<double> knots, int degree);
[[nodiscard]] Point3D evaluate(double t) const;
[[nodiscard]] Vector3D derivative(double t, int order = 1) const;
[[nodiscard]] int degree() const;
[[nodiscard]] std::pair<double, double> domain() const;
[[nodiscard]] const std::vector<Point3D>& control_points() const;
[[nodiscard]] const std::vector<double>& knots() const;
[[nodiscard]] int find_span(double t) const; // 节点区间定位
[[nodiscard]] std::vector<double> basis_functions(double t, int span = -1) const;
[[nodiscard]] std::vector<double> basis_derivatives(double t, int span = -1) const;
};
} // namespace vde::curves
nurbs_operations.h — NURBS 操作
namespace vde::curves {
[[nodiscard]] NurbsSurface ruled_surface(const NurbsCurve& curve_a, const NurbsCurve& curve_b); // 直纹面
[[nodiscard]] NurbsSurface offset_surface(const NurbsSurface& surf, double distance); // 等距偏移曲面
// 参数域裁剪 / 融合
[[nodiscard]] NurbsSurface trim_surface(const NurbsSurface& surf,
double u_min, double u_max,
double v_min, double v_max);
[[nodiscard]] NurbsSurface blend_surfaces(const NurbsSurface& surf_a, const NurbsSurface& surf_b,
int edge_a, int edge_b, double blend_radius);
// 其他曲面生成
[[nodiscard]] NurbsSurface coons_patch(const NurbsCurve& curve_u0, const NurbsCurve& curve_u1,
const NurbsCurve& curve_v0, const NurbsCurve& curve_v1);
[[nodiscard]] NurbsSurface extrude_curve(const NurbsCurve& curve, const Vector3D& direction);
[[nodiscard]] NurbsSurface revolve_surface(const NurbsCurve& profile, const Point3D& axis_origin,
const Vector3D& axis_dir,
double start_angle = 0.0, double end_angle = 2.0 * M_PI);
[[nodiscard]] NurbsSurface pipe_surface(const NurbsCurve& spine, double radius, int sections = 8);
// 边界提取 / 填充 / 延伸
[[nodiscard]] NurbsCurve extract_boundary_curve(const NurbsSurface& surf, int edge);
[[nodiscard]] NurbsSurface fill_n_sided(const std::vector<NurbsCurve>& boundary_curves,
int continuity = 1);
[[nodiscard]] NurbsSurface extend_surface(const NurbsSurface& surf, int edge, double length);
// 分析
[[nodiscard]] std::pair<double, double> surface_curvature(const NurbsSurface& surf, double u, double v); // {H, K}
[[nodiscard]] bool is_g2_continuous(const NurbsSurface& surf_a, const NurbsSurface& surf_b,
int edge, int samples = 10);
[[nodiscard]] bool is_g3_continuous(const NurbsSurface& surf_a, const NurbsSurface& surf_b,
int edge, int samples = 10);
[[nodiscard]] double surface_torsion(const NurbsSurface& surf, double u, double v);
} // namespace vde::curves
其余曲线曲面模块摘要
namespace vde::curves {
// continuity_types.h — 连续性枚举
enum class Continuity { G0 = 0, G1 = 1, G2 = 2, G3 = 3 };
enum class ContinuityLevel { None, G0, G1, G2, G3 };
// curve_tools.h — 曲线工具
[[nodiscard]] NurbsCurve parallel_curve(const NurbsCurve& curve, double distance,
const Vector3D& plane_normal = Vector3D(0,0,1), int samples = 100); // 等距偏移
[[nodiscard]] NurbsCurve connect_curve(const NurbsCurve& c1, const NurbsCurve& c2,
Continuity continuity, int samples = 50); // 过渡连接(G1/G2/G3)
[[nodiscard]] NurbsCurve helix_curve(const Point3D& axis_origin, const Vector3D& axis_dir,
double radius, double pitch, double height, int samples = 50); // 螺旋线
[[nodiscard]] NurbsCurve conic(const Point3D& start, const Point3D& apex_control,
const Point3D& end, double rho = 0.5); // 二次曲线(rho 参数)
[[nodiscard]] CornerResult corner_curves(const NurbsCurve& curve_a, const NurbsCurve& curve_b,
double radius); // 曲线倒圆角
[[nodiscard]] NurbsCurve combine_curves(const NurbsCurve& c_xz, const NurbsCurve& c_xy); // 组合曲线
[[nodiscard]] IsoparametricCurves isoparametric_curves(const NurbsSurface& surface,
int u_count, int v_count); // 等参线提取
// surface_intersection.h — 曲面求交(返回 IntersectionCurve 采样点集)
[[nodiscard]] std::vector<IntersectionCurve> intersect_surfaces(
const NurbsSurface& surf_a, const NurbsSurface& surf_b,
int max_depth = 5, double tolerance = 1e-4);
[[nodiscard]] std::vector<IntersectionCurve> intersect_plane_surface(
const NurbsSurface& surf, const Point3D& point, const Vector3D& normal, int grid_res = 32);
[[nodiscard]] std::vector<IntersectionCurve> adaptive_intersection(
const NurbsSurface& s1, const NurbsSurface& s2, int min_samples = 8, double tolerance = 1e-4);
[[nodiscard]] IntersectionQuality intersection_quality(
const IntersectionCurve& curve, const NurbsSurface& s1, const NurbsSurface& s2);
// surface_continuity.h — 连续性分析
[[nodiscard]] const char* to_string(ContinuityLevel level);
[[nodiscard]] ContinuityLevel continuity_type(
const NurbsCurve& curve_a, double t_a, const NurbsCurve& curve_b, double t_b, double tol = 1e-6);
[[nodiscard]] ContinuityLevel surface_continuity(
const NurbsSurface& surf_a, const NurbsSurface& surf_b, int samples = 20, double tol = 1e-6);
[[nodiscard]] SurfaceContinuityReport surface_continuity_report(
const NurbsSurface& surf_a, const NurbsSurface& surf_b, int samples = 50, double tol = 1e-6);
[[nodiscard]] ZebraAnalysisResult zebra_analysis(const NurbsSurface& s1, const NurbsSurface& s2, int edge);
// surface_extension.h — 曲面延伸 / 填充
[[nodiscard]] NurbsSurface extend_surface(const NurbsSurface& surface, int edge_id,
double distance, Continuity continuity = Continuity::G1);
[[nodiscard]] NurbsSurface n_sided_fill(const std::vector<NurbsCurve>& boundary_curves,
Continuity continuity = Continuity::G2); // N 边孔洞填充
[[nodiscard]] NurbsSurface blend_surfaces(const NurbsSurface& surf_a, const NurbsSurface& surf_b,
double radius); // 两面间过渡
[[nodiscard]] NurbsSurface extend_by_curvature(const NurbsSurface& surface, int direction, double length);
[[nodiscard]] NurbsSurface extend_to_curve(const NurbsSurface& surface, const NurbsCurve& target_curve);
// surface_editing.h — 曲面匹配(Match Surface)
struct MatchSurfaceOptions; struct MatchSurfaceResult;
[[nodiscard]] MatchSurfaceResult match_surface(
const NurbsSurface& target, const NurbsSurface& reference,
BoundaryEdge edge, const MatchSurfaceOptions& options = {});
// surface_analysis.h — 曲面分析
[[nodiscard]] CurvatureMap curvature_map(const NurbsSurface& surf, int res_u, int res_v);
[[nodiscard]] ZebraStripeResult zebra_stripe(const NurbsSurface& surf, const Vector3D& light_dir,
int res_u, int res_v);
[[nodiscard]] CurvatureComb curvature_comb(const NurbsCurve& curve, int res, double scale = 0.0);
[[nodiscard]] DeviationResult deviation_analysis(const NurbsSurface& surf_a,
const NurbsSurface& surf_b, int samples);
[[nodiscard]] double draft_face_angle(const NurbsSurface& surf, double u, double v,
const Vector3D& pull_dir);
[[nodiscard]] GaussianCurvatureAnalysis gaussian_curvature_analysis(
const NurbsSurface& surface, int resolution = 32);
[[nodiscard]] MeanCurvatureMap mean_curvature_map(const NurbsSurface& surface);
[[nodiscard]] IsoPhoteResult isophote_analysis(const NurbsSurface& surface, const Vector3D& direction);
[[nodiscard]] SurfaceCheckerReport surface_checker_report(const NurbsSurface& surf, int res = 60);
// surface_fairing.h — 曲面光顺
struct FairingConstraints; struct FairingResult;
[[nodiscard]] FairingResult fair_surface(const NurbsSurface& surf,
const FairingConstraints& constraints = {});
[[nodiscard]] FairingResult interactive_fairing(const NurbsSurface& surface,
const std::array<double, 4>& region);
[[nodiscard]] EnergyDiagnostics energy_diagnostics(const NurbsSurface& surface);
// control_point_edit.h — 控制点编辑(全部返回 ControlPointEditResult)
struct ControlPointEditResult;
[[nodiscard]] ControlPointEditResult control_point_edit(
const NurbsSurface& surface,
const std::vector<std::pair<int, int>>& cp_indices,
const std::vector<Point3D>& new_positions); // 批量移动控制点
[[nodiscard]] ControlPointEditResult move_cp(const NurbsSurface& surface,
int i, int j, const Vector3D& delta);
[[nodiscard]] ControlPointEditResult soft_move_cp(const NurbsSurface& surface,
int i, int j, const Vector3D& delta, double radius); // 软编辑(距离衰减)
[[nodiscard]] ControlPointEditResult weight_edit(const NurbsSurface& surface,
int i, int j, double weight);
[[nodiscard]] ControlPointEditResult deform_surface_region(const NurbsSurface& surface,
const std::array<double, 4>& region_uv, const Vector3D& deformation_field);
[[nodiscard]] ControlPointEditResult match_surface_boundary(const NurbsSurface& s1,
const NurbsSurface& s2, int edge_id);
[[nodiscard]] ControlPointEditResult smooth_surface_region(const NurbsSurface& surface,
const std::array<double, 4>& region);
// curve_surface_projection.h — 投影
[[nodiscard]] std::pair<double, double> project_point_on_surface(const NurbsSurface& surf,
const Point3D& p); // 返回 (u,v)
[[nodiscard]] NurbsCurve project_curve_on_surface(const NurbsCurve& curve, const NurbsSurface& surf,
const Vector3D& direction);
[[nodiscard]] NurbsCurve surface_isocurve(const NurbsSurface& surf, bool is_u, double param);
[[nodiscard]] NurbsCurve geodesic_curve(const NurbsSurface& surf, const Point3D& start, const Point3D& end);
// tessellation.h — 离散化(自由函数,配合曲面求值回调)
std::pair<std::vector<Point3D>, std::vector<std::array<int, 3>>>
tessellate(const std::function<Point3D(double,double)>& eval, int res_u, int res_v);
std::pair<std::vector<Point3D>, std::vector<std::array<int, 3>>>
adaptive_tessellate(const std::function<Point3D(double,double)>& eval,
const std::function<Vector3D(double,double)>& normal_fn,
int min_res = 2, int max_depth = 6, double angle_threshold_deg = 5.0);
// exact_offset.h — 精确偏移
[[nodiscard]] NurbsSurface exact_offset(const NurbsSurface& surf, double distance);
[[nodiscard]] std::vector<NurbsSurface> offset_with_trimming(const NurbsSurface& surf, double distance);
[[nodiscard]] ShellBodyResult shell_body(const NurbsSurface& surf, double thickness, bool inward = true);
[[nodiscard]] OffsetQuality offset_quality_check(const NurbsSurface& original,
const NurbsSurface& offset, double distance);
} // namespace vde::curves
代码示例
示例 1: 曲面建模管道
#include <vde/curves/nurbs_curve.h>
#include <vde/curves/nurbs_surface.h>
#include <vde/curves/surface_tools.h>
using namespace vde::curves;
using namespace vde::core;
// 创建截面圆
auto profile = NurbsCurve::circle(Point3D(0, 0, 0), 2.0, Vector3D::UnitX());
// 创建路径螺旋线
auto path = NurbsCurve::helix(10.0, 5.0, 50.0, 4.0);
// NURBS 曲面生成: 直纹面连接
// 也可用 brep::sweep() 直接生成实体
// 曲面加厚
auto pipe_surface = /* ... */;
auto solid_pipe = thicken_surface(pipe_surface, 0.5, true, true);
示例 2: NURBS 曲线操作
#include <vde/curves/nurbs_curve.h>
#include <vde/curves/nurbs_operations.h>
using namespace vde::curves;
using namespace vde::core;
// 创建四分之一圆弧(精确 NURBS 表示)
auto arc = NurbsCurve::arc(Point3D::Zero(), 5.0, 0.0, M_PI/2, Vector3D::UnitZ());
// 创建直线段
auto line = NurbsCurve::line(Point3D(0, 5, 0), Point3D(10, 5, 0));
// 计算弧长
double len = arc_length(arc);
// 曲线求点
for (double t = 0; t <= 1.0; t += 0.1) {
auto pt = arc.evaluate(t);
auto tangent = arc.derivative(t);
}