sla_test_utils.hpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. #ifndef SLA_TEST_UTILS_HPP
  2. #define SLA_TEST_UTILS_HPP
  3. #include <catch2/catch.hpp>
  4. #include <test_utils.hpp>
  5. // Debug
  6. #include <fstream>
  7. #include <unordered_set>
  8. #include "libslic3r/libslic3r.h"
  9. #include "libslic3r/Format/OBJ.hpp"
  10. #include "libslic3r/SLAPrint.hpp"
  11. #include "libslic3r/TriangleMesh.hpp"
  12. #include "libslic3r/SLA/Pad.hpp"
  13. #include "libslic3r/SLA/SupportTreeBuilder.hpp"
  14. #include "libslic3r/SLA/SupportPointGenerator.hpp"
  15. #include "libslic3r/SLA/AGGRaster.hpp"
  16. #include "libslic3r/SLA/ConcaveHull.hpp"
  17. #include "libslic3r/MTUtils.hpp"
  18. #include "libslic3r/SVG.hpp"
  19. using namespace Slic3r;
  20. enum e_validity {
  21. ASSUME_NO_EMPTY = 1,
  22. ASSUME_MANIFOLD = 2,
  23. ASSUME_NO_REPAIR = 4
  24. };
  25. void check_validity(const TriangleMesh &input_mesh,
  26. int flags = ASSUME_NO_EMPTY | ASSUME_MANIFOLD |
  27. ASSUME_NO_REPAIR);
  28. struct PadByproducts
  29. {
  30. ExPolygons model_contours;
  31. ExPolygons support_contours;
  32. TriangleMesh mesh;
  33. };
  34. void test_concave_hull(const ExPolygons &polys);
  35. void test_pad(const std::string & obj_filename,
  36. const sla::PadConfig &padcfg,
  37. PadByproducts & out);
  38. inline void test_pad(const std::string & obj_filename,
  39. const sla::PadConfig &padcfg = {})
  40. {
  41. PadByproducts byproducts;
  42. test_pad(obj_filename, padcfg, byproducts);
  43. }
  44. struct SupportByproducts
  45. {
  46. std::string obj_fname;
  47. std::vector<float> slicegrid;
  48. std::vector<ExPolygons> model_slices;
  49. sla::SupportTreeBuilder suptree_builder;
  50. TriangleMesh input_mesh;
  51. };
  52. const constexpr float CLOSING_RADIUS = 0.005f;
  53. void check_support_tree_integrity(const sla::SupportTreeBuilder &stree,
  54. const sla::SupportTreeConfig &cfg,
  55. double gnd);
  56. void test_supports(const std::string &obj_filename,
  57. const sla::SupportTreeConfig &supportcfg,
  58. const sla::HollowingConfig &hollowingcfg,
  59. const sla::DrainHoles &drainholes,
  60. SupportByproducts &out);
  61. inline void test_supports(const std::string &obj_filename,
  62. const sla::SupportTreeConfig &supportcfg,
  63. SupportByproducts &out)
  64. {
  65. sla::HollowingConfig hcfg;
  66. hcfg.enabled = false;
  67. test_supports(obj_filename, supportcfg, hcfg, {}, out);
  68. }
  69. inline void test_supports(const std::string &obj_filename,
  70. const sla::SupportTreeConfig &supportcfg = {})
  71. {
  72. SupportByproducts byproducts;
  73. test_supports(obj_filename, supportcfg, byproducts);
  74. }
  75. void export_failed_case(const std::vector<ExPolygons> &support_slices,
  76. const SupportByproducts &byproducts);
  77. void test_support_model_collision(
  78. const std::string &obj_filename,
  79. const sla::SupportTreeConfig &input_supportcfg,
  80. const sla::HollowingConfig &hollowingcfg,
  81. const sla::DrainHoles &drainholes);
  82. inline void test_support_model_collision(
  83. const std::string &obj_filename,
  84. const sla::SupportTreeConfig &input_supportcfg = {})
  85. {
  86. sla::HollowingConfig hcfg;
  87. hcfg.enabled = false;
  88. test_support_model_collision(obj_filename, input_supportcfg, hcfg, {});
  89. }
  90. // SLA Raster test utils:
  91. using TPixel = uint8_t;
  92. static constexpr const TPixel FullWhite = 255;
  93. static constexpr const TPixel FullBlack = 0;
  94. template <class A, int N> constexpr int arraysize(const A (&)[N]) { return N; }
  95. void check_raster_transformations(sla::RasterBase::Orientation o,
  96. sla::RasterBase::TMirroring mirroring);
  97. ExPolygon square_with_hole(double v);
  98. inline double pixel_area(TPixel px, const sla::PixelDim &pxdim)
  99. {
  100. return (pxdim.h_mm * pxdim.w_mm) * px * 1. / (FullWhite - FullBlack);
  101. }
  102. double raster_white_area(const sla::RasterGrayscaleAA &raster);
  103. long raster_pxsum(const sla::RasterGrayscaleAA &raster);
  104. double predict_error(const ExPolygon &p, const sla::PixelDim &pd);
  105. sla::SupportPoints calc_support_pts(
  106. const TriangleMesh & mesh,
  107. const sla::SupportPointGenerator::Config &cfg = {});
  108. #endif // SLA_TEST_UTILS_HPP