MeshEdit 1 - Halfedge Mesh 半边数据结构

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 = hnext();				// 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)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值