It's the first time I use OpenMesh and I am trying to do a very simple function to compute the valence of all vertex in a mesh.
My first attempt looks like this
Mesh::VertexIter vIterator, vBegin, vEnd;
Mesh::HalfedgeHandle initialEdge, nextEdge;
vBegin = mesh_.vertices_begin();
vEnd = mesh_.vertices_end();
int vertexValence;
for (vIterator = vBegin; vIterator != vEnd; ++vIterator) {
initialEdge = mesh_.halfedge_handle(vIterator.handle());
nextEdge = mesh_.next_halfedge_handle(initialEdge);
vertexValence = 0;
while (nextEdge != initialEdge) {
vertexValence++;
nextEdge = mesh_.next_halfedge_handle(nextEdge);
}
if(vIterator == vBegin){
std::cout << "myCount = " << vertexValence << std::endl; // prints 2
std::cout << "meshCount = "<< mesh_.valence(vIterator)<< std::endl; // prints 10
}
}
The valence count is different from what the mesh counts (see std::cout). I know I am missing something, can anyone see where's the error?
UPDATE
I made it work by using the following code
for(vIterator = vBegin; vIterator != vEnd; ++vIterator){
vertexValence = 0;
for (voIterator = mesh_.voh_iter(vIterator); voIterator; ++voIterator) {
vertexValence++;
}
if(vIterator == vBegin){
std::cout << "myCount = " << vertexValence << std::endl;
std::cout << "openMeshCount = " << mesh_.valence(vIterator) << std::endl;
}
}
Now both numbers match. However, I would like to know if it is possible to implement the same with the first code I put. The idea should be the same.
You should try this :
for (vIterator = vBegin; vIterator != vEnd; ++vIterator) {
vertexValence = 0;
initialEdge = mesh_.halfedge_handle(vIterator.handle());
nextEdge = initialEdge;
do {
vertexValence++;
oppositeEdge = mesh_.opposite_halfedge_handle(nextEdge);
nextEdge = mesh_.next_halfedge_handle(oppositeEdge);
} while (initialEdge != nextEdge);
}
You have to use the opposite halfedge to go back to the original vertex, take a look at this page, there is a brief description of the halfedge data structure.