feat(v10): tolerant modeling + Class-A deep + hex mesh + constraint solver + drawing standards
CI / Build & Test (push) Failing after 31s
CI / Release Build (push) Failing after 31s
Build & Test / build-and-test (push) Has been cancelled
Build & Test / python-bindings (push) Has been cancelled

v10.1 — Tolerant Modeling (对标 Parasolid):
- tolerant_modeling.h/.cpp: TolerantVertex/Edge, merge_within_tolerance (BFS)
- gap_bridging (free edge detection → triangle filling)
- overlap_resolution (normal+centroid+AABB detection)
- tolerant_boolean (heal→degenerate detect→boolean→heal) + BooleanDiagnostic
- import_heal_pipeline (STEP one-shot repair)
- ssi_boolean enhanced: coplanar/collinear/tangent detection, GMP on all classify paths
- step_import enhanced: broken file recovery, non-standard entity mapping, diagnostic report
- 30 tests, 4112 total lines

v10.2 — Class-A Deep + Hex Mesh (对标 CGM + ANSYS):
- class_a_surfacing enhanced: g3_blend_with_constraints, surface_energy_minimization
- curvature_continuity_optimization, reflection_line_discontinuity (+720 lines)
- fea_mesh enhanced: mapped_hex, submapped_hex, multi_block_hex (TFI), hex_quality_optimization (+522 lines)
- 22 tests

v10.3 — Constraint Solver + Drawing Standards (对标 D-Cubed + AutoCAD):
- constraint_solver enhanced: DOFAnalyzer, RedundancyDetector, ConstraintPropagator, KinematicChainSolver
- drawing_standards.h/.cpp: IsoStandard (ISO 128/129), AnsiStandard (ASME Y14.5), JisStandard (JIS B 0001)
- 12 tests

12 files, ~5000 lines, 64 tests. Target: 87% → 93%
This commit is contained in:
茂之钳
2026-07-27 00:33:30 +08:00
parent ddcfe01cba
commit 63fba5389a
21 changed files with 6333 additions and 468 deletions
+202
View File
@@ -18,6 +18,7 @@
#include "vde/core/point.h"
#include <vector>
#include <array>
#include <tuple>
#include <utility>
#include <string>
#include <functional>
@@ -362,4 +363,205 @@ struct ShapeModificationResult {
const NurbsSurface& surface,
const std::vector<ShapeConstraint>& constraints);
// ═══════════════════════════════════════════════════════════
// G3 Blend with Constraints — 带约束的 G3 过渡
// ═══════════════════════════════════════════════════════════
/// G0/G1/G2/G3 连续性约束边参数
struct G3ConstraintEdges {
EdgeParams g0_edge; ///< G0 位置约束边
EdgeParams g1_edge; ///< G1 切平面约束边
EdgeParams g2_edge; ///< G2 曲率约束边
EdgeParams g3_edge; ///< G3 曲率变化率约束边
bool enforce_g0 = true;
bool enforce_g1 = true;
bool enforce_g2 = true;
bool enforce_g3 = true;
};
/**
* @brief 带约束的 G3 过渡曲面
*
* 在两面之间构造过渡曲面,并精确满足指定的 G0/G1/G2/G3 约束。
* 与 g3_blend 相比,此函数允许用户显式指定每条边的连续性等级。
*
* 算法:
* 1. 根据各约束边采样控制点
* 2. 构造最小二乘系统满足 G0→G3 逐级约束
* 3. 使用 Lagrange 乘子法确保约束精确满足
*
* @param surf_a 曲面 A
* @param surf_b 曲面 B
* @param edges 显式 G0/G1/G2/G3 约束边参数
* @return G3 过渡结果
*
* @ingroup curves
*/
[[nodiscard]] G3BlendResult g3_blend_with_constraints(
const NurbsSurface& surf_a,
const NurbsSurface& surf_b,
const G3ConstraintEdges& edges);
// ═══════════════════════════════════════════════════════════
// Surface Energy Minimization — 薄板能量最小化
// ═══════════════════════════════════════════════════════════
/// 能量最小化选项
struct EnergyMinimizationOptions {
double bending_weight = 1.0; ///< 弯曲能量权重
double membrane_weight = 0.1; ///< 薄膜能量权重
double constraint_weight = 10.0; ///< 约束满足权重
int max_iterations = 100; ///< 最大迭代次数
double tolerance = 1e-6; ///< 收敛容差
double regularization = 1e-4; ///< Tikhonov 正则化
bool preserve_boundary = true; ///< 是否保持边界不变
};
/// 能量最小化结果
struct EnergyMinimizationResult {
NurbsSurface optimized_surface; ///< 优化后的曲面
double initial_bending_energy = 0.0; ///< 初始弯曲能量
double final_bending_energy = 0.0; ///< 最终弯曲能量
double initial_membrane_energy = 0.0; ///< 初始薄膜能量
double final_membrane_energy = 0.0; ///< 最终薄膜能量
int iterations = 0; ///< 实际迭代次数
bool converged = false; ///< 是否收敛
std::vector<Point3D> control_displacements; ///< 控制点位移
double max_displacement = 0.0; ///< 最大控制点位移
};
/**
* @brief 薄板能量最小化曲面优化
*
* 最小化薄板弯曲能量(二阶导数平方积分)和薄膜能量(一阶导数平方积分),
* 同时满足约束条件,实现曲面的全局光顺。
*
* 能量泛函:
* E = w_bend * ∫(κ₁² + κ₂²)dA + w_membrane * ∫(‖∂S/∂u‖² + ‖∂S/∂v‖²)dA
* + w_constraint * Σ‖S(u_i, v_i) - target_i‖²
*
* 算法:基于控制点的 Gauss-Newton 非线性最小二乘优化。
*
* @param surface 输入 NURBS 曲面
* @param constraints 约束点列表(可为空,仅做光顺)
* @param options 优化选项
* @return 能量最小化结果
*
* @note 对标 ICEM Surf / Alias AutoStudio 的 Surface Fairing
* @ingroup curves
*/
[[nodiscard]] EnergyMinimizationResult surface_energy_minimization(
const NurbsSurface& surface,
const std::vector<ShapeConstraint>& constraints,
const EnergyMinimizationOptions& options = {});
// ═══════════════════════════════════════════════════════════
// Curvature Continuity Optimization — 曲率连续性迭代精化
// ═══════════════════════════════════════════════════════════
/// 曲率连续性优化选项
struct CurvatureContinuityOptions {
double position_tolerance = 1e-7; ///< 位置连续性容差
double tangent_tolerance = 1e-5; ///< 切平面角度容差 (rad)
double curvature_tolerance = 1e-4; ///< 曲率偏差容差
int max_iterations = 50; ///< 最大迭代次数
int boundary_samples = 30; ///< 边界采样点数
double step_size = 0.05; ///< 步长因子
bool optimize_both_surfaces = false; ///< 是否同时优化两面
};
/// 曲率连续性优化结果
struct CurvatureContinuityResult {
NurbsSurface optimized_a; ///< 优化后的曲面 A(若 optimize_both_surfaces=true
NurbsSurface optimized_b; ///< 优化后的曲面 B
double initial_g0_error = 0.0; ///< 初始 G0 误差
double final_g0_error = 0.0; ///< 最终 G0 误差
double initial_g1_error = 0.0; ///< 初始 G1 误差 (rad)
double final_g1_error = 0.0; ///< 最终 G1 误差 (rad)
double initial_g2_error = 0.0; ///< 初始 G2 误差
double final_g2_error = 0.0; ///< 最终 G2 误差
int iterations = 0; ///< 实际迭代次数
bool converged = false; ///< 是否收敛
};
/**
* @brief 曲率连续性迭代精化优化
*
* 在两曲面公共边界处迭代调整控制点,逐步提升 G0→G1→G2 连续性。
* 每次迭代沿公共边界采样,计算当前连续性误差,梯度下降调整影响区域控制点。
*
* 算法:
* 1. 检测公共边界
* 2. 沿边界采样,计算各点 G0/G1/G2 误差
* 3. 梯度下降调整边界面附近控制点
* 4. 重新评估,调整步长(adaptive step size
* 5. 收敛检测
*
* @param surf_a 曲面 A
* @param surf_b 曲面 B
* @param options 优化选项
* @return 优化结果(含优化后的曲面和收敛历史)
*
* @note 对标 CATIA GSD Join / ICEM Surf Match
* @ingroup curves
*/
[[nodiscard]] CurvatureContinuityResult curvature_continuity_optimization(
const NurbsSurface& surf_a,
const NurbsSurface& surf_b,
const CurvatureContinuityOptions& options = {});
// ═══════════════════════════════════════════════════════════
// Reflection Line Discontinuity — 反射线不连续检测+修复
// ═══════════════════════════════════════════════════════════
/// 反射线不连续检测参数
struct ReflectionDiscontinuityParams {
Vector3D light_direction; ///< 光源方向(归一化)
int res_u = 40; ///< u 方向分辨率
int res_v = 40; ///< v 方向分辨率
double discontinuity_threshold = 0.05; ///< 不连续判定阈值(方向变化率)
int max_fix_iterations = 20; ///< 最大修复迭代次数
double fix_strength = 0.1; ///< 修复强度
bool auto_fix = true; ///< 是否自动修复
};
/// 反射线不连续检测结果
struct ReflectionDiscontinuityResult {
int res_u = 0, res_v = 0; ///< 网格分辨率
/// 反射场 grid
std::vector<std::vector<Vector3D>> reflection_field;
/// 不连续强度网格 ∈ [0, ∞)
std::vector<std::vector<double>> discontinuity_map;
/// 不连续点列表 (u, v, intensity)
std::vector<std::tuple<double, double, double>> discontinuities;
int total_discontinuities = 0; ///< 不连续点总数
double max_discontinuity = 0.0; ///< 最大不连续强度
double mean_discontinuity = 0.0; ///< 平均不连续强度
bool is_smooth = false; ///< 是否判定为光顺
NurbsSurface fixed_surface; ///< 修复后的曲面(若 auto_fix=true
bool fixed = false; ///< 是否已修复
double fix_residual = 0.0; ///< 修复残差
};
/**
* @brief 反射线不连续检测与修复
*
* 计算曲面在给定光源方向下的反射线场,检测反射方向的局部突变点,
* 并可选择性地自动修复(通过局部控制点微调消除不连续)。
*
* 算法:
* - 检测:计算反射方向场的梯度幅值,超过阈值的标记为不连续
* - 修复:对不连续区域的控制点施加局部高斯加权偏移,最小化反射梯度
*
* @param surface NURBS 曲面
* @param params 检测参数(光源方向、分辨率、阈值、修复选项)
* @return 反射线不连续检测与修复结果
*
* @note 对标 CGM Reflection Line Analysis + Repair
* @ingroup curves
*/
[[nodiscard]] ReflectionDiscontinuityResult reflection_line_discontinuity(
const NurbsSurface& surface,
const ReflectionDiscontinuityParams& params);
} // namespace vde::curves