From d27c282b9bda6783fce99c62a6ccbc46a6e8309a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20M=C3=B6bius?= Date: Thu, 1 Sep 2011 10:04:15 +0000 Subject: [PATCH] Added patch to speed up add_face function. Thanks to Stephen Webb git-svn-id: http://www.openmesh.org/svnrepo/OpenMesh/trunk@406 fdac6126-5c0c-442c-9429-916003d36597 --- src/OpenMesh/Core/Mesh/PolyConnectivity.cc | 94 ++++++++++------------ src/OpenMesh/Core/Mesh/PolyConnectivity.hh | 14 ++++ 2 files changed, 57 insertions(+), 51 deletions(-) diff --git a/src/OpenMesh/Core/Mesh/PolyConnectivity.cc b/src/OpenMesh/Core/Mesh/PolyConnectivity.cc index 0b17ecd5..787465db 100644 --- a/src/OpenMesh/Core/Mesh/PolyConnectivity.cc +++ b/src/OpenMesh/Core/Mesh/PolyConnectivity.cc @@ -109,40 +109,26 @@ void PolyConnectivity::adjust_outgoing_halfedge(VertexHandle _vh) } //----------------------------------------------------------------------------- -namespace -{ -template -struct NextCacheEntryT : public std::pair<_Handle, _Handle> -{ - typedef std::pair<_Handle, _Handle> Base; - - NextCacheEntryT(_Handle _heh0, _Handle _heh1) - : Base(_heh0, _heh1) - { - assert(_heh0.is_valid()); - assert(_heh1.is_valid()); - } -}; -} PolyConnectivity::FaceHandle PolyConnectivity::add_face(const VertexHandle* _vertex_handles, uint _vhs_size) { VertexHandle vh; uint i, ii, n(_vhs_size), id; - std::vector halfedge_handles(n); - std::vector is_new(n), needs_adjust(n, false); HalfedgeHandle inner_next, inner_prev, outer_next, outer_prev, boundary_next, boundary_prev, patch_start, patch_end; - // cache for set_next_halfedge and vertex' set_halfedge - typedef NextCacheEntryT NextCacheEntry; - typedef std::vector NextCache; - NextCache next_cache; - next_cache.reserve(3*n); + // Check sufficient working storage available + if (edgeData_.size() < n) + { + edgeData_.resize(n); + next_cache_.resize(6*n); + } + next_cache_count_ = 0; + // don't allow degenerated faces assert (n > 2); @@ -155,11 +141,13 @@ PolyConnectivity::add_face(const VertexHandle* _vertex_handles, uint _vhs_size) return InvalidFaceHandle; } - halfedge_handles[i] = find_halfedge(_vertex_handles[i], - _vertex_handles[ii]); - is_new[i] = !halfedge_handles[i].is_valid(); + // Initialise edge attributes + edgeData_[i].halfedge_handle = find_halfedge(_vertex_handles[i], + _vertex_handles[ii]); + edgeData_[i].is_new = !edgeData_[i].halfedge_handle.is_valid(); + edgeData_[i].needs_adjust = false; - if (!is_new[i] && !is_boundary(halfedge_handles[i])) + if (!edgeData_[i].is_new && !is_boundary(edgeData_[i].halfedge_handle)) { omerr() << "PolyMeshT::add_face: complex edge\n"; return InvalidFaceHandle; @@ -169,10 +157,11 @@ PolyConnectivity::add_face(const VertexHandle* _vertex_handles, uint _vhs_size) // re-link patches if necessary for (i=0, ii=1; ifirst, ncIt->second); + for (i = 0; i < next_cache_count_; ++i) + set_next_halfedge_handle(next_cache_[i].first, next_cache_[i].second); + // adjust vertices' halfedge handle for (i=0; i edgeData_; // + std::vector > next_cache_; // cache for set_next_halfedge and vertex' set_halfedge + uint next_cache_count_; + }; }//namespace OpenMesh