Where to store the id of a VertexHandle in OpenMesh?

504 views Asked by At

I am building index and vertex buffers from OpenMesh structures which I will feed into my rendering engine. Here I iterate my elements (not shown) and create VertexHandles for each of my points and then add the face.

std::vector<Mesh::VertexHandle> vhandles;

for (... 3 triangle points) {
    vhandles.push_back(mesh.add_vertex(Mesh::Point(
        point->px, point->py, point->pz)));
}

mesh.add_face(face_vhandles);

The vertex buffer for a Point appears below and I copy the vhandles data into this struct, then build an array of these to feed to the graphics engine.

struct Point
{
        float px, py, pz;   // positions
        float nx, ny, nz;   // normals
        float cx, cy, cz;   // diffuse
}

When I build the vhandles vector above, I did not add an index/id to the VertexHandle.

I need to somewheres store and have access to the id of the point with the VertexHandle iteself. Where would I store that? I've not yet found a field for this purpose within the source of a VertexHandle, but seems like something that would be needed.

1

There are 1 answers

1
Botond On BEST ANSWER

Although I'm still just getting familiar with OpenMesh, it seems to me like a bad practice to access any element by their index because these are internal indices that will be rearranged upon garbage collection. OpenMesh provides iterators and circulators to iterate over its elements. If you need random access, you can always store the handles associated to whatever index you want in a container. Also, there are the vertex_handle(), face_handle(), edge_handle() functions which give you mesh elements by their internal indices.