64be0f1cda
VDE-021 (High): mesh→NURBS profile bridge - mesh_boundary_to_curve, extract_profiles_from_mesh, mesh_contour_to_curves - Mesh overloads: extrude/revolve/sweep/loft with HalfedgeMesh input - 7/8 tests pass (1 minor contour bug, non-blocking) VDE-023 (High): Marked Fixed — VDE-022 position API resolves ID mapping VDE-024 (High): CAM mesh contour extraction - extract_contour_from_mesh, contour_toolpath/pocket_toolpath mesh variants - 11/11 tests pass VDE-025 (Medium): MeshData→Assembly batch build - PartInput struct, build_assembly_from_meshes with OpenMP - 11/11 tests pass
119 lines
4.5 KiB
C++
119 lines
4.5 KiB
C++
#pragma once
|
|
/**
|
|
* @file cam_mesh.h
|
|
* @brief CAM mesh contour 提取 API — 从 HalfedgeMesh 提取截面轮廓并生成刀路
|
|
*
|
|
* 提供:
|
|
* - extract_contour_from_mesh: 射线平面切割 mesh → 截面交线段排序 → NURBS 曲线拟合
|
|
* - contour_toolpath (mesh 版): 基于 mesh 截面轮廓生成轮廓加工刀路
|
|
* - pocket_toolpath (mesh 版): 基于 mesh 截面轮廓+孤岛生成口袋加工刀路
|
|
*
|
|
* @ingroup core
|
|
*/
|
|
#include "vde/core/point.h"
|
|
#include "vde/core/cam_toolpath.h"
|
|
#include "vde/core/cam_strategies.h"
|
|
#include "vde/mesh/halfedge_mesh.h"
|
|
#include "vde/curves/nurbs_curve.h"
|
|
#include <vector>
|
|
|
|
namespace vde::core {
|
|
|
|
// ═══════════════════════════════════════════════════════════════════════════
|
|
// 参数定义
|
|
// ═══════════════════════════════════════════════════════════════════════════
|
|
|
|
/// 轮廓加工参数(mesh 版)
|
|
struct ContourParams {
|
|
double safe_z = 10.0; ///< 安全高度 (mm)
|
|
double step_down = 1.0; ///< 每层切深 (mm)
|
|
double feed_rate = 800.0; ///< 进给速度 (mm/min)
|
|
double stock_to_leave = 0.0; ///< 留量 (mm)
|
|
};
|
|
|
|
/// 口袋加工参数(mesh 版)
|
|
struct PocketParams {
|
|
double step_over = 2.0; ///< 横向步距 (mm)
|
|
double safe_z = 10.0; ///< 安全高度 (mm)
|
|
double step_down = 1.0; ///< 每层切深 (mm)
|
|
double feed_rate = 800.0; ///< 进给速度 (mm/min)
|
|
double cut_angle = 0.0; ///< 平行走刀角度(度,0=水平)
|
|
};
|
|
|
|
// ═══════════════════════════════════════════════════════════════════════════
|
|
// API 函数
|
|
// ═══════════════════════════════════════════════════════════════════════════
|
|
|
|
/// 从 HalfedgeMesh 在指定 Z 高度提取截面轮廓
|
|
///
|
|
/// 算法流程:
|
|
/// 1. 遍历所有面,对每条边做 Z 平面相交测试
|
|
/// 2. 收集所有交线段端点 (2D)
|
|
/// 3. 按端点近邻将线段连接为闭环
|
|
/// 4. 对每个闭环拟合为 NURBS 曲线
|
|
///
|
|
/// @param mesh 输入半边形网格
|
|
/// @param z_height 截面 Z 高度
|
|
/// @return 截面轮廓 NURBS 曲线列表(每条曲线为一个闭合轮廓)
|
|
///
|
|
/// @ingroup core
|
|
[[nodiscard]] std::vector<curves::NurbsCurve> extract_contour_from_mesh(
|
|
const mesh::HalfedgeMesh& mesh,
|
|
double z_height);
|
|
|
|
/// 从 HalfedgeMesh 在指定 Z 高度提取截面轮廓(VDE-024 规范命名)
|
|
///
|
|
/// 等效于 extract_contour_from_mesh。
|
|
///
|
|
/// @param mesh 输入半边形网格
|
|
/// @param z_height 截面 Z 高度
|
|
/// @return 截面轮廓 NURBS 曲线列表
|
|
///
|
|
/// @ingroup core
|
|
[[nodiscard]] inline std::vector<curves::NurbsCurve> extract_slice_contour(
|
|
const mesh::HalfedgeMesh& mesh,
|
|
double z_height)
|
|
{
|
|
return extract_contour_from_mesh(mesh, z_height);
|
|
}
|
|
|
|
/// 基于 mesh 截面生成轮廓加工刀路
|
|
///
|
|
/// 在指定 Z 高度提取 mesh 截面轮廓,并沿轮廓生成加工刀路。
|
|
/// 支持分层下刀(step_down 控制每层深度)。
|
|
///
|
|
/// @param mesh 输入半边形网格
|
|
/// @param z_height 目标加工 Z 高度
|
|
/// @param tool 使用的刀具
|
|
/// @param params 轮廓加工参数
|
|
/// @return 轮廓加工刀路
|
|
///
|
|
/// @ingroup core
|
|
[[nodiscard]] Toolpath contour_toolpath(
|
|
const mesh::HalfedgeMesh& mesh,
|
|
double z_height,
|
|
const Tool& tool,
|
|
const ContourParams& params);
|
|
|
|
/// 基于 mesh 截面生成口袋加工刀路
|
|
///
|
|
/// 在指定 Z 高度提取 mesh 外轮廓和孤岛轮廓,生成平行走刀填充刀路。
|
|
/// 对边界轮廓裁剪走刀线段,跳过孤岛区域。
|
|
///
|
|
/// @param mesh 输入半边形网格(外边界)
|
|
/// @param islands 内部孤岛网格列表
|
|
/// @param z_height 目标加工 Z 高度
|
|
/// @param tool 使用的刀具
|
|
/// @param params 口袋加工参数
|
|
/// @return 口袋加工刀路
|
|
///
|
|
/// @ingroup core
|
|
[[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
|