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
|
|
|
|
2019-11-01 14:31:26 +00:00
|
|
|
#include "libslic3r/OpenVDBUtils.hpp"
|
2019-11-05 13:48:00 +00:00
|
|
|
#include <openvdb/tools/Filter.h>
|
2019-10-29 15:27:53 +00:00
|
|
|
#include "libslic3r/Format/OBJ.hpp"
|
|
|
|
|
2019-11-05 13:48:00 +00:00
|
|
|
#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;
|
|
|
|
}
|
|
|
|
|
2019-11-05 13:48:00 +00:00
|
|
|
TEST_CASE("Negative 3D offset should produce smaller object.", "[Hollowing]")
|
2019-11-04 13:33:29 +00:00
|
|
|
{
|
2019-11-05 08:43:42 +00:00
|
|
|
Slic3r::TriangleMesh in_mesh = load_model("20mm_cube.obj");
|
2019-11-05 13:48:00 +00:00
|
|
|
in_mesh.scale(3.);
|
2019-11-05 08:43:42 +00:00
|
|
|
Slic3r::sla::Contour3D imesh = Slic3r::sla::Contour3D{in_mesh};
|
2019-10-29 15:27:53 +00:00
|
|
|
|
2019-11-05 13:48:00 +00:00
|
|
|
Benchmark bench;
|
|
|
|
bench.start();
|
2019-10-30 11:38:23 +00:00
|
|
|
|
2019-11-05 13:48:00 +00:00
|
|
|
openvdb::math::Transform tr;
|
|
|
|
auto ptr = Slic3r::meshToVolume(imesh, {}, 0.0f, 10.0f);
|
2019-10-31 13:36:33 +00:00
|
|
|
|
2019-11-05 13:48:00 +00:00
|
|
|
REQUIRE(ptr);
|
2019-11-05 08:43:42 +00:00
|
|
|
|
2019-11-05 13:48:00 +00:00
|
|
|
openvdb::tools::Filter<openvdb::FloatGrid>{*ptr}.gaussian(1, 3);
|
2019-10-30 11:38:23 +00:00
|
|
|
|
2019-11-04 13:33:29 +00:00
|
|
|
|
2019-11-05 13:48:00 +00:00
|
|
|
double iso_surface = -3.0;
|
|
|
|
double adaptivity = 0.5;
|
|
|
|
Slic3r::sla::Contour3D omesh = Slic3r::volumeToMesh(*ptr, iso_surface, adaptivity);
|
2019-11-04 13:33:29 +00:00
|
|
|
|
2019-11-05 13:48:00 +00:00
|
|
|
REQUIRE(!omesh.empty());
|
2019-10-30 11:38:23 +00:00
|
|
|
|
2019-11-05 13:48:00 +00:00
|
|
|
imesh.merge(omesh);
|
2019-11-05 08:43:42 +00:00
|
|
|
|
2019-11-05 13:48:00 +00:00
|
|
|
for (auto &p : imesh.points) p /= 3.;
|
2019-11-05 08:43:42 +00:00
|
|
|
|
2019-11-05 13:48:00 +00:00
|
|
|
bench.stop();
|
2019-11-05 08:43:42 +00:00
|
|
|
|
2019-11-05 13:48:00 +00:00
|
|
|
std::cout << "Elapsed processing time: " << bench.getElapsedSec() << std::endl;
|
|
|
|
std::fstream merged_outfile("merged_out.obj", std::ios::out);
|
|
|
|
imesh.to_obj(merged_outfile);
|
2019-11-05 08:43:42 +00:00
|
|
|
|
2019-11-05 13:48:00 +00:00
|
|
|
std::fstream outfile("out.obj", std::ios::out);
|
|
|
|
omesh.to_obj(outfile);
|
|
|
|
}
|