PrusaSlicer-NonPlainar/tests/libslic3r/test_hollowing.cpp

66 lines
1.9 KiB
C++
Raw Normal View History

2019-10-29 15:27:53 +00:00
#include <iostream>
2019-10-31 13:36:33 +00:00
#include <fstream>
#include <catch2/catch.hpp>
2019-10-29 15:27:53 +00:00
#include "libslic3r/OpenVDBUtils.hpp"
#include <openvdb/tools/Filter.h>
2019-10-29 15:27:53 +00:00
#include "libslic3r/Format/OBJ.hpp"
#include <libnest2d/tools/benchmark.h>
2019-10-29 15:27:53 +00:00
#if defined(WIN32) || defined(_WIN32)
#define PATH_SEPARATOR R"(\)"
#else
#define PATH_SEPARATOR R"(/)"
#endif
static Slic3r::TriangleMesh load_model(const std::string &obj_filename)
{
Slic3r::TriangleMesh mesh;
auto fpath = TEST_DATA_DIR PATH_SEPARATOR + obj_filename;
Slic3r::load_obj(fpath.c_str(), &mesh);
return mesh;
}
//static Slic3r::TriangleMesh hollowed_interior(const Slic3r::TriangleMesh &mesh,
// double min_thickness)
//{
// Slic3r::sla::Contour3D imesh = Slic3r::sla::Contour3D{mesh};
2019-10-30 11:38:23 +00:00
// double scale = std::max(1.0, 3. / min_thickness);
// double offset = scale * min_thickness;
// float range = float(std::max(2 * offset, scale));
2019-10-31 13:36:33 +00:00
// for (auto &p : imesh.points) p *= scale;
// auto ptr = Slic3r::meshToVolume(imesh, {}, 0.1f * float(offset), range);
// REQUIRE(ptr);
2019-10-30 11:38:23 +00:00
// openvdb::tools::Filter<openvdb::FloatGrid>{*ptr}.gaussian(int(scale), 1);
// double iso_surface = -offset;
// double adaptivity = 0.;
// Slic3r::sla::Contour3D omesh = Slic3r::volumeToMesh(*ptr, iso_surface, adaptivity);
2019-10-30 11:38:23 +00:00
// for (auto &p : omesh.points) p /= scale;
2019-11-05 16:00:11 +00:00
// return to_triangle_mesh(omesh);
//}
2019-11-05 16:00:11 +00:00
TEST_CASE("Negative 3D offset should produce smaller object.", "[Hollowing]")
{
Slic3r::TriangleMesh in_mesh = load_model("20mm_cube.obj");
2019-11-05 16:00:11 +00:00
Benchmark bench;
bench.start();
Slic3r::TriangleMesh out_mesh = hollowed_interior(in_mesh, 0.5);
bench.stop();
std::cout << "Elapsed processing time: " << bench.getElapsedSec() << std::endl;
2019-11-05 16:00:11 +00:00
in_mesh.merge(out_mesh);
in_mesh.require_shared_vertices();
in_mesh.WriteOBJFile("merged_out.obj");
}