// Copyright (c) 2012 GeometryFactory (France). All rights reserved. // All rights reserved. // // Licensees holding a valid commercial license may use this file in // accordance with the commercial license agreement provided with the software. // // This file is part of CGAL (www.cgal.org); you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public License as // published by the Free Software Foundation; version 2.1 of the License. // See the file LICENSE.LGPL distributed with CGAL. // // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. // // $URL$ // $Id$ // // // Author(s) : Philipp Möller #ifndef CGAL_PROPERTIES_SURFACE_MESH_H #define CGAL_PROPERTIES_SURFACE_MESH_H #include #include #include #include #include namespace CGAL { template class SM_edge_weight_pmap : public boost::put_get_helper::type::FT, SM_edge_weight_pmap > { typedef CGAL::Surface_mesh SM; public: typedef boost::readable_property_map_tag category; typedef typename CGAL::Kernel_traits::type::FT value_type; typedef value_type reference; typedef typename SM::Edge_index key_type; SM_edge_weight_pmap(const CGAL::Surface_mesh& sm) : pm_(sm. template get_property_map< typename SM::Vertex_index, typename SM::Point >("v:point")), sm_(sm) {} value_type operator[](const key_type& e) const { return CGAL::sqrt(CGAL::squared_distance(pm_[source(e, sm_)], pm_[target(e, sm_)])); } private: typename CGAL::Property_map< typename SM::Vertex_index, typename SM::Point > pm_; const SM& sm_; }; template class SM_index_pmap : public boost::put_get_helper > { public: typedef boost::readable_property_map_tag category; typedef std::size_t value_type; typedef std::size_t reference; typedef VEF key_type; value_type operator[](const key_type& vd) const { return vd.idx(); } }; } // CGAL // 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 CGAL::Property_map type; typedef typename CGAL::Property_map const_type; }; template typename property_map, boost::vertex_property_t >::const_type get(boost::vertex_property_t vprop, const CGAL::Surface_mesh& sm) { return sm.template get_property_map::Vertex_index, T>(vprop.s); } template typename property_map, boost::vertex_property_t >::const_type add(boost::vertex_property_t vprop, CGAL::Surface_mesh& sm) { return sm.template add_property_map::Vertex_index, T>(vprop.s, vprop.t); } template void remove(CGAL::Property_map pm, CGAL::Surface_mesh

& sm) { return sm.remove_property_map(pm); } #endif // // edge_weight // template struct property_map, boost::edge_weight_t > { typedef CGAL::SM_edge_weight_pmap type; typedef CGAL::SM_edge_weight_pmap const_type; }; template typename property_map, boost::edge_weight_t>::const_type get(boost::edge_weight_t, const CGAL::Surface_mesh& sm) { return CGAL::SM_edge_weight_pmap(sm); } template typename CGAL::Kernel_traits::type::FT get(boost::edge_weight_t, const CGAL::Surface_mesh& sm, const typename boost::graph_traits >::edge_descriptor& e) { return CGAL::SM_edge_weight_pmap(sm)[e]; } // // vertex_index // template struct property_map, boost::vertex_index_t > { typedef CGAL::SM_index_pmap >::vertex_descriptor> type; typedef CGAL::SM_index_pmap >::vertex_descriptor> const_type; }; template CGAL::SM_index_pmap >::vertex_descriptor> get(const boost::vertex_index_t&, const CGAL::Surface_mesh&) { return CGAL::SM_index_pmap >::vertex_descriptor>(); } // // face_index // template struct property_map, boost::face_index_t > { typedef CGAL::SM_index_pmap >::face_descriptor> type; typedef CGAL::SM_index_pmap >::face_descriptor> const_type; }; template typename property_map, boost::face_index_t>::const_type get(const boost::face_index_t&, const CGAL::Surface_mesh&) { return CGAL::SM_index_pmap >::face_descriptor>(); } // // edge_index // template struct property_map, boost::edge_index_t > { typedef CGAL::SM_index_pmap >::edge_descriptor> type; typedef CGAL::SM_index_pmap >::edge_descriptor> const_type; }; template CGAL::SM_index_pmap >::edge_descriptor> get(const boost::edge_index_t&, const CGAL::Surface_mesh&) { return CGAL::SM_index_pmap >::edge_descriptor>(); } // // halfedge_index // template struct property_map, boost::halfedge_index_t > { typedef CGAL::SM_index_pmap >::halfedge_descriptor> type; typedef CGAL::SM_index_pmap >::halfedge_descriptor> const_type; }; template CGAL::SM_index_pmap >::halfedge_descriptor> get(const boost::halfedge_index_t&, const CGAL::Surface_mesh&) { return CGAL::SM_index_pmap >::halfedge_descriptor>(); } // // vertex_point // template struct property_map, CGAL::vertex_point_t > { typedef CGAL::Surface_mesh SM; typedef typename CGAL::Property_map< typename SM::Vertex_index, K > type; typedef type const_type; }; template typename property_map, CGAL::vertex_point_t >::const_type get(CGAL::vertex_point_t, const CGAL::Surface_mesh& g) { return g.points(); } // get for intrinsic properties #define CGAL_SM_INTRINSIC_PROPERTY(RET, PROP, TYPE) \ template \ RET \ get(PROP p, const CGAL::Surface_mesh& sm, \ typename boost::graph_traits< CGAL::Surface_mesh >::TYPE x) \ { return get(get(p, sm), x); } \ CGAL_SM_INTRINSIC_PROPERTY(std::size_t, boost::vertex_index_t, vertex_descriptor) CGAL_SM_INTRINSIC_PROPERTY(std::size_t, boost::edge_index_t, edge_descriptor) CGAL_SM_INTRINSIC_PROPERTY(std::size_t, boost::halfedge_index_t, halfedge_descriptor) CGAL_SM_INTRINSIC_PROPERTY(std::size_t, boost::face_index_t, face_descriptor) CGAL_SM_INTRINSIC_PROPERTY(Point&, CGAL::vertex_point_t, vertex_descriptor) #undef CGAL_SM_INTRINSIC_PROPERTY // put for intrinsic properties // only available for vertex_point template void put(CGAL::vertex_point_t p, const CGAL::Surface_mesh& g, typename boost::graph_traits< CGAL::Surface_mesh >::vertex_descriptor x, const K& point) { typedef CGAL::Surface_mesh SM; CGAL_assertion(g.is_valid(x)); CGAL::Property_map< typename boost::graph_traits::vertex_descriptor, K> prop = get(p, g); prop[x] = point; } } // boost #endif /* CGAL_PROPERTIES_SURFACE_MESH_H */