Hafledge Mesh 半边数据结构
对于一条边,它连接两个顶点 i 和 j。这条边的其中一条半边从 i 指向 j,另一条半边则从 j 指向 i。
- 两条半边方向相反
- 其中一个半边与边“左边”的面相关联;另一个半边则与“右”面有关
- twin:反方向的半边
一般来说,标准的网格元素(顶点、边和面)只知道其中的一个半边。
- 一个顶点知道它的一个“外向”半边
- 一条边知道它的两个半边中的一个
- 一个面知道它的内部有许多半边环
总之,我们可以得到以下关系:
Mesh Element 网格元素 | Pointers 指针 |
---|---|
Vertex 顶点 | halfedge (只有一条) |
Edge 边 | halfedge (只有一条) |
Face 面 | halfedge (只有一条) |
Halfedge 半边 | next、twin、vertex、edge、face |
因此,半边可以把所有元素联系起来。
例子一:打印出一个面 f 包含的所有顶点的位置
void printVertexPositions(FaceRef f) {
HalfedgeRef h = f->halfegde(); // get the first halfedge of the face
do {
VertexRef v = h->vertex(); // get the vertex of the current halfedge
cout << v->pos << endl; // print the vertex position
h = hnext(); // move to the next halfedge around the face
} while (h != f->halfedge()); // keep going until we’re back at the beginning
}
例子二:打印出一个给定的顶点包含的所有相邻顶点的位置
void printNeighborPositions(VertexRef v) {
HalfedgeRef h = v->halfedge(); // get one of the outgoing halfedge of the vertex
do {
HalfedgeRef h_twin = h->twin(); // get the vertex of the current halfedge
VertexRef vN = h_twin->vertex();// vertex is ‘source’ of the half edge
// so h->vertex() is v
// whereas h_twin->vertex() is the neighbor vertex
cout << vN->pos << endl; // print the vertex position
h = h_twin->next(); // move to the next outgoing halfedge of the vertex
} while(h != v->halfedge()); // keep going until we’re back at the beginning
}
例子三:遍历半边网格中的所有顶点
for(VertexRef v = vertices_begin(); v != vertices_end(); v++) {
printNeighborPositions(v);
}
需要注意:边是否为边界(boundary)