I’m working on performing a Laplacian smooth on an ofMesh. In order to execute the algorithm I need to be able to find the vertices that are adjacent to any given vertex, i.e. the ones with which it shares triangles.
I know that I could iterate through the mesh’s vertices and construct a directed acyclic graph based on the order that the vertices appear in the array (i.e. assuming it’s a triangle mesh) and then query that to get the adjacent vertices for any given vertex.
Before I set about all of that, though, is there a simpler way to do this? For example, is this connectivity data already stored internally to the mesh in such a way that I could simply query it? If not, would something like this be of interest? (i.e. would an implementation of a connectivity graph be a useful addition to ofMesh?)
I ended up doing it myself. It wasn’t that bad. The code is here:
That gist includes three functions: buildGraph(), smoothMesh(), and performSmooth(). buildGraph() calculates the DAG of vertex connectivity for a triangle mesh. smoothMesh() runs through multiple iterations of performSmooth() which uses the DAG created by buildGraph() to perform a single iteration of Laplacian smoothing on the mesh.
This only works if you have a mesh with each vertex once and then indices indicating connectivity. It’s pretty fast, especially after the DAG is created.
It does seem like having something like this inside of ofMesh would be nice. Obviously, it would have to be able to handle meshes with QUAD connectivity as well as triangles, but that wouldn’t be that different, just some minor changes in the DAG construction.