mirror of https://github.com/CGAL/cgal
Revert "Cleaner and safer way of accessing elements in pmaps with indices"
This reverts commit 97c31a8327.
This commit is contained in:
parent
97c31a8327
commit
4ce6cffe9e
|
|
@ -23,7 +23,6 @@
|
||||||
|
|
||||||
#include <stack>
|
#include <stack>
|
||||||
|
|
||||||
#include <boost/iterator/counting_iterator.hpp>
|
|
||||||
#include <CGAL/Surface_mesh/Properties.h>
|
#include <CGAL/Surface_mesh/Properties.h>
|
||||||
|
|
||||||
namespace CGAL {
|
namespace CGAL {
|
||||||
|
|
@ -69,7 +68,6 @@ public:
|
||||||
|
|
||||||
/// \cond SKIP_IN_MANUAL
|
/// \cond SKIP_IN_MANUAL
|
||||||
typedef typename Properties::Property_container<Index> Base;
|
typedef typename Properties::Property_container<Index> Base;
|
||||||
typedef Properties::Property_map<Index, Index> Index_map;
|
|
||||||
/// \endcond
|
/// \endcond
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|
@ -85,43 +83,17 @@ public:
|
||||||
: public Properties::Property_map<Index, Type>
|
: public Properties::Property_map<Index, Type>
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
/// \cond SKIP_IN_MANUAL
|
|
||||||
typedef Property_map<Type> Self;
|
|
||||||
typedef typename Properties::Property_map<Index, Type> 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<Base*>(this)->operator[]((*m_indices)[i]);
|
|
||||||
}
|
|
||||||
const reference operator[](const Index& i) const
|
|
||||||
{
|
|
||||||
return dynamic_cast<const Base*>(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<std::size_t> Index_map;
|
||||||
|
/// \endcond
|
||||||
typedef Property_map<Point> Point_map; ///< Property map of points
|
typedef Property_map<Point> Point_map; ///< Property map of points
|
||||||
typedef Property_map<Vector> Vector_map; ///< Property map of vectors
|
typedef Property_map<Vector> Vector_map; ///< Property map of vectors
|
||||||
|
|
||||||
// typedef typename Index_map::iterator iterator; ///< Iterator type of the point set
|
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 Index_map::const_iterator const_iterator; ///< Constant iterator type of the point set
|
||||||
typedef typename boost::counting_iterator<Index> iterator;
|
|
||||||
typedef typename boost::counting_iterator<Index> const_iterator;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -145,11 +117,9 @@ public:
|
||||||
/*!
|
/*!
|
||||||
\brief Create an empty point set with no additional property.
|
\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();
|
clear();
|
||||||
if (with_normals)
|
|
||||||
add_normal_map();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename TypeProp1>
|
template <typename TypeProp1>
|
||||||
|
|
@ -192,7 +162,7 @@ public:
|
||||||
Point_set_3& operator= (const Point_set_3& ps)
|
Point_set_3& operator= (const Point_set_3& ps)
|
||||||
{
|
{
|
||||||
m_base = ps.m_base;
|
m_base = ps.m_base;
|
||||||
m_indices = m_base.template add<Index> ("index").first;
|
m_indices = this->property_map<Index> ("index").first;
|
||||||
m_points = this->property_map<Point> ("point").first;
|
m_points = this->property_map<Point> ("point").first;
|
||||||
m_normals = this->property_map<Vector> ("normal").first;
|
m_normals = this->property_map<Vector> ("normal").first;
|
||||||
m_nb_removed = ps.m_nb_removed;
|
m_nb_removed = ps.m_nb_removed;
|
||||||
|
|
@ -235,7 +205,7 @@ public:
|
||||||
void clear()
|
void clear()
|
||||||
{
|
{
|
||||||
m_base.clear();
|
m_base.clear();
|
||||||
boost::tie (m_indices, boost::tuples::ignore) = m_base.template add<std::size_t>("index", (std::size_t)(-1));
|
boost::tie (m_indices, boost::tuples::ignore) = this->add_property_map<std::size_t>("index", (std::size_t)(-1));
|
||||||
boost::tie (m_points, boost::tuples::ignore) = this->add_property_map<Point>("point", Point (0., 0., 0.));
|
boost::tie (m_points, boost::tuples::ignore) = this->add_property_map<Point>("point", Point (0., 0., 0.));
|
||||||
m_nb_removed = 0;
|
m_nb_removed = 0;
|
||||||
}
|
}
|
||||||
|
|
@ -290,12 +260,12 @@ public:
|
||||||
{
|
{
|
||||||
m_base.push_back();
|
m_base.push_back();
|
||||||
m_indices[size()-1] = size()-1;
|
m_indices[size()-1] = size()-1;
|
||||||
return iterator(size() - 1);
|
return m_indices.end() - 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
-- m_nb_removed;
|
-- 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 insert (const Point& p)
|
||||||
{
|
{
|
||||||
iterator out = insert();
|
iterator out = insert();
|
||||||
m_points[*out] = p;
|
m_points[size()-1] = p;
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -329,29 +299,29 @@ public:
|
||||||
iterator insert (const Point& p, const Vector& n)
|
iterator insert (const Point& p, const Vector& n)
|
||||||
{
|
{
|
||||||
iterator out = insert (p);
|
iterator out = insert (p);
|
||||||
assert (has_normal_map());
|
assert (has_normals());
|
||||||
m_normals[*out] = n;
|
m_normals[size()-1] = n;
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Return the begin iterator.
|
\brief Return the begin iterator.
|
||||||
*/
|
*/
|
||||||
iterator begin() { return iterator(0); }
|
iterator begin() { return m_indices.begin(); }
|
||||||
/*!
|
/*!
|
||||||
\brief Return the past-the-end iterator.
|
\brief Return the past-the-end iterator.
|
||||||
\note The returned value is the same as `garbage_begin()`.
|
\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.
|
\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.
|
\brief Return the past-the-end constant iterator.
|
||||||
\note The returned value is the same as `garbage_begin()`.
|
\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.
|
\brief Returns `true` if the number of non-removed element is 0.
|
||||||
|
|
||||||
|
|
@ -382,31 +352,74 @@ public:
|
||||||
|
|
||||||
\param index Index of the wanted point.
|
\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.
|
\brief Get a constant reference to the wanted indexed point.
|
||||||
|
|
||||||
\param index Index of the wanted 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.
|
\brief Get a reference to the wanted indexed normal.
|
||||||
|
|
||||||
\param index Index of the wanted normal.
|
\param index Index of the wanted normal.
|
||||||
|
|
||||||
\note The normal property must have been added to the point set
|
\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.
|
\brief Get a constant reference to the wanted indexed normal.
|
||||||
|
|
||||||
\param index Index of the wanted normal.
|
\param index Index of the wanted normal.
|
||||||
|
|
||||||
\note The normal property must have been added to the point set
|
\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)
|
void remove (iterator it)
|
||||||
{
|
{
|
||||||
std::swap (m_indices[*it], m_indices[*(garbage_begin() - 1)]);
|
std::swap (*it, *(garbage_begin() - 1));
|
||||||
++ m_nb_removed;
|
++ m_nb_removed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -462,22 +475,29 @@ public:
|
||||||
return (std::distance (it, garbage_begin()) < 0);
|
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
|
\brief Constant iterator to the first removed element (equal to `garbage_end()` if
|
||||||
no elements are marked as removed.
|
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.
|
\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.
|
\brief Number of removed points.
|
||||||
*/
|
*/
|
||||||
std::size_t number_of_removed_points () const { return m_nb_removed; }
|
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.
|
\brief Returns `true` if there are still removed elements in memory.
|
||||||
*/
|
*/
|
||||||
|
|
@ -527,7 +547,7 @@ public:
|
||||||
\param name Name of the property.
|
\param name Name of the property.
|
||||||
*/
|
*/
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool has_property_map (const std::string& name) const
|
bool has_property (const std::string& name) const
|
||||||
{
|
{
|
||||||
std::pair<typename Properties::template Property_map<Index, T>, bool>
|
std::pair<typename Properties::template Property_map<Index, T>, bool>
|
||||||
pm = m_base.template get<T> (name);
|
pm = m_base.template get<T> (name);
|
||||||
|
|
@ -551,12 +571,10 @@ public:
|
||||||
std::pair<Property_map<T>, bool>
|
std::pair<Property_map<T>, bool>
|
||||||
add_property_map (const std::string& name, const T t=T())
|
add_property_map (const std::string& name, const T t=T())
|
||||||
{
|
{
|
||||||
Properties::Property_map<Index,T> ppm;
|
Properties::Property_map<Index,T> pm;
|
||||||
bool added = false;
|
bool added = false;
|
||||||
boost::tie (ppm, added) = m_base.template add<T> (name, t);
|
boost::tie (pm, added) = m_base.template add<T> (name, t);
|
||||||
Property_map<T>& pm = reinterpret_cast<Property_map<T>&>(ppm);
|
return std::make_pair (reinterpret_cast<Property_map<T>&>(pm), added);
|
||||||
pm.m_indices = &m_indices;
|
|
||||||
return std::make_pair (pm, added);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|
@ -602,7 +620,7 @@ public:
|
||||||
This method tests if a property of type `CGAL::Vector_3<Gt>` and
|
This method tests if a property of type `CGAL::Vector_3<Gt>` and
|
||||||
named `normal` exists.
|
named `normal` exists.
|
||||||
*/
|
*/
|
||||||
bool has_normal_map() const
|
bool has_normals() const
|
||||||
{
|
{
|
||||||
std::pair<Vector_map, bool> pm = this->property_map<Vector> ("normal");
|
std::pair<Vector_map, bool> pm = this->property_map<Vector> ("normal");
|
||||||
return pm.second;
|
return pm.second;
|
||||||
|
|
@ -616,7 +634,7 @@ public:
|
||||||
\return `true` if the property was added, `false` if it already
|
\return `true` if the property was added, `false` if it already
|
||||||
existed.
|
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;
|
bool out = false;
|
||||||
boost::tie (m_normals, out) = this->add_property_map<Vector> ("normal", default_value);
|
boost::tie (m_normals, out) = this->add_property_map<Vector> ("normal", default_value);
|
||||||
|
|
@ -626,7 +644,7 @@ public:
|
||||||
\brief Get the property map of the normal attribute.
|
\brief Get the property map of the normal attribute.
|
||||||
|
|
||||||
\note The normal property must have been added to the point set
|
\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 ()
|
Vector_map normal_map ()
|
||||||
{
|
{
|
||||||
|
|
@ -636,7 +654,7 @@ public:
|
||||||
\brief Get the property map of the normal attribute (constant version).
|
\brief Get the property map of the normal attribute (constant version).
|
||||||
|
|
||||||
\note The normal property must have been added to the point set
|
\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
|
const Vector_map normal_map () const
|
||||||
{
|
{
|
||||||
|
|
@ -648,7 +666,7 @@ public:
|
||||||
\return Returns `true` if the property was removed and `false` if
|
\return Returns `true` if the property was removed and `false` if
|
||||||
the property was not found.
|
the property was not found.
|
||||||
*/
|
*/
|
||||||
bool remove_normal_map()
|
bool remove_normal_property()
|
||||||
{
|
{
|
||||||
return m_base.remove (m_normals);
|
return m_base.remove (m_normals);
|
||||||
}
|
}
|
||||||
|
|
@ -813,7 +831,7 @@ public:
|
||||||
\brief Get the push property map of the normal attribute.
|
\brief Get the push property map of the normal attribute.
|
||||||
|
|
||||||
\note The normal property must have been added to the point set
|
\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 ()
|
Vector_push_map normal_push_map ()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue