From 4ce6cffe9e55f9f789312f5482e8adf44b6a2fc4 Mon Sep 17 00:00:00 2001 From: Simon Giraudot Date: Mon, 26 Sep 2016 08:54:01 +0200 Subject: [PATCH] Revert "Cleaner and safer way of accessing elements in pmaps with indices" This reverts commit 97c31a8327a1e6426374a1a83ca79e172ef6d49c. --- Point_set_3/include/CGAL/Point_set_3.h | 162 ++++++++++++++----------- 1 file changed, 90 insertions(+), 72 deletions(-) diff --git a/Point_set_3/include/CGAL/Point_set_3.h b/Point_set_3/include/CGAL/Point_set_3.h index 3d96540b92e..287c7704faf 100644 --- a/Point_set_3/include/CGAL/Point_set_3.h +++ b/Point_set_3/include/CGAL/Point_set_3.h @@ -23,7 +23,6 @@ #include -#include #include namespace CGAL { @@ -69,7 +68,6 @@ public: /// \cond SKIP_IN_MANUAL typedef typename Properties::Property_container Base; - typedef Properties::Property_map Index_map; /// \endcond /*! @@ -85,43 +83,17 @@ public: : public Properties::Property_map #endif { - /// \cond SKIP_IN_MANUAL - typedef Property_map Self; - typedef typename Properties::Property_map Base; - typedef typename Base::reference reference; - typedef typename Base::key_type key_type; - typedef typename Base::value_type value_type; - - Index_map* m_indices; - - reference operator[](const Index& i) - { - return dynamic_cast(this)->operator[]((*m_indices)[i]); - } - const reference operator[](const Index& i) const - { - return dynamic_cast(this)->operator[]((*m_indices)[i]); - } - - friend reference get(const Self& s, const key_type& k) - { - return (*(s.m_indices))[k]; - } - - friend void put(const Self& s,key_type& k, const value_type& v) - { - (*(s.m_indices))[k] = v; - } - /// \endcond }; + /// \cond SKIP_IN_MANUAL + typedef Property_map Index_map; + /// \endcond typedef Property_map Point_map; ///< Property map of points typedef Property_map Vector_map; ///< Property map of vectors - // typedef typename Index_map::iterator iterator; ///< Iterator type of the point set - // typedef typename Index_map::const_iterator const_iterator; ///< Constant iterator type of the point set - typedef typename boost::counting_iterator iterator; - typedef typename boost::counting_iterator const_iterator; + typedef typename Index_map::iterator iterator; ///< Iterator type of the point set + typedef typename Index_map::const_iterator const_iterator; ///< Constant iterator type of the point set + @@ -145,11 +117,9 @@ public: /*! \brief Create an empty point set with no additional property. */ - Point_set_3 (bool with_normals = false) : m_base() + Point_set_3 () : m_base() { clear(); - if (with_normals) - add_normal_map(); } template @@ -192,7 +162,7 @@ public: Point_set_3& operator= (const Point_set_3& ps) { m_base = ps.m_base; - m_indices = m_base.template add ("index").first; + m_indices = this->property_map ("index").first; m_points = this->property_map ("point").first; m_normals = this->property_map ("normal").first; m_nb_removed = ps.m_nb_removed; @@ -235,7 +205,7 @@ public: void clear() { m_base.clear(); - boost::tie (m_indices, boost::tuples::ignore) = m_base.template add("index", (std::size_t)(-1)); + boost::tie (m_indices, boost::tuples::ignore) = this->add_property_map("index", (std::size_t)(-1)); boost::tie (m_points, boost::tuples::ignore) = this->add_property_map("point", Point (0., 0., 0.)); m_nb_removed = 0; } @@ -290,12 +260,12 @@ public: { m_base.push_back(); m_indices[size()-1] = size()-1; - return iterator(size() - 1); + return m_indices.end() - 1; } else { -- m_nb_removed; - return iterator(m_base.size() - m_nb_removed - 1); + return m_indices.end() - m_nb_removed - 1; } } @@ -310,7 +280,7 @@ public: iterator insert (const Point& p) { iterator out = insert(); - m_points[*out] = p; + m_points[size()-1] = p; return out; } @@ -329,29 +299,29 @@ public: iterator insert (const Point& p, const Vector& n) { iterator out = insert (p); - assert (has_normal_map()); - m_normals[*out] = n; + assert (has_normals()); + m_normals[size()-1] = n; return out; } /*! \brief Return the begin iterator. */ - iterator begin() { return iterator(0); } + iterator begin() { return m_indices.begin(); } /*! \brief Return the past-the-end iterator. \note The returned value is the same as `garbage_begin()`. */ - iterator end() { return iterator(m_base.size() - m_nb_removed); } + iterator end() { return m_indices.end() - m_nb_removed; } /*! \brief Return the begin constant iterator. */ - const_iterator begin() const { return const_iterator(0); } + const_iterator begin() const { return m_indices.begin(); } /*! \brief Return the past-the-end constant iterator. \note The returned value is the same as `garbage_begin()`. */ - const_iterator end() const { return const_iterator(m_base.size() - m_nb_removed); } + const_iterator end() const { return m_indices.end() - m_nb_removed; } /*! \brief Returns `true` if the number of non-removed element is 0. @@ -382,31 +352,74 @@ public: \param index Index of the wanted point. */ - Point& point (Index index) { return m_points[index]; } + Point& point (Index index) { return m_points[m_indices[index]]; } /*! \brief Get a constant reference to the wanted indexed point. \param index Index of the wanted point. */ - const Point& point (Index index) const { return m_points[index]; } + const Point& point (Index index) const { return m_points[m_indices[index]]; } + /*! + \brief Get a reference to the wanted indexed point. + + \param it Iterator of the wanted item. + */ + Point& point (iterator it) { return m_points[*it]; } + /*! + \brief Get a constant reference to the wanted indexed point. + + \param it Iterator of the wanted item. + */ + const Point& point (const_iterator it) const { return m_points[*it]; } + /*! + \brief Get a reference to the wanted indexed point (convenience method). + + \param index Index of the wanted point. + */ + Point& operator[] (Index index) { return m_points[m_indices[index]]; } + /*! + \brief Get a const reference the wanted indexed point (convenience method). + + \param index Index of the wanted point. + */ + const Point& operator[] (Index index) const { return m_points[m_indices[index]]; } + /*! \brief Get a reference to the wanted indexed normal. \param index Index of the wanted normal. \note The normal property must have been added to the point set - before calling this method (see `add_normal_map()`). + before calling this method (see `add_normal_property()`). */ - Vector& normal (Index index) { return m_normals[index]; } + Vector& normal (Index index) { return m_normals[m_indices[index]]; } /*! \brief Get a constant reference to the wanted indexed normal. \param index Index of the wanted normal. \note The normal property must have been added to the point set - before calling this method (see `add_normal_map()`). + before calling this method (see `add_normal_property()`). */ - const Vector& normal (Index index) const { return m_normals[index]; } + const Vector& normal (Index index) const { return m_normals[m_indices[index]]; } + /*! + \brief Get a reference to the wanted indexed normal. + + \param it Iterator of the wanted item. + + \note The normal property must have been added to the point set + before calling this method (see `add_normal_property()`). + */ + Vector& normal (iterator it) { return m_normals[*it]; } + /*! + \brief Get a constant reference to the wanted indexed normal. + + \param it Iterator of the wanted item. + + \note The normal property must have been added to the point set + before calling this method (see `add_normal_property()`). + */ + const Vector& normal (const_iterator it) const { return m_normals[*it]; } /// @} @@ -447,7 +460,7 @@ public: */ void remove (iterator it) { - std::swap (m_indices[*it], m_indices[*(garbage_begin() - 1)]); + std::swap (*it, *(garbage_begin() - 1)); ++ m_nb_removed; } @@ -462,22 +475,29 @@ public: return (std::distance (it, garbage_begin()) < 0); } + /*! + \brief Iterator to the first removed element (equal to `garbage_end()` if + no elements are marked as removed. + */ + iterator garbage_begin () { return m_indices.end() - m_nb_removed; } + /*! + \brief Past-the-end iterator of the removed elements. + */ + iterator garbage_end () { return m_indices.end(); } /*! \brief Constant iterator to the first removed element (equal to `garbage_end()` if no elements are marked as removed. */ - const_iterator garbage_begin () const { return const_iterator(m_base.size() - m_nb_removed); } + const_iterator garbage_begin () const { return m_indices.end() - m_nb_removed; } /*! \brief Past-the-end constant iterator of the removed elements. */ - const_iterator garbage_end () const { return const_iterator(m_base.size()); } + const_iterator garbage_end () const { return m_indices.end(); } /*! \brief Number of removed points. */ std::size_t number_of_removed_points () const { return m_nb_removed; } - /// \cond SKIP_IN_MANUAL - std::size_t garbage_size () const { return number_of_removed_points(); } - /// \endcond + /*! \brief Returns `true` if there are still removed elements in memory. */ @@ -527,7 +547,7 @@ public: \param name Name of the property. */ template - bool has_property_map (const std::string& name) const + bool has_property (const std::string& name) const { std::pair, bool> pm = m_base.template get (name); @@ -551,12 +571,10 @@ public: std::pair, bool> add_property_map (const std::string& name, const T t=T()) { - Properties::Property_map ppm; + Properties::Property_map pm; bool added = false; - boost::tie (ppm, added) = m_base.template add (name, t); - Property_map& pm = reinterpret_cast&>(ppm); - pm.m_indices = &m_indices; - return std::make_pair (pm, added); + boost::tie (pm, added) = m_base.template add (name, t); + return std::make_pair (reinterpret_cast&>(pm), added); } /*! @@ -602,7 +620,7 @@ public: This method tests if a property of type `CGAL::Vector_3` and named `normal` exists. */ - bool has_normal_map() const + bool has_normals() const { std::pair pm = this->property_map ("normal"); return pm.second; @@ -616,7 +634,7 @@ public: \return `true` if the property was added, `false` if it already existed. */ - bool add_normal_map(const Vector& default_value = Vector(0., 0., 0.)) + bool add_normal_property(const Vector& default_value = Vector(0., 0., 0.)) { bool out = false; boost::tie (m_normals, out) = this->add_property_map ("normal", default_value); @@ -626,7 +644,7 @@ public: \brief Get the property map of the normal attribute. \note The normal property must have been added to the point set - before calling this method (see `add_normal_map()`). + before calling this method (see `add_normal_property()`). */ Vector_map normal_map () { @@ -636,7 +654,7 @@ public: \brief Get the property map of the normal attribute (constant version). \note The normal property must have been added to the point set - before calling this method (see `add_normal_map()`). + before calling this method (see `add_normal_property()`). */ const Vector_map normal_map () const { @@ -648,7 +666,7 @@ public: \return Returns `true` if the property was removed and `false` if the property was not found. */ - bool remove_normal_map() + bool remove_normal_property() { return m_base.remove (m_normals); } @@ -813,7 +831,7 @@ public: \brief Get the push property map of the normal attribute. \note The normal property must have been added to the point set - before calling this method (see `add_normal_map()`). + before calling this method (see `add_normal_property()`). */ Vector_push_map normal_push_map () {