2019-10-29 16:27:53 +01:00
|
|
|
#include <iostream>
|
2019-10-31 14:36:33 +01:00
|
|
|
#include <fstream>
|
|
|
|
|
#include <catch2/catch.hpp>
|
2019-10-29 16:27:53 +01:00
|
|
|
|
2019-11-01 15:31:26 +01:00
|
|
|
#include "libslic3r/OpenVDBUtils.hpp"
|
2019-10-29 16:27:53 +01:00
|
|
|
#include "libslic3r/Format/OBJ.hpp"
|
|
|
|
|
|
|
|
|
|
#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-04 14:33:29 +01:00
|
|
|
static bool _check_normals(const Slic3r::sla::Contour3D &mesh)
|
|
|
|
|
{
|
|
|
|
|
for (auto & face : mesh.faces3)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
2019-10-31 14:36:33 +01:00
|
|
|
|
2019-11-04 14:33:29 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-05 09:43:42 +01:00
|
|
|
TEST_CASE("Passing OpenVDB grid conversion produce similar geometry.", "[Hollowing]")
|
2019-11-04 14:33:29 +01:00
|
|
|
{
|
2019-11-05 09:43:42 +01:00
|
|
|
Slic3r::TriangleMesh in_mesh = load_model("20mm_cube.obj");
|
|
|
|
|
Slic3r::sla::Contour3D imesh = Slic3r::sla::Contour3D{in_mesh};
|
2019-10-31 14:36:33 +01:00
|
|
|
auto ptr = Slic3r::meshToVolume(imesh, {});
|
2019-10-29 16:27:53 +01:00
|
|
|
|
2019-10-30 12:38:23 +01:00
|
|
|
REQUIRE(ptr);
|
|
|
|
|
|
2019-11-05 09:43:42 +01:00
|
|
|
std::cout << "Grid class = " << ptr->getGridClass() << std::endl;
|
|
|
|
|
|
|
|
|
|
Slic3r::sla::Contour3D omesh = Slic3r::volumeToMesh(*ptr, -2.9, 1.0, true);
|
|
|
|
|
|
|
|
|
|
std::cout << "Triangle count: " << omesh.faces3.size() << std::endl;
|
|
|
|
|
std::cout << "Quad count: " << omesh.faces4.size() << std::endl;
|
2019-10-30 12:38:23 +01:00
|
|
|
|
2019-10-31 14:36:33 +01:00
|
|
|
REQUIRE(!omesh.empty());
|
2019-10-30 12:38:23 +01:00
|
|
|
|
2019-11-05 09:43:42 +01:00
|
|
|
SECTION("Converting to Contour3D to TriangleMesh") {
|
|
|
|
|
Slic3r::TriangleMesh msh = Slic3r::sla::to_triangle_mesh(omesh);
|
|
|
|
|
|
|
|
|
|
msh.require_shared_vertices();
|
|
|
|
|
msh.WriteOBJFile("out_tr.obj");
|
|
|
|
|
|
|
|
|
|
REQUIRE(msh.volume() == Approx(in_mesh.volume()));
|
|
|
|
|
}
|
2019-11-04 14:33:29 +01:00
|
|
|
|
2019-11-05 09:43:42 +01:00
|
|
|
// omesh.faces4.clear();
|
2019-10-31 14:36:33 +01:00
|
|
|
std::fstream outfile{"out.obj", std::ios::out};
|
|
|
|
|
omesh.to_obj(outfile);
|
|
|
|
|
|
2019-10-29 16:27:53 +01:00
|
|
|
}
|
2019-11-05 09:43:42 +01:00
|
|
|
|
|
|
|
|
//TEST_CASE("Negative 3D offset should produce smaller object.", "[Hollowing]")
|
|
|
|
|
//{
|
|
|
|
|
// Slic3r::sla::Contour3D imesh = Slic3r::sla::Contour3D{load_model("20mm_cube.obj")};
|
|
|
|
|
// auto ptr = Slic3r::meshToVolume(imesh, {});
|
|
|
|
|
|
|
|
|
|
// REQUIRE(ptr);
|
|
|
|
|
|
|
|
|
|
// Slic3r::sla::Contour3D omesh = Slic3r::volumeToMesh(*ptr, -1., 0.0, true);
|
|
|
|
|
|
|
|
|
|
// REQUIRE(!omesh.empty());
|
|
|
|
|
|
|
|
|
|
// imesh.merge(omesh);
|
|
|
|
|
// std::fstream merged_outfile("merged_out.obj", std::ios::out);
|
|
|
|
|
// imesh.to_obj(merged_outfile);
|
|
|
|
|
//}
|