Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFilip Sykala <filip.sykala@prusa3d.cz>2021-06-22 10:21:16 +0300
committerFilip Sykala <filip.sykala@prusa3d.cz>2021-06-22 10:21:16 +0300
commite3cdeda67324a4f2ff4edc8d8d14ecc2e8642749 (patch)
treec25166ff6690cd4727b0c8edebd16c21c9db7f6e /tests/libslic3r
parentc64ce8777f81a32b95edeb6828e735cb76da9cff (diff)
Add quadric edge collapse
Diffstat (limited to 'tests/libslic3r')
-rw-r--r--tests/libslic3r/test_indexed_triangle_set.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/libslic3r/test_indexed_triangle_set.cpp b/tests/libslic3r/test_indexed_triangle_set.cpp
index 4c1128345..0ec7e3bd0 100644
--- a/tests/libslic3r/test_indexed_triangle_set.cpp
+++ b/tests/libslic3r/test_indexed_triangle_set.cpp
@@ -4,6 +4,8 @@
#include "libslic3r/TriangleMesh.hpp"
+using namespace Slic3r;
+
TEST_CASE("Split empty mesh", "[its_split][its]") {
using namespace Slic3r;
@@ -100,3 +102,41 @@ TEST_CASE("Split two watertight meshes", "[its_split][its]") {
debug_write_obj(res, "parts_watertight");
}
+#include <libslic3r/QuadricEdgeCollapse.hpp>
+TEST_CASE("Reduce one edge by Quadric Edge Collapse", "[its]")
+{
+ indexed_triangle_set its;
+ its.vertices = {Vec3f(-1.f, 0.f, 0.f), Vec3f(0.f, 1.f, 0.f),
+ Vec3f(1.f, 0.f, 0.f), Vec3f(0.f, 0.f, 1.f),
+ // vertex to be removed
+ Vec3f(0.9f, .1f, -.1f)};
+ its.indices = {Vec3i(1, 0, 3), Vec3i(2, 1, 3), Vec3i(0, 2, 3),
+ Vec3i(0, 1, 4), Vec3i(1, 2, 4), Vec3i(2, 0, 4)};
+ // edge to remove is between vertices 2 and 4 on trinagles 4 and 5
+
+ indexed_triangle_set its_ = its; // copy
+ // its_write_obj(its, "tetrhedron_in.obj");
+ size_t wanted_count = its.indices.size() - 1;
+ CHECK(its_quadric_edge_collapse(its, wanted_count));
+ // its_write_obj(its, "tetrhedron_out.obj");
+ CHECK(its.indices.size() == 4);
+ CHECK(its.vertices.size() == 4);
+
+ for (size_t i = 0; i < 3; i++) {
+ CHECK(its.indices[i] == its_.indices[i]);
+ }
+
+ for (size_t i = 0; i < 4; i++) {
+ if (i == 2) continue;
+ CHECK(its.vertices[i] == its_.vertices[i]);
+ }
+
+ const Vec3f &v = its.vertices[2]; // new vertex
+ const Vec3f &v2 = its_.vertices[2]; // moved vertex
+ const Vec3f &v4 = its_.vertices[4]; // removed vertex
+ for (size_t i = 0; i < 3; i++) {
+ bool is_between = (v[i] < v4[i] && v[i] > v2[i]) ||
+ (v[i] > v4[i] && v[i] < v2[i]);
+ CHECK(is_between);
+ }
+} \ No newline at end of file