2020-01-08 16:10:11 +00:00
|
|
|
#ifndef SLA_TEST_UTILS_HPP
|
|
|
|
#define SLA_TEST_UTILS_HPP
|
|
|
|
|
|
|
|
#include <catch2/catch.hpp>
|
|
|
|
#include <test_utils.hpp>
|
|
|
|
|
|
|
|
// Debug
|
|
|
|
#include <fstream>
|
2020-01-30 14:53:32 +00:00
|
|
|
#include <unordered_set>
|
2020-01-08 16:10:11 +00:00
|
|
|
|
|
|
|
#include "libslic3r/libslic3r.h"
|
|
|
|
#include "libslic3r/Format/OBJ.hpp"
|
|
|
|
#include "libslic3r/SLAPrint.hpp"
|
|
|
|
#include "libslic3r/TriangleMesh.hpp"
|
|
|
|
#include "libslic3r/SLA/Pad.hpp"
|
|
|
|
#include "libslic3r/SLA/SupportTreeBuilder.hpp"
|
|
|
|
#include "libslic3r/SLA/SupportPointGenerator.hpp"
|
2020-04-13 10:31:37 +00:00
|
|
|
#include "libslic3r/SLA/AGGRaster.hpp"
|
2020-01-08 16:10:11 +00:00
|
|
|
#include "libslic3r/SLA/ConcaveHull.hpp"
|
|
|
|
#include "libslic3r/MTUtils.hpp"
|
|
|
|
|
|
|
|
#include "libslic3r/SVG.hpp"
|
|
|
|
|
|
|
|
using namespace Slic3r;
|
|
|
|
|
|
|
|
enum e_validity {
|
|
|
|
ASSUME_NO_EMPTY = 1,
|
|
|
|
ASSUME_MANIFOLD = 2,
|
|
|
|
ASSUME_NO_REPAIR = 4
|
|
|
|
};
|
|
|
|
|
|
|
|
void check_validity(const TriangleMesh &input_mesh,
|
|
|
|
int flags = ASSUME_NO_EMPTY | ASSUME_MANIFOLD |
|
|
|
|
ASSUME_NO_REPAIR);
|
|
|
|
|
|
|
|
struct PadByproducts
|
|
|
|
{
|
|
|
|
ExPolygons model_contours;
|
|
|
|
ExPolygons support_contours;
|
|
|
|
TriangleMesh mesh;
|
|
|
|
};
|
|
|
|
|
|
|
|
void test_concave_hull(const ExPolygons &polys);
|
|
|
|
|
|
|
|
void test_pad(const std::string & obj_filename,
|
|
|
|
const sla::PadConfig &padcfg,
|
|
|
|
PadByproducts & out);
|
|
|
|
|
|
|
|
inline void test_pad(const std::string & obj_filename,
|
|
|
|
const sla::PadConfig &padcfg = {})
|
|
|
|
{
|
|
|
|
PadByproducts byproducts;
|
|
|
|
test_pad(obj_filename, padcfg, byproducts);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct SupportByproducts
|
|
|
|
{
|
|
|
|
std::string obj_fname;
|
|
|
|
std::vector<float> slicegrid;
|
|
|
|
std::vector<ExPolygons> model_slices;
|
2022-05-17 08:52:52 +00:00
|
|
|
sla::SupportTreeBuilder suptree_builder;
|
2020-01-08 16:10:11 +00:00
|
|
|
TriangleMesh input_mesh;
|
|
|
|
};
|
|
|
|
|
|
|
|
const constexpr float CLOSING_RADIUS = 0.005f;
|
|
|
|
|
|
|
|
void check_support_tree_integrity(const sla::SupportTreeBuilder &stree,
|
2022-05-11 10:08:32 +00:00
|
|
|
const sla::SupportTreeConfig &cfg,
|
|
|
|
double gnd);
|
2020-01-08 16:10:11 +00:00
|
|
|
|
|
|
|
void test_supports(const std::string &obj_filename,
|
2020-06-25 11:58:51 +00:00
|
|
|
const sla::SupportTreeConfig &supportcfg,
|
2020-01-08 16:10:11 +00:00
|
|
|
const sla::HollowingConfig &hollowingcfg,
|
|
|
|
const sla::DrainHoles &drainholes,
|
|
|
|
SupportByproducts &out);
|
|
|
|
|
|
|
|
inline void test_supports(const std::string &obj_filename,
|
2020-06-25 11:58:51 +00:00
|
|
|
const sla::SupportTreeConfig &supportcfg,
|
2020-01-08 16:10:11 +00:00
|
|
|
SupportByproducts &out)
|
|
|
|
{
|
|
|
|
sla::HollowingConfig hcfg;
|
|
|
|
hcfg.enabled = false;
|
|
|
|
test_supports(obj_filename, supportcfg, hcfg, {}, out);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void test_supports(const std::string &obj_filename,
|
2020-06-25 11:58:51 +00:00
|
|
|
const sla::SupportTreeConfig &supportcfg = {})
|
2020-01-08 16:10:11 +00:00
|
|
|
{
|
|
|
|
SupportByproducts byproducts;
|
|
|
|
test_supports(obj_filename, supportcfg, byproducts);
|
|
|
|
}
|
|
|
|
|
|
|
|
void export_failed_case(const std::vector<ExPolygons> &support_slices,
|
|
|
|
const SupportByproducts &byproducts);
|
|
|
|
|
|
|
|
|
|
|
|
void test_support_model_collision(
|
|
|
|
const std::string &obj_filename,
|
2020-06-25 11:58:51 +00:00
|
|
|
const sla::SupportTreeConfig &input_supportcfg,
|
2020-01-08 16:10:11 +00:00
|
|
|
const sla::HollowingConfig &hollowingcfg,
|
|
|
|
const sla::DrainHoles &drainholes);
|
|
|
|
|
|
|
|
inline void test_support_model_collision(
|
|
|
|
const std::string &obj_filename,
|
2020-06-25 11:58:51 +00:00
|
|
|
const sla::SupportTreeConfig &input_supportcfg = {})
|
2020-01-08 16:10:11 +00:00
|
|
|
{
|
|
|
|
sla::HollowingConfig hcfg;
|
|
|
|
hcfg.enabled = false;
|
|
|
|
test_support_model_collision(obj_filename, input_supportcfg, hcfg, {});
|
|
|
|
}
|
|
|
|
|
2020-01-30 14:53:32 +00:00
|
|
|
// SLA Raster test utils:
|
|
|
|
|
|
|
|
using TPixel = uint8_t;
|
|
|
|
static constexpr const TPixel FullWhite = 255;
|
|
|
|
static constexpr const TPixel FullBlack = 0;
|
|
|
|
|
|
|
|
template <class A, int N> constexpr int arraysize(const A (&)[N]) { return N; }
|
|
|
|
|
2020-04-13 10:31:37 +00:00
|
|
|
void check_raster_transformations(sla::RasterBase::Orientation o,
|
|
|
|
sla::RasterBase::TMirroring mirroring);
|
2020-01-30 14:53:32 +00:00
|
|
|
|
|
|
|
ExPolygon square_with_hole(double v);
|
|
|
|
|
2022-01-12 12:54:18 +00:00
|
|
|
inline double pixel_area(TPixel px, const sla::PixelDim &pxdim)
|
2020-01-30 14:53:32 +00:00
|
|
|
{
|
|
|
|
return (pxdim.h_mm * pxdim.w_mm) * px * 1. / (FullWhite - FullBlack);
|
|
|
|
}
|
|
|
|
|
2020-04-13 10:31:37 +00:00
|
|
|
double raster_white_area(const sla::RasterGrayscaleAA &raster);
|
|
|
|
long raster_pxsum(const sla::RasterGrayscaleAA &raster);
|
2020-01-30 14:53:32 +00:00
|
|
|
|
2022-01-12 12:54:18 +00:00
|
|
|
double predict_error(const ExPolygon &p, const sla::PixelDim &pd);
|
2020-01-30 14:53:32 +00:00
|
|
|
|
2020-08-18 09:41:14 +00:00
|
|
|
sla::SupportPoints calc_support_pts(
|
|
|
|
const TriangleMesh & mesh,
|
|
|
|
const sla::SupportPointGenerator::Config &cfg = {});
|
|
|
|
|
2020-01-08 16:10:11 +00:00
|
|
|
#endif // SLA_TEST_UTILS_HPP
|