feat(v7): B-Rep deep attack + Class-A surfacing + CAM deep + performance tuning
v7.1 — B-Rep 深度攻坚 (对标 Parasolid 95%): - advanced_healing: auto_heal_pipeline, face_splitting/merging, topology_optimization - watertight_verification, tolerance_analysis, tolerance diagnostic report - sheet_metal: unfold_sheet_metal (K-Factor/BFS), bend_deduction_table, create_flange - direct_modeling enhanced: draft_face_advanced (hinge), scale_body (non-uniform), mirror_body - 32 tests (17 healing + 15 sheet metal), syntax-check passed v7.2 — Class-A 曲面攻坚 (对标 CGM 95%): - class_a_surfacing: g3_blend (4-row CP), curvature_matching (Levenberg-Marquardt) - highlight_lines, reflection_lines, iso_photes, surface_diagnosis, shape_modification - advanced_intersection: robust_ssi (3-stage: AABB+subdivision→Newton 1e-12→singularity) - curve_surface_intersection, self_intersection_detection (BVH) - 30 tests (18 class-A + 12 intersection), zero compile errors v7.3 — CAM 深化 + 性能优化: - cam_advanced: adaptive_clearing, trochoidal_milling, rest_machining, pencil_tracing - tool_holder_collision_check, toolpath_optimization, feed_rate_optimization - performance_tuning: parallel_task_graph (DAG+Kahn), work_stealing_scheduler - memory_pool_integration, cache_optimization_hints, profile_guided_layout - Fixed BrepModel API compatibility (body.bounds()/to_mesh() instead of .faces()) - 20 tests 12 files, ~5200 lines, 82 tests
This commit is contained in:
@@ -0,0 +1,311 @@
|
||||
#pragma once
|
||||
/**
|
||||
* @file advanced_healing.h
|
||||
* @brief 高级 B-Rep 修复 — 对标 Parasolid 95%
|
||||
*
|
||||
* 提供 Parasolid 级别的全自动修复流水线和诊断工具:
|
||||
*
|
||||
* | 操作 | 对标 Parasolid 功能 |
|
||||
* |----------------------------|-----------------------------------------|
|
||||
* | auto_heal_pipeline | auto-heal / optimize |
|
||||
* | face_splitting | face splitting with p-curve |
|
||||
* | face_merging | coplanar merge / face stitching |
|
||||
* | topology_optimization | redundant edge/vertex cleanup |
|
||||
* | tolerance_analysis | tolerance diagnostic report |
|
||||
* | watertight_verification | strict watertightness certification |
|
||||
*
|
||||
* @ingroup brep
|
||||
*/
|
||||
#include "vde/brep/brep.h"
|
||||
#include "vde/brep/brep_validate.h"
|
||||
#include "vde/brep/tolerance.h"
|
||||
#include "vde/brep/brep_heal.h"
|
||||
#include "vde/curves/nurbs_curve.h"
|
||||
#include "vde/curves/nurbs_surface.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <functional>
|
||||
|
||||
namespace vde::brep {
|
||||
|
||||
// ═══════════════════════════════════════════════════════════
|
||||
// 修复诊断报告
|
||||
// ═══════════════════════════════════════════════════════════
|
||||
|
||||
/**
|
||||
* @brief 高级修复诊断报告
|
||||
*
|
||||
* 包含自动修复流水线每一步的详细结果,
|
||||
* 用于日志记录、UI 展示和下游分析。
|
||||
*/
|
||||
struct AdvancedHealingReport {
|
||||
/** @brief 修复是否完全成功 */
|
||||
bool success = false;
|
||||
|
||||
/** @brief 执行步骤链 */
|
||||
std::vector<std::string> steps_executed;
|
||||
|
||||
/** @brief 每步修复的详情 */
|
||||
struct StepDetail {
|
||||
std::string step_name; ///< 步骤名称
|
||||
bool ok = false; ///< 该步骤是否通过
|
||||
int items_fixed = 0; ///< 修复项数
|
||||
std::string message; ///< 该步骤的消息
|
||||
};
|
||||
std::vector<StepDetail> details;
|
||||
|
||||
/** @brief 修复前验证结果 */
|
||||
ValidationResult before_validation;
|
||||
|
||||
/** @brief 修复后验证结果 */
|
||||
ValidationResult after_validation;
|
||||
|
||||
/** @brief 警告汇总 */
|
||||
std::vector<std::string> warnings;
|
||||
|
||||
/** @brief 总修复项数 */
|
||||
int total_fixes = 0;
|
||||
};
|
||||
|
||||
// ═══════════════════════════════════════════════════════════
|
||||
// 容差诊断报告
|
||||
// ═══════════════════════════════════════════════════════════
|
||||
|
||||
/**
|
||||
* @brief 容差分析项
|
||||
*
|
||||
* 记录单个拓扑元素的容差诊断信息。
|
||||
*/
|
||||
struct ToleranceItem {
|
||||
int element_id = -1; ///< 拓扑元素 ID
|
||||
std::string element_type; ///< "vertex", "edge", "face"
|
||||
double observed_value = 0.0; ///< 观测值(距离/角度/面积)
|
||||
double tolerance = 0.0; ///< 适用的容差阈值
|
||||
bool pass = true; ///< 是否通过检查
|
||||
std::string description; ///< 可读诊断描述
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief 容差诊断报告
|
||||
*
|
||||
* 全面的几何质量诊断报告,对标 Parasolid 的 tolerance analysis。
|
||||
* 包含顶点间距、边长度、面面积、角度偏差、水密性间隙等诊断项。
|
||||
*/
|
||||
struct ToleranceAnalysisReport {
|
||||
/** @brief 整体通过 */
|
||||
bool overall_pass = false;
|
||||
|
||||
/** @brief 模型信息 */
|
||||
size_t total_vertices = 0;
|
||||
size_t total_edges = 0;
|
||||
size_t total_faces = 0;
|
||||
double model_size = 0.0; ///< 包围盒对角线长度
|
||||
|
||||
/** @brief 容差配置 */
|
||||
ToleranceConfig config_used;
|
||||
|
||||
/** @brief 诊断项列表 */
|
||||
std::vector<ToleranceItem> items;
|
||||
|
||||
/** @brief 通过/失败统计 */
|
||||
size_t items_passed = 0;
|
||||
size_t items_failed = 0;
|
||||
|
||||
/** @brief 最小间隙(水密性相关) */
|
||||
double min_gap = std::numeric_limits<double>::max();
|
||||
|
||||
/** @brief 最大间隙 */
|
||||
double max_gap = 0.0;
|
||||
|
||||
/** @brief 平均间隙 */
|
||||
double avg_gap = 0.0;
|
||||
|
||||
/** @brief 间隙超过容差的边对数量 */
|
||||
size_t gap_violations = 0;
|
||||
|
||||
/** @brief 退化元素计数 */
|
||||
size_t degenerate_edges = 0; ///< 长度 < sliver_area 的边
|
||||
size_t degenerate_faces = 0; ///< 面积 < sliver_area 的面
|
||||
size_t near_degenerate_elements = 0; ///< 接近退化的元素
|
||||
|
||||
/** @brief 建议的操作列表 */
|
||||
std::vector<std::string> recommendations;
|
||||
};
|
||||
|
||||
// ═══════════════════════════════════════════════════════════
|
||||
// 水密性验证
|
||||
// ═══════════════════════════════════════════════════════════
|
||||
|
||||
/**
|
||||
* @brief 水密性严格验证结果
|
||||
*
|
||||
* 对标 Parasolid 的 watertight 验证,提供更详细的间隙/穿透分析。
|
||||
*/
|
||||
struct WatertightVerificationResult {
|
||||
/** @brief 是否水密 */
|
||||
bool is_watertight = false;
|
||||
|
||||
/** @brief 水密性分数 (0.0 ~ 1.0) */
|
||||
double watertight_score = 0.0;
|
||||
|
||||
/** @brief 总边数 */
|
||||
size_t total_edges = 0;
|
||||
|
||||
/** @brief 边界边数(恰好被 1 个面引用的边) */
|
||||
size_t boundary_edges = 0;
|
||||
|
||||
/** @brief 非流形边数(被 > 2 个面引用的边) */
|
||||
size_t non_manifold_edges = 0;
|
||||
|
||||
/** @brief 悬挂边(0 个面引用) */
|
||||
size_t dangling_edges = 0;
|
||||
|
||||
/** @brief 间隙位置列表 */
|
||||
struct GapLocation {
|
||||
int edge_id = -1; ///< 间隙对应的边 ID
|
||||
int face_a = -1; ///< 相邻面 A
|
||||
int face_b = -1; ///< 相邻面 B (可能为 -1)
|
||||
double gap_size = 0.0; ///< 间隙尺寸
|
||||
core::Point3D location; ///< 间隙位置
|
||||
};
|
||||
std::vector<GapLocation> gaps;
|
||||
|
||||
/** @brief 穿透位置 */
|
||||
struct PenetrationLocation {
|
||||
int face_a = -1;
|
||||
int face_b = -1;
|
||||
double depth = 0.0;
|
||||
core::Point3D location;
|
||||
};
|
||||
std::vector<PenetrationLocation> penetrations;
|
||||
|
||||
/** @brief 壳闭合检查 */
|
||||
struct ShellStatus {
|
||||
int shell_id = -1;
|
||||
bool closed = false;
|
||||
size_t boundary_edge_count = 0;
|
||||
};
|
||||
std::vector<ShellStatus> shell_statuses;
|
||||
|
||||
/** @brief 错误消息 */
|
||||
std::vector<std::string> errors;
|
||||
};
|
||||
|
||||
// ═══════════════════════════════════════════════════════════
|
||||
// Advanced Healing API
|
||||
// ═══════════════════════════════════════════════════════════
|
||||
|
||||
/**
|
||||
* @brief 全自动修复流水线
|
||||
*
|
||||
* 对标 Parasolid auto-heal。按最佳顺序执行:
|
||||
*
|
||||
* 1. 容差分析 → 确定自适应容差
|
||||
* 2. 间隙闭合 (heal_gaps)
|
||||
* 3. 退化元素移除 (heal_slivers)
|
||||
* 4. 冗余边顶点清理 (拓扑优化)
|
||||
* 5. 共面面合并
|
||||
* 6. 面方向统一 (heal_orientation)
|
||||
* 7. 水密性验证
|
||||
*
|
||||
* @param body 输入 B-Rep 模型(原地修改)
|
||||
* @return AdvancedHealingReport 含详细诊断报表
|
||||
*/
|
||||
[[nodiscard]] AdvancedHealingReport auto_heal_pipeline(BrepModel& body);
|
||||
|
||||
/**
|
||||
* @brief 面分割 — 使用 p-curve 在参数域分割面
|
||||
*
|
||||
* 对标 Parasolid face splitting。根据给定的参数曲线(p-curve)
|
||||
* 在面的参数域 (u,v) 中切割面,生成两个或多个子面。
|
||||
*
|
||||
* 算法:
|
||||
* 1. 将 p-curve 投影到面的 3D 曲面上
|
||||
* 2. 查找 p-curve 与面边界的交点
|
||||
* 3. 在交点和端点处分割原始边
|
||||
* 4. 为每个子区域构建新环和新面
|
||||
*
|
||||
* @param body 输入 B-Rep 模型(原地修改面的拓扑)
|
||||
* @param face_id 要分割的面索引
|
||||
* @param pcurve_2d 二维参数曲线(在面的 (u,v) 参数域中定义)
|
||||
* @return 新生成的面 ID 列表(包含原面,因原地修改后原面 ID 变为第一个新面)
|
||||
*/
|
||||
[[nodiscard]] std::vector<int> face_splitting(
|
||||
BrepModel& body, int face_id,
|
||||
const curves::NurbsCurve& pcurve_2d);
|
||||
|
||||
/**
|
||||
* @brief 共面面合并
|
||||
*
|
||||
* 对标 Parasolid coplanar face merge。
|
||||
* 检测并合并给定面列表中彼此共面且共享边的面。
|
||||
*
|
||||
* 算法:
|
||||
* 1. 对每个面计算平面方程(法向量 + 距原点距离)
|
||||
* 2. 分组:具有相同平面方程的面归为一组
|
||||
* 3. 在每组中查找共享边的面对
|
||||
* 4. 使用 KEF 欧拉操作合并共享边
|
||||
* 5. 重建合并面的环和曲面
|
||||
*
|
||||
* @param body 输入 B-Rep 模型(原地修改)
|
||||
* @param face_ids 候选面 ID 列表
|
||||
* @return 实际合并的面对数量
|
||||
*/
|
||||
int face_merging(BrepModel& body, const std::vector<int>& face_ids);
|
||||
|
||||
/**
|
||||
* @brief 拓扑优化 — 冗余边/顶点清理
|
||||
*
|
||||
* 对标 Parasolid topology optimization。
|
||||
* 移除对几何形状无贡献的冗余拓扑元素:
|
||||
*
|
||||
* 1. **冗余顶点**: 度为 2 且两侧边共线的顶点 → KEV
|
||||
* 2. **冗余边**: 共面面之间的共享边 → KEF
|
||||
* 3. **零长边**: 两端点重叠的边 → 合并顶点 + 移除边
|
||||
* 4. **冗余内环**: 空内环或无面积内环
|
||||
*
|
||||
* @param body 输入 B-Rep 模型(原地修改)
|
||||
* @return 优化项数(移除的顶点数 + 边数 + 面合并数)
|
||||
*/
|
||||
int topology_optimization(BrepModel& body);
|
||||
|
||||
/**
|
||||
* @brief 容差诊断报告
|
||||
*
|
||||
* 对标 Parasolid tolerance analysis。
|
||||
* 生成全面的几何质量诊断报告,包括:
|
||||
* - 顶点间距检查
|
||||
* - 边长度检查
|
||||
* - 面面积与平面性检查
|
||||
* - 面间角度偏差
|
||||
* - 水密性间隙扫描
|
||||
*
|
||||
* @param body 输入 B-Rep 模型
|
||||
* @param cfg 容差配置(默认使用全局配置)
|
||||
* @return ToleranceAnalysisReport 含完整诊断报表
|
||||
*/
|
||||
[[nodiscard]] ToleranceAnalysisReport tolerance_analysis(
|
||||
const BrepModel& body,
|
||||
const ToleranceConfig& cfg = ToleranceConfig::global());
|
||||
|
||||
/**
|
||||
* @brief 水密性严格验证
|
||||
*
|
||||
* 对标 Parasolid watertight verification。
|
||||
* 提供比 validate() 更详细的水密性分析,包括:
|
||||
* - 每条边的相邻面数统计
|
||||
* - 间隙位置精确识别
|
||||
* - 穿透检测(面间非法相交)
|
||||
* - 逐壳闭合性检查
|
||||
* - 0.0~1.0 的连续水密性评分
|
||||
*
|
||||
* @param body 输入 B-Rep 模型
|
||||
* @param tolerance 容差(默认 1e-6)
|
||||
* @return WatertightVerificationResult 含详细报表
|
||||
*/
|
||||
[[nodiscard]] WatertightVerificationResult watertight_verification(
|
||||
const BrepModel& body,
|
||||
double tolerance = 1e-6);
|
||||
|
||||
} // namespace vde::brep
|
||||
@@ -187,4 +187,87 @@ struct DirectModelingResult {
|
||||
[[nodiscard]] DirectModelingResult offset_face(const BrepModel& body,
|
||||
int face_id, double offset_distance);
|
||||
|
||||
// ═══════════════════════════════════════════════════════════
|
||||
// Advanced Direct Modeling Operations — v5.4
|
||||
// ═══════════════════════════════════════════════════════════
|
||||
|
||||
/**
|
||||
* @brief 高级拔模 — 面按拔模方向和角度倾斜
|
||||
*
|
||||
* 将指定面相对于拔模方向旋转到目标拔模角。
|
||||
* 面的与邻面共享的边作为铰链轴(hinge line)。
|
||||
*
|
||||
* 对标 Parasolid Draft Face。
|
||||
*
|
||||
* @param body 输入 B-Rep 实体
|
||||
* @param face_id 目标面索引
|
||||
* @param angle_deg 拔模角度(度),> 0 且 < 90
|
||||
* @param pull_dir 拔模方向(通常是模具开模方向)
|
||||
* @return DirectModelingResult 含新模型和诊断
|
||||
*
|
||||
* @pre angle_deg 必须在 (0, 90) 度范围内
|
||||
* @pre pull_dir 不能与面法向量平行
|
||||
*
|
||||
* @code{.cpp}
|
||||
* auto box = make_box(10, 5, 3);
|
||||
* // 面 0 向 Z+ 方向拔模 5 度
|
||||
* auto result = draft_face_advanced(box, 0, 5.0, Vector3D::UnitZ());
|
||||
* @endcode
|
||||
*/
|
||||
[[nodiscard]] DirectModelingResult draft_face_advanced(const BrepModel& body,
|
||||
int face_id, double angle_deg,
|
||||
const core::Vector3D& pull_dir);
|
||||
|
||||
/**
|
||||
* @brief 非均匀缩放体
|
||||
*
|
||||
* 沿 X/Y/Z 轴以独立缩放因子缩放整个 B-Rep 实体。
|
||||
* 对标 Parasolid Scale Body (non-uniform)。
|
||||
*
|
||||
* 均匀缩放时(所有因子相等)使用 Transform3D 加速。
|
||||
* 非均匀缩放时逐个顶点变换并重建曲面控制点网格。
|
||||
*
|
||||
* @param body 输入 B-Rep 实体
|
||||
* @param factors 各轴缩放因子 (sx, sy, sz),均必须 > 0
|
||||
* @return DirectModelingResult 含缩放后的新模型
|
||||
*
|
||||
* @pre factors.x() > 0, factors.y() > 0, factors.z() > 0
|
||||
*
|
||||
* @code{.cpp}
|
||||
* auto box = make_box(10, 5, 3);
|
||||
* // X 方向拉伸 2x, Y/Z 不变
|
||||
* auto stretched = scale_body(box, Vector3D(2.0, 1.0, 1.0));
|
||||
* @endcode
|
||||
*/
|
||||
[[nodiscard]] DirectModelingResult scale_body(const BrepModel& body,
|
||||
const core::Vector3D& factors);
|
||||
|
||||
/**
|
||||
* @brief 镜像体
|
||||
*
|
||||
* 关于指定平面镜像整个 B-Rep 实体。
|
||||
* 对标 Parasolid Mirror Body。
|
||||
*
|
||||
* 算法:
|
||||
* 1. 所有顶点关于镜像平面对称映射
|
||||
* 2. 曲面控制点网格镜像(保持参数化方向)
|
||||
* 3. 环方向反转以保持正确的面朝向
|
||||
*
|
||||
* @param body 输入 B-Rep 实体
|
||||
* @param plane_point 镜像平面上的一点
|
||||
* @param plane_normal 镜像平面法向量
|
||||
* @return DirectModelingResult 含镜像体
|
||||
*
|
||||
* @pre plane_normal 不能为零向量
|
||||
*
|
||||
* @code{.cpp}
|
||||
* auto box = make_box(10, 5, 3);
|
||||
* // 关于 YZ 平面 (x=0) 镜像
|
||||
* auto mirrored = mirror_body(box, Point3D(0,0,0), Vector3D::UnitX());
|
||||
* @endcode
|
||||
*/
|
||||
[[nodiscard]] DirectModelingResult mirror_body(const BrepModel& body,
|
||||
const core::Point3D& plane_point,
|
||||
const core::Vector3D& plane_normal);
|
||||
|
||||
} // namespace vde::brep
|
||||
|
||||
@@ -0,0 +1,311 @@
|
||||
#pragma once
|
||||
/**
|
||||
* @file sheet_metal.h
|
||||
* @brief 钣金设计模块 — 对标 Parasolid Sheet Metal
|
||||
*
|
||||
* 提供钣金件的展开、折弯扣除、法兰创建和 K-factor 计算功能。
|
||||
* 对标业界标准钣金设计工作流。
|
||||
*
|
||||
* ## 功能概览
|
||||
*
|
||||
* | 操作 | 对标 Parasolid 功能 |
|
||||
* |------------------------|---------------------------------------|
|
||||
* | unfold_sheet_metal | Unbend / Flatten |
|
||||
* | bend_deduction_table | Bend Allowance / Deduction Table |
|
||||
* | create_flange | Flange / Edge Flange |
|
||||
* | compute_k_factor | K-Factor Calculation |
|
||||
*
|
||||
* ## 钣金术语
|
||||
*
|
||||
* - **K-Factor**: 中性轴位置比例 (0~1),通常取 0.33~0.5
|
||||
* - K = t_neutral_axis / t (t = 板厚)
|
||||
* - **Bend Allowance (BA)**: 折弯区展开长度
|
||||
* - BA = (π × (R + K×T) × A) / 180
|
||||
* - **Bend Deduction (BD)**: 折弯扣除值
|
||||
* - BD = 2 × OSSB - BA
|
||||
* - OSSB = (R + T) × tan(A/2) (外侧退让量)
|
||||
*
|
||||
* @ingroup brep
|
||||
*/
|
||||
#include "vde/brep/brep.h"
|
||||
#include "vde/brep/direct_modeling.h"
|
||||
#include "vde/core/point.h"
|
||||
#include "vde/core/transform.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <cmath>
|
||||
|
||||
namespace vde::brep {
|
||||
|
||||
// ═══════════════════════════════════════════════════════════
|
||||
// 材料与折弯表
|
||||
// ═══════════════════════════════════════════════════════════
|
||||
|
||||
/**
|
||||
* @brief 钣金材料定义
|
||||
*
|
||||
* 包含材料的力学特性,用于 K-factor 计算和折弯扣除。
|
||||
*/
|
||||
struct SheetMetalMaterial {
|
||||
std::string name; ///< 材料名称(如 "Steel_A36", "Aluminum_6061")
|
||||
double yield_strength_mpa = 250.0; ///< 屈服强度 (MPa)
|
||||
double tensile_strength_mpa = 400.0; ///< 抗拉强度 (MPa)
|
||||
double elastic_modulus_gpa = 200.0; ///< 弹性模量 (GPa)
|
||||
double poisson_ratio = 0.3; ///< 泊松比
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief 折弯扣除表条目
|
||||
*
|
||||
* 记录特定材料/厚度/角度/半径组合下的折弯扣除值。
|
||||
*/
|
||||
struct BendDeductionEntry {
|
||||
double thickness = 1.0; ///< 板厚 (mm)
|
||||
double bend_radius = 1.0; ///< 折弯内半径 (mm)
|
||||
double bend_angle_deg = 90.0; ///< 折弯角度(度)
|
||||
double bend_deduction = 0.0; ///< 折弯扣除值 (mm)
|
||||
double k_factor = 0.33; ///< 使用的 K-factor
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief 折弯扣除表
|
||||
*
|
||||
* 材料/厚度 → 折弯扣除值的查找表。
|
||||
* 支持精确半径匹配和插值逼近。
|
||||
*/
|
||||
class BendDeductionTable {
|
||||
public:
|
||||
/// 添加一条记录
|
||||
void add_entry(const BendDeductionEntry& entry);
|
||||
|
||||
/// 通过精确匹配查找
|
||||
[[nodiscard]] BendDeductionEntry lookup(
|
||||
double thickness, double bend_radius, double bend_angle_deg) const;
|
||||
|
||||
/// 通过插值查找(未找到精确匹配时)
|
||||
[[nodiscard]] BendDeductionEntry lookup_interpolated(
|
||||
double thickness, double bend_radius, double bend_angle_deg) const;
|
||||
|
||||
/// 获取表大小
|
||||
[[nodiscard]] size_t size() const { return entries_.size(); }
|
||||
|
||||
/// 获取所有条目
|
||||
[[nodiscard]] const std::vector<BendDeductionEntry>& entries() const {
|
||||
return entries_;
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<BendDeductionEntry> entries_;
|
||||
};
|
||||
|
||||
// ═══════════════════════════════════════════════════════════
|
||||
// K-Factor 计算
|
||||
// ═══════════════════════════════════════════════════════════
|
||||
|
||||
/**
|
||||
* @brief 计算 K-Factor
|
||||
*
|
||||
* K-Factor = 中性轴到内表面的距离 / 板厚
|
||||
*
|
||||
* 使用经验公式,基于材料屈服强度和板厚:
|
||||
* - 软材料 (低碳钢): K ≈ 0.33
|
||||
* - 中等材料: K ≈ 0.40
|
||||
* - 硬材料 (不锈钢): K ≈ 0.45~0.50
|
||||
*
|
||||
* 更精确的计算考虑 R/T 比率:
|
||||
* - R/T < 1.0: K = 0.25 + 0.1 × (R/T)
|
||||
* - 1.0 ≤ R/T < 3.0: K = 0.33 + 0.05 × (R/T)
|
||||
* - R/T ≥ 3.0: K = 0.45 + 0.02 × (R/T), 上限 0.5
|
||||
*
|
||||
* @param material 材料属性
|
||||
* @param thickness 板厚 (mm)
|
||||
* @param bend_radius 折弯内半径 (mm)
|
||||
* @return K-factor 值 (0.0 ~ 0.5)
|
||||
*/
|
||||
[[nodiscard]] double compute_k_factor(
|
||||
const SheetMetalMaterial& material,
|
||||
double thickness,
|
||||
double bend_radius);
|
||||
|
||||
/**
|
||||
* @brief 快速 K-Factor 估算(材料无关)
|
||||
*
|
||||
* @param thickness 板厚 (mm)
|
||||
* @param bend_radius 折弯半径 (mm)
|
||||
* @return 估算的 K-factor
|
||||
*/
|
||||
[[nodiscard]] double compute_k_factor_simple(
|
||||
double thickness, double bend_radius);
|
||||
|
||||
// ═══════════════════════════════════════════════════════════
|
||||
// 折弯计算
|
||||
// ═══════════════════════════════════════════════════════════
|
||||
|
||||
/**
|
||||
* @brief 计算折弯余量 (Bend Allowance)
|
||||
*
|
||||
* BA = (π/180) × (R + K×T) × A
|
||||
*
|
||||
* @param bend_radius 折弯内半径
|
||||
* @param thickness 板厚
|
||||
* @param bend_angle_deg 折弯角度(度)
|
||||
* @param k_factor K-factor
|
||||
* @return 折弯余量长度 (mm)
|
||||
*/
|
||||
[[nodiscard]] double compute_bend_allowance(
|
||||
double bend_radius, double thickness,
|
||||
double bend_angle_deg, double k_factor);
|
||||
|
||||
/**
|
||||
* @brief 计算折弯扣除 (Bend Deduction)
|
||||
*
|
||||
* BD = 2 × OSSB - BA
|
||||
* OSSB = (R + T) × tan(A/2)
|
||||
*
|
||||
* @param bend_radius 折弯内半径
|
||||
* @param thickness 板厚
|
||||
* @param bend_angle_deg 折弯角度(度)
|
||||
* @param k_factor K-factor
|
||||
* @return 折弯扣除值 (mm)
|
||||
*/
|
||||
[[nodiscard]] double compute_bend_deduction(
|
||||
double bend_radius, double thickness,
|
||||
double bend_angle_deg, double k_factor);
|
||||
|
||||
// ═══════════════════════════════════════════════════════════
|
||||
// 折弯扣除表生成
|
||||
// ═══════════════════════════════════════════════════════════
|
||||
|
||||
/**
|
||||
* @brief 为指定材料和厚度范围生成折弯扣除表
|
||||
*
|
||||
* 自动计算 90° 折弯在不同板厚和内半径下的扣除值。
|
||||
* 使用该材料的 compute_k_factor 确定 K-factor。
|
||||
*
|
||||
* @param material 钣金材料
|
||||
* @param thickness 板厚 (mm)
|
||||
* @param radii 要计算的内半径列表
|
||||
* @return 生成的折弯扣除表
|
||||
*/
|
||||
[[nodiscard]] BendDeductionTable bend_deduction_table(
|
||||
const SheetMetalMaterial& material,
|
||||
double thickness,
|
||||
const std::vector<double>& radii = {0.5, 1.0, 1.5, 2.0, 3.0, 4.0, 5.0, 6.0});
|
||||
|
||||
/**
|
||||
* @brief 为指定材料和折弯角生成折弯扣除表(多角度)
|
||||
*
|
||||
* @param material 钣金材料
|
||||
* @param thickness 板厚 (mm)
|
||||
* @param radius 折弯内半径 (mm)
|
||||
* @param angles_deg 角度列表
|
||||
* @return 生成的折弯扣除表
|
||||
*/
|
||||
[[nodiscard]] BendDeductionTable bend_deduction_table_angles(
|
||||
const SheetMetalMaterial& material,
|
||||
double thickness, double radius,
|
||||
const std::vector<double>& angles_deg = {30, 45, 60, 90, 120, 135, 150});
|
||||
|
||||
// ═══════════════════════════════════════════════════════════
|
||||
// 钣金展开
|
||||
// ═══════════════════════════════════════════════════════════
|
||||
|
||||
/**
|
||||
* @brief 钣金展开结果
|
||||
*/
|
||||
struct UnfoldResult {
|
||||
/** @brief 是否成功 */
|
||||
bool success = false;
|
||||
|
||||
/** @brief 展开后的平面 B-Rep */
|
||||
BrepModel flattened_body;
|
||||
|
||||
/** @brief 折弯面列表(展开前) */
|
||||
std::vector<int> bend_faces;
|
||||
|
||||
/** @brief 各折弯的展开信息 */
|
||||
struct BendUnfoldInfo {
|
||||
int bend_face_id = -1; ///< 折弯面 ID
|
||||
double bend_angle_deg = 0.0; ///< 折弯角度
|
||||
double bend_radius = 0.0; ///< 折弯半径
|
||||
double unbend_length = 0.0; ///< 展开长度
|
||||
};
|
||||
std::vector<BendUnfoldInfo> bend_details;
|
||||
|
||||
/** @brief 使用的 K-Factor */
|
||||
double k_factor_used = 0.33;
|
||||
|
||||
/** @brief 错误/警告 */
|
||||
std::vector<std::string> errors;
|
||||
std::vector<std::string> warnings;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief 钣金展开
|
||||
*
|
||||
* 对标 Parasolid Unbend/Flatten。
|
||||
* 将钣金件的折弯面展开为平面布局。
|
||||
*
|
||||
* 算法:
|
||||
* 1. 识别基准面(face_id 指定的面)
|
||||
* 2. BFS 遍历相邻面,识别折弯面(柱面或锥面)
|
||||
* 3. 对每个折弯面计算展开长度(使用 K-factor)
|
||||
* 4. 将折弯面映射到基准面所在平面
|
||||
* 5. 重建平坦拓扑
|
||||
*
|
||||
* @param body 钣金 B-Rep 模型
|
||||
* @param face_id 基准面索引(展开时的固定参考面)
|
||||
* @param material 钣金材料(用于 K-factor 计算)
|
||||
* @param thickness 板厚 (mm),0 表示自动从模型估算
|
||||
* @return UnfoldResult 含展开后的平面模型
|
||||
*/
|
||||
[[nodiscard]] UnfoldResult unfold_sheet_metal(
|
||||
const BrepModel& body, int face_id,
|
||||
const SheetMetalMaterial& material = SheetMetalMaterial{},
|
||||
double thickness = 0.0);
|
||||
|
||||
// ═══════════════════════════════════════════════════════════
|
||||
// 法兰创建
|
||||
// ═══════════════════════════════════════════════════════════
|
||||
|
||||
/**
|
||||
* @brief 法兰创建结果
|
||||
*/
|
||||
struct FlangeResult {
|
||||
bool success = false;
|
||||
BrepModel body; ///< 含新法兰的结果体
|
||||
std::vector<int> new_face_ids; ///< 新创建的面 ID 列表
|
||||
std::vector<int> new_edge_ids; ///< 新创建的边 ID 列表
|
||||
std::vector<std::string> errors;
|
||||
std::vector<std::string> warnings;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief 沿边创建法兰
|
||||
*
|
||||
* 对标 Parasolid Flange / Edge Flange。
|
||||
* 沿钣金件的一条边创建折弯法兰。
|
||||
*
|
||||
* 算法:
|
||||
* 1. 确定边所属的基面
|
||||
* 2. 计算折弯线(沿边的偏移)
|
||||
* 3. 生成折弯区的柱面
|
||||
* 4. 生成法兰面的平面曲面
|
||||
* 5. 通过布尔或拓扑编辑将法兰附加到模型
|
||||
*
|
||||
* @param body 输入钣金 B-Rep 模型
|
||||
* @param edge_id 附着边索引
|
||||
* @param angle_deg 法兰折弯角度(度),90=标准法兰
|
||||
* @param length 法兰长度(从折弯线到法兰自由边的距离)
|
||||
* @param material 钣金材料
|
||||
* @param thickness 板厚 (mm),0 表示自动估算
|
||||
* @return FlangeResult 含新模型
|
||||
*/
|
||||
[[nodiscard]] FlangeResult create_flange(
|
||||
const BrepModel& body, int edge_id,
|
||||
double angle_deg, double length,
|
||||
const SheetMetalMaterial& material = SheetMetalMaterial{},
|
||||
double thickness = 0.0);
|
||||
|
||||
} // namespace vde::brep
|
||||
Reference in New Issue
Block a user