实现 VDE-353 提案 2:simulate_material_removal(stock, toolpath, tool_diameter, tool_flute_length) → BrepModel。 以立铣刀参数调用既有 material_removal_simulation 得剩余材料网格, 再经 brep::mesh_to_brep_model 转回 B-Rep;刀具直径/刃长非法或无剩余 网格时原样返回毛坯。 - include/vde_cam/cam_toolpath.h:前置声明 brep::BrepModel + 声明 - src/vde_cam/cam_toolpath.cpp:实现 - tests/cam/test_cam_toolpath.cpp:VDE353Test 2 项(含"剩余体积严格小于 毛坯"的真实性校验,验证确非空转) 回归:test_cam_toolpath 13/13 全绿。 更新 VDE-353.md 与 audit-proposal-batch.md(已实现 28→29 / 缺失 252→251)。
129 lines
4.3 KiB
C++
129 lines
4.3 KiB
C++
#pragma once
|
||
#include "vde/core/point.h"
|
||
#include <vector>
|
||
#include <string>
|
||
|
||
namespace vde::curves {
|
||
class NurbsCurve;
|
||
}
|
||
|
||
namespace vde::brep {
|
||
class BrepModel;
|
||
}
|
||
|
||
namespace vde::cam {
|
||
|
||
using core::Point3D;
|
||
using core::Vector3D;
|
||
|
||
/// Toolpath segment types
|
||
enum class PathSegmentType {
|
||
Rapid, ///< G0 — rapid traverse (不切削)
|
||
Linear, ///< G1 — linear feed (直线切削)
|
||
ArcCW, ///< G2 — clockwise arc
|
||
ArcCCW ///< G3 — counter-clockwise arc
|
||
};
|
||
|
||
/// Single toolpath segment
|
||
struct PathSegment {
|
||
Point3D start;
|
||
Point3D end;
|
||
Point3D center = Point3D::Zero(); ///< arc center (for G2/G3)
|
||
PathSegmentType type = PathSegmentType::Linear;
|
||
double feed_rate = 1000.0; ///< mm/min
|
||
double z_depth = 0.0; ///< Z cutting depth
|
||
};
|
||
|
||
/// Complete toolpath for one operation
|
||
struct Toolpath {
|
||
std::string name;
|
||
std::vector<PathSegment> segments;
|
||
double safe_z = 10.0; ///< safe retract height
|
||
double cut_z = -1.0; ///< cutting depth
|
||
double step_down = 0.5; ///< depth per pass
|
||
};
|
||
|
||
/// Offset a planar curve outward by a distance
|
||
///
|
||
/// Samples the curve at regular intervals, computes the normal at each sample,
|
||
/// offsets each point, and fits a NURBS curve through the offset points.
|
||
///
|
||
/// @param curve Input curve (must lie in XY plane, Z coordinate ignored)
|
||
/// @param distance Offset distance (> 0 for offset outward, < 0 for inward)
|
||
/// @return Offset curve
|
||
///
|
||
/// @ingroup core
|
||
[[nodiscard]] curves::NurbsCurve offset_contour(
|
||
const curves::NurbsCurve& curve, double distance);
|
||
|
||
/// Generate contour toolpath (follow curve at cutting depth)
|
||
///
|
||
/// Creates multiple depth passes from safe_z stepping down to cut_depth.
|
||
/// Adds rapid moves between passes.
|
||
///
|
||
/// @param curve Input contour curve
|
||
/// @param cut_depth Cutting Z depth
|
||
/// @param safe_z Safe retract Z height
|
||
/// @param step_down Depth per pass
|
||
/// @return Toolpath with spiral-down contour cuts
|
||
///
|
||
/// @ingroup core
|
||
[[nodiscard]] Toolpath contour_toolpath(
|
||
const curves::NurbsCurve& curve,
|
||
double cut_depth, double safe_z = 10.0, double step_down = 1.0);
|
||
|
||
/// Generate pocket toolpath (clear area inside contour, zigzag fill)
|
||
///
|
||
/// Computes the bounding box of the boundary, generates zigzag lines at the
|
||
/// specified angle, clips them to the boundary and islands, then sorts
|
||
/// segments for efficient tool movement.
|
||
///
|
||
/// @param boundary Outer boundary curve
|
||
/// @param islands Interior island curves (optional)
|
||
/// @param cut_depth Cutting Z depth
|
||
/// @param step_over Tool step-over (fraction of tool diameter)
|
||
/// @param angle Zigzag angle in degrees (0=horizontal, 90=vertical)
|
||
/// @return Toolpath with spiral-down pocket cuts
|
||
///
|
||
/// @ingroup core
|
||
[[nodiscard]] Toolpath pocket_toolpath(
|
||
const curves::NurbsCurve& boundary,
|
||
const std::vector<curves::NurbsCurve>& islands,
|
||
double cut_depth, double step_over = 0.5, double angle = 0.0);
|
||
|
||
/// Export toolpath to G-code string (basic ISO format)
|
||
///
|
||
/// @param tp Toolpath to export
|
||
/// @return G-code string
|
||
///
|
||
/// @ingroup core
|
||
[[nodiscard]] std::string export_gcode(const Toolpath& tp);
|
||
|
||
// ═══════════════════════════════════════════════════════════
|
||
// VDE-353 提案 2:刀路材料去除仿真
|
||
// ═══════════════════════════════════════════════════════════
|
||
|
||
/**
|
||
* @brief 刀路材料去除仿真(VDE-353 提案 2)
|
||
*
|
||
* 以直径 `tool_diameter`、刃长 `tool_flute_length` 的立铣刀沿 `toolpath`
|
||
* 去除毛坯材料,输出加工后的剩余材料实体(B-Rep)。
|
||
* 内部复用 `material_removal_simulation`(网格级仿真)并以
|
||
* `mesh_to_brep_model` 转回 B-Rep。
|
||
*
|
||
* @param stock 毛坯实体
|
||
* @param toolpath 加工刀路
|
||
* @param tool_diameter 刀具直径(>0)
|
||
* @param tool_flute_length 有效刃长(>0)
|
||
* @return 加工后剩余材料实体;参数非法或仿真无剩余网格时返回原毛坯
|
||
*
|
||
* @note 调用方需包含 `vde/brep/brep.h` 以获得 BrepModel 完整类型。
|
||
*
|
||
* @ingroup core
|
||
*/
|
||
[[nodiscard]] brep::BrepModel simulate_material_removal(
|
||
const brep::BrepModel& stock, const Toolpath& toolpath,
|
||
double tool_diameter, double tool_flute_length);
|
||
|
||
} // namespace vde::cam
|