From d96f8986bef609e03e8ca121ffab3fbef5a5d039 Mon Sep 17 00:00:00 2001 From: Julian Komaromy Date: Wed, 9 Jun 2021 21:10:04 +0200 Subject: [PATCH] fix constructors and uncomment lines --- .../Edge_collapse/GarlandHeckbert_policies.h | 20 +++++- .../internal/GarlandHeckbert_policy_base.h | 64 ++++++++++--------- 2 files changed, 51 insertions(+), 33 deletions(-) diff --git a/Surface_mesh_simplification/include/CGAL/Surface_mesh_simplification/Policies/Edge_collapse/GarlandHeckbert_policies.h b/Surface_mesh_simplification/include/CGAL/Surface_mesh_simplification/Policies/Edge_collapse/GarlandHeckbert_policies.h index a1f4ba5d99c..5daad9b712f 100644 --- a/Surface_mesh_simplification/include/CGAL/Surface_mesh_simplification/Policies/Edge_collapse/GarlandHeckbert_policies.h +++ b/Surface_mesh_simplification/include/CGAL/Surface_mesh_simplification/Policies/Edge_collapse/GarlandHeckbert_policies.h @@ -20,6 +20,10 @@ namespace Surface_mesh_simplification { template class GarlandHeckbert_policies; +template +using Cost_property = CGAL::dynamic_vertex_property_t>; + template using Vertex_cost_map = typename boost::property_map>>::type; @@ -59,8 +63,20 @@ class GarlandHeckbert_policies : typedef typename GeomTraits::FT FT; - GarlandHeckbert_policies() { } - GarlandHeckbert_policies(TriangleMesh tm) : tm_(tm) { } + GarlandHeckbert_policies(TriangleMesh& tmesh, FT dm = FT(100)) + : Get_cost(dm) { + /** + * TODO call base class constructors? + */ + Vertex_cost_map vcm_ = get(Cost_property(), + tmesh); + + /** + * initialize the two base class cost matrices (protected members) + */ + Get_cost::m_cost_matrices = vcm_; + Get_placement::m_cost_matrices = vcm_; + } /** * TODO implementations of all functions needed by the base implementation diff --git a/Surface_mesh_simplification/include/CGAL/Surface_mesh_simplification/Policies/Edge_collapse/internal/GarlandHeckbert_policy_base.h b/Surface_mesh_simplification/include/CGAL/Surface_mesh_simplification/Policies/Edge_collapse/internal/GarlandHeckbert_policy_base.h index 631fcc677c5..1ebb64bed7d 100644 --- a/Surface_mesh_simplification/include/CGAL/Surface_mesh_simplification/Policies/Edge_collapse/internal/GarlandHeckbert_policy_base.h +++ b/Surface_mesh_simplification/include/CGAL/Surface_mesh_simplification/Policies/Edge_collapse/internal/GarlandHeckbert_policy_base.h @@ -19,6 +19,7 @@ #include #include +#include #include #include @@ -28,6 +29,11 @@ namespace CGAL { namespace Surface_mesh_simplification { namespace internal { + +template +Mat_4 combine_matrices(const Mat_4& a, const Mat_4& b) { + return a + b; +} template; - using Vector_3 = typename GeomTraits::Vector_3; - using Point_3 = typename GeomTraits::Point_3; - Mat_4 zero_mat = Mat_4::Zero(); for(vertex_descriptor v : vertices(tmesh)) @@ -107,7 +113,9 @@ class GarlandHeckbert_cost_base put(m_cost_matrices, vt, get(m_cost_matrices, vt) + quadric); if(!is_border_edge(shd, tmesh)) + { continue; + } //TODO behaviour at discontinuous edges is largely untested at this stage //TODO helper function to add to target @@ -115,8 +123,10 @@ class GarlandHeckbert_cost_base const Vector_3 discontinuity_normal = cross_product(edge_vector, face_normal); // normalize - const Vector_3 normalized = discontinuity_normal / sqrt(discontinuity_normal.squared_length()); - const Mat_4 discontinuous_quadric = construct_quadric(normalized, get(vpm, vs)); + const Vector_3 normalized = discontinuity_normal + / sqrt(discontinuity_normal.squared_length()); + const Mat_4 discontinuous_quadric + = discontinuity_multiplier * construct_quadric(normalized, get(vpm, vs)); put(m_cost_matrices, vs, get(m_cost_matrices, vs) + discontinuous_quadric); put(m_cost_matrices, vt, get(m_cost_matrices, vt) + discontinuous_quadric); @@ -129,7 +139,6 @@ class GarlandHeckbert_cost_base const boost::optional& placement) const { typedef boost::optional Optional_FT; - return boost::optional(); if(!placement) { // return empty value @@ -151,18 +160,18 @@ class GarlandHeckbert_cost_base void update_after_collapse(const Profile& profile, const VertexDescriptor new_v) const { - /* put(m_cost_matrices, new_v, combine_matrices(get(m_cost_matrices, profile.v0()), get(m_cost_matrices, profile.v1()))); - */ } + protected: + Vertex_cost_map m_cost_matrices; + private: - Mat_4 combine_matrices(const Mat_4& a, const Mat_4& b) const { - return a + b; - } - + + FT discontinuity_multiplier; + Col_4 point_to_homogenous_column(const Point_3& point) const { return Col_4(point.x(), point.y(), point.z(), FT(1)); } @@ -171,8 +180,6 @@ class GarlandHeckbert_cost_base Mat_4 construct_quadric(const Vector_3& normal , const Point_3& point) const { return static_cast(this)->construct_quadric_from_normal(normal, point); } - - Vertex_cost_map m_cost_matrices; }; //TODO should probably take a TirangleMesh as Parameter and define the VCM type in base classes @@ -202,13 +209,13 @@ class GarlandHeckbert_placement_base template boost::optional operator()(const Profile& profile) const { - //CGAL_precondition(!get(m_cost_matrices, profile.v0()).isZero(0)); - //CGAL_precondition(!get(m_cost_matrices, profile.v1()).isZero(0)); + CGAL_precondition(!get(m_cost_matrices, profile.v0()).isZero(0)); + CGAL_precondition(!get(m_cost_matrices, profile.v1()).isZero(0)); // the combined matrix has already been computed in the evaluation of the cost... - const Mat_4 combinedMatrix = Mat_4::Zero();//combine_matrices( - //get(m_cost_matrices, profile.v0()), - //get(m_cost_matrices, profile.v1())); + const Mat_4 combinedMatrix = combine_matrices( + get(m_cost_matrices, profile.v0()), + get(m_cost_matrices, profile.v1())); const Col_4 p0 = point_to_homogenous_column(profile.p0()); const Col_4 p1 = point_to_homogenous_column(profile.p1()); @@ -222,6 +229,9 @@ class GarlandHeckbert_placement_base return pt; } + protected: + Vertex_cost_map m_cost_matrices; + private: // use CRTP to call the quadric implementation @@ -229,17 +239,9 @@ class GarlandHeckbert_placement_base return static_cast(this)->construct_optimal_point(mat, p0, p1); } - //TODO move static helper functions into the enclosing namespace - Mat_4 combine_matrices(const Mat_4& a, const Mat_4& b) const { - return a + b; - } - Col_4 point_to_homogenous_column(const Point_3& point) const { return Col_4(point.x(), point.y(), point.z(), FT(1)); } - - - Vertex_cost_map m_cost_matrices; }; } // namespace internal