From 3e09542e0e31f1a0f2ca8c003f5de6a8e3e1c00a Mon Sep 17 00:00:00 2001 From: Simon Giraudot Date: Mon, 25 Jan 2016 15:28:32 +0100 Subject: [PATCH] Replace push_pmap with generalized template version --- .../include/CGAL/Point_set_3.h | 149 ++++++++---------- 1 file changed, 67 insertions(+), 82 deletions(-) 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 e86ab308c5e..edaa9dbb0b8 100644 --- a/Point_set_processing_3/include/CGAL/Point_set_3.h +++ b/Point_set_processing_3/include/CGAL/Point_set_3.h @@ -60,7 +60,6 @@ public: typedef typename Gt::FT FT; typedef typename Gt::Point_3 Point; typedef typename Gt::Vector_3 Vector; - typedef CGAL::cpp11::array Color; typedef typename Gt::Iso_cuboid_3 Iso_cuboid; typedef typename Gt::Sphere_3 Sphere; @@ -70,7 +69,6 @@ public: typedef typename Base::template Property_map Index_pmap; typedef typename Base::template Property_map Point_pmap; typedef typename Base::template Property_map Vector_pmap; - typedef typename Base::template Property_map Color_pmap; typedef typename Index_pmap::Array::vector_type::iterator iterator; typedef typename Index_pmap::Array::vector_type::const_iterator const_iterator; @@ -92,83 +90,47 @@ private: public: - Index_back_inserter(Point_set& ps, std::size_t ind=0) - : ps(ps), ind(ind) - {} - - Index_back_inserter& operator++() - { - return *this; - } - Index_back_inserter& operator++(int) - { - return *this; - } - + Index_back_inserter(Point_set& ps, std::size_t ind=0) : ps(ps), ind(ind) {} + Index_back_inserter& operator++() { return *this; } + Index_back_inserter& operator++(int) { return *this; } + 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))){ - std::cerr << "Add vertex from index " << ind << std::endl; + if(! ps.surface_mesh().has_valid_index(typename Point_set::Item(ind))) ps.surface_mesh().add_vertex(); - } put(ps.indices(), Point_set::Item(ind),ind); ++ ind; return *this; } - Index_back_inserter& operator*() - { - return *this; - } - }; - struct Point_push_pmap { + template + struct Property_push_pmap + { Point_set& ps; + Property& prop; std::size_t ind; - Point_push_pmap(Point_set& ps, std::size_t ind=0) - : ps(ps), ind(ind) - {} - - inline friend void put(Point_push_pmap& pm, std::size_t& i, Point& p) + 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.surface_mesh().has_valid_index(typename Point_set::Item(pm.ind))){ std::cerr << "Add vertex from point " << pm.ind << std::endl; pm.ps.surface_mesh().add_vertex(); } - put(pm.ps.points(), Point_set::Item(pm.ind),p); + put(pm.prop, Point_set::Item(pm.ind),t); i = pm.ind; ++pm.ind; } }; - - struct Normal_push_pmap { - Point_set& ps; - std::size_t ind; - - Normal_push_pmap(Point_set& ps, std::size_t ind=0) - : ps(ps), ind(ind) - {} - - inline friend void put(Normal_push_pmap& pm, std::size_t& i , Vector& v) - { - if(! pm.ps.surface_mesh().has_valid_index(typename Point_set::Item(pm.ind))){ - std::cerr << "Add vertex from normal " << pm.ind << std::endl; - pm.ps.surface_mesh().add_vertex(); - } - put(pm.ps.normals(), Point_set::Item(pm.ind),v); - i = pm.ind; - ++pm.ind; - } - }; - - + + typedef Property_push_pmap Point_push_pmap; + typedef Property_push_pmap Normal_push_pmap; Base m_base; Index_pmap m_indices; Vector_pmap m_normals; - Color_pmap m_colors; // Assignment operator not implemented and declared private to make // sure nobody uses the default one without knowing it @@ -258,12 +220,14 @@ public: } Point_push_pmap point_push_pmap () { - return Point_push_pmap (*this, size()); + Point_pmap pm = m_base.points(); + return Property_push_pmap (*this, pm, size()); } Normal_push_pmap normal_push_pmap () { - return Normal_push_pmap (*this, size()); + return Property_push_pmap (*this, m_normals, size()); } + bool add_index_property() { @@ -290,40 +254,61 @@ public: Vector& normal (std::size_t index) { return m_normals[Item (index)]; } const Vector& normal (std::size_t index) const { return this->normal(index); } - bool has_colors() const + template + bool has_property (const std::string& name) const { - std::pair pm = m_base.template property_map ("color"); + std::pair, bool> + pm = m_base.template property_map (name); return pm.second; } - bool add_color_property() + template + bool add_property (const std::string& name) { - bool out = false; - boost::tie (m_colors, out) = m_base.template add_property_map ("color"); - return out; + std::pair, bool> + pm = m_base.template add_property_map (name); + return pm.second; } - void remove_color_property() - { - m_base.remove_property_map (m_colors); - } - Color& color (std::size_t index) { return m_colors[Item (index)]; } - const Color& color (std::size_t index) const { return this->color(index); } - - static CGAL::Second_of_pair_property_map > - point_property_map () - { - return CGAL::make_second_of_pair_property_map (std::pair()); - } - static CGAL::First_of_pair_property_map > - normal_property_map () - { - return CGAL::make_first_of_pair_property_map (std::pair()); - } - -private: - - + template + void remove_property (PMap& prop) + { + m_base.remove_property_map (prop); + } + template + bool remove_property (const std::string& name) + { + std::pair, bool> + pm = m_base.template property_map (name); + if (!(pm.second)) + return false; + remove_property (pm.first); + return true; + } + + template + T& property (typename Base::template Property_map& pmap, std::size_t index) + { + return pmap[Item (index)]; + } + template + const T& property (typename Base::template Property_map& pmap, std::size_t index) const + { + return property (pmap, index); + } + + template + T& property (const std::string& name, std::size_t index) + { + std::pair, bool> + pm = m_base.template add_property_map (name); + return property (pm.first, index); + } + template + const T& property (const std::string& name, std::size_t index) const + { + return property (name, index); + } }; // end of class Point_set_3