mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-17 19:57:55 -06:00
Add quadric edge collapse
This commit is contained in:
parent
c64ce8777f
commit
e3cdeda673
5 changed files with 687 additions and 2 deletions
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue