diff --git a/Surface_mesh_simplification/include/CGAL/Surface_mesh_simplification/Policies/Edge_collapse/GarlandHeckbert_triangle_policies.h b/Surface_mesh_simplification/include/CGAL/Surface_mesh_simplification/Policies/Edge_collapse/GarlandHeckbert_triangle_policies.h index a59f4f61fa7..ab02854c6d7 100644 --- a/Surface_mesh_simplification/include/CGAL/Surface_mesh_simplification/Policies/Edge_collapse/GarlandHeckbert_triangle_policies.h +++ b/Surface_mesh_simplification/include/CGAL/Surface_mesh_simplification/Policies/Edge_collapse/GarlandHeckbert_triangle_policies.h @@ -16,10 +16,7 @@ #include #include -#include #include -#include - #include #include #include diff --git a/Surface_mesh_simplification/include/CGAL/Surface_mesh_simplification/Policies/Edge_collapse/internal/GarlandHeckbert_common.h b/Surface_mesh_simplification/include/CGAL/Surface_mesh_simplification/Policies/Edge_collapse/internal/GarlandHeckbert_common.h deleted file mode 100644 index 5671b206c17..00000000000 --- a/Surface_mesh_simplification/include/CGAL/Surface_mesh_simplification/Policies/Edge_collapse/internal/GarlandHeckbert_common.h +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (c) 2019 GeometryFactory (France). All rights reserved. -// -// This file is part of CGAL (www.cgal.org). -// -// $URL$ -// $Id$ -// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial -// -// Author(s) : Baskin Burak Senbaslar, -// Mael Rouxel-Labbé, -// Julian Komaromy - -#ifndef CGAL_SURFACE_MESH_SIMPLIFICATION_POLICIES_GARLANDHECKBERT_INTERNAL_COMMON_H -#define CGAL_SURFACE_MESH_SIMPLIFICATION_POLICIES_GARLANDHECKBERT_INTERNAL_COMMON_H - -#include - -namespace CGAL { -namespace Surface_mesh_simplification { -namespace internal { - -namespace common { - template - typename GeomTraits::Vector_3 construct_unit_normal_from_face( - const VPM& point_map, - const TM& tmesh, - typename boost::graph_traits::face_descriptor f, - const GeomTraits& gt) - { - // initialize all necessary kernel functions - auto unit_normal = gt.construct_unit_normal_3_object(); - - // reference and descriptor types - typedef typename boost::property_traits::reference Point_reference; - typedef typename boost::graph_traits::halfedge_descriptor halfedge_descriptor; - - const halfedge_descriptor h = halfedge(f, tmesh); - - // get the three points of the face and calculate their unit normal - const Point_reference p = get(point_map, source(h, tmesh)); - const Point_reference q = get(point_map, target(h, tmesh)); - const Point_reference r = get(point_map, target(next(h, tmesh), tmesh)); - - return unit_normal(p, q, r); - } -} //namespace common -} //namespace internal -} //namespace Surface_mesh_simplification -} //namespace CGAL - -#endif //CGAL_SURFACE_MESH_SIMPLIFICATION_POLICIES_GARLANDHECKBERT_INTERNAL_COMMON_H diff --git a/Surface_mesh_simplification/include/CGAL/Surface_mesh_simplification/Policies/Edge_collapse/internal/GarlandHeckbert_optimizers.h b/Surface_mesh_simplification/include/CGAL/Surface_mesh_simplification/Policies/Edge_collapse/internal/GarlandHeckbert_optimizers.h deleted file mode 100644 index f5d8553a767..00000000000 --- a/Surface_mesh_simplification/include/CGAL/Surface_mesh_simplification/Policies/Edge_collapse/internal/GarlandHeckbert_optimizers.h +++ /dev/null @@ -1,110 +0,0 @@ -// Copyright (c) 2019 GeometryFactory (France). All rights reserved. -// -// This file is part of CGAL (www.cgal.org). -// -// $URL$ -// $Id$ -// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial -// -// Author(s) : Mael Rouxel-Labbé, -// Julian Komaromy - -#ifndef CGAL_SURFACE_MESH_SIMPLIFICATION_POLICIES_GARLANDHECKBERT_OPTIMIZERS_H -#define CGAL_SURFACE_MESH_SIMPLIFICATION_POLICIES_GARLANDHECKBERT_OPTIMIZERS_H - -#include - -#include - -#include -#include - -namespace CGAL { -namespace Surface_mesh_simplification { -namespace internal { -template -class GarlandHeckbert_invertible_optimizer -{ - typedef typename GeomTraits::FT FT; - typedef typename Eigen::Matrix Col_4; - typedef typename Eigen::Matrix Mat_4; - - public: - - Col_4 construct_optimal_point(const Mat_4& aQuadric, const Col_4& p0, const Col_4& p1) const - { - Mat_4 X; - X << aQuadric.block(0, 0, 3, 4), 0, 0, 0, 1; - - Col_4 opt_pt; - - opt_pt = X.inverse().col(3); // == X.inverse() * (0 0 0 1) - - return opt_pt; - } -}; - -template -class GarlandHeckbert_singular_optimizer -{ - typedef typename GeomTraits::FT FT; - typedef typename Eigen::Matrix Col_4; - typedef typename Eigen::Matrix Mat_4; - - public: - Col_4 construct_optimal_point(const Mat_4& aQuadric, const Col_4& p0, const Col_4& p1) const - { - Mat_4 X; - X << aQuadric.block(0, 0, 3, 4), 0, 0, 0, 1; - - Col_4 opt_pt; - - if(X.determinant() == 0) - { - // not invertible - const Col_4 p1mp0 = std::move(p1 - p0); - const FT a = (p1mp0.transpose() * aQuadric * p1mp0)(0, 0); - const FT b = 2 * (p0.transpose() * aQuadric * p1mp0)(0, 0); - - if(a == 0) - { - if(b < 0) - opt_pt = p1; - else if(b == 0) - opt_pt = 0.5 * (p0 + p1); - else - opt_pt = p0; - } - else - { - FT ext_t = -b/(2*a); - if(ext_t < 0 || ext_t > 1 || a < 0) - { - // one of endpoints - FT p0_cost = (p0.transpose() * aQuadric * p0)(0, 0); - FT p1_cost = (p1.transpose() * aQuadric * p1)(0, 0); - if(p0_cost > p1_cost) - opt_pt = p1; - else - opt_pt = p0; - } - else - { - // extremum of the parabola - opt_pt = p0 + ext_t * (p1 - p0); - } - } - } - else // invertible - { - opt_pt = X.inverse().col(3); // == X.inverse() * (0 0 0 1) - } - return opt_pt; - } -}; - -} //namespace internal -} //namespace Surface_mesh_simplification -} //namespace CGAL - -#endif //CGAL_SURFACE_MESH_SIMPLIFICATION_POLICIES_GARLANDHECKBERT_OPTIMIZERS_H diff --git a/Surface_mesh_simplification/include/CGAL/Surface_mesh_simplification/Policies/Edge_collapse/internal/GarlandHeckbert_plane_quadrics.h b/Surface_mesh_simplification/include/CGAL/Surface_mesh_simplification/Policies/Edge_collapse/internal/GarlandHeckbert_plane_quadrics.h deleted file mode 100644 index 07217741f74..00000000000 --- a/Surface_mesh_simplification/include/CGAL/Surface_mesh_simplification/Policies/Edge_collapse/internal/GarlandHeckbert_plane_quadrics.h +++ /dev/null @@ -1,141 +0,0 @@ -// Copyright (c) 2019 GeometryFactory (France). All rights reserved. -// -// This file is part of CGAL (www.cgal.org). -// -// $URL$ -// $Id$ -// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial -// -// Author(s) : Baskin Burak Senbaslar, -// Mael Rouxel-Labbé, -// Julian Komaromy - -#ifndef CGAL_SURFACE_MESH_SIMPLIFICATION_POLICIES_GARLANDHECKBERT_PLANE_QUADRICS_H -#define CGAL_SURFACE_MESH_SIMPLIFICATION_POLICIES_GARLANDHECKBERT_PLANE_QUADRICS_H - -#include - -#include -#include -#include - -#include - -namespace CGAL { -namespace Surface_mesh_simplification { -namespace internal { - -namespace plane_quadric_helpers { - template - typename Eigen::Matrix construct_quadric_from_normal( - const typename GeomTraits::Vector_3& normal, - const typename GeomTraits::Point_3& point, - const GeomTraits& gt) - { - typedef typename GeomTraits::FT FT; - - auto dot_product = gt.compute_scalar_product_3_object(); - auto construct_vector = gt.construct_vector_3_object(); - - // negative dot product between the normal and the position vector - const FT d = - dot_product(normal, construct_vector(ORIGIN, point)); - - // row vector given by d appended to the normal - const Eigen::Matrix row(normal.x(), normal.y(), normal.z(), d); - - // outer product - return row.transpose() * row; - } -} - -// change the quadric construction for faces, but keep the standard plane quadric -// method for (discontinous) edges -// -// this means we inherit from GarlandHeckbert_policies so we have the implementation -// for discontinous edges and from the cost base class so that out implementation -// of face quadrics will be used -template -class GarlandHeckbert_plane_faces -{ - typedef typename GeomTraits::FT FT; - typedef typename GeomTraits::Vector_3 Vector_3; - typedef typename GeomTraits::Point_3 Point_3; - - typedef typename Eigen::Matrix Mat_4; - - public: - template - Mat_4 construct_quadric_from_face( - const VPM& point_map, - const TM& tmesh, - typename boost::graph_traits::face_descriptor f, - const GeomTraits& gt) const - { - // this-> is used because we are calling a base class function - const Vector_3 normal = common::construct_unit_normal_from_face< - GeomTraits, VPM, TM>(point_map, tmesh, f, gt); - - // get any point of the face - const auto p = get(point_map, source(halfedge(f, tmesh), tmesh)); - - return plane_quadric_helpers::construct_quadric_from_normal(normal, p, gt); - } -}; - -template -class GarlandHeckbert_plane_edges -{ - typedef typename GeomTraits::FT FT; - typedef typename GeomTraits::Vector_3 Vector_3; - typedef typename Eigen::Matrix Mat_4; - - public: - template - Mat_4 construct_quadric_from_edge( - const VPM& point_map, - const TM& tmesh, - typename boost::graph_traits::halfedge_descriptor he, - const GeomTraits& gt) const - { - const Vector_3 normal = construct_edge_normal(point_map, tmesh, he, gt); - - return plane_quadric_helpers::construct_quadric_from_normal(normal, - get(point_map, source(he, tmesh)), gt); - } - - private: - - template - Vector_3 construct_edge_normal( - const VPM& point_map, - const TM& tmesh, - typename boost::graph_traits::halfedge_descriptor he, - const GeomTraits& gt) const - { - typedef typename GeomTraits::Vector_3 Vector_3; - - typedef typename boost::graph_traits::vertex_descriptor vertex_descriptor; - - // TODO we do a potentially redundant calculation here, as we have - // almost certainly already calculated this when constructing a quadric for the face - const Vector_3 face_normal = common::construct_unit_normal_from_face( - point_map, tmesh, face(he, tmesh), gt); - - const vertex_descriptor vs = source(he, tmesh); - const vertex_descriptor vt = target(he, tmesh); - - const Vector_3 edge_vector = Vector_3(get(point_map, vs), get(point_map, vt)); - const Vector_3 discontinuity_normal = cross_product(edge_vector, face_normal); - - // normalize - const Vector_3 normal = discontinuity_normal - / sqrt(discontinuity_normal.squared_length()); - - return normal; - } -}; -} //namespace internal -} //namespace Surface_mesh_simplification -} //namespace CGAL - -#endif //CGAL_SURFACE_MESH_SIMPLIFICATION_POLICIES_GARLANDHECKBERT_PLANE_QUADRICS_H