diff --git a/BGL/examples/BGL_polyhedron_3/CMakeLists.txt b/BGL/examples/BGL_polyhedron_3/CMakeLists.txt index 5fab077f346..56cecc799e6 100644 --- a/BGL/examples/BGL_polyhedron_3/CMakeLists.txt +++ b/BGL/examples/BGL_polyhedron_3/CMakeLists.txt @@ -67,6 +67,7 @@ create_single_source_cgal_program( "transform_iterator.cpp" ) create_single_source_cgal_program( "copy_polyhedron.cpp" ) +create_single_source_cgal_program( "polyhedron_generic_properties.cpp" ) if(OpenMesh_FOUND) target_link_libraries( copy_polyhedron ${OPENMESH_LIBRARIES} ) diff --git a/BGL/examples/BGL_polyhedron_3/polyhedron_generic_properties.cpp b/BGL/examples/BGL_polyhedron_3/polyhedron_generic_properties.cpp new file mode 100644 index 00000000000..597942469ef --- /dev/null +++ b/BGL/examples/BGL_polyhedron_3/polyhedron_generic_properties.cpp @@ -0,0 +1,23 @@ + +#include +#include +#include + +typedef CGAL::Simple_cartesian K; +typedef K::Point_3 Point_3; +typedef CGAL::Polyhedron_3 Mesh; + +int main() +{ + Mesh m; + CGAL::make_triangle(Point_3(0,0,0),Point_3(1,0,0),Point_3(1,1,0),m); + + typedef boost::property_map >::type VIM; + VIM vim = add(boost::vertex_property_t("index"), m); + put(vim, *(vertices(m).first), 7812); + std::cout << get(vim, *(vertices(m).first)) << std::endl; + remove(vim,m); + + return 0; +} + diff --git a/Polyhedron/include/CGAL/boost/graph/properties_Polyhedron_3.h b/Polyhedron/include/CGAL/boost/graph/properties_Polyhedron_3.h index 8fa5295751d..8616f8eb357 100644 --- a/Polyhedron/include/CGAL/boost/graph/properties_Polyhedron_3.h +++ b/Polyhedron/include/CGAL/boost/graph/properties_Polyhedron_3.h @@ -30,6 +30,7 @@ #include #include #include +#include #define CGAL_HDS_PARAM_ template < class Traits, class Items, class Alloc> class HDS @@ -37,6 +38,55 @@ namespace CGAL { namespace internal { +template +struct Dynamic_polyhedron_property_map { + + typedef K key_type; + typedef V value_type; + typedef value_type& reference; + typedef boost::read_write_property_map_tag category; + + + + Dynamic_polyhedron_property_map(const V& default_value) + : map_(new Map()), default_value(default_value) + {} + + void clear() + { + map_ = boost::shared_ptr(0); + } + + + friend value_type get(const Dynamic_polyhedron_property_map& m, const key_type& k) + { + typename Map::const_iterator it = m.map_->find(k); + if(it == m.map_->end()){ + return m.default(); + } + return it->second; + } + + + friend void put(Dynamic_polyhedron_property_map& m, const key_type& k, const value_type& v) + { + if(v != m.default()){ + (*(m.map_))[k] = v; + } + } + + + const V& default() const + { + return default_value; + } + + + V default_value; + typedef boost::unordered_map Map; + boost::shared_ptr map_; +}; + template class Polyhedron_index_map_external : public boost::put_get_helper > @@ -484,8 +534,37 @@ struct graph_has_property, vertex_index_t> > {}; + +template +struct property_map, boost::vertex_property_t > +{ + typedef CGAL::Polyhedron_3 SM; + typedef typename boost::graph_traits::vertex_descriptor vertex_descriptor; + typedef CGAL::internal::Dynamic_polyhedron_property_map type; + typedef type const_type; +}; + + } // namespace boost +namespace CGAL { + +template +typename boost::property_map, boost::vertex_property_t >::const_type +add(boost::vertex_property_t vprop, Polyhedron_3& poly) +{ + typedef CGAL::Polyhedron_3 SM; + typedef typename boost::graph_traits::vertex_descriptor vertex_descriptor; + return internal::Dynamic_polyhedron_property_map(V()); +} + + template +void remove(Pmap pm, Polyhedron_3&) +{ + pm.clear(); +} + +} // namespace CGAL #undef CGAL_HDS_PARAM_ diff --git a/Surface_mesh/include/CGAL/boost/graph/properties_Surface_mesh.h b/Surface_mesh/include/CGAL/boost/graph/properties_Surface_mesh.h index ff2d1fc5cc2..fe4cd005566 100644 --- a/Surface_mesh/include/CGAL/boost/graph/properties_Surface_mesh.h +++ b/Surface_mesh/include/CGAL/boost/graph/properties_Surface_mesh.h @@ -87,19 +87,30 @@ public: // overloads and specializations in the boost namespace namespace boost { -#if 1 + template struct property_map, boost::vertex_property_t > { typedef CGAL::Surface_mesh SM; - typedef typename SM:: template Property_map type; + typedef typename SM:: template Property_map type; typedef type const_type; }; +template +struct property_map, boost::face_property_t > +{ + typedef CGAL::Surface_mesh SM; + typedef typename SM:: template Property_map type; + typedef type const_type; +}; -#endif - - +template +struct property_map, boost::edge_property_t > +{ + typedef CGAL::Surface_mesh SM; + typedef typename SM:: template Property_map type; + typedef type const_type; +}; // // edge_weight //