From 361f6e2f63c57410fcabbcb05f8bf3baddbd66d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mael=20Rouxel-Labb=C3=A9?= Date: Fri, 4 Aug 2023 13:30:26 +0200 Subject: [PATCH] Clean code to use Face_location / Barycentric_coordinates everywhere --- .../CGAL/Polygon_mesh_processing/locate.h | 144 ++++++------------ 1 file changed, 50 insertions(+), 94 deletions(-) diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/locate.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/locate.h index 26d0266e03ad..a8359779125b 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/locate.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/locate.h @@ -52,6 +52,36 @@ namespace CGAL { namespace Polygon_mesh_processing { + +/// \ingroup PMP_locate_grp +/// +/// A variant used in the function `get_descriptor_from_location()`. +template +using descriptor_variant = boost::variant::vertex_descriptor, + typename boost::graph_traits::halfedge_descriptor, + typename boost::graph_traits::face_descriptor>; + +/// \ingroup PMP_locate_grp +/// +/// A triplet of coordinates describing the barycentric coordinates of a point +/// with respect to the vertices of a triangular face. +/// +/// \sa `Face_location` +template +using Barycentric_coordinates = std::array; + +/// \ingroup PMP_locate_grp +/// +/// If `tm` is the input triangulated surface mesh and given the pair (`f`, `bc`) +/// such that `bc` is the triplet of barycentric coordinates `(w0, w1, w2)`, the correspondence +/// between the coordinates in `bc` and the vertices of the face `f` is the following: +/// - `w0` corresponds to `source(halfedge(f, tm), tm)` +/// - `w1` corresponds to `target(halfedge(f, tm), tm)` +/// - `w2` corresponds to `target(next(halfedge(f, tm), tm), tm)` +template +using Face_location = std::pair::face_descriptor, + Barycentric_coordinates >; + namespace internal { // The Ray must have the same ambient dimension as the property map's value type (aka, the point type) @@ -85,51 +115,20 @@ struct Location_traits typedef typename boost::graph_traits::face_descriptor face_descriptor; - typedef std::array Barycentric_coordinates; - typedef std::pair Face_location; + typedef CGAL::Polygon_mesh_processing::Barycentric_coordinates Barycentric_coordinates; + typedef CGAL::Polygon_mesh_processing::Face_location Face_location; }; } // end namespace internal -/// \ingroup PMP_locate_grp -/// -/// A variant used in the function `get_descriptor_from_location()`. -template -using descriptor_variant = boost::variant::vertex_descriptor, - typename boost::graph_traits::halfedge_descriptor, - typename boost::graph_traits::face_descriptor>; - -/// \ingroup PMP_locate_grp -/// -/// A triplet of coordinates describing the barycentric coordinates of a point -/// with respect to the vertices of a triangular face. -/// -/// \sa `Face_location` -template -using Barycentric_coordinates = std::array; - -/// \ingroup PMP_locate_grp -/// -/// If `tm` is the input triangulated surface mesh and given the pair (`f`, `bc`) -/// such that `bc` is the triplet of barycentric coordinates `(w0, w1, w2)`, the correspondence -/// between the coordinates in `bc` and the vertices of the face `f` is the following: -/// - `w0` corresponds to `source(halfedge(f, tm), tm)` -/// - `w1` corresponds to `target(halfedge(f, tm), tm)` -/// - `w2` corresponds to `target(next(halfedge(f, tm), tm), tm)` -template -using Face_location = std::pair::face_descriptor, - Barycentric_coordinates >; - // forward declarations template -bool is_in_face(const std::pair::face_descriptor, - std::array >& loc, +bool is_in_face(const Face_location& loc, const TriangleMesh& tm); template descriptor_variant -get_descriptor_from_location(const std::pair::face_descriptor, - std::array >& loc, +get_descriptor_from_location(const Face_location& loc, const TriangleMesh& tm); // end of forward declarations @@ -138,8 +137,7 @@ namespace internal { template OutputIterator -incident_faces(const std::pair::face_descriptor, - std::array >& location, +incident_faces(const Face_location& loc, const TriangleMesh& tm, OutputIterator out) { @@ -147,7 +145,7 @@ incident_faces(const std::pair::face_ typedef typename boost::graph_traits::halfedge_descriptor halfedge_descriptor; typedef typename boost::graph_traits::face_descriptor face_descriptor; - const descriptor_variant dv = get_descriptor_from_location(location, tm); + const descriptor_variant dv = get_descriptor_from_location(loc, tm); if(const vertex_descriptor* vd_ptr = boost::get(&dv)) { @@ -173,7 +171,7 @@ incident_faces(const std::pair::face_ // Snapping coordinates for robustness template bool -snap_coordinates_to_border(std::array& coords, +snap_coordinates_to_border(Barycentric_coordinates& coords, const FT tolerance = std::numeric_limits::epsilon()) { #ifdef CGAL_PMP_LOCATE_DEBUG @@ -224,8 +222,7 @@ snap_coordinates_to_border(std::array& coords, template bool -snap_location_to_border(std::pair::face_descriptor, - std::array >& loc, +snap_location_to_border(Face_location& loc, const TriangleMesh /*tm*/, const FT tolerance = std::numeric_limits::epsilon()) { @@ -235,7 +232,7 @@ snap_location_to_border(std::pair::fa template struct Barycentric_coordinate_calculator // 2D version { - std::array + Barycentric_coordinates operator()(const P& ip, const P& iq, const P& ir, const P& iquery, const K& k) const { typedef typename K::FT FT; @@ -273,7 +270,7 @@ struct Barycentric_coordinate_calculator // 2D version template struct Barycentric_coordinate_calculator { - std::array + Barycentric_coordinates operator()(const P& ip, const P& iq, const P& ir, const P& iquery, const K& k) const { typedef typename K::FT FT; @@ -364,7 +361,7 @@ struct Barycentric_point_constructor // 3D version /// \pre `query` lies on the plane defined by `p`, `q`, and `r`. /// template -std::array +Barycentric_coordinates barycentric_coordinates(const Point& p, const Point& q, const Point& r, const Point& query, const GeomTraits& gt) { @@ -373,7 +370,7 @@ barycentric_coordinates(const Point& p, const Point& q, const Point& r, const Po } template -std::array::type::FT, 3> +Barycentric_coordinates::type::FT> barycentric_coordinates(const Point& p, const Point& q, const Point& r, const Point& query) { typedef typename CGAL::Kernel_traits::type Kernel; @@ -411,7 +408,7 @@ random_location_on_halfedge(typename boost::graph_traits::halfedge const int h_id = halfedge_index_in_face(hd, tm); const FT t(rnd.uniform_real(0., 1.)); - std::array coordinates; + Barycentric_coordinates coordinates; coordinates[h_id] = t; coordinates[(h_id+1)%3] = FT(1)-t; coordinates[(h_id+2)%3] = FT(0); @@ -510,8 +507,7 @@ descriptor_variant #ifdef DOXYGEN_RUNNING // just for convenience because template alias do not allow template deduction get_descriptor_from_location(const Face_location& loc, #else -get_descriptor_from_location(const std::pair::face_descriptor, - std::array >& loc, +get_descriptor_from_location(const Face_location& loc, #endif const TriangleMesh& tm) { @@ -589,12 +585,10 @@ get_descriptor_from_location(const std::pair #ifdef DOXYGEN_RUNNING Point -construct_point(const Face_location& loc, #else typename internal::Location_traits::Point -construct_point(const std::pair::face_descriptor, - std::array >& loc, #endif +construct_point(const Face_location& loc, const TriangleMesh& tm, const NamedParameters& np = parameters::default_values()) { @@ -648,12 +642,7 @@ construct_point(const std::pair::face /// template bool -#ifdef DOXYGEN_RUNNING is_on_vertex(const Face_location& loc, -#else -is_on_vertex(const std::pair::face_descriptor, - std::array >& loc, -#endif const typename boost::graph_traits::vertex_descriptor vd, const TriangleMesh& tm) { @@ -692,12 +681,7 @@ is_on_vertex(const std::pair::face_de /// template bool -#ifdef DOXYGEN_RUNNING is_on_halfedge(const Face_location& loc, -#else -is_on_halfedge(const std::pair::face_descriptor, - std::array >& loc, -#endif const typename boost::graph_traits::halfedge_descriptor hd, const TriangleMesh& tm) { @@ -738,11 +722,7 @@ is_on_halfedge(const std::pair::face_ /// template bool -#ifdef DOXYGEN_RUNNING is_in_face(const Barycentric_coordinates& bar, -#else -is_in_face(const std::array& bar, -#endif const TriangleMesh& tm) { CGAL_USE(tm); @@ -780,12 +760,7 @@ is_in_face(const std::array& bar, /// template bool -#ifdef DOXYGEN_RUNNING is_in_face(const Face_location& loc, -#else -is_in_face(const std::pair::face_descriptor, - std::array >& loc, -#endif const TriangleMesh& tm) { return is_in_face(loc.second, tm); @@ -812,12 +787,7 @@ is_in_face(const std::pair::face_desc /// template bool -#ifdef DOXYGEN_RUNNING is_on_face_border(const Face_location& loc, -#else -is_on_face_border(const std::pair::face_descriptor, - std::array >& loc, -#endif const TriangleMesh& tm) { if(!is_in_face(loc, tm)) @@ -853,12 +823,7 @@ is_on_face_border(const std::pair::fa /// template bool -#ifdef DOXYGEN_RUNNING is_on_mesh_border(const Face_location& loc, -#else -is_on_mesh_border(const std::pair::face_descriptor, - std::array >& loc, -#endif const TriangleMesh& tm) { typedef typename boost::graph_traits::halfedge_descriptor halfedge_descriptor; @@ -1136,7 +1101,7 @@ locate_in_face(const typename internal::Location_traits coords = barycentric_coordinates(p0, p1, p2, query, gt); + Barycentric_coordinates coords = barycentric_coordinates(p0, p1, p2, query, gt); if(snap_tolerance != FT(0) && !is_in_face(coords, tm)) { @@ -1174,12 +1139,7 @@ locate_in_face(const typename internal::Location_traits Face_location -#ifdef DOXYGEN_RUNNING locate_in_adjacent_face(const Face_location& loc, -#else -locate_in_adjacent_face(const std::pair::face_descriptor, - std::array >& loc, -#endif const typename boost::graph_traits::face_descriptor fd, const TriangleMesh& tm) { @@ -1247,11 +1207,9 @@ locate_in_adjacent_face(const std::pair bool -locate_in_common_face(std::pair::face_descriptor, - std::array >& known_location, +locate_in_common_face(Face_location& known_location, const typename internal::Location_traits::Point& query, - std::pair::face_descriptor, - std::array >& query_location, + Face_location& query_location, const TriangleMesh& tm, const NamedParameters& np, const FT tolerance = std::numeric_limits::epsilon()) @@ -1323,10 +1281,8 @@ locate_in_common_face(std::pair::face // - both locations must be known but can change template bool -locate_in_common_face(std::pair::face_descriptor, - std::array >& first_location, - std::pair::face_descriptor, - std::array >& second_location, +locate_in_common_face(Face_location& first_location, + Face_location& second_location, const TriangleMesh& tm) { typedef typename boost::graph_traits::face_descriptor face_descriptor;