docs/reference/: README.md (136) — index api-reference-core.md (690) — Matrix4D/CAM/platform api-reference-brep.md (549) — section/gizmo/dimension/hlr/snap/gear api-reference-curves.md (304) — surface_tools/factory methods api-reference-foundation.md (342) — 22 formats + DWG bridge api-reference-mesh.md (248) — blend/point cloud api-reference-spatial.md (203) — BVH indices api-reference-capi.md (238) — C API + Python ctypes format-support.md (118) — 22 formats matrix changelog.md (187) — v1.0.1 additions
8.9 KiB
8.9 KiB
Mesh 模块 API 参考
网格模块 — 半边网格、网格→曲线转换、点云(E57/LAS)、网格曲面混合
模块概述
mesh 模块提供三角网格处理、网格与 NURBS 之间的桥接、点云数据处理能力。核心数据结构为 HalfedgeMesh(半边网格),支持简化、平滑、布尔、参数化、修复等操作。
头文件列表
| 头文件 | 说明 |
|---|---|
halfedge_mesh.h |
半边网格核心数据结构 |
mesh_to_curve.h |
网格→NURBS 曲线桥接(VDE-021) |
mesh_blend.h |
网格曲面混合(fillet/chamfer/shell/draft) |
point_cloud.h |
点云(E57/LAS/PLY/PTX 加载,降采样,法线估计) |
mesh_simplify.h |
网格简化 |
mesh_smooth.h |
网格平滑 |
mesh_repair.h |
网格修复 |
mesh_boolean.h |
网格布尔运算 |
mesh_curvature.h |
网格曲率分析 |
mesh_parameterize.h |
网格参数化 |
mesh_quality.h |
网格质量评估 |
mesh_lod.h |
网格 LOD |
marching_cubes.h |
Marching Cubes 等值面提取 |
delaunay_2d.h |
二维 Delaunay 三角剖分 |
delaunay_3d.h |
三维 Delaunay 四面体剖分 |
cdt_2d.h |
约束 Delaunay 三角剖分 |
alpha_shapes.h |
Alpha Shapes |
geodesic.h |
测地线距离 |
reverse_engineering.h |
逆向工程(点云→B-Rep) |
fea_mesh.h |
FEA 有限元网格 |
visualization_quality.h |
可视化质量 |
parallel_mc.h |
并行 Marching Cubes |
详细 API
halfedge_mesh.h — 半边网格核心
namespace vde::mesh {
struct HalfedgeMesh {
std::vector<Point3D> vertices;
std::vector<std::array<int, 3>> faces; // 三角形面(索引三元组)
std::vector<int> halfedges; // 半边数组
[[nodiscard]] size_t num_vertices() const;
[[nodiscard]] size_t num_faces() const;
[[nodiscard]] size_t num_edges() const;
[[nodiscard]] AABB3D bounds() const;
void add_vertex(const Point3D& v);
int add_face(int v0, int v1, int v2);
void remove_face(int face_id);
// 半边邻接查询
[[nodiscard]] int opposite_halfedge(int he) const;
[[nodiscard]] int next_halfedge(int he) const;
[[nodiscard]] int prev_halfedge(int he) const;
[[nodiscard]] int halfedge_face(int he) const;
[[nodiscard]] int halfedge_vertex(int he) const;
// 边界检测
[[nodiscard]] bool is_boundary_edge(int edge_id) const;
[[nodiscard]] bool is_boundary_vertex(int vertex_id) const;
[[nodiscard]] bool is_closed() const; // 是否为闭合流形
// 拓扑查询
[[nodiscard]] std::vector<int> vertex_neighbors(int vertex_id) const;
[[nodiscard]] std::vector<int> face_neighbors(int face_id) const;
};
} // namespace vde::mesh
mesh_to_curve.h — 网格→曲线桥接(VDE-021)
namespace vde::mesh {
[[nodiscard]] curves::NurbsCurve mesh_boundary_to_curve(const HalfedgeMesh& mesh); // 边界环→NURBS
[[nodiscard]] curves::NurbsCurve extract_boundary_curves(const HalfedgeMesh& mesh); // 等效别名
[[nodiscard]] std::vector<curves::NurbsCurve> extract_profiles_from_mesh(
const HalfedgeMesh& mesh, const core::Vector3D& projection_axis); // 多轮廓提取
[[nodiscard]] std::vector<curves::NurbsCurve> mesh_to_directed_curve(
const HalfedgeMesh& mesh, const core::Vector3D& axis); // 有向轮廓(别名)
[[nodiscard]] std::vector<curves::NurbsCurve> mesh_contour_to_curves(
const HalfedgeMesh& mesh, double z_height); // Z 层截面轮廓
} // namespace vde::mesh
mesh_blend.h — 网格曲面混合
namespace vde::mesh {
[[nodiscard]] HalfedgeMesh mesh_fillet(const HalfedgeMesh& mesh, int edge_id, double radius); // 圆角
[[nodiscard]] HalfedgeMesh mesh_chamfer(const HalfedgeMesh& mesh, int edge_id, double distance); // 倒角
[[nodiscard]] HalfedgeMesh mesh_shell(const HalfedgeMesh& mesh, int face_id, double thickness); // 抽壳
[[nodiscard]] HalfedgeMesh mesh_draft(const HalfedgeMesh& mesh, int face_id, double angle_deg, // 拔模
const Vector3D& pull_direction);
} // namespace vde::mesh
point_cloud.h — 点云
namespace vde::mesh {
class PointCloud {
public:
std::vector<Point3D> vertices;
std::vector<Vector3D> normals;
std::vector<std::array<uint8_t, 3>> colors;
std::vector<double> intensities;
PointCloud();
explicit PointCloud(std::vector<Point3D> pts);
[[nodiscard]] size_t size() const;
[[nodiscard]] bool has_normals() const;
[[nodiscard]] bool has_colors() const;
[[nodiscard]] bool has_intensity() const;
[[nodiscard]] AABB3D bounds() const;
// I/O
static PointCloud load_ply(const std::string& path); // PLY 加载
static PointCloud load_e57(const std::string& path); // E57 加载(ASTM E2807)
static PointCloud load_las(const std::string& path); // LAS/LAZ 加载(1.2/1.3/1.4)
static PointCloud load_ptx(const std::string& path); // PTX 加载(Leica)
bool save_ply(const std::string& path) const; // PLY 保存
// 滤波/降采样
[[nodiscard]] PointCloud voxel_downsample(double voxel_size) const; // 体素降采样
[[nodiscard]] PointCloud statistical_outlier_removal(int k=6, double std_ratio=1.0) const; // SOR 离群点剔除
[[nodiscard]] std::vector<size_t> curvature_aware_sampling(size_t target_count) const; // 曲率感知采样
[[nodiscard]] PointCloud smoothing_filter(double sigma_c=0.0, double sigma_n=0.3, int iterations=3) const; // 双边滤波
// 法线估计
[[nodiscard]] PointCloud normal_estimation(int k = 10) const; // kNN 法线估计
};
} // namespace vde::mesh
其余网格模块摘要
namespace vde::mesh {
// mesh_simplify.h
[[nodiscard]] HalfedgeMesh simplify_mesh(const HalfedgeMesh& mesh, double target_ratio); // 简化(QEM)
[[nodiscard]] HalfedgeMesh decimate(const HalfedgeMesh& mesh, int target_faces); // 减面
// mesh_smooth.h
[[nodiscard]] HalfedgeMesh smooth_mesh(const HalfedgeMesh& mesh, int iterations = 3, double lambda = 0.5); // Laplacian 平滑
[[nodiscard]] HalfedgeMesh taubin_smooth(const HalfedgeMesh& mesh, int iterations = 5); // Taubin 平滑
// mesh_repair.h
[[nodiscard]] HalfedgeMesh repair_mesh(const HalfedgeMesh& mesh); // 自动修复
[[nodiscard]] HalfedgeMesh fill_holes(const HalfedgeMesh& mesh); // 补洞
[[nodiscard]] HalfedgeMesh remove_duplicates(const HalfedgeMesh& mesh, double tol = 1e-8); // 去重
// mesh_boolean.h
[[nodiscard]] HalfedgeMesh mesh_union(const HalfedgeMesh& a, const HalfedgeMesh& b);
[[nodiscard]] HalfedgeMesh mesh_intersect(const HalfedgeMesh& a, const HalfedgeMesh& b);
[[nodiscard]] HalfedgeMesh mesh_subtract(const HalfedgeMesh& a, const HalfedgeMesh& b);
// marching_cubes.h
[[nodiscard]] HalfedgeMesh marching_cubes_2d(const std::function<double(double,double)>& sdf, double xmin, double xmax, double ymin, double ymax, int resolution);
[[nodiscard]] HalfedgeMesh marching_cubes_3d(const std::function<double(double,double,double)>& sdf, const AABB3D& bounds, int resolution);
// delaunay_2d.h
[[nodiscard]] std::vector<std::array<int,3>> delaunay_triangulate(const std::vector<Point2D>& points);
[[nodiscard]] std::vector<std::array<int,2>> voronoi_edges(const std::vector<Point2D>& points);
// delaunay_3d.h
[[nodiscard]] std::vector<std::array<int,4>> delaunay_tetrahedralize(const std::vector<Point3D>& points);
// geodesic.h
[[nodiscard]] std::vector<double> geodesic_distances(const HalfedgeMesh& mesh, int source_vertex);
[[nodiscard]] std::vector<int> shortest_path(const HalfedgeMesh& mesh, int from, int to);
// reverse_engineering.h
[[nodiscard]] brep::BrepModel point_cloud_to_brep(const PointCloud& cloud, double tolerance = 0.01);
} // namespace vde::mesh
代码示例
示例 1: 网格→B-Rep 建模流水线
#include <vde/mesh/mesh_to_curve.h>
#include <vde/brep/modeling.h>
using namespace vde;
// 加载 STL 网格(假设已有)
mesh::HalfedgeMesh mesh = /* ... */;
// 提取边界轮廓 → NURBS 曲线
auto profile = mesh::mesh_boundary_to_curve(mesh);
// 挤出为 B-Rep 实体
auto brep_body = brep::extrude(profile, core::Vector3D(0, 0, 10.0));
// 倒角
auto result = brep::fillet(brep_body, 0, 2.0);
示例 2: 点云处理
#include <vde/mesh/point_cloud.h>
using namespace vde::mesh;
// 加载 E57 点云(激光扫描仪数据)
auto cloud = PointCloud::load_e57("scan_001.e57");
std::cout << "原始点数: " << cloud.size() << "\n";
// 体素降采样
auto downsampled = cloud.voxel_downsample(0.01); // 1cm 体素
// 离群点剔除
auto filtered = downsampled.statistical_outlier_removal(6, 1.0);
// 法线估计
auto with_normals = filtered.normal_estimation(10);
// 保存为 PLY
with_normals.save_ply("processed.ply");