sla_archive_readwrite_tests.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #include <catch2/catch.hpp>
  2. #include <test_utils.hpp>
  3. #include "libslic3r/SLAPrint.hpp"
  4. #include "libslic3r/TriangleMesh.hpp"
  5. #include "libslic3r/Format/SLAArchiveFormatRegistry.hpp"
  6. #include "libslic3r/Format/SLAArchiveWriter.hpp"
  7. #include "libslic3r/Format/SLAArchiveReader.hpp"
  8. #include <boost/filesystem.hpp>
  9. using namespace Slic3r;
  10. TEST_CASE("Archive export test", "[sla_archives]") {
  11. auto registry = registered_sla_archives();
  12. for (const char * pname : {"20mm_cube", "extruder_idler"})
  13. for (const ArchiveEntry &entry : registry) {
  14. INFO(std::string("Testing archive type: ") + entry.id + " -- writing...");
  15. SLAPrint print;
  16. SLAFullPrintConfig fullcfg;
  17. auto m = Model::read_from_file(TEST_DATA_DIR PATH_SEPARATOR + std::string(pname) + ".obj", nullptr);
  18. fullcfg.printer_technology.setInt(ptSLA); // FIXME this should be ensured
  19. fullcfg.set("sla_archive_format", entry.id);
  20. fullcfg.set("supports_enable", false);
  21. fullcfg.set("pad_enable", false);
  22. DynamicPrintConfig cfg;
  23. cfg.apply(fullcfg);
  24. print.set_status_callback([](const PrintBase::SlicingStatus&) {});
  25. print.apply(m, cfg);
  26. print.process();
  27. ThumbnailsList thumbnails;
  28. auto outputfname = std::string("output_") + pname + "." + entry.ext;
  29. print.export_print(outputfname, thumbnails, pname);
  30. // Not much can be checked about the archives...
  31. REQUIRE(boost::filesystem::exists(outputfname));
  32. double vol_written = m.mesh().volume();
  33. if (entry.rdfactoryfn) {
  34. INFO(std::string("Testing archive type: ") + entry.id + " -- reading back...");
  35. indexed_triangle_set its;
  36. DynamicPrintConfig cfg;
  37. try {
  38. // Leave format_id deliberetaly empty, guessing should always
  39. // work here.
  40. import_sla_archive(outputfname, "", its, cfg);
  41. } catch (...) {
  42. REQUIRE(false);
  43. }
  44. // its_write_obj(its, (outputfname + ".obj").c_str());
  45. REQUIRE(!cfg.empty());
  46. REQUIRE(!its.empty());
  47. double vol_read = its_volume(its);
  48. double rel_err = std::abs(vol_written - vol_read) / vol_written;
  49. REQUIRE(rel_err < 0.1);
  50. }
  51. }
  52. }