From bd3dcc8ebcecffa03ea8b72ced708300a116ad4e Mon Sep 17 00:00:00 2001 From: Lingjie Zhu Date: Mon, 28 Aug 2017 09:50:04 +0800 Subject: [PATCH] simplify self-defined metric --- .../vsa_metric_example.cpp | 21 ++++++------------ .../include/CGAL/VSA_approximation.h | 8 +++---- .../vsa_metric_test.cpp | 22 ++++++------------- 3 files changed, 18 insertions(+), 33 deletions(-) diff --git a/Surface_mesh_approximation/examples/Surface_mesh_approximation/vsa_metric_example.cpp b/Surface_mesh_approximation/examples/Surface_mesh_approximation/vsa_metric_example.cpp index 68aa06ac5f1..2c8afb47c27 100644 --- a/Surface_mesh_approximation/examples/Surface_mesh_approximation/vsa_metric_example.cpp +++ b/Surface_mesh_approximation/examples/Surface_mesh_approximation/vsa_metric_example.cpp @@ -23,12 +23,10 @@ typedef boost::property_map::type VertexPoint typedef boost::associative_property_map > FacetAreaMap; typedef boost::associative_property_map > FacetCenterMap; -// proxy -struct PointProxy { - Point center; -}; +// use a point as proxy +typedef Point PointProxy; -// metric functor +// user defined point-wise compact metric struct CompactMetric { typedef PointProxy Proxy; @@ -38,9 +36,9 @@ struct CompactMetric { // calculate the error of a facet to a proxy // here is just the Euclidean distance - FT operator()(const Facet_handle &f, const PointProxy &px) const { + FT operator()(const Facet_handle &f, const Proxy &px) const { return FT(std::sqrt(CGAL::to_double( - CGAL::squared_distance(center_pmap[f], px.center)))); + CGAL::squared_distance(center_pmap[f], px)))); } const FacetCenterMap center_pmap; @@ -56,7 +54,7 @@ struct PointProxyFitting { // a template functor fit a new proxy from a range of facets template - PointProxy operator()(const FacetIterator beg, const FacetIterator end) const { + Proxy operator()(const FacetIterator beg, const FacetIterator end) const { // fitting center Vector center = CGAL::NULL_VECTOR; FT area = FT(0.0); @@ -65,12 +63,7 @@ struct PointProxyFitting { area += area_pmap[*fitr]; } center = center / area; - - // construct proxy - PointProxy px; - px.center = CGAL::ORIGIN + center; - - return px; + return CGAL::ORIGIN + center; } const FacetCenterMap center_pmap; diff --git a/Surface_mesh_approximation/include/CGAL/VSA_approximation.h b/Surface_mesh_approximation/include/CGAL/VSA_approximation.h index ea800c90195..dffa5c88c82 100644 --- a/Surface_mesh_approximation/include/CGAL/VSA_approximation.h +++ b/Surface_mesh_approximation/include/CGAL/VSA_approximation.h @@ -246,7 +246,7 @@ public: /*! * Initialize and prepare for the approximation. * @param _mesh `CGAL TriangleMesh` on which approximation operate. - * @param _point_map vertex point map of the mesh + * @param _point_pmap vertex point map of the mesh */ VSA_approximation(const TriangleMesh &_mesh, const VertexPointMap &_point_pmap) : @@ -267,7 +267,7 @@ public: * Set the mesh for approximation and rebuild the internal data structure. * @pre @a _mesh.is_pure_triangle() * @param _mesh `CGAL TriangleMesh` on which approximation operate. - * @param _point_map vertex point map of the mesh + * @param _point_pmap vertex point map of the mesh */ void set_mesh(const TriangleMesh &_mesh, const VertexPointMap &_point_pmap) { m_pmesh = &_mesh; @@ -484,9 +484,9 @@ public: /*! * @brief Adding proxies. The proxies are not updated via fitting process. - * @param num_proxies number of proxies * @param adding_method select one of the adding method: hierarchical or incremental(furthest). - * @param inner_iteration the coarse re-fitting iteration before incremental insertion + * @param num_proxies number of proxies + * @param inner_iteration coarse re-fitting before each insertion if incremental is selected * @return number of proxies successfully added. */ std::size_t add_proxies(const Initialization &adding_method, diff --git a/Surface_mesh_approximation/test/Surface_mesh_approximation/vsa_metric_test.cpp b/Surface_mesh_approximation/test/Surface_mesh_approximation/vsa_metric_test.cpp index d74c74343da..7b59f88ce43 100644 --- a/Surface_mesh_approximation/test/Surface_mesh_approximation/vsa_metric_test.cpp +++ b/Surface_mesh_approximation/test/Surface_mesh_approximation/vsa_metric_test.cpp @@ -22,32 +22,29 @@ typedef boost::associative_property_map > FacetAreaMa typedef boost::associative_property_map > FacetCenterMap; typedef boost::property_map::type VertexPointMap; -struct PointProxy { - Point center; -}; - +// user defined point-wise compact metric struct CompactMetric { - typedef PointProxy Proxy; + typedef Point Proxy; CompactMetric(const FacetCenterMap &_center_pmap) : center_pmap(_center_pmap) {} - FT operator()(const Facet_handle &f, const PointProxy &px) const { + FT operator()(const Facet_handle &f, const Proxy &px) const { return FT(std::sqrt(CGAL::to_double( - CGAL::squared_distance(center_pmap[f], px.center)))); + CGAL::squared_distance(center_pmap[f], px)))); } const FacetCenterMap center_pmap; }; struct PointProxyFitting { - typedef PointProxy Proxy; + typedef Point Proxy; PointProxyFitting(const FacetCenterMap &_center_pmap, const FacetAreaMap &_area_pmap) : center_pmap(_center_pmap), area_pmap(_area_pmap) {} template - PointProxy operator()(const FacetIterator beg, const FacetIterator end) const { + Proxy operator()(const FacetIterator beg, const FacetIterator end) const { // fitting center Vector center = CGAL::NULL_VECTOR; FT area(0); @@ -56,12 +53,7 @@ struct PointProxyFitting { area += area_pmap[*fitr]; } center = center / area; - - // construct proxy - PointProxy px; - px.center = CGAL::ORIGIN + center; - - return px; + return CGAL::ORIGIN + center; } const FacetCenterMap center_pmap;