From 7c13cfa1d9f540c0505a9d1d835f21736f0e48be Mon Sep 17 00:00:00 2001 From: Filip Sykala Date: Tue, 22 Jun 2021 09:41:38 +0200 Subject: [PATCH] Add test checking diference in volume before/after simplification FIX warnings ..\src\libslic3r\QuadricEdgeCollapse.cpp(173): warning C4056: overflow in floating-point constant arithmetic ..\src\libslic3r\QuadricEdgeCollapse.cpp(232): warning C4056: overflow in floating-point constant arithmetic --- src/libslic3r/QuadricEdgeCollapse.cpp | 2 +- tests/libslic3r/test_indexed_triangle_set.cpp | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/libslic3r/QuadricEdgeCollapse.cpp b/src/libslic3r/QuadricEdgeCollapse.cpp index 1974f5101..13313da1f 100644 --- a/src/libslic3r/QuadricEdgeCollapse.cpp +++ b/src/libslic3r/QuadricEdgeCollapse.cpp @@ -123,7 +123,7 @@ bool Slic3r::its_quadric_edge_collapse(indexed_triangle_set &its, EdgeInfos e_infos; std::tie(t_infos, v_infos, e_infos) = init(its); - static constexpr double max_error = std::numeric_limits::max(); + static constexpr float max_error = std::numeric_limits::max(); auto cmp = [&t_infos](size_t vi0, size_t vi1) -> bool { const Error &e0 = t_infos[vi0].e; diff --git a/tests/libslic3r/test_indexed_triangle_set.cpp b/tests/libslic3r/test_indexed_triangle_set.cpp index 0ec7e3bd0..ac676267a 100644 --- a/tests/libslic3r/test_indexed_triangle_set.cpp +++ b/tests/libslic3r/test_indexed_triangle_set.cpp @@ -139,4 +139,19 @@ TEST_CASE("Reduce one edge by Quadric Edge Collapse", "[its]") (v[i] > v4[i] && v[i] < v2[i]); CHECK(is_between); } +} + +#include "test_utils.hpp" +TEST_CASE("Symplify mesh by Quadric edge collapse to 5%", "[its]") +{ + TriangleMesh mesh = load_model("frog_legs.obj"); + double original_volume = its_volume(mesh.its); + size_t wanted_count = mesh.its.indices.size() * 0.05; + REQUIRE_FALSE(mesh.empty()); + indexed_triangle_set its = mesh.its; // copy + its_quadric_edge_collapse(its, wanted_count); + // its_write_obj(its, "frog_legs_qec.obj"); + CHECK(its.indices.size() <= wanted_count); + double volume = its_volume(its); + CHECK(fabs(original_volume - volume) < 30.); } \ No newline at end of file