diff --git a/Point_set_processing_3/include/CGAL/Point_set_3.h b/Point_set_processing_3/include/CGAL/Point_set_3.h index 9712a849774..32c6cab6188 100644 --- a/Point_set_processing_3/include/CGAL/Point_set_3.h +++ b/Point_set_processing_3/include/CGAL/Point_set_3.h @@ -25,7 +25,7 @@ #include #include #include -#include +#include #include #include @@ -63,12 +63,13 @@ public: typedef typename Gt::Iso_cuboid_3 Iso_cuboid; typedef typename Gt::Sphere_3 Sphere; - typedef CGAL::Surface_mesh Base; - typedef typename Base::Vertex_index Item; - typedef typename Properties::template Property_map Index_pmap; - typedef typename Properties::template Property_map Point_pmap; - typedef typename Properties::template Property_map Vector_pmap; + typedef typename std::size_t Item; + + typedef typename Properties::Property_container Base; + typedef typename Properties::Property_map Index_pmap; + typedef typename Properties::Property_map Point_pmap; + typedef typename Properties::Property_map Vector_pmap; typedef typename Index_pmap::Array::vector_type::iterator iterator; typedef typename Index_pmap::Array::vector_type::const_iterator const_iterator; @@ -96,8 +97,8 @@ private: Index_back_inserter& operator*() { return *this; } Index_back_inserter& operator= (std::size_t& ind) { - if(! ps.surface_mesh().has_valid_index(typename Point_set::Item(ind))) - ps.surface_mesh().add_vertex(); + if(!(ps.size() <= (typename Point_set::Item(ind)))) + ps.add_item(); put(ps.indices(), Point_set::Item(ind),ind); ++ ind; return *this; @@ -115,7 +116,7 @@ private: Property_push_pmap(Point_set& ps, Property& prop, std::size_t ind=0) : ps(ps), prop(prop), ind(ind) {} inline friend void put(Property_push_pmap& pm, std::size_t& i, typename Property::value_type& t) { - if(!pm.ps.has_valid_index(pm.ind)) + if(!(pm.ps.size() <= (pm.ind))) pm.ps.add_item(); put(pm.prop, Point_set::Item(pm.ind), t); i = pm.ind; @@ -127,6 +128,7 @@ private: typedef Property_push_pmap Normal_push_pmap; Base m_base; + Point_pmap m_points; Index_pmap m_indices; Vector_pmap m_normals; @@ -137,28 +139,25 @@ private: return *this; } + // Copy constructor not implemented and declared private to make + // sure nobody uses the default one without knowing it + Point_set_3 (const Point_set_3& p) + { + } + public: Point_set_3 () : m_base() { - assert (add_index_property()); - } - - // copy constructor - Point_set_3 (const Point_set_3& p) : m_base(p.m_base) - { - assert (add_index_property()); + m_indices = m_base.template add ("index").first; + m_points = m_base.template add ("point").first; } void push_back (const Point& p) { - m_base.add_vertex (p); - } - - Base& surface_mesh() - { - return m_base; + Item i = m_base.push_back(); + m_points[i] = p; } Index_pmap& indices() @@ -168,44 +167,55 @@ public: Point_pmap points() { - return m_base.points(); + return m_points; } - Vector_pmap& normals() { return m_normals; } - iterator begin() { return m_indices.array().begin(); } iterator end() { return m_indices.array().end(); } const_iterator begin() const { return m_indices.array().begin(); } const_iterator end() const { return m_indices.array().end(); } - bool empty() const { return m_base.is_empty(); } - std::size_t size () const { return m_base.number_of_vertices(); } + bool empty() const { return (m_base.size() == 0); } + std::size_t size () const { return m_base.size(); } void clear() { m_base.clear(); } - Point& operator[] (std::size_t index) { return m_base.point (Item (index)); } - const Point& operator[] (std::size_t index) const { return (*this)[index]; } + Point& operator[] (Item index) { return m_points[index]; } + const Point& operator[] (Item index) const { return (*this)[index]; } - void erase (iterator begin, iterator end) + void erase (iterator first, iterator beyond) { - for (iterator it = begin; it != end; ++ it) - m_base.remove_vertex (Item (*it)); - m_base.collect_garbage(); - reset_indices(); + if (beyond != end()) + { + // TODO + } + + if (are_indices_up_to_date()) + { + m_base.erase (*first, *beyond); + } + else + { + std::size_t size = (beyond - first); + apply_indices_change(); + m_base.resize (m_base.size() - size); + } } void add_item () { - m_base.add_vertex(); + m_base.push_back(); } - bool has_valid_index (std::size_t i) const + void apply_indices_change() { - return m_base.has_valid_index (Item (i)); + for (std::size_t i = 0; i < size(); ++ i) + if (i != m_indices[i]) + m_base.swap (i, m_indices[i]); } - + void reset_indices() { std::size_t i = 0; @@ -228,8 +238,7 @@ public: } Point_push_pmap point_push_pmap () { - Point_pmap& pm = m_base.points(); - return Property_push_pmap (*this, pm, size()); + return Property_push_pmap (*this, m_points, size()); } Normal_push_pmap normal_push_pmap () { @@ -237,57 +246,50 @@ public: } - bool add_index_property() - { - bool out = false; - boost::tie (m_indices, out) = m_base.template add_property_map ("index"); - return out; - } - bool has_normals() const { - std::pair pm = m_base.template property_map ("normal"); + std::pair pm = m_base.template get ("normal"); return pm.second; } bool add_normal_property() { bool out = false; - boost::tie (m_normals, out) = m_base.template add_property_map ("normal"); + boost::tie (m_normals, out) = m_base.template add ("normal"); return out; } void remove_normal_property() { - m_base.remove_property_map (m_normals); + m_base.remove (m_normals); } - Vector& normal (std::size_t index) { return m_normals[Item (index)]; } - const Vector& normal (std::size_t index) const { return this->normal(index); } + Vector& normal (Item index) { return m_normals[index]; } + const Vector& normal (Item index) const { return this->normal(index); } template bool has_property (const std::string& name) const { std::pair, bool> - pm = m_base.template property_map (name); + pm = m_base.template get (name); return pm.second; } template bool add_property (const std::string& name) { std::pair, bool> - pm = m_base.template add_property_map (name); + pm = m_base.template add (name); return pm.second; } template void remove_property (PMap& prop) { - m_base.remove_property_map (prop); + m_base.remove (prop); } template bool remove_property (const std::string& name) { std::pair, bool> - pm = m_base.template property_map (name); + pm = m_base.template get (name); if (!(pm.second)) return false; remove_property (pm.first); @@ -297,7 +299,7 @@ public: template T& property (typename Properties::template Property_map& pmap, std::size_t index) { - return pmap[Item (index)]; + return pmap[index]; } template const T& property (typename Properties::template Property_map& pmap, std::size_t index) const @@ -309,7 +311,7 @@ public: T& property (const std::string& name, std::size_t index) { std::pair, bool> - pm = m_base.template add_property_map (name); + pm = m_base.template get (name); return property (pm.first, index); } template diff --git a/Surface_mesh/include/CGAL/Surface_mesh/Properties.h b/Surface_mesh/include/CGAL/Surface_mesh/Properties.h index 6d4e2ec8ddd..41added27ac 100644 --- a/Surface_mesh/include/CGAL/Surface_mesh/Properties.h +++ b/Surface_mesh/include/CGAL/Surface_mesh/Properties.h @@ -64,6 +64,9 @@ public: /// Let two elements swap their storage place. virtual void swap(size_t i0, size_t i1) = 0; + /// Erase range + virtual void erase(size_t first, size_t beyond) = 0; + /// Return a deep copy of self. virtual Base_property_array* clone () const = 0; @@ -137,6 +140,11 @@ public: // virtual interface of Base_property_array data_[i1]=d; } + virtual void erase(size_t first, size_t beyond) + { + data_.erase (data_.begin() + first, data_.begin() + beyond); + } + virtual Base_property_array* clone() const { Property_array* p = new Property_array(this->name_, this->value_); @@ -148,6 +156,8 @@ public: // virtual interface of Base_property_array typename vector_type::iterator begin () { return data_.begin (); } typename vector_type::iterator end () { return data_.end (); } + typename vector_type::const_iterator begin () const { return data_.begin (); } + typename vector_type::const_iterator end () const { return data_.end (); } public: @@ -351,6 +361,13 @@ public: } + // erase elements from each vector + void erase (size_t first, size_t beyond) + { + for (unsigned int i=0; ierase(first, beyond); + size_ -= (beyond-first); + } // reserve memory for n entries in all arrays void reserve(size_t n) const { @@ -388,7 +405,6 @@ public: parrays_[i]->swap(i0, i1); } - private: std::vector parrays_; size_t size_;