ViewDesignEngine  3.1.0
高性能 CAD 计算几何引擎
vde::mesh::HalfedgeMesh类 参考

半边数据结构三角网格 更多...

#include <halfedge_mesh.h>

Public 成员函数

 HalfedgeMesh ()=default
 
void clear ()
 清空所有数据 更多...
 
int add_vertex (const Point3D &p)
 添加顶点 更多...
 
int add_face (const std::vector< int > &vertex_indices)
 添加面 更多...
 
void build_from_triangles (const std::vector< Point3D > &verts, const std::vector< std::array< int, 3 >> &tris)
 从三角形列表批量构建半边形网格 更多...
 
size_t num_vertices () const
 顶点数量 更多...
 
size_t num_faces () const
 面数量 更多...
 
size_t num_edges () const
 边数量 更多...
 
const Point3D & vertex (size_t idx) const
 访问顶点 更多...
 
const Faceface (size_t idx) const
 访问面 更多...
 
const Halfedgehalfedge (size_t idx) const
 访问半边 更多...
 
void set_vertex (size_t idx, const Point3D &p)
 更新顶点位置 更多...
 
std::vector< int > face_vertices (int fi) const
 获取面的所有顶点索引(按环绕顺序) 更多...
 
std::vector< int > vertex_faces (int vi) const
 获取顶点的邻面索引环 更多...
 
bool is_boundary_edge (int hei) const
 是否为边界半边 更多...
 
bool is_boundary_vertex (int vi) const
 是否为边界顶点 更多...
 
Vector3D face_normal (int fi) const
 面法向(几何法向,非归一化?由实现决定) 更多...
 
Vector3D vertex_normal (int vi) const
 顶点法向(邻面法向的面积加权平均) 更多...
 
void update_normals ()
 重新计算所有面法向和顶点法向 更多...
 
AABB3D bounds () const
 网格包围盒 更多...
 
FaceRange faces_range () const
 获取所有面范围(range-based for 支持) 更多...
 
VertexOneRing vertex_one_ring (int vi) const
 获取顶点的 1-ring 邻域迭代器 更多...
 

详细描述

半边数据结构三角网格

核心拓扑数据结构,支持 O(1) 访问面的邻面、顶点的邻面环、 边界检测等拓扑查询。数据内部一致性由构造方法保证。

数据成员:

  • vertices_: 顶点位置数组
  • halfedges_: 半边数组,相邻索引为对侧半边(0↔1, 2↔3, ...)
  • faces_: 面数组,每个面对应一条起始半边
  • face_normals_ / vertex_normals_: 延迟计算的法向缓存

在文件 halfedge_mesh.h54 行定义.

构造及析构函数说明

◆ HalfedgeMesh()

vde::mesh::HalfedgeMesh::HalfedgeMesh ( )
default

成员函数说明

◆ add_face()

int vde::mesh::HalfedgeMesh::add_face ( const std::vector< int > &  vertex_indices)

添加面

参数
vertex_indices按逆时针顺序排列的顶点索引(至少 3 个)
返回
新面的索引,失败返回 -1
注解
自动创建/查找半边并设置对侧关系;面法向遵循右手定则

◆ add_vertex()

int vde::mesh::HalfedgeMesh::add_vertex ( const Point3D &  p)

添加顶点

参数
p3D 坐标
返回
新顶点的索引(0-based)

◆ bounds()

AABB3D vde::mesh::HalfedgeMesh::bounds ( ) const

网格包围盒

返回
AABB3D 轴对齐包围盒

◆ build_from_triangles()

void vde::mesh::HalfedgeMesh::build_from_triangles ( const std::vector< Point3D > &  verts,
const std::vector< std::array< int, 3 >> &  tris 
)

从三角形列表批量构建半边形网格

参数
verts顶点位置数组
tris三角形索引数组,每个 {i0,i1,i2}
注解
等价于反复调用 add_vertex + add_face,但内部做批处理优化
mesh.build_from_triangles(vertices, triangles);

◆ clear()

void vde::mesh::HalfedgeMesh::clear ( )

清空所有数据

◆ face()

const Face& vde::mesh::HalfedgeMesh::face ( size_t  idx) const
inline

访问面

参数
idx面索引
返回
Face 只读引用

在文件 halfedge_mesh.h125 行定义.

◆ face_normal()

Vector3D vde::mesh::HalfedgeMesh::face_normal ( int  fi) const

面法向(几何法向,非归一化?由实现决定)

参数
fi面索引
返回
(v1-v0)×(v2-v0) 归一化结果

◆ face_vertices()

std::vector<int> vde::mesh::HalfedgeMesh::face_vertices ( int  fi) const

获取面的所有顶点索引(按环绕顺序)

参数
fi面索引
返回
顶点索引序列

◆ faces_range()

FaceRange vde::mesh::HalfedgeMesh::faces_range ( ) const

获取所有面范围(range-based for 支持)

返回
FaceRange 对象
for (auto& f : mesh.faces_range()) { ... }

◆ halfedge()

const Halfedge& vde::mesh::HalfedgeMesh::halfedge ( size_t  idx) const
inline

访问半边

参数
idx半边索引
返回
Halfedge 只读引用

在文件 halfedge_mesh.h132 行定义.

◆ is_boundary_edge()

bool vde::mesh::HalfedgeMesh::is_boundary_edge ( int  hei) const
inline

是否为边界半边

参数
hei半边索引
返回
没有所属面时为 true

在文件 halfedge_mesh.h163 行定义.

◆ is_boundary_vertex()

bool vde::mesh::HalfedgeMesh::is_boundary_vertex ( int  vi) const

是否为边界顶点

参数
vi顶点索引
返回
邻接任何边界半边时为 true

◆ num_edges()

size_t vde::mesh::HalfedgeMesh::num_edges ( ) const
inline

边数量

返回
halfedges_.size() / 2

在文件 halfedge_mesh.h111 行定义.

◆ num_faces()

size_t vde::mesh::HalfedgeMesh::num_faces ( ) const
inline

面数量

返回
faces_ 大小

在文件 halfedge_mesh.h105 行定义.

◆ num_vertices()

size_t vde::mesh::HalfedgeMesh::num_vertices ( ) const
inline

顶点数量

返回
vertices_ 大小

在文件 halfedge_mesh.h99 行定义.

◆ set_vertex()

void vde::mesh::HalfedgeMesh::set_vertex ( size_t  idx,
const Point3D &  p 
)
inline

更新顶点位置

参数
idx顶点索引
p新坐标
注解
标记法向缓存为脏,下次查询时重新计算

在文件 halfedge_mesh.h140 行定义.

◆ update_normals()

void vde::mesh::HalfedgeMesh::update_normals ( )

重新计算所有面法向和顶点法向

注解
修改顶点位置后自动标记脏位,调用此方法触发重新计算

◆ vertex()

const Point3D& vde::mesh::HalfedgeMesh::vertex ( size_t  idx) const
inline

访问顶点

参数
idx顶点索引,0 ≤ idx < num_vertices()
返回
顶点坐标只读引用

在文件 halfedge_mesh.h118 行定义.

◆ vertex_faces()

std::vector<int> vde::mesh::HalfedgeMesh::vertex_faces ( int  vi) const

获取顶点的邻面索引环

参数
vi顶点索引
返回
所有以 vi 为顶点的面索引

◆ vertex_normal()

Vector3D vde::mesh::HalfedgeMesh::vertex_normal ( int  vi) const

顶点法向(邻面法向的面积加权平均)

参数
vi顶点索引
返回
归一化顶点法向

◆ vertex_one_ring()

VertexOneRing vde::mesh::HalfedgeMesh::vertex_one_ring ( int  vi) const

获取顶点的 1-ring 邻域迭代器

参数
vi顶点索引
返回
VertexOneRing 对象
for (int vj : mesh.vertex_one_ring(vi)) {
// vj 是 vi 的直接邻居
}

该类的文档由以下文件生成: