|
Easy3D 3.0.0
|
Constructing a SurfaceMesh (a tetrahedron) from vertices and face connectivity, two ways.
Overview
This is the first surface-mesh tutorial. Where a PointCloud is just a bag of points, a SurfaceMesh also records how the points are connected into faces. We build the simplest closed surface — a tetrahedron with 4 vertices and 4 triangular faces — and print its element counts. The same mesh is built twice, once with each of Easy3D's two construction APIs, so you can compare them. It is console-only; later tutorials (105/106/107) reuse this tetrahedron.
The technique
SurfaceMesh is a halfedge data structure for orientable 2-manifold polygonal meshes. Every edge is split into two oppositely oriented halfedges, and each halfedge stores links to its target vertex, its opposite twin, the next halfedge around the face, and the face it bounds. Those pointers make adjacency queries (neighbors of a vertex, faces around an edge, ...) cheap and local — see Tutorial_105_SurfaceMesh_Connectivity. The structure assumes a manifold: each edge is shared by exactly two faces (a boundary edge pairs with a null face) and the faces around a vertex form a single fan. Because of that assumption there are two ways to build a mesh: (1) call SurfaceMesh::add_vertex()/add_triangle() directly, which is only safe when you already know the input is manifold; or (2) use SurfaceMeshBuilder, which detects and repairs non-manifold configurations as it goes and is the recommended default. Faces must be given a consistent winding (counter-clockwise seen from outside) so the surface stays orientable. A tetrahedron has V=4, F=4 and E=6, satisfying Euler's formula V - E + F = 2 for a closed sphere- like surface.
Easy3D API
Running it
Console-only. With the default option (2) it prints "#face: 4", "#vertex: 4", "#edge: 6". Change the 'option' variable to 1 to build the same mesh through the direct SurfaceMesh API and observe identical counts. The mesh is a local object, so it is freed when main returns.