1

I've recently started using OpenMesh on a project where I have to refine meshes. I need to use the face split(FaceHandle _fh, Point _p) operation to insert a vertex at a triangle's centroid. But when I use this method and try to grab the faces of the newly created vertex using a VertexFaceIterator, I always get invalid faces with vertex indexes such as (87, 87, -1) or (12, 12, -1). It seems as though OpenMesh isn't updating the meshes topology after a split.

My code looks something like this. faceStartIt is what gives me these weird indexes.

    typedef OpenMesh::TriMesh_ArrayKernelT<> TriMesh;

    TriMesh::FaceIter triangleIt = mesh.faces_begin();

    for( ; triangleIt != mesh.faces_end(); )
    {            
        TriMesh::Point centroid = mesh.calc_face_centroid( *triangleIt );

        if( hasToSplit( centroid ) )
        {               
            TriMesh::VertexHandle centroidHandle = mesh.split( *triangleIt, centroid ); 
            TriMesh::VertexFaceIter faceStartIt = mesh.vf_begin( centroidHandle );
            TriMesh::VertexFaceIter faceEndIt = mesh.vf_end( centroidHandle );
            TriMesh::VertexFaceIter faceIt = faceStartIt; //faceIt++;

            for( ; faceIt != faceEndIt; ++faceIt )
            {                   
                // Do something for each face
            } 
        }
        else
        {
            ++triangleIt;
        }
    }
Krish Munot
  • 1,093
  • 2
  • 18
  • 29
murf
  • 21
  • 5
  • Show actual input and output. Also, does the `TriMesh` object guarantee that changes you make to `mesh` will not invalidate `triangleIt`? – paddy Dec 07 '16 at 02:16
  • Yes. If you don't use the `garbage_collection()` method all iterators should be valid after any operation. As for input and output, the `split` method return a valid VertexHandle with a newly created index, while `vf_begin` returns an iterator pointing to faces with these weird indexes. (87, 87, -1) and (12, 12, -1) are actual examples of what it returns. Don't know if this is what you meant by input and output. – murf Dec 07 '16 at 02:58
  • I copied your code (for the most part) and fed it an example mesh but I was unable to reproduce your bug (i.e., all handles were vaild). Can you show your code used to output the vertex handle IDs of the new faces? – jsb Dec 07 '16 at 09:31

2 Answers2

1

I figured out the problem I was having. The split method works fine, what I was doing wrong was inside the // Do something for each face commentary. For each face I was doing edge flip operations, but references were being lost because a flip causes changes on later faces being evaluated. The solution was to in one iteration, after splitting a face, insert each edge I wanted flipped in a std::set to guarantee they were unique. Then in another iteration do the actual flips on marked edges.

murf
  • 21
  • 5
0

Maybe you can instead

TriMesh::FaceIter triangleIt = mesh.faces_begin();

with

TriMesh::FaceIter triangleIt = mesh.faces_sbegin();

garbage_collection() can also be ok, but it is low coefficient.If you use face_sbegin(),the iterators will skip invalid faces.