feat(v8): ultimate performance + CAM full optimization + visualization/IGA/quality
CI / Build & Test (push) Failing after 1m31s
CI / Release Build (push) Failing after 31s
Build & Test / build-and-test (push) Has been cancelled
Build & Test / python-bindings (push) Has been cancelled

v8.1 — 极致性能 (SIMD + LockFree + Transaction + NUMA):
- simd_vector.h: Vec4d/Vec4f SSE/AVX/NEON auto-detect, batch AABB, SoA transpose
- concurrent_data: LockFreeQueue (MPMC CAS), LockFreeStack (Treiber), ConcurrentHashMap (64-segment sharded)
- transaction: Command pattern, UndoManager (infinite undo/redo), crash-recovery journal
- performance_tuning: NUMA-aware, cache_line aligned, prefetch, hot/cold separation
- 20 tests (concurrent + transaction), ~2600 lines

v8.2 — CAM 全面优化 + 装配模式:
- cam_optimization: chip_thinning, HSM, constant_engagement, trochoidal_turn_milling
- tool_life_management, probing_cycle, thread_milling
- cam_advanced enhanced: Mazak/Okuma/Haas/DMG post-processors (8 total)
- assembly_patterns: Circular/Rectangular/Mirror/PatternDriven/fill arrays
- assembly_feature enhanced: assembly-level PMI propagation, batch interference check
- 28 tests, compiled 0 errors (~2800 lines)

v8.3 — 可视化+压缩+IGA+质量闭环:
- visualization_quality: ambient_occlusion, edge_highlighting, wireframe, normals
- topology_compression: Brep compression, Edgebreaker, vertex quantization
- iga_prep: knot_insertion, degree_elevation, Bezier extraction for IGA analysis
- quality_feedback: design_rule_check, manufacturability, cost_estimation, quality_score (0-100)
- 28 tests, ~2349 lines

27 files, ~7750 lines, 76 tests
This commit is contained in:
茂之钳
2026-07-26 23:13:22 +08:00
parent 921c29cb22
commit 2ecad1543f
35 changed files with 8119 additions and 2 deletions
+139 -1
View File
@@ -1,8 +1,146 @@
#pragma once
#include "vde/brep/brep.h"
#include "vde/brep/assembly.h"
namespace vde::brep {
// ═══════════════════════════════════════════════════════════════════════════
// 装配特征类型
// ═══════════════════════════════════════════════════════════════════════════
enum class AssemblyFeatureType { BoltHole, PinSlot, WeldJoint, RivetPattern };
struct AssemblyFeatureParams { AssemblyFeatureType type; std::vector<double> values; core::Vector3D direction{0,0,1}; };
struct AssemblyFeatureParams {
AssemblyFeatureType type;
std::vector<double> values;
core::Vector3D direction{0, 0, 1};
};
void apply_assembly_feature(Assembly& assembly, const AssemblyFeatureParams& params);
// ═══════════════════════════════════════════════════════════════════════════
// PMI (Product Manufacturing Information) 标注传播
// ═══════════════════════════════════════════════════════════════════════════
/// PMI 标注类型
enum class PMIType {
Dimension, ///< 尺寸标注
GeometricTol, ///< 几何公差 (GD&T)
SurfaceFinish, ///< 表面粗糙度
Datum, ///< 基准标识
Note, ///< 注释
WeldSymbol ///< 焊接符号
};
/// PMI 标注数据
struct PMIAnnotation {
PMIType type = PMIType::Dimension;
std::string id; ///< 标注唯一标识
std::string label; ///< 标注文本
core::Point3D position; ///< 标注位置
core::Vector3D normal; ///< 标注平面法向
std::string target_feature_id; ///< 关联的特征 ID
std::vector<double> tolerance_values; ///< 公差值 (如 [0.1, 0.05] = 上/下偏差)
std::string datum_references; ///< 基准参考 (如 "A|B|C")
};
/// PMI 传播结果
struct PMIPropagationResult {
std::vector<PMIAnnotation> propagated_annotations; ///< 传播后的 PMI 标注列表
size_t total_source_count = 0; ///< 源标注总数
size_t propagated_count = 0; ///< 成功传播数
size_t unresolved_count = 0; ///< 无法解析的标注数
std::vector<std::string> warnings; ///< 警告消息
};
/// 将零件级 PMI 标注传播到装配级
///
/// 扫描装配体中的所有零件,收集其 PMI 标注(GD&T/尺寸/粗糙度等),
/// 通过装配变换将标注位置和方向转换到装配坐标系。
///
/// 典型用例:
/// - 在装配图中显示所有零件的关键尺寸和公差
/// - 装配级的 GD&T 基准传递
/// - 焊接符号的装配级聚合
///
/// @param assembly 目标装配体
/// @param source_annotations 零件级 PMI 标注列表(相对于各自零件坐标系)
/// @return PMI 传播结果
///
/// @ingroup brep
[[nodiscard]] PMIPropagationResult propagate_pmi_to_assembly(
const Assembly& assembly,
const std::vector<PMIAnnotation>& source_annotations);
/// 获取装配体中所有零件的 PMI 标注(扫描)
///
/// @param assembly 目标装配体
/// @return 装配坐标系下的所有 PMI 标注
///
/// @ingroup brep
[[nodiscard]] std::vector<PMIAnnotation> collect_assembly_pmi(
const Assembly& assembly);
// ═══════════════════════════════════════════════════════════════════════════
// 装配级干涉检查批处理
// ═══════════════════════════════════════════════════════════════════════════
/// 干涉检查批处理参数
struct InterferenceBatchParams {
bool check_part_to_part = true; ///< 零件间干涉检查
bool check_part_to_fastener = true; ///< 零件与紧固件干涉检查
bool check_kinematic_range = false; ///< 运动包络干涉检查
double clearance_threshold = 0.01; ///< 间隙阈值 (mm) — 小于此值视为干涉
bool generate_report = true; ///< 是否生成详细报告
int max_threads = 4; ///< 并行线程数
};
/// 干涉检查批处理结果
struct InterferenceBatchResult {
size_t total_pairs_checked = 0; ///< 检查的零件对数
size_t interference_count = 0; ///< 干涉对数
size_t clearance_violations = 0; ///< 间隙违规数
std::vector<std::string> interference_details; ///< 干涉详情
double total_check_time_ms = 0.0; ///< 总检查耗时 (ms)
std::string summary_report; ///< 摘要报告
};
/// 装配级干涉检查批处理
///
/// 对装配体中所有零件对进行批量的干涉/间隙检查。
/// 支持零件-零件、零件-紧固件、运动包络三种检查模式。
/// 可并行加速。
///
/// 算法:
/// 1. 对装配体构建 BVH (Bounding Volume Hierarchy) 加速结构
/// 2. 利用 BVH 快速筛选可能相交的零件对 (broad phase)
/// 3. 对候选对进行精确三角面片干涉检测 (narrow phase)
/// 4. 生成干涉报告
///
/// @param assembly 目标装配体
/// @param params 批处理参数
/// @return 干涉检查批处理结果
///
/// @ingroup brep
[[nodiscard]] InterferenceBatchResult interference_check_batch(
const Assembly& assembly,
const InterferenceBatchParams& params = InterferenceBatchParams{});
/// 检查两个特定零件是否干涉
///
/// @param model_a 零件 A
/// @param transform_a 零件 A 的世界变换
/// @param model_b 零件 B
/// @param transform_b 零件 B 的世界变换
/// @param clearance_threshold 间隙阈值
/// @return true 如果发生干涉
///
/// @ingroup brep
[[nodiscard]] bool check_part_interference(
const BrepModel& model_a,
const core::Transform3D& transform_a,
const BrepModel& model_b,
const core::Transform3D& transform_b,
double clearance_threshold = 0.01);
} // namespace vde::brep
+204
View File
@@ -0,0 +1,204 @@
#pragma once
/**
* @file assembly_patterns.h
* @brief 装配体阵列/模式 — 环形阵列、矩形阵列、镜像、特征驱动阵列、填充阵列
*
* 提供类似 SolidWorks/Inventor 的装配级阵列功能:
* - CircularPattern — 环形阵列(绕轴旋转分布零件)
* - RectangularPattern — 矩形阵列(沿两个方向的网格分布)
* - MirrorPattern — 镜像阵列(相对于平面镜像复制)
* - PatternDriven — 特征驱动阵列(由装配特征自动驱动布件)
* - fill_pattern — 填充阵列(在指定区域内自动填充零件)
*
* @ingroup brep
*/
#include "vde/core/point.h"
#include "vde/core/transform.h"
#include "vde/brep/brep.h"
#include "vde/brep/assembly.h"
#include <vector>
#include <string>
#include <memory>
#include <functional>
namespace vde::brep {
using core::Point3D;
using core::Vector3D;
using core::Transform3D;
// ═══════════════════════════════════════════════════════════════════════════
// 阵列参数结构体
// ═══════════════════════════════════════════════════════════════════════════
/// 环形阵列参数
struct CircularPatternParams {
Point3D center = Point3D::Zero(); ///< 环形中心点
Vector3D axis = Vector3D::UnitZ(); ///< 旋转轴(自动归一化)
int count = 6; ///< 实例总数(含源)
double total_angle_deg = 360.0; ///< 总角度 (度)
bool equal_spacing = true; ///< 等距分布
/// 可选:仅生成指定索引的实例(跳过的实例不会创建)
std::vector<int> skip_instances;
};
/// 矩形阵列参数
struct RectangularPatternParams {
Vector3D direction1 = Vector3D::UnitX(); ///< 第一方向
Vector3D direction2 = Vector3D::UnitY(); ///< 第二方向
double spacing1 = 10.0; ///< 第一方向间距 (mm)
double spacing2 = 10.0; ///< 第二方向间距 (mm)
int count1 = 3; ///< 第一方向实例数(含源)
int count2 = 3; ///< 第二方向实例数(含源)
bool staggered = false; ///< 交错排列
double stagger_offset = 0.5; ///< 交错偏移量 (间距比例)
};
/// 镜像阵列参数
struct MirrorPatternParams {
Point3D plane_origin = Point3D::Zero(); ///< 镜像平面上的点
Vector3D plane_normal = Vector3D::UnitX(); ///< 镜像平面法向(自动归一化)
bool copy_original = true; ///< 是否保留原始零件
};
/// 特征驱动阵列参数
struct PatternDrivenParams {
/// 驱动特征的类型:孔、槽、凸台
enum class FeatureType { Hole, Slot, Boss };
FeatureType feature_type = FeatureType::Hole;
double min_spacing = 5.0; ///< 最小间距 (mm)
double max_instances = 100; ///< 最大实例数
/// 驱动特征位置的来源装配体
const Assembly* source_assembly = nullptr;
};
/// 填充阵列参数
struct FillPatternParams {
/// 填充区域 — 由 AABB 定义矩形边界
Point3D fill_min = Point3D::Zero();
Point3D fill_max = Point3D(100, 100, 0);
Vector3D fill_plane_normal = Vector3D::UnitZ(); ///< 填充平面法向
double spacing = 10.0; ///< 实例间距 (mm)
double margin = 5.0; ///< 边界留白 (mm)
double angle_deg = 0.0; ///< 填充方向角度 (度)
bool hexagonal = false; ///< 六边形密排(vs 正方形网格)
/// 可选:排除区域(在这些 AABB 内不放置实例)
std::vector<std::pair<Point3D, Point3D>> exclude_regions;
};
// ═══════════════════════════════════════════════════════════════════════════
// 阵列结果
// ═══════════════════════════════════════════════════════════════════════════
/// 阵列实例信息
struct PatternInstance {
Transform3D transform; ///< 世界变换矩阵
std::string name; ///< 实例名称(含序号)
int index = 0; ///< 实例序号(源为 0
};
/// 阵列结果
struct PatternResult {
std::vector<PatternInstance> instances; ///< 生成的实例列表
size_t total_count = 0; ///< 总实例数(含源)
size_t skipped_count = 0; ///< 跳过的实例数
};
// ═══════════════════════════════════════════════════════════════════════════
// 阵列函数
// ═══════════════════════════════════════════════════════════════════════════
/// 环形阵列 — 绕轴旋转分布零件的多个副本
///
/// 以源零件的世界变换为基准,绕指定轴旋转生成 count 个等距副本。
///
/// @param source_transform 源零件的世界变换矩阵
/// @param source_name 源零件名称
/// @param params 环形阵列参数
/// @return 包含所有实例变换的阵列结果
///
/// @ingroup brep
[[nodiscard]] PatternResult circular_pattern(
const Transform3D& source_transform,
const std::string& source_name,
const CircularPatternParams& params);
/// 矩形阵列 — 沿两个方向生成网格分布副本
///
/// 支持交错排列 (staggered),方向可任意指定(不必正交)。
///
/// @param source_transform 源零件的世界变换矩阵
/// @param source_name 源零件名称
/// @param params 矩形阵列参数
/// @return 包含所有实例变换的阵列结果
///
/// @ingroup brep
[[nodiscard]] PatternResult rectangular_pattern(
const Transform3D& source_transform,
const std::string& source_name,
const RectangularPatternParams& params);
/// 镜像阵列 — 相对于平面镜像复制
///
/// 将源零件相对于指定平面镜像,可选是否保留原始零件。
///
/// @param source_transform 源零件的世界变换矩阵
/// @param source_name 源零件名称
/// @param params 镜像参数
/// @return 包含源和镜像(或仅镜像)实例的阵列结果
///
/// @ingroup brep
[[nodiscard]] PatternResult mirror_pattern(
const Transform3D& source_transform,
const std::string& source_name,
const MirrorPatternParams& params);
/// 特征驱动阵列 — 根据装配特征自动布件
///
/// 扫描装配体中的特征(孔/槽/凸台),在每个特征位置放置零件实例。
/// 适用于螺栓孔阵列自动装配、焊接点阵列等。
///
/// @param source_transform 源零件的世界变换矩阵
/// @param source_name 源零件名称
/// @param params 特征驱动参数
/// @return 包含所有实例变换的阵列结果
///
/// @ingroup brep
[[nodiscard]] PatternResult pattern_driven(
const Transform3D& source_transform,
const std::string& source_name,
const PatternDrivenParams& params);
/// 填充阵列 — 在指定区域内自动填充零件实例
///
/// 在由 AABB 定义的矩形区域内,以指定间距和角度自动填充零件实例。
/// 支持正方形网格和六边形密排两种模式,可设置边界留白和排除区域。
///
/// @param source_transform 源零件的世界变换矩阵
/// @param source_name 源零件名称
/// @param params 填充参数
/// @return 包含所有实例变换的阵列结果
///
/// @ingroup brep
[[nodiscard]] PatternResult fill_pattern(
const Transform3D& source_transform,
const std::string& source_name,
const FillPatternParams& params);
/// 将阵列结果应用到装配体
///
/// 根据阵列结果,在装配体中创建所有实例的副本。
///
/// @param assembly 目标装配体(将在其根节点下添加实例)
/// @param result 阵列结果
/// @param source_name 源零件名称(用于查找)
/// @return 成功创建的实例数
///
/// @ingroup brep
size_t apply_pattern_to_assembly(
Assembly& assembly,
const PatternResult& result,
const std::string& source_name);
} // namespace vde::brep
+210
View File
@@ -0,0 +1,210 @@
#pragma once
/**
* @file quality_feedback.h
* @brief 设计质量闭环 — 规则检查、可制造性、成本估算、综合评分
*
* 从设计数据(BrepModel)出发,进行:
* - 设计规则检查(DRC):壁厚、圆角、拔模角、最小特征等
* - 可制造性分析(DFM):机加工/注塑/增材可行性
* - 成本估算:材料+加工成本
* - 质量评分:综合 0-100 分
*
* @ingroup brep
*/
#include "vde/brep/brep.h"
#include "vde/core/point.h"
#include "vde/mesh/halfedge_mesh.h"
#include <vector>
#include <string>
#include <map>
namespace vde::brep {
using core::Point3D;
using core::Vector3D;
// ═══════════════════════════════════════════════════════════
// 设计规则
// ═══════════════════════════════════════════════════════════
/// 单项设计规则
struct DesignRule {
std::string name; ///< 规则名称
std::string description; ///< 规则描述
double min_value; ///< 最小值(< 0 = 不检查下限)
double max_value; ///< 最大值(< 0 = 不检查上限)
double weight; ///< 权重 [0,1](用于综合评分)
bool critical; ///< 是否为关键规则(不通过则整体失败)
};
/// 设计规则检查结果
struct DesignRuleResult {
std::string rule_name; ///< 规则名称
double actual_value;///< 实际检测值
double min_allowed; ///< 允许下限
double max_allowed; ///< 允许上限
bool passed; ///< 是否通过
std::string message; ///< 检测信息
double score; ///< 单项得分 [0, 1]
};
/// DRC 报告
struct DRCRreport {
std::vector<DesignRuleResult> results; ///< 各规则检测结果
int total_rules; ///< 总规则数
int passed_count; ///< 通过数
int failed_count; ///< 失败数
double overall_score; ///< 综合得分 [0, 1]
bool all_critical_passed; ///< 所有关键规则是否通过
};
// ═══════════════════════════════════════════════════════════
// 可制造性分析
// ═══════════════════════════════════════════════════════════
/// 制造工艺类型
enum class ManufacturingProcess {
Machining, ///< 机加工(铣削/车削)
InjectionMolding,///< 注塑成型
Additive, ///< 增材制造/3D打印
SheetMetal, ///< 钣金
Casting, ///< 铸造
};
/// 可制造性问题
struct MfgIssue {
std::string description; ///< 问题描述
std::string location; ///< 问题位置(如面 ID
int severity; ///< 严重度 1-51=提示,5=致命)
std::string suggestion; ///< 改进建议
};
/// 可制造性分析报告
struct MfgReport {
ManufacturingProcess process; ///< 分析工艺
std::vector<MfgIssue> issues; ///< 问题列表
int total_issues; ///< 总问题数
int critical_issues; ///< 严重问题数(severity>=4
double feasibility; ///< 可行性 [0, 1]
double dfm_score; ///< DFM 得分 [0, 100]
};
// ═══════════════════════════════════════════════════════════
// 成本估算
// ═══════════════════════════════════════════════════════════
/// 材料类型
struct MaterialInfo {
std::string name; ///< 材料名称
double density_kgm3; ///< 密度 (kg/m³)
double cost_per_kg; ///< 材料单价 (元/kg)
std::string grade; ///< 材料牌号
};
/// 成本估算结果
struct CostEstimate {
double volume_m3; ///< 零件体积 (m³)
double mass_kg; ///< 零件质量 (kg)
double material_cost; ///< 材料成本
double machining_cost; ///< 加工成本
double tooling_cost; ///< 工装/模具成本
double finishing_cost; ///< 表面处理成本
double overhead; ///< 管理/间接费用
double total_cost; ///< 总成本
std::string currency; ///< 币种
MaterialInfo material; ///< 材料信息
};
// ═══════════════════════════════════════════════════════════
// 综合质量评分
// ═══════════════════════════════════════════════════════════
/// 质量评分报告
struct QualityReport {
double geometric_score; ///< 几何质量 [0, 100] — 连续性、公差
double rule_score; ///< 规则检查得分 [0, 100]
double dfm_score; ///< 可制造性得分 [0, 100]
double cost_score; ///< 成本效益得分 [0, 100]
double overall_score; ///< 综合质量评分 [0, 100]
std::string grade; ///< 评级: A(≥90) B(≥75) C(≥60) D(<60)
std::vector<std::string> recommendations; ///< 改进建议
};
// ═══════════════════════════════════════════════════════════
// 函数声明
// ═══════════════════════════════════════════════════════════
/**
* @brief 设计规则检查(DRC
*
* 对 BrepModel 执行一组设计规则检查。
* 如果 rules 为空,使用默认规则集(壁厚、最小圆角、拔模角等)。
*
* @param body BrepModel
* @param rules 规则列表(空 = 默认规则)
* @return DRCReport
*
* @ingroup brep
*/
DRCRreport design_rule_check(const BrepModel& body,
const std::vector<DesignRule>& rules = {});
/**
* @brief 可制造性分析(DFM
*
* 根据指定工艺评估设计的可制造性。
*
* @param body BrepModel
* @param process 目标制造工艺
* @return MfgReport
*
* @ingroup brep
*/
MfgReport manufacturability_analysis(const BrepModel& body,
ManufacturingProcess process);
/**
* @brief 成本估算
*
* 基于零件体积和材料估算制造成本。
*
* @param body BrepModel
* @param material 材料信息
* @return CostEstimate
*
* @ingroup brep
*/
CostEstimate cost_estimation(const BrepModel& body,
const MaterialInfo& material);
/**
* @brief 综合质量评分
*
* 综合几何质量、规则检查、可制造性、成本效益,
* 给出 0-100 分质量评分与改进建议。
*
* @param body BrepModel
* @return QualityReport
*
* @ingroup brep
*/
QualityReport quality_score(const BrepModel& body);
/**
* @brief 获取默认设计规则集
*
* 包括:最小壁厚、最小圆角半径、拔模角、最小孔直径、
* 最大纵横比、最小特征尺寸等通用工程规则。
*
* @return 默认规则列表
*/
std::vector<DesignRule> default_design_rules();
/**
* @brief 获取常用材料库
*
* @return 常用工程材料列表
*/
std::vector<MaterialInfo> material_library();
} // namespace vde::brep