test_hollowing.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #include <iostream>
  2. #include <fstream>
  3. #include <catch2/catch.hpp>
  4. #include <libslic3r/TriangleMesh.hpp>
  5. #include "libslic3r/SLA/Hollowing.hpp"
  6. #include <openvdb/tools/Filter.h>
  7. #include "libslic3r/Format/OBJ.hpp"
  8. #include <libnest2d/tools/benchmark.h>
  9. #include <libslic3r/SimplifyMesh.hpp>
  10. #if defined(WIN32) || defined(_WIN32)
  11. #define PATH_SEPARATOR R"(\)"
  12. #else
  13. #define PATH_SEPARATOR R"(/)"
  14. #endif
  15. static Slic3r::TriangleMesh load_model(const std::string &obj_filename)
  16. {
  17. Slic3r::TriangleMesh mesh;
  18. auto fpath = TEST_DATA_DIR PATH_SEPARATOR + obj_filename;
  19. Slic3r::load_obj(fpath.c_str(), &mesh);
  20. return mesh;
  21. }
  22. TEST_CASE("Negative 3D offset should produce smaller object.", "[Hollowing]")
  23. {
  24. Slic3r::TriangleMesh in_mesh = load_model("20mm_cube.obj");
  25. Benchmark bench;
  26. bench.start();
  27. std::unique_ptr<Slic3r::TriangleMesh> out_mesh_ptr =
  28. Slic3r::sla::generate_interior(in_mesh);
  29. bench.stop();
  30. std::cout << "Elapsed processing time: " << bench.getElapsedSec() << std::endl;
  31. if (out_mesh_ptr) in_mesh.merge(*out_mesh_ptr);
  32. in_mesh.require_shared_vertices();
  33. in_mesh.WriteOBJFile("merged_out.obj");
  34. }