From c63c2a24e2afa83277b4107489267b9d9ff8f966 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Thu, 22 May 2025 14:51:31 +0100 Subject: [PATCH] Activate Leo's code --- .../edge_collapse_bounded_normal_change.cpp | 5 ++-- .../include/CGAL/Cartesian/MatrixC33.h | 23 ++++++++++--------- .../internal/Lindstrom_Turk_core.h | 16 ++++++------- 3 files changed, 23 insertions(+), 21 deletions(-) diff --git a/Surface_mesh_simplification/examples/Surface_mesh_simplification/edge_collapse_bounded_normal_change.cpp b/Surface_mesh_simplification/examples/Surface_mesh_simplification/edge_collapse_bounded_normal_change.cpp index 04561d2239c..e4d0de6ed33 100644 --- a/Surface_mesh_simplification/examples/Surface_mesh_simplification/edge_collapse_bounded_normal_change.cpp +++ b/Surface_mesh_simplification/examples/Surface_mesh_simplification/edge_collapse_bounded_normal_change.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include @@ -36,8 +37,8 @@ int main(int argc, char** argv) { Surface_mesh surface_mesh; const std::string filename = (argc > 1) ? argv[1] : CGAL::data_file_path("meshes/fold.off"); - std::ifstream is(filename); - if(!is || !(is >> surface_mesh)) + + if(!CGAL::IO::read_polygon_mesh(filename, surface_mesh)) { std::cerr << "Failed to read input mesh: " << filename << std::endl; return EXIT_FAILURE; diff --git a/Surface_mesh_simplification/include/CGAL/Cartesian/MatrixC33.h b/Surface_mesh_simplification/include/CGAL/Cartesian/MatrixC33.h index 70399434bb2..b2b3d59f51b 100644 --- a/Surface_mesh_simplification/include/CGAL/Cartesian/MatrixC33.h +++ b/Surface_mesh_simplification/include/CGAL/Cartesian/MatrixC33.h @@ -220,19 +220,19 @@ std::optional< MatrixC33 > inverse_matrix(const MatrixC33& m) if(! CGAL_NTS is_zero(det)) { +#if 1 + RT c00 = diff_of_products(m.r1().y(),m.r2().z(),m.r2().y(),m.r1().z()) / det; + RT c01 = diff_of_products(m.r2().y(),m.r0().z(),m.r0().y(),m.r2().z()) / det; + RT c02 = diff_of_products(m.r0().y(),m.r1().z(),m.r1().y(),m.r0().z()) / det; - // RT c00 = diff_of_products(m.r1().y(),m.r2().z(),m.r2().y(),m.r1().z()) / det; - // RT c01 = diff_of_products(m.r2().y(),m.r0().z(),m.r0().y(),m.r2().z()) / det; - // RT c02 = diff_of_products(m.r0().y(),m.r1().z(),m.r1().y(),m.r0().z()) / det; - - // RT c10 = diff_of_products(m.r2().x(),m.r1().z(),m.r1().x(),m.r2().z()) / det; - // RT c11 = diff_of_products(m.r0().x(),m.r2().z(),m.r2().x(),m.r0().z()) / det; - // RT c12 = diff_of_products(m.r1().x(),m.r0().z(),m.r0().x(),m.r1().z()) / det; - - // RT c20 = diff_of_products(m.r1().x(),m.r2().y(),m.r2().x(),m.r1().y()) / det; - // RT c21 = diff_of_products(m.r2().x(),m.r0().y(),m.r0().x(),m.r2().y()) / det; - // RT c22 = diff_of_products(m.r0().x(),m.r1().y(),m.r1().x(),m.r0().y()) / det; + RT c10 = diff_of_products(m.r2().x(),m.r1().z(),m.r1().x(),m.r2().z()) / det; + RT c11 = diff_of_products(m.r0().x(),m.r2().z(),m.r2().x(),m.r0().z()) / det; + RT c12 = diff_of_products(m.r1().x(),m.r0().z(),m.r0().x(),m.r1().z()) / det; + RT c20 = diff_of_products(m.r1().x(),m.r2().y(),m.r2().x(),m.r1().y()) / det; + RT c21 = diff_of_products(m.r2().x(),m.r0().y(),m.r0().x(),m.r2().y()) / det; + RT c22 = diff_of_products(m.r0().x(),m.r1().y(),m.r1().x(),m.r0().y()) / det; +#else RT c00 = (m.r1().y()*m.r2().z() - m.r1().z()*m.r2().y()) / det; RT c01 = (m.r2().y()*m.r0().z() - m.r0().y()*m.r2().z()) / det; RT c02 = (m.r0().y()*m.r1().z() - m.r1().y()*m.r0().z()) / det; @@ -244,6 +244,7 @@ std::optional< MatrixC33 > inverse_matrix(const MatrixC33& m) RT c20 = (m.r1().x()*m.r2().y() - m.r2().x()*m.r1().y()) / det; RT c21 = (m.r2().x()*m.r0().y() - m.r0().x()*m.r2().y()) / det; RT c22 = (m.r0().x()*m.r1().y() - m.r0().y()*m.r1().x()) / det; +#endif rInverse = result_type(Matrix(c00,c01,c02, c10,c11,c12, diff --git a/Surface_mesh_simplification/include/CGAL/Surface_mesh_simplification/Policies/Edge_collapse/internal/Lindstrom_Turk_core.h b/Surface_mesh_simplification/include/CGAL/Surface_mesh_simplification/Policies/Edge_collapse/internal/Lindstrom_Turk_core.h index d9ea2691883..df70aabd1c1 100644 --- a/Surface_mesh_simplification/include/CGAL/Surface_mesh_simplification/Policies/Edge_collapse/internal/Lindstrom_Turk_core.h +++ b/Surface_mesh_simplification/include/CGAL/Surface_mesh_simplification/Policies/Edge_collapse/internal/Lindstrom_Turk_core.h @@ -319,7 +319,7 @@ LindstromTurkCore:: extract_triangle_data() { mTriangle_data.reserve(mProfile.triangles().size()); - + maxBb = 0.0; for(const Triangle& tri : mProfile.triangles()) { const Point_reference p0 = get_point(tri.v0); @@ -327,9 +327,9 @@ extract_triangle_data() const Point_reference p2 = get_point(tri.v2); //TODO for obscur reason, computing this maxBb increase running time by 10% - maxBb=(std::max)({maxBb,std::abs(p0.x()),std::abs(p0.y()),std::abs(p0.z()), - std::abs(p1.x()),std::abs(p1.y()),std::abs(p1.z()), - std::abs(p2.x()),std::abs(p2.y()),std::abs(p2.z())}); + maxBb=(std::max)({maxBb,CGAL::abs(p0.x()),CGAL::abs(p0.y()),CGAL::abs(p0.z()), + CGAL::abs(p1.x()),CGAL::abs(p1.y()),CGAL::abs(p1.z()), + CGAL::abs(p2.x()),CGAL::abs(p2.y()),CGAL::abs(p2.z())}); Vector v01 = p1 - p0; Vector v02 = p2 - p0; @@ -342,6 +342,7 @@ extract_triangle_data() mTriangle_data.push_back(Triangle_data(lNormalV,lNormalL)); } + maxBb *= 2.0; // to avoid numerical problems } template @@ -659,11 +660,10 @@ add_constraint_if_alpha_compatible(const Vector& Ai, FT l = CGAL_NTS sqrt(slai); CGAL_SMS_LT_TRACE(3, " l: " << n_to_string(l)); - // Due to double number type, l may have a small value instead of zero (example sum of the faces normals of a tetrahedra for volumic constraint) + // Due to double number type, l may have a small value instead of zero (example sum of the face normals of a tetrahedron for volumic constraint) // if bi is greater than maxBb, we consider that l is zero - CGAL_SMS_LT_TRACE(3, " error consider: " << (std::abs(bi) / (2*maxBb))); - if(l > (std::abs(bi) / (2*maxBb))) - // if(!CGAL_NTS is_zero(l)) + CGAL_SMS_LT_TRACE(3, " error consider: " << (CGAL::abs(bi) / maxBb)); + if(l > (std::abs(bi) / maxBb)) { Vector Ain = Ai / l; FT bin = bi / l;