diff --git a/src/OpenMesh/Core/Mesh/ArrayKernel.cc b/src/OpenMesh/Core/Mesh/ArrayKernel.cc index d2f95871..7446f074 100644 --- a/src/OpenMesh/Core/Mesh/ArrayKernel.cc +++ b/src/OpenMesh/Core/Mesh/ArrayKernel.cc @@ -114,7 +114,7 @@ void ArrayKernel::garbage_collection(bool _v, bool _e, bool _f) std::vector empty_vh; std::vector empty_hh; std::vector empty_fh; - garbage_collection( _v, _e, _f, &empty_vh,&empty_hh,&empty_fh); + garbage_collection( empty_vh,empty_hh,empty_fh,_v, _e, _f); } void ArrayKernel::clear() diff --git a/src/OpenMesh/Core/Mesh/ArrayKernel.hh b/src/OpenMesh/Core/Mesh/ArrayKernel.hh index 608280ca..2fc9d2c3 100644 --- a/src/OpenMesh/Core/Mesh/ArrayKernel.hh +++ b/src/OpenMesh/Core/Mesh/ArrayKernel.hh @@ -266,6 +266,9 @@ public: * Usually if you delete primitives in OpenMesh, they are only flagged as deleted. * Only when you call garbage collection, they will be actually removed. * + * \note Garbage collection invalidates all handles. If you need to keep track of + * a set of handles, you can pass them to the second garbage collection + * function, which will update a vector of handles. * * @param _v Remove deleted vertices? * @param _e Remove deleted edges? @@ -273,13 +276,15 @@ public: */ void garbage_collection(bool _v=true, bool _e=true, bool _f=true); - /** \brief garbage collection + /** \brief garbage collection with handle tracking * * Usually if you delete primitives in OpenMesh, they are only flagged as deleted. * Only when you call garbage collection, they will be actually removed. * * \note Garbage collection invalidates all handles. If you need to keep track of - * a set of handles, you can pass vectors of pointers to the handles to this function + * a set of handles, you can pass them to this function and they will get updated. + * + * * * @param vh_to_update Vertex handles that should get updated * @param hh_to_update Halfedge handles that should get updated @@ -291,10 +296,10 @@ public: template - void garbage_collection(bool _v=true, bool _e=true, bool _f=true, - std_API_Container_VHandlePointer* vh_to_update = 0, - std_API_Container_HHandlePointer* hh_to_update = 0, - std_API_Container_FHandlePointer* fh_to_update = 0); + void garbage_collection(std_API_Container_VHandlePointer& vh_to_update, + std_API_Container_HHandlePointer& hh_to_update, + std_API_Container_FHandlePointer& fh_to_update, + bool _v=true, bool _e=true, bool _f=true); void clear(); diff --git a/src/OpenMesh/Core/Mesh/ArrayKernelT.cc b/src/OpenMesh/Core/Mesh/ArrayKernelT.cc index c8e7e88a..1abcb80a 100644 --- a/src/OpenMesh/Core/Mesh/ArrayKernelT.cc +++ b/src/OpenMesh/Core/Mesh/ArrayKernelT.cc @@ -56,11 +56,10 @@ namespace OpenMesh template -void ArrayKernel::garbage_collection(bool _v, bool _e, bool _f, - std_API_Container_VHandlePointer* vh_to_update, - std_API_Container_HHandlePointer* hh_to_update, - std_API_Container_FHandlePointer* fh_to_update - ) +void ArrayKernel::garbage_collection(std_API_Container_VHandlePointer& vh_to_update, + std_API_Container_HHandlePointer& hh_to_update, + std_API_Container_FHandlePointer& fh_to_update, + bool _v, bool _e, bool _f) { int i, i0, i1, nV(n_vertices()), nE(n_edges()), nH(2*n_edges()), nF(n_faces()); @@ -205,47 +204,37 @@ void ArrayKernel::garbage_collection(bool _v, bool _e, bool _f, } } + const int vertexCount = vertices_.size(); + const int halfedgeCount = edges_.size() * 2; + const int faceCount = faces_.size(); + // Update the vertex handles in the vertex handle vector - if ( vh_to_update ) { - - const int vertexCount = vertices_.size(); - typename std_API_Container_VHandlePointer::iterator v_it(vh_to_update->begin()), v_it_end(vh_to_update->end()); - for(; v_it != v_it_end; ++v_it) - { - if ( (*v_it)->idx() >= vertexCount ) - (*v_it)->invalidate(); - else - *(*v_it) = vh_map[(*v_it)->idx()]; - } - + typename std_API_Container_VHandlePointer::iterator v_it(vh_to_update.begin()), v_it_end(vh_to_update.end()); + for(; v_it != v_it_end; ++v_it) + { + if ( (*v_it)->idx() >= vertexCount ) + (*v_it)->invalidate(); + else + *(*v_it) = vh_map[(*v_it)->idx()]; } // Update the halfedge handles in the halfedge handle vector - if ( hh_to_update ) { - const int halfedgeCount = edges_.size() * 2; - - typename std_API_Container_HHandlePointer::iterator hh_it(hh_to_update->begin()), hh_it_end(hh_to_update->end()); - for(; hh_it != hh_it_end; ++hh_it) - { - if ( (*hh_it)->idx() >= halfedgeCount ) - (*hh_it)->invalidate(); - else - *(*hh_it) = hh_map[(*hh_it)->idx()]; - } + typename std_API_Container_HHandlePointer::iterator hh_it(hh_to_update.begin()), hh_it_end(hh_to_update.end()); + for(; hh_it != hh_it_end; ++hh_it) + { + if ( (*hh_it)->idx() >= halfedgeCount ) + (*hh_it)->invalidate(); + else + *(*hh_it) = hh_map[(*hh_it)->idx()]; } - // Update the face handles in the face handle vector - if(fh_to_update) { - const int faceCount = faces_.size(); - - typename std_API_Container_FHandlePointer::iterator fh_it(fh_to_update->begin()), fh_it_end(fh_to_update->end()); - for(; fh_it != fh_it_end; ++fh_it) - { - if ( (*fh_it)->idx() >= faceCount ) - (*fh_it)->invalidate(); - else - *(*fh_it) = fh_map[(*fh_it)->idx()]; - } + typename std_API_Container_FHandlePointer::iterator fh_it(fh_to_update.begin()), fh_it_end(fh_to_update.end()); + for(; fh_it != fh_it_end; ++fh_it) + { + if ( (*fh_it)->idx() >= faceCount ) + (*fh_it)->invalidate(); + else + *(*fh_it) = fh_map[(*fh_it)->idx()]; } }