Files

291 lines
7.6 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# API 使用手册
> 常用 API 速查与代码示例
## 命名约定
```cpp
namespace vde::brep { /* B-Rep 建模 */ }
namespace vde::curves { /* 曲线曲面 */ }
namespace vde::mesh { /* 网格处理 */ }
namespace vde::core { /* 基础类型(重新导出 foundation 定义) */ }
namespace vde::foundation { /* IO格式 */ }
// 基础类型(Point3D 定义于 vde::foundation,经 vde::core 重新导出)
using vde::core::Point3D; // 3D点,.x() .y() .z()
using vde::core::Vector3D; // 3D向量,.dot() .cross() .norm() .normalized()
using vde::core::AABB3D; // 包围盒,.min() .max() .extent() .intersects() .expand()
```
---
## B-Rep 建模
### 创建基本体
```cpp
#include <vde/brep/modeling.h>
using namespace vde::brep;
auto box = make_box(2, 3, 4); // 宽×深×高
auto cyl = make_cylinder(1.5, 6, 32); // 半径, 高度, 分段
auto sphere = make_sphere(2, 32, 16); // 半径, u分段, v分段
// 查询
size_t n_faces = box.num_faces();
auto bb = box.bounds(); // AABB3D
auto mesh = box.to_mesh(0.01); // HalfedgeMesh
```
### 布尔运算
```cpp
#include <vde/brep/brep_boolean.h>
auto result_union = brep_union(a, b);
auto result_intersection = brep_intersection(a, b);
auto result_difference = brep_difference(a, b);
```
### 拓扑修复与验证
```cpp
#include <vde/brep/brep_heal.h>
#include <vde/brep/brep_validate.h>
heal_topology(body); // 一站式修复
heal_gaps(body, 1e-6); // 合并临近顶点
heal_orientation(body); // 统一面方向
auto report = validate(body); // 验证
// report.valid, report.errors, report.warnings
```
### 直接建模
```cpp
#include <vde/brep/direct_modeling.h>
// 所有直接建模操作均返回 DirectModelingResult
// (.success / .body / .errors / .warnings)
auto pulled = push_pull(body, face_id, 5.0); // 挤出5mm
auto tweaked = tweak_face(body, face_id, 2.0); // 面偏移2mm
auto moved = move_face(body, face_id, transform);
auto scaled = scale_body(body, {2, 1, 1}); // X方向放大2倍
auto mirrored = mirror_body(body, plane); // 镜像
// if (pulled.success) { auto new_body = pulled.body; }
```
---
## 曲线曲面
### NURBS 曲面操作
```cpp
#include <vde/curves/nurbs_surface.h>
#include <vde/curves/generative_surfaces.h>
using namespace vde::curves;
// 创建
auto ruled = NurbsSurface::ruled(curve1, curve2);
auto rev = NurbsSurface::revolve(profile, origin, axis, M_PI);
// 求值
Point3D p = surf.evaluate(0.5, 0.5);
Vector3D n = surf.normal(0.5, 0.5);
// 生成曲面
auto swept = sweep_surface(profile, path, SweepOption{SweepType::Explicit});
auto lofted = loft_surface(sections); // 放样
auto netted = net_surface(u_curves, v_curves); // 网格面
```
### 曲面编辑
```cpp
#include <vde/curves/surface_editing.h>
#include <vde/curves/continuity_types.h>
auto matched = match_surface(target, reference, BoundaryEdge::UMax,
MatchSurfaceOptions{.continuity = ContinuityLevel::G2});
auto edited = control_point_edit(surf, {{0, 0}}, {new_pos});
```
### 曲面分析
```cpp
#include <vde/curves/surface_analysis.h>
#include <vde/curves/surface_continuity.h>
auto cmap = curvature_map(surf, 64, 64); // 曲率图
auto zebra = zebra_stripe(surf, light_dir); // 斑马纹
auto cont = surface_continuity(a, b, edge); // 连续性分析
```
---
## 格式 IO
### STEP/IGES
```cpp
#include <vde/brep/step_import.h>
#include <vde/brep/step_export.h>
#include <vde/brep/iges_import.h>
#include <vde/brep/iges_export.h>
using namespace vde::brep;
auto bodies = import_step("input.step"); // 返回 vector<BrepModel>
auto bodies2 = import_step_from_string(step_data);
export_step_file("output.step", bodies); // (路径, 实体列表)
auto iges = import_iges("input.igs");
export_iges_file("output.igs", iges);
```
### 工业格式
```cpp
#include <vde/foundation/industrial_formats.h>
using namespace vde::io;
auto body = import_parasolid_xt("model.x_t"); // Parasolid XT
auto body = import_acis_sat("model.sat"); // ACIS SAT
auto body = import_jt("model.jt"); // JT
auto bodies = import_ifc("building.ifc"); // IFC(返回 vector<BrepModel>)
export_jt(body, "output.jt");
```
### 网格格式
```cpp
// STL/OBJ/PLY/glTF/3MF 均在 foundation 模块
#include <vde/foundation/io_stl.h>
#include <vde/foundation/io_gltf.h>
auto tris = read_stl("input.stl"); // STL 读取(StlTriangle 列表)
write_stl("output.stl", tris); // STL 写出(二进制)
write_gltf("output.glb", mesh, GltfOptions{}); // glTF Binary
```
---
## CAM 加工
```cpp
// CAM 是独立模块:头文件在 include/vde_cam/,命名空间 vde::cam
#include <vde_cam/cam_strategies.h>
#include <vde_cam/cam_5axis.h>
using namespace vde::cam;
Tool tool; // 直径10mm 4刃 平底铣刀
tool.type = ToolType::ENDMILL;
tool.diameter = 10.0;
tool.flutes = 4;
tool.length = 50.0;
// 3轴
auto rough = roughing_toolpath(body, tool, RoughingParams{});
auto finish = finishing_toolpath(body, tool, FinishingParams{});
auto drill = drilling_toolpath(points, tool, DrillingCycle::G83); // 啄钻
// 5轴
auto swarf = swarf_machining(surface, tool, SwarfParams{});
auto m5 = multi_axis_finishing(surface, tool, MultiAxisFinishingParams{});
// 后处理
FanucPost post;
auto gcode = post.post_process(toolpath);
```
---
## 装配体
```cpp
#include <vde/brep/assembly.h>
#include <vde/brep/assembly_constraints.h>
using namespace vde::brep;
using vde::core::translate;
Assembly assy{"robot_arm"};
auto* base = assy.root().add_part("base", make_box(10, 10, 2));
auto* arm = assy.root().add_subassembly("arm", translate(0, 0, 2));
arm->add_part("link", make_cylinder(0.5, 8));
// 约束(node_b 移动以满足约束)
apply_constraint(assy, base, arm, ConstraintType::Coincident);
```
---
## 网格处理
```cpp
#include <vde/mesh/halfedge_mesh.h>
#include <vde/mesh/mesh_simplify.h>
#include <vde/mesh/mesh_smooth.h>
#include <vde/mesh/marching_cubes.h>
#include <vde/mesh/fea_mesh.h>
// 简化
auto simplified = simplify_mesh(mesh, SimplifyOptions{0.5}); // 保留50%面
// 平滑
auto smoothed = smooth_laplacian(mesh, 10, 0.5);
// SDF → Mesh(f 为 std::function<double(double,double,double)>)
auto mc = marching_cubes(f, 0.0, bmin, bmax, 64);
// FEA网格
auto tets = tetrahedral_mesh(body, TetMeshParams{});
FaceRegion src{{0, 1, 2, 3}, "top"}; // 源面(面顶点索引)
FaceRegion dst{{4, 5, 6, 7}, "bottom"}; // 目标面
auto hex = mapped_hex_mesh(body, src, dst, 4);
```
---
## 点云/逆向工程
```cpp
#include <vde/mesh/point_cloud.h>
#include <vde/mesh/reverse_engineering.h>
auto cloud = PointCloud::load_ply("scan.ply"); // 静态工厂
auto downsampled = cloud.voxel_downsample(0.5); // 返回新点云
auto with_normals = downsampled.normal_estimation(16);
auto mesh = point_cloud_to_mesh(with_normals);
auto surf = mesh_to_nurbs_surface(mesh);
```
---
## 性能调优
```cpp
#include <vde/brep/parallel_boolean.h> // vde::brep::set_parallel_threads
#include <vde_infra/performance_tuning.h> // vde::infra::ParallelTaskGraph
set_parallel_threads(8); // 设置并行布尔/网格处理线程数(0 = 自动)
ParallelTaskGraph graph(4); // 4 线程并行任务图
graph.add_task({0, "read", []{ /* 读取数据 */ }, {}});
graph.add_task({1, "proc", []{ /* 处理 */ }, {0}}); // 依赖任务 0
graph.execute();
// 使用内存池
ObjectPool<Point3D> pool;
auto* p = pool.acquire();
pool.release(p);
// 事务
Transaction txn;
txn.begin();
// ... 操作 ...
txn.commit(); // 或 txn.rollback();
```