2019-10-02 12:55:02 +00:00
|
|
|
#include <unordered_set>
|
|
|
|
#include <unordered_map>
|
|
|
|
#include <random>
|
2019-09-26 07:42:08 +00:00
|
|
|
|
2020-01-08 16:10:11 +00:00
|
|
|
#include "sla_test_utils.hpp"
|
2019-11-04 13:33:29 +00:00
|
|
|
|
2020-01-08 16:10:11 +00:00
|
|
|
namespace {
|
2019-09-24 13:24:47 +00:00
|
|
|
|
2019-11-04 13:33:29 +00:00
|
|
|
const char *const BELOW_PAD_TEST_OBJECTS[] = {
|
2019-09-24 13:24:47 +00:00
|
|
|
"20mm_cube.obj",
|
|
|
|
"V.obj",
|
|
|
|
};
|
|
|
|
|
2019-11-04 13:33:29 +00:00
|
|
|
const char *const AROUND_PAD_TEST_OBJECTS[] = {
|
2019-09-24 13:24:47 +00:00
|
|
|
"20mm_cube.obj",
|
|
|
|
"V.obj",
|
|
|
|
"frog_legs.obj",
|
|
|
|
"cube_with_concave_hole_enlarged.obj",
|
|
|
|
};
|
|
|
|
|
|
|
|
const char *const SUPPORT_TEST_MODELS[] = {
|
2019-10-03 12:23:03 +00:00
|
|
|
"cube_with_concave_hole_enlarged_standing.obj",
|
2019-10-03 14:15:11 +00:00
|
|
|
"A_upsidedown.obj",
|
|
|
|
"extruder_idler.obj"
|
2019-09-24 13:24:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2019-10-04 12:47:02 +00:00
|
|
|
TEST_CASE("Pillar pairhash should be unique", "[SLASupportGeneration]") {
|
2019-10-07 08:21:59 +00:00
|
|
|
test_pairhash<int, int>();
|
2019-09-26 07:42:08 +00:00
|
|
|
test_pairhash<int, long>();
|
|
|
|
test_pairhash<unsigned, unsigned>();
|
|
|
|
test_pairhash<unsigned, unsigned long>();
|
|
|
|
}
|
|
|
|
|
2020-01-14 09:41:42 +00:00
|
|
|
TEST_CASE("Support point generator should be deterministic if seeded",
|
|
|
|
"[SLASupportGeneration], [SLAPointGen]") {
|
|
|
|
TriangleMesh mesh = load_model("A_upsidedown.obj");
|
|
|
|
|
|
|
|
sla::EigenMesh3D emesh{mesh};
|
|
|
|
|
|
|
|
sla::SupportConfig supportcfg;
|
|
|
|
sla::SupportPointGenerator::Config autogencfg;
|
|
|
|
autogencfg.head_diameter = float(2 * supportcfg.head_front_radius_mm);
|
|
|
|
sla::SupportPointGenerator point_gen{emesh, autogencfg, [] {}, [](int) {}};
|
|
|
|
|
|
|
|
TriangleMeshSlicer slicer{&mesh};
|
|
|
|
|
|
|
|
auto bb = mesh.bounding_box();
|
|
|
|
double zmin = bb.min.z();
|
|
|
|
double zmax = bb.max.z();
|
|
|
|
double gnd = zmin - supportcfg.object_elevation_mm;
|
|
|
|
auto layer_h = 0.05f;
|
|
|
|
|
|
|
|
auto slicegrid = grid(float(gnd), float(zmax), layer_h);
|
|
|
|
std::vector<ExPolygons> slices;
|
2020-02-09 08:43:15 +00:00
|
|
|
slicer.slice(slicegrid, SlicingMode::Regular, CLOSING_RADIUS, &slices, []{});
|
2020-01-14 09:41:42 +00:00
|
|
|
|
2020-01-15 16:44:15 +00:00
|
|
|
point_gen.seed(0);
|
|
|
|
point_gen.execute(slices, slicegrid);
|
2020-01-14 09:41:42 +00:00
|
|
|
|
|
|
|
auto get_chksum = [](const std::vector<sla::SupportPoint> &pts){
|
|
|
|
long long chksum = 0;
|
|
|
|
for (auto &pt : pts) {
|
|
|
|
auto p = scaled(pt.pos);
|
|
|
|
chksum += p.x() + p.y() + p.z();
|
|
|
|
}
|
|
|
|
|
|
|
|
return chksum;
|
|
|
|
};
|
|
|
|
|
|
|
|
long long checksum = get_chksum(point_gen.output());
|
|
|
|
size_t ptnum = point_gen.output().size();
|
|
|
|
REQUIRE(point_gen.output().size() > 0);
|
|
|
|
|
|
|
|
for (int i = 0; i < 20; ++i) {
|
|
|
|
point_gen.output().clear();
|
2020-01-16 13:03:43 +00:00
|
|
|
point_gen.seed(0);
|
2020-01-15 16:44:15 +00:00
|
|
|
point_gen.execute(slices, slicegrid);
|
2020-01-14 09:41:42 +00:00
|
|
|
REQUIRE(point_gen.output().size() == ptnum);
|
|
|
|
REQUIRE(checksum == get_chksum(point_gen.output()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-04 12:47:02 +00:00
|
|
|
TEST_CASE("Flat pad geometry is valid", "[SLASupportGeneration]") {
|
2019-09-24 13:24:47 +00:00
|
|
|
sla::PadConfig padcfg;
|
2019-11-04 13:33:29 +00:00
|
|
|
|
2019-09-24 13:24:47 +00:00
|
|
|
// Disable wings
|
|
|
|
padcfg.wall_height_mm = .0;
|
2019-11-04 13:33:29 +00:00
|
|
|
|
2019-09-24 13:24:47 +00:00
|
|
|
for (auto &fname : BELOW_PAD_TEST_OBJECTS) test_pad(fname, padcfg);
|
|
|
|
}
|
|
|
|
|
2019-10-04 12:47:02 +00:00
|
|
|
TEST_CASE("WingedPadGeometryIsValid", "[SLASupportGeneration]") {
|
2019-09-24 13:24:47 +00:00
|
|
|
sla::PadConfig padcfg;
|
2019-11-04 13:33:29 +00:00
|
|
|
|
2019-09-24 13:24:47 +00:00
|
|
|
// Add some wings to the pad to test the cavity
|
|
|
|
padcfg.wall_height_mm = 1.;
|
2019-11-04 13:33:29 +00:00
|
|
|
|
2019-09-24 13:24:47 +00:00
|
|
|
for (auto &fname : BELOW_PAD_TEST_OBJECTS) test_pad(fname, padcfg);
|
|
|
|
}
|
|
|
|
|
2019-10-04 12:47:02 +00:00
|
|
|
TEST_CASE("FlatPadAroundObjectIsValid", "[SLASupportGeneration]") {
|
2019-09-24 13:24:47 +00:00
|
|
|
sla::PadConfig padcfg;
|
2019-11-04 13:33:29 +00:00
|
|
|
|
2019-09-24 13:24:47 +00:00
|
|
|
// Add some wings to the pad to test the cavity
|
|
|
|
padcfg.wall_height_mm = 0.;
|
|
|
|
// padcfg.embed_object.stick_stride_mm = 0.;
|
|
|
|
padcfg.embed_object.enabled = true;
|
|
|
|
padcfg.embed_object.everywhere = true;
|
2019-11-04 13:33:29 +00:00
|
|
|
|
2019-09-24 13:24:47 +00:00
|
|
|
for (auto &fname : AROUND_PAD_TEST_OBJECTS) test_pad(fname, padcfg);
|
|
|
|
}
|
|
|
|
|
2019-10-04 12:47:02 +00:00
|
|
|
TEST_CASE("WingedPadAroundObjectIsValid", "[SLASupportGeneration]") {
|
2019-09-24 13:24:47 +00:00
|
|
|
sla::PadConfig padcfg;
|
2019-11-04 13:33:29 +00:00
|
|
|
|
2019-09-24 13:24:47 +00:00
|
|
|
// Add some wings to the pad to test the cavity
|
|
|
|
padcfg.wall_height_mm = 1.;
|
|
|
|
padcfg.embed_object.enabled = true;
|
|
|
|
padcfg.embed_object.everywhere = true;
|
2019-11-04 13:33:29 +00:00
|
|
|
|
2019-09-24 13:24:47 +00:00
|
|
|
for (auto &fname : AROUND_PAD_TEST_OBJECTS) test_pad(fname, padcfg);
|
|
|
|
}
|
|
|
|
|
2019-10-04 12:47:02 +00:00
|
|
|
TEST_CASE("ElevatedSupportGeometryIsValid", "[SLASupportGeneration]") {
|
2019-09-24 13:24:47 +00:00
|
|
|
sla::SupportConfig supportcfg;
|
|
|
|
supportcfg.object_elevation_mm = 5.;
|
2019-11-04 13:33:29 +00:00
|
|
|
|
2019-09-24 13:24:47 +00:00
|
|
|
for (auto fname : SUPPORT_TEST_MODELS) test_supports(fname);
|
|
|
|
}
|
|
|
|
|
2019-10-04 12:47:02 +00:00
|
|
|
TEST_CASE("FloorSupportGeometryIsValid", "[SLASupportGeneration]") {
|
2019-09-24 13:24:47 +00:00
|
|
|
sla::SupportConfig supportcfg;
|
|
|
|
supportcfg.object_elevation_mm = 0;
|
2019-11-04 13:33:29 +00:00
|
|
|
|
2019-09-24 13:24:47 +00:00
|
|
|
for (auto &fname: SUPPORT_TEST_MODELS) test_supports(fname, supportcfg);
|
|
|
|
}
|
|
|
|
|
2019-10-04 12:47:02 +00:00
|
|
|
TEST_CASE("ElevatedSupportsDoNotPierceModel", "[SLASupportGeneration]") {
|
2019-11-04 13:33:29 +00:00
|
|
|
|
2019-09-24 13:24:47 +00:00
|
|
|
sla::SupportConfig supportcfg;
|
2019-11-04 13:33:29 +00:00
|
|
|
|
2019-09-24 13:24:47 +00:00
|
|
|
for (auto fname : SUPPORT_TEST_MODELS)
|
|
|
|
test_support_model_collision(fname, supportcfg);
|
|
|
|
}
|
|
|
|
|
2019-10-04 12:47:02 +00:00
|
|
|
TEST_CASE("FloorSupportsDoNotPierceModel", "[SLASupportGeneration]") {
|
2019-11-04 13:33:29 +00:00
|
|
|
|
2019-10-03 14:15:11 +00:00
|
|
|
sla::SupportConfig supportcfg;
|
|
|
|
supportcfg.object_elevation_mm = 0;
|
2019-11-04 13:33:29 +00:00
|
|
|
|
2019-10-03 14:15:11 +00:00
|
|
|
for (auto fname : SUPPORT_TEST_MODELS)
|
|
|
|
test_support_model_collision(fname, supportcfg);
|
|
|
|
}
|
|
|
|
|
2019-10-04 12:47:02 +00:00
|
|
|
TEST_CASE("DefaultRasterShouldBeEmpty", "[SLARasterOutput]") {
|
2019-10-01 11:27:58 +00:00
|
|
|
sla::Raster raster;
|
2019-10-04 12:47:02 +00:00
|
|
|
REQUIRE(raster.empty());
|
2019-10-01 11:27:58 +00:00
|
|
|
}
|
|
|
|
|
2019-10-04 12:47:02 +00:00
|
|
|
TEST_CASE("InitializedRasterShouldBeNONEmpty", "[SLARasterOutput]") {
|
2019-10-01 11:27:58 +00:00
|
|
|
// Default Prusa SL1 display parameters
|
|
|
|
sla::Raster::Resolution res{2560, 1440};
|
|
|
|
sla::Raster::PixelDim pixdim{120. / res.width_px, 68. / res.height_px};
|
2019-11-04 13:33:29 +00:00
|
|
|
|
2019-10-01 11:27:58 +00:00
|
|
|
sla::Raster raster;
|
|
|
|
raster.reset(res, pixdim);
|
2019-10-04 12:47:02 +00:00
|
|
|
REQUIRE_FALSE(raster.empty());
|
|
|
|
REQUIRE(raster.resolution().width_px == res.width_px);
|
|
|
|
REQUIRE(raster.resolution().height_px == res.height_px);
|
|
|
|
REQUIRE(raster.pixel_dimensions().w_mm == Approx(pixdim.w_mm));
|
|
|
|
REQUIRE(raster.pixel_dimensions().h_mm == Approx(pixdim.h_mm));
|
2019-10-01 11:27:58 +00:00
|
|
|
}
|
|
|
|
|
2019-10-04 12:47:02 +00:00
|
|
|
TEST_CASE("MirroringShouldBeCorrect", "[SLARasterOutput]") {
|
2019-10-01 11:27:58 +00:00
|
|
|
sla::Raster::TMirroring mirrorings[] = {sla::Raster::NoMirror,
|
|
|
|
sla::Raster::MirrorX,
|
|
|
|
sla::Raster::MirrorY,
|
|
|
|
sla::Raster::MirrorXY};
|
2019-11-04 13:33:29 +00:00
|
|
|
|
2019-10-01 11:27:58 +00:00
|
|
|
sla::Raster::Orientation orientations[] = {sla::Raster::roLandscape,
|
|
|
|
sla::Raster::roPortrait};
|
|
|
|
for (auto orientation : orientations)
|
|
|
|
for (auto &mirror : mirrorings)
|
|
|
|
check_raster_transformations(orientation, mirror);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-10-04 12:47:02 +00:00
|
|
|
TEST_CASE("RasterizedPolygonAreaShouldMatch", "[SLARasterOutput]") {
|
2019-10-01 11:27:58 +00:00
|
|
|
double disp_w = 120., disp_h = 68.;
|
|
|
|
sla::Raster::Resolution res{2560, 1440};
|
|
|
|
sla::Raster::PixelDim pixdim{disp_w / res.width_px, disp_h / res.height_px};
|
2019-11-04 13:33:29 +00:00
|
|
|
|
2019-10-01 11:27:58 +00:00
|
|
|
sla::Raster raster{res, pixdim};
|
|
|
|
auto bb = BoundingBox({0, 0}, {scaled(disp_w), scaled(disp_h)});
|
2019-11-04 13:33:29 +00:00
|
|
|
|
2019-10-01 11:27:58 +00:00
|
|
|
ExPolygon poly = square_with_hole(10.);
|
|
|
|
poly.translate(bb.center().x(), bb.center().y());
|
|
|
|
raster.draw(poly);
|
2019-11-04 13:33:29 +00:00
|
|
|
|
2019-10-01 11:27:58 +00:00
|
|
|
double a = poly.area() / (scaled<double>(1.) * scaled(1.));
|
|
|
|
double ra = raster_white_area(raster);
|
|
|
|
double diff = std::abs(a - ra);
|
2019-11-04 13:33:29 +00:00
|
|
|
|
2019-10-04 12:47:02 +00:00
|
|
|
REQUIRE(diff <= predict_error(poly, pixdim));
|
2019-11-04 13:33:29 +00:00
|
|
|
|
2019-10-01 11:27:58 +00:00
|
|
|
raster.clear();
|
|
|
|
poly = square_with_hole(60.);
|
|
|
|
poly.translate(bb.center().x(), bb.center().y());
|
|
|
|
raster.draw(poly);
|
2019-11-04 13:33:29 +00:00
|
|
|
|
2019-10-01 11:27:58 +00:00
|
|
|
a = poly.area() / (scaled<double>(1.) * scaled(1.));
|
|
|
|
ra = raster_white_area(raster);
|
|
|
|
diff = std::abs(a - ra);
|
2019-11-04 13:33:29 +00:00
|
|
|
|
2019-10-04 12:47:02 +00:00
|
|
|
REQUIRE(diff <= predict_error(poly, pixdim));
|
2019-09-24 13:24:47 +00:00
|
|
|
}
|
2019-11-04 13:33:29 +00:00
|
|
|
|
|
|
|
TEST_CASE("Triangle mesh conversions should be correct", "[SLAConversions]")
|
|
|
|
{
|
|
|
|
sla::Contour3D cntr;
|
|
|
|
|
|
|
|
{
|
|
|
|
std::fstream infile{"extruder_idler_quads.obj", std::ios::in};
|
|
|
|
cntr.from_obj(infile);
|
|
|
|
}
|
|
|
|
}
|