PrusaSlicer-NonPlainar/tests/libslic3r/test_meshboolean.cpp

52 lines
1.6 KiB
C++
Raw Normal View History

#include <catch2/catch.hpp>
#include <test_utils.hpp>
#include <libslic3r/TriangleMesh.hpp>
#include <libslic3r/MeshBoolean.hpp>
using namespace Slic3r;
TEST_CASE("CGAL and TriangleMesh conversions", "[MeshBoolean]") {
TriangleMesh sphere = make_sphere(1.);
auto cgalmesh_ptr = MeshBoolean::cgal::triangle_mesh_to_cgal(sphere);
REQUIRE(cgalmesh_ptr);
REQUIRE(! MeshBoolean::cgal::does_self_intersect(*cgalmesh_ptr));
TriangleMesh M = MeshBoolean::cgal::cgal_to_triangle_mesh(*cgalmesh_ptr);
REQUIRE(M.its.vertices.size() == sphere.its.vertices.size());
REQUIRE(M.its.indices.size() == sphere.its.indices.size());
REQUIRE(M.volume() == Approx(sphere.volume()));
REQUIRE(! MeshBoolean::cgal::does_self_intersect(M));
}
2021-08-30 08:51:58 +00:00
Vec3d calc_normal(const Vec3i &triangle, const std::vector<Vec3f> &vertices)
{
Vec3d v0 = vertices[triangle[0]].cast<double>();
Vec3d v1 = vertices[triangle[1]].cast<double>();
Vec3d v2 = vertices[triangle[2]].cast<double>();
// n = triangle normal
Vec3d n = (v1 - v0).cross(v2 - v0);
n.normalize();
return n;
}
TEST_CASE("Add TriangleMeshes", "[MeshBoolean]")
{
TriangleMesh tm1 = make_sphere(1.6, 1.6);
2021-10-21 06:36:38 +00:00
size_t init_size = tm1.its.indices.size();
2021-10-19 10:39:16 +00:00
Vec3f move(5, -3, 7);
2021-08-30 08:51:58 +00:00
move.normalize();
tm1.translate(0.3 * move);
2021-10-21 06:36:38 +00:00
//its_write_obj(tm1.its, "tm1.obj");
2021-08-30 08:51:58 +00:00
TriangleMesh tm2 = make_cube(1., 1., 1.);
2021-10-21 06:36:38 +00:00
//its_write_obj(tm2.its, "tm2.obj");
2021-08-30 08:51:58 +00:00
MeshBoolean::cgal::plus(tm1, tm2);
2021-10-21 06:36:38 +00:00
//its_write_obj(tm1.its, "test_add.obj");
CHECK(tm1.its.indices.size() > init_size);
2021-08-30 08:51:58 +00:00
}