From 552598141c02adbf92f5c26e719d811cf33128af Mon Sep 17 00:00:00 2001 From: Martin Marinov Date: Fri, 23 Oct 2015 17:19:06 +0100 Subject: [PATCH 1/2] Fixed the most obvious issues with StatusSeT<> and its derivatives. Improved slightly the formatting and added a few lines documentation. --- src/OpenMesh/Core/Mesh/ArrayKernel.hh | 110 ++++++++++++++------------ 1 file changed, 59 insertions(+), 51 deletions(-) diff --git a/src/OpenMesh/Core/Mesh/ArrayKernel.hh b/src/OpenMesh/Core/Mesh/ArrayKernel.hh index b83f3a6d..29e74a55 100644 --- a/src/OpenMesh/Core/Mesh/ArrayKernel.hh +++ b/src/OpenMesh/Core/Mesh/ArrayKernel.hh @@ -573,54 +573,62 @@ public: /// --- StatusSet API --- - template + /*! + Implements a set of connectivity entities (vertex, edge, face, halfedge) + using the available bits in the corresponding mesh status field. + + Status-based sets are much faster using std::set<> and equivalent + in performance to std::vector, but much more convenient. + */ + template class StatusSetT { + public: + typedef HandleT Handle; + protected: - ArrayKernel& kernel_; + ArrayKernel& kernel_; public: - const unsigned int bit_mask_; + const unsigned int bit_mask_; public: - StatusSetT(ArrayKernel& _kernel, unsigned int _bit_mask) + StatusSetT(ArrayKernel& _kernel, const unsigned int _bit_mask) : kernel_(_kernel), bit_mask_(_bit_mask) {} ~StatusSetT() {} - inline bool is_in(Handle _hnd) const + inline bool is_in(Handle _hnd) const { return kernel_.status(_hnd).is_bit_set(bit_mask_); } - inline void insert(Handle _hnd) + inline void insert(Handle _hnd) { kernel_.status(_hnd).set_bit(bit_mask_); } - inline void erase(Handle _hnd) + inline void erase(Handle _hnd) { kernel_.status(_hnd).unset_bit(bit_mask_); } - /// Note: 0(n) complexity - unsigned int size() const + //! Note: 0(n) complexity + size_t size() const { - unsigned int n_elements = kernel_.status_pph(Handle()).is_valid() ? - kernel_.property(kernel_.status_pph(Handle())).n_elements() : 0; - unsigned int sz = 0; - for (unsigned int i = 0; i < n_elements; ++i) - { - sz += (unsigned int)is_in(Handle(i)); - } + const int n = kernel_.status_pph(Handle()).is_valid() ? + (int)kernel_.property(kernel_.status_pph(Handle())).n_elements() : 0; + + size_t sz = 0; + for (int i = 0; i < n; ++i) + sz += (size_t)is_in(Handle(i)); return sz; } - /// Note: O(n) complexity - void clear() + //! Note: O(n) complexity + void clear() { - unsigned int n_elements = kernel_.status_pph(Handle()).is_valid() ? - kernel_.property(kernel_.status_pph(Handle())).n_elements() : 0; - for (unsigned int i = 0; i < n_elements; ++i) - { + const int n = kernel_.status_pph(Handle()).is_valid() ? + (int)kernel_.property(kernel_.status_pph(Handle())).n_elements() : 0; + + for (int i = 0; i < n; ++i) erase(Handle(i)); - } } }; @@ -629,13 +637,14 @@ public: friend class StatusSetT; friend class StatusSetT; - /// --- AutoStatusSet API --- - - template - class AutoStatusSetT : public StatusSetT + //! AutoStatusSetT: A status set that automatically picks a free bit to use + template + class AutoStatusSetT : public StatusSetT { private: - typedef StatusSetT Base; + typedef StatusSetT Base; + typedef HandleT Handle; + public: AutoStatusSetT(ArrayKernel& _kernel) : StatusSetT(_kernel, _kernel.pop_bit_mask(Handle())) @@ -658,13 +667,13 @@ public: typedef AutoStatusSetT FaceStatusSet; typedef AutoStatusSetT HalfedgeStatusSet; - /// --- ExtStatusSet API --- (hybrid between a set and an array) - - template - class ExtStatusSetT : public AutoStatusSetT + //! ExtStatusSet: A status set augmented with an array + template + class ExtStatusSetT : public AutoStatusSetT { public: - typedef AutoStatusSetT Base; + typedef HandleT Handle; + typedef AutoStatusSetT Base; protected: typedef std::vector HandleContainer; @@ -683,9 +692,8 @@ public: ~ExtStatusSetT() { clear(); } - //set API // Complexity: O(1) - inline void insert(Handle _hnd) + inline void insert(Handle _hnd) { if (!is_in(_hnd)) { @@ -694,8 +702,8 @@ public: } } - // Complexity: O(k), (k - number of the elements in the set) - inline void erase(Handle _hnd) + //! Complexity: O(k), (k - number of the elements in the set) + inline void erase(Handle _hnd) { if (is_in(_hnd)) { @@ -704,16 +712,16 @@ public: } } - // Complexity: O(1) - inline void erase(iterator _it) + //! Complexity: O(1) + inline void erase(iterator _it) { assert(_it != end() && is_in(*_it)); - clear(*_it); + Base::erase(*_it); *_it = handles_.back(); _it.pop_back(); } - inline void clear() + inline void clear() { for (iterator it = begin(); it != end(); ++it) { @@ -724,30 +732,30 @@ public: } /// Complexity: 0(1) - inline unsigned int size() const + inline unsigned int size() const { return handles_.size(); } - inline bool empty() const + inline bool empty() const { return handles_.empty(); } //Vector API - inline iterator begin() + inline iterator begin() { return handles_.begin(); } - inline const_iterator begin() const + inline const_iterator begin() const { return handles_.begin(); } - inline iterator end() + inline iterator end() { return handles_.end(); } - inline const_iterator end() const + inline const_iterator end() const { return handles_.end(); } - inline Handle& front() + inline Handle& front() { return handles_.front(); } - inline const Handle& front() const + inline const Handle& front() const { return handles_.front(); } - inline Handle& back() + inline Handle& back() { return handles_.back(); } - inline const Handle& back() const + inline const Handle& back() const { return handles_.back(); } }; From acce6af3c0141c972476b0941314a78f8c599360 Mon Sep 17 00:00:00 2001 From: Martin Marinov Date: Fri, 23 Oct 2015 17:45:29 +0100 Subject: [PATCH 2/2] Some minor changes to the StatusSet<> docs. --- src/OpenMesh/Core/Mesh/ArrayKernel.hh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OpenMesh/Core/Mesh/ArrayKernel.hh b/src/OpenMesh/Core/Mesh/ArrayKernel.hh index 29e74a55..736d4a4b 100644 --- a/src/OpenMesh/Core/Mesh/ArrayKernel.hh +++ b/src/OpenMesh/Core/Mesh/ArrayKernel.hh @@ -577,7 +577,7 @@ public: Implements a set of connectivity entities (vertex, edge, face, halfedge) using the available bits in the corresponding mesh status field. - Status-based sets are much faster using std::set<> and equivalent + Status-based sets are much faster than std::set<> and equivalent in performance to std::vector, but much more convenient. */ template @@ -637,7 +637,7 @@ public: friend class StatusSetT; friend class StatusSetT; - //! AutoStatusSetT: A status set that automatically picks a free bit to use + //! AutoStatusSetT: A status set that automatically picks a status bit template class AutoStatusSetT : public StatusSetT {