vcg.tri.HalfEdgeTopology
vcg.tri.HalfEdgeTopology是一个半边数据结构,用于描述三维网格的拓扑结构。它提供了一个高效的方法来遍历三角形、边和顶点之间的关系。
属性:
方法:
示例代码:
#include <vcg/complex/complex.h>
#include <vcg/complex/algorithms/clean.h>
#include <vcg/complex/algorithms/update/topology.h>
using namespace vcg;
class MyVertex;
class MyEdge;
class MyFace;
struct MyUsedTypes : public UsedTypes<Use<MyVertex>::AsVertexType, Use<MyEdge>::AsEdgeType, Use<MyFace>::AsFaceType>{};
class MyVertex : public Vertex<MyUsedTypes, vertex::Coord3f, vertex::Normal3f, vertex::Qualityf, vertex::BitFlags>{};
class MyEdge : public Edge<MyUsedTypes>{};
class MyFace : public Face<MyUsedTypes, face::VertexRef, face::BitFlags>{};
class MyMesh : public vcg::tri::TriMesh<std::vector<MyVertex>, std::vector<MyFace>> {};
int main () {
MyMesh mesh;
tri::BuildBox(mesh, 2, 2, 2);
tri::Clean<MyMesh>::RemoveDuplicateVertex(mesh);
tri::UpdateTopology<MyMesh>::FaceFace(mesh);
vcg::tri::HalfEdgeTopology<MyMesh> he_Topology(mesh);
he_Topology.Build();
// 遍历顶点
for(CVertexIterator vi(mesh); !vi.End(); ++vi) {
MyVertex *v = &*vi;
auto he = he_Topology.vertEE(*v);
do {
/* 遍历当前顶点所在的半边 */
he = he_Topology.vertEE(*v, he);
} while(he != nullptr);
}
// 遍历面
for(CFaceIterator fi(mesh); !fi.End(); ++fi) {
MyFace *f = &*fi;
auto e = he_Topology.faceEE(*f);
do {
/* 遍历当前面所在的半边 */
e = he_Topology.faceEE(*f, e);
} while(e != nullptr);
}
return 0;
}