diff --git a/Installation/CHANGES.md b/Installation/CHANGES.md index 7a159e087bf9..e6cffb6a15d2 100644 --- a/Installation/CHANGES.md +++ b/Installation/CHANGES.md @@ -11,6 +11,10 @@ - Introduces two traits decorators, namely `Arr_tracing_traits_2` and `Arr_counting_traits_2`, which can be used to extract debugging and informative metadata about the traits in use while a program is being executed. +### [Polygon Mesh Processing](https://doc.cgal.org/6.0/Manual/packages.html#PkgPolygonMeshProcessing) + +- Added the function `minmax_dihedral_angle()` to identify the sharpest edges of a triangle mesh + ## [Release 6.0.1](https://github.com/CGAL/cgal/releases/tag/v6.0.1) ### [Poisson Surface Reconstruction](https://doc.cgal.org/6.0.1/Manual/packages.html#PkgPoissonSurfaceReconstruction3) diff --git a/Lab/demo/Lab/Scene_surface_mesh_item.cpp b/Lab/demo/Lab/Scene_surface_mesh_item.cpp index a3e317451c39..8395153fa749 100644 --- a/Lab/demo/Lab/Scene_surface_mesh_item.cpp +++ b/Lab/demo/Lab/Scene_surface_mesh_item.cpp @@ -32,7 +32,6 @@ #include #include #include -#include #include "triangulate_primitive.h" #include diff --git a/Lab/demo/Lab/include/CGAL/statistics_helpers.h b/Lab/demo/Lab/include/CGAL/statistics_helpers.h index 6ea808ff4084..40d2a1aebd37 100644 --- a/Lab/demo/Lab/include/CGAL/statistics_helpers.h +++ b/Lab/demo/Lab/include/CGAL/statistics_helpers.h @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -84,7 +85,7 @@ void angles(Mesh* poly, double& mini, double& maxi, double& ave) template void dihedral_angles(Mesh* poly, double& minda, double& maxda) { - auto da = CGAL::Polygon_mesh_processing::detect_sharp_edges(*poly); + auto da = CGAL::Polygon_mesh_processing::minmax_dihedral_angle(*poly); minda = da.first.second; maxda = da.second.second; } diff --git a/Polygon_mesh_processing/doc/Polygon_mesh_processing/PackageDescription.txt b/Polygon_mesh_processing/doc/Polygon_mesh_processing/PackageDescription.txt index 6b74ce9696a3..85ed3a4b1822 100644 --- a/Polygon_mesh_processing/doc/Polygon_mesh_processing/PackageDescription.txt +++ b/Polygon_mesh_processing/doc/Polygon_mesh_processing/PackageDescription.txt @@ -249,6 +249,7 @@ The page \ref bgl_namedparameters "Named Parameters" describes their usage. - \link PMP_measure_grp `CGAL::Polygon_mesh_processing::longest_border()` \endlink - \link PMP_measure_grp `CGAL::Polygon_mesh_processing::centroid()` \endlink - \link PMP_measure_grp `CGAL::Polygon_mesh_processing::match_faces()` \endlink +- \link PMP_measure_grp `CGAL::Polygon_mesh_processing::minmax_dihedral_angle()` \endlink \cgalCRPSection{Feature Detection Functions} - `CGAL::Polygon_mesh_processing::sharp_edges_segmentation()` diff --git a/Polygon_mesh_processing/examples/Polygon_mesh_processing/detect_features_example.cpp b/Polygon_mesh_processing/examples/Polygon_mesh_processing/detect_features_example.cpp index a13057628a40..d1204e96ace9 100644 --- a/Polygon_mesh_processing/examples/Polygon_mesh_processing/detect_features_example.cpp +++ b/Polygon_mesh_processing/examples/Polygon_mesh_processing/detect_features_example.cpp @@ -1,6 +1,7 @@ #include #include +#include #include #include @@ -25,7 +26,7 @@ int main(int argc, char* argv[]) return 1; } - std::pair, std::pair> res = PMP::detect_sharp_edges(mesh); + std::pair, std::pair> res = PMP::minmax_dihedral_angle(mesh); std::cout << "Sharpest dihedral angles: " << res.first.second << " " << res.second.second << std::endl; diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/detect_features.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/detect_features.h index 45f9df61e3bb..cca9abe97353 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/detect_features.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/detect_features.h @@ -306,102 +306,6 @@ void detect_sharp_edges(const PolygonMesh& pmesh, get_parameter(np, internal_np::vertex_feature_degree)); } -/*! - * \ingroup PMP_detect_features_grp - * - * \brief detects the edges with the smallest and largest dihedral angle in degrees. - * - * \tparam TriangleMesh a model of `HalfedgeListGraph` - * \tparam FT a number type. It is - * either deduced from the `geom_traits` \ref bgl_namedparameters "Named Parameters" if provided, - * or from the geometric traits class deduced from the point property map - * of `TriangleMesh`. - * \tparam EdgeIsFeatureMap a model of `ReadWritePropertyMap` with `boost::graph_traits::%edge_descriptor` - * as key type and `bool` as value type. It must be default constructible. - * \tparam NamedParameters a sequence of \ref bgl_namedparameters "Named Parameters" - * - * \param pmesh the polygon mesh - * \param np an optional sequence of \ref bgl_namedparameters "Named Parameters" among the ones listed below. - * `GT` stands for the type of the object provided to the named parameter `geom_traits()`. - * - * \cgalNamedParamsBegin - * - * \cgalParamNBegin{vertex_point_map} - * \cgalParamDescription{a property map associating points to the vertices of `pmesh`.} - * \cgalParamType{a class model of `ReadablePropertyMap` with - * `boost::graph_traits::%vertex_descriptor` - * as key type and `GT::Point_3` as value type.} - * \cgalParamDefault{`boost::get(CGAL::vertex_point, pmesh)`.} - * \cgalParamExtra{If this parameter is omitted, an internal property map for - * `CGAL::vertex_point_t` must be available in `TriangleMesh`.} - * \cgalParamNEnd - - * \cgalParamNBegin{geom_traits} - * \cgalParamDescription{an instance of a geometric traits class} - * \cgalParamType{a class model of `Kernel`} - * \cgalParamDefault{a \cgal Kernel deduced from the point type, using `CGAL::Kernel_traits`} - * \cgalParamExtra{The geometric traits class must be compatible with the vertex point type.} - * \cgalParamNEnd - * \cgalNamedParamsEnd - * - * \see `sharp_edges_segmentation()` - */ -#ifdef DOXYGEN_RUNNING -template -#else -template -#endif -#ifdef DOXYGEN_RUNNING -std::pair, std::pair> -#else -std::pair< - std::pair::edge_descriptor, typename GetGeomTraits::type::FT>, - std::pair::edge_descriptor, typename GetGeomTraits::type::FT> - > -#endif -detect_sharp_edges(const TriangleMesh& pmesh, - const CGAL_NP_CLASS& np = parameters::default_values()) -{ - using parameters::choose_parameter; - using parameters::get_parameter; - - // extract types from NPs - typedef typename GetGeomTraits::type GT; - // GT gt = choose_parameter(get_parameter(np, internal_np::geom_traits)); - - typedef typename GetVertexPointMap::const_type VPM; - VPM vpm = choose_parameter(get_parameter(np, internal_np::vertex_point), - get_const_property_map(boost::vertex_point, pmesh)); - - typedef typename GT::FT FT; - typedef typename boost::graph_traits::edge_descriptor edge_descriptor; - typedef typename boost::graph_traits::halfedge_descriptor halfedge_descriptor; - typedef typename boost::graph_traits::vertex_descriptor vertex_descriptor; - edge_descriptor low, high; - FT lo(200), hi(-200); - for (edge_descriptor e : edges(pmesh)){ - if(! is_border(e,pmesh)){ - halfedge_descriptor h = halfedge(e,pmesh); - vertex_descriptor p = source(h,pmesh); - vertex_descriptor q = target(h,pmesh); - vertex_descriptor r = target(next(h,pmesh),pmesh); - vertex_descriptor s = target(next(opposite(h,pmesh),pmesh),pmesh); - FT da = approximate_dihedral_angle(get(vpm,p),get(vpm,q),get(vpm,r),get(vpm,s)); - if(da < lo){ - low = e; - lo = da; - } - if(da > hi){ - high = e; - hi = da; - } - } - } - return std::make_pair(std::make_pair(low, lo),std::make_pair(high,hi)); -} - /*! * \ingroup PMP_detect_features_grp * diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/measure.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/measure.h index fd1ad888f5ab..e0b8d66d6585 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/measure.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/measure.h @@ -1113,6 +1113,103 @@ void match_faces(const PolygonMesh1& m1, } } + +/*! + * \ingroup PMP_measure_grp + * + * \brief detects the edges with the smallest and largest dihedral angle in degrees. + * + * \tparam TriangleMesh a model of `HalfedgeListGraph` + * \tparam FT a number type. It is + * either deduced from the `geom_traits` \ref bgl_namedparameters "Named Parameters" if provided, + * or from the geometric traits class deduced from the point property map + * of `TriangleMesh`. + * \tparam EdgeIsFeatureMap a model of `ReadWritePropertyMap` with `boost::graph_traits::%edge_descriptor` + * as key type and `bool` as value type. It must be default constructible. + * \tparam NamedParameters a sequence of \ref bgl_namedparameters "Named Parameters" + * + * \param pmesh the polygon mesh + * \param np an optional sequence of \ref bgl_namedparameters "Named Parameters" among the ones listed below. + * `GT` stands for the type of the object provided to the named parameter `geom_traits()`. + * + * \cgalNamedParamsBegin + * + * \cgalParamNBegin{vertex_point_map} + * \cgalParamDescription{a property map associating points to the vertices of `pmesh`.} + * \cgalParamType{a class model of `ReadablePropertyMap` with + * `boost::graph_traits::%vertex_descriptor` + * as key type and `GT::Point_3` as value type.} + * \cgalParamDefault{`boost::get(CGAL::vertex_point, pmesh)`.} + * \cgalParamExtra{If this parameter is omitted, an internal property map for + * `CGAL::vertex_point_t` must be available in `TriangleMesh`.} + * \cgalParamNEnd + + * \cgalParamNBegin{geom_traits} + * \cgalParamDescription{an instance of a geometric traits class} + * \cgalParamType{a class model of `Kernel`} + * \cgalParamDefault{a \cgal Kernel deduced from the point type, using `CGAL::Kernel_traits`} + * \cgalParamExtra{The geometric traits class must be compatible with the vertex point type.} + * \cgalParamNEnd + * \cgalNamedParamsEnd + * + * \see `sharp_edges_segmentation()` + */ +#ifdef DOXYGEN_RUNNING +template +#else +template +#endif +#ifdef DOXYGEN_RUNNING +std::pair, std::pair> +#else +std::pair< + std::pair::edge_descriptor, typename GetGeomTraits::type::FT>, + std::pair::edge_descriptor, typename GetGeomTraits::type::FT> + > +#endif +minmax_dihedral_angle(const TriangleMesh& pmesh, + const CGAL_NP_CLASS& np = parameters::default_values()) +{ + using parameters::choose_parameter; + using parameters::get_parameter; + + // extract types from NPs + typedef typename GetGeomTraits::type GT; + // GT gt = choose_parameter(get_parameter(np, internal_np::geom_traits)); + + typedef typename GetVertexPointMap::const_type VPM; + VPM vpm = choose_parameter(get_parameter(np, internal_np::vertex_point), + get_const_property_map(boost::vertex_point, pmesh)); + + typedef typename GT::FT FT; + typedef typename boost::graph_traits::edge_descriptor edge_descriptor; + typedef typename boost::graph_traits::halfedge_descriptor halfedge_descriptor; + typedef typename boost::graph_traits::vertex_descriptor vertex_descriptor; + edge_descriptor low, high; + FT lo(200), hi(-200); + for (edge_descriptor e : edges(pmesh)){ + if(! is_border(e,pmesh)){ + halfedge_descriptor h = halfedge(e,pmesh); + vertex_descriptor p = source(h,pmesh); + vertex_descriptor q = target(h,pmesh); + vertex_descriptor r = target(next(h,pmesh),pmesh); + vertex_descriptor s = target(next(opposite(h,pmesh),pmesh),pmesh); + FT da = approximate_dihedral_angle(get(vpm,p),get(vpm,q),get(vpm,r),get(vpm,s)); + if(da < lo){ + low = e; + lo = da; + } + if(da > hi){ + high = e; + hi = da; + } + } + } + return std::make_pair(std::make_pair(low, lo),std::make_pair(high,hi)); +} + } // namespace Polygon_mesh_processing } // namespace CGAL