mirror of
https://github.com/QIDITECH/QIDIStudio.git
synced 2026-01-31 00:48:41 +03:00
update
This commit is contained in:
11
tests/sla_print/CMakeLists.txt
Normal file
11
tests/sla_print/CMakeLists.txt
Normal file
@@ -0,0 +1,11 @@
|
||||
get_filename_component(_TEST_NAME ${CMAKE_CURRENT_LIST_DIR} NAME)
|
||||
add_executable(${_TEST_NAME}_tests ${_TEST_NAME}_tests_main.cpp
|
||||
sla_print_tests.cpp
|
||||
sla_test_utils.hpp sla_test_utils.cpp
|
||||
sla_supptgen_tests.cpp
|
||||
sla_raycast_tests.cpp)
|
||||
target_link_libraries(${_TEST_NAME}_tests test_common libslic3r)
|
||||
set_property(TARGET ${_TEST_NAME}_tests PROPERTY FOLDER "tests")
|
||||
|
||||
# catch_discover_tests(${_TEST_NAME}_tests TEST_PREFIX "${_TEST_NAME}: ")
|
||||
add_test(${_TEST_NAME}_tests ${_TEST_NAME}_tests ${CATCH_EXTRA_ARGS})
|
||||
244
tests/sla_print/sla_print_tests.cpp
Normal file
244
tests/sla_print/sla_print_tests.cpp
Normal file
@@ -0,0 +1,244 @@
|
||||
#include <unordered_set>
|
||||
#include <unordered_map>
|
||||
#include <random>
|
||||
#include <numeric>
|
||||
#include <cstdint>
|
||||
|
||||
#include "sla_test_utils.hpp"
|
||||
|
||||
#include <libslic3r/TriangleMeshSlicer.hpp>
|
||||
#include <libslic3r/SLA/SupportTreeMesher.hpp>
|
||||
#include <libslic3r/SLA/Concurrency.hpp>
|
||||
|
||||
namespace {
|
||||
|
||||
const char *const BELOW_PAD_TEST_OBJECTS[] = {
|
||||
"20mm_cube.obj",
|
||||
"V.obj",
|
||||
};
|
||||
|
||||
const char *const AROUND_PAD_TEST_OBJECTS[] = {
|
||||
"20mm_cube.obj",
|
||||
"V.obj",
|
||||
"frog_legs.obj",
|
||||
"cube_with_concave_hole_enlarged.obj",
|
||||
};
|
||||
|
||||
const char *const SUPPORT_TEST_MODELS[] = {
|
||||
"cube_with_concave_hole_enlarged_standing.obj",
|
||||
"A_upsidedown.obj",
|
||||
"extruder_idler.obj"
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("Pillar pairhash should be unique", "[SLASupportGeneration]") {
|
||||
test_pairhash<int, int>();
|
||||
test_pairhash<int, long>();
|
||||
test_pairhash<unsigned, unsigned>();
|
||||
test_pairhash<unsigned, unsigned long>();
|
||||
}
|
||||
|
||||
TEST_CASE("Support point generator should be deterministic if seeded",
|
||||
"[SLASupportGeneration], [SLAPointGen]") {
|
||||
TriangleMesh mesh = load_model("A_upsidedown.obj");
|
||||
|
||||
sla::IndexedMesh emesh{mesh};
|
||||
|
||||
sla::SupportTreeConfig supportcfg;
|
||||
sla::SupportPointGenerator::Config autogencfg;
|
||||
autogencfg.head_diameter = float(2 * supportcfg.head_front_radius_mm);
|
||||
sla::SupportPointGenerator point_gen{emesh, autogencfg, [] {}, [](int) {}};
|
||||
|
||||
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 = slice_mesh_ex(mesh.its, slicegrid, CLOSING_RADIUS);
|
||||
|
||||
point_gen.seed(0);
|
||||
point_gen.execute(slices, slicegrid);
|
||||
|
||||
auto get_chksum = [](const std::vector<sla::SupportPoint> &pts){
|
||||
int64_t chksum = 0;
|
||||
for (auto &pt : pts) {
|
||||
auto p = scaled(pt.pos);
|
||||
chksum += p.x() + p.y() + p.z();
|
||||
}
|
||||
|
||||
return chksum;
|
||||
};
|
||||
|
||||
int64_t 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();
|
||||
point_gen.seed(0);
|
||||
point_gen.execute(slices, slicegrid);
|
||||
REQUIRE(point_gen.output().size() == ptnum);
|
||||
REQUIRE(checksum == get_chksum(point_gen.output()));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("Flat pad geometry is valid", "[SLASupportGeneration]") {
|
||||
sla::PadConfig padcfg;
|
||||
|
||||
// Disable wings
|
||||
padcfg.wall_height_mm = .0;
|
||||
|
||||
for (auto &fname : BELOW_PAD_TEST_OBJECTS) test_pad(fname, padcfg);
|
||||
}
|
||||
|
||||
TEST_CASE("WingedPadGeometryIsValid", "[SLASupportGeneration]") {
|
||||
sla::PadConfig padcfg;
|
||||
|
||||
// Add some wings to the pad to test the cavity
|
||||
padcfg.wall_height_mm = 1.;
|
||||
|
||||
for (auto &fname : BELOW_PAD_TEST_OBJECTS) test_pad(fname, padcfg);
|
||||
}
|
||||
|
||||
TEST_CASE("FlatPadAroundObjectIsValid", "[SLASupportGeneration]") {
|
||||
sla::PadConfig padcfg;
|
||||
|
||||
// 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;
|
||||
|
||||
for (auto &fname : AROUND_PAD_TEST_OBJECTS) test_pad(fname, padcfg);
|
||||
}
|
||||
|
||||
TEST_CASE("WingedPadAroundObjectIsValid", "[SLASupportGeneration]") {
|
||||
sla::PadConfig padcfg;
|
||||
|
||||
// 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;
|
||||
|
||||
for (auto &fname : AROUND_PAD_TEST_OBJECTS) test_pad(fname, padcfg);
|
||||
}
|
||||
|
||||
TEST_CASE("ElevatedSupportGeometryIsValid", "[SLASupportGeneration]") {
|
||||
sla::SupportTreeConfig supportcfg;
|
||||
supportcfg.object_elevation_mm = 10.;
|
||||
|
||||
for (auto fname : SUPPORT_TEST_MODELS) test_supports(fname, supportcfg);
|
||||
}
|
||||
|
||||
TEST_CASE("FloorSupportGeometryIsValid", "[SLASupportGeneration]") {
|
||||
sla::SupportTreeConfig supportcfg;
|
||||
supportcfg.object_elevation_mm = 0;
|
||||
|
||||
for (auto &fname: SUPPORT_TEST_MODELS) test_supports(fname, supportcfg);
|
||||
}
|
||||
|
||||
TEST_CASE("ElevatedSupportsDoNotPierceModel", "[SLASupportGeneration]") {
|
||||
|
||||
sla::SupportTreeConfig supportcfg;
|
||||
|
||||
for (auto fname : SUPPORT_TEST_MODELS)
|
||||
test_support_model_collision(fname, supportcfg);
|
||||
}
|
||||
|
||||
TEST_CASE("FloorSupportsDoNotPierceModel", "[SLASupportGeneration]") {
|
||||
|
||||
sla::SupportTreeConfig supportcfg;
|
||||
supportcfg.object_elevation_mm = 0;
|
||||
|
||||
for (auto fname : SUPPORT_TEST_MODELS)
|
||||
test_support_model_collision(fname, supportcfg);
|
||||
}
|
||||
|
||||
TEST_CASE("InitializedRasterShouldBeNONEmpty", "[SLARasterOutput]") {
|
||||
// Default SL1 display parameters
|
||||
sla::RasterBase::Resolution res{2560, 1440};
|
||||
sla::RasterBase::PixelDim pixdim{120. / res.width_px, 68. / res.height_px};
|
||||
|
||||
sla::RasterGrayscaleAAGammaPower raster(res, pixdim, {}, 1.);
|
||||
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));
|
||||
}
|
||||
|
||||
TEST_CASE("MirroringShouldBeCorrect", "[SLARasterOutput]") {
|
||||
sla::RasterBase::TMirroring mirrorings[] = {sla::RasterBase::NoMirror,
|
||||
sla::RasterBase::MirrorX,
|
||||
sla::RasterBase::MirrorY,
|
||||
sla::RasterBase::MirrorXY};
|
||||
|
||||
sla::RasterBase::Orientation orientations[] =
|
||||
{sla::RasterBase::roLandscape, sla::RasterBase::roPortrait};
|
||||
|
||||
for (auto orientation : orientations)
|
||||
for (auto &mirror : mirrorings)
|
||||
check_raster_transformations(orientation, mirror);
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("RasterizedPolygonAreaShouldMatch", "[SLARasterOutput]") {
|
||||
double disp_w = 120., disp_h = 68.;
|
||||
sla::RasterBase::Resolution res{2560, 1440};
|
||||
sla::RasterBase::PixelDim pixdim{disp_w / res.width_px, disp_h / res.height_px};
|
||||
|
||||
double gamma = 1.;
|
||||
sla::RasterGrayscaleAAGammaPower raster(res, pixdim, {}, gamma);
|
||||
auto bb = BoundingBox({0, 0}, {scaled(disp_w), scaled(disp_h)});
|
||||
|
||||
ExPolygon poly = square_with_hole(10.);
|
||||
poly.translate(bb.center().x(), bb.center().y());
|
||||
raster.draw(poly);
|
||||
|
||||
double a = poly.area() / (scaled<double>(1.) * scaled(1.));
|
||||
double ra = raster_white_area(raster);
|
||||
double diff = std::abs(a - ra);
|
||||
|
||||
REQUIRE(diff <= predict_error(poly, pixdim));
|
||||
|
||||
raster.clear();
|
||||
poly = square_with_hole(60.);
|
||||
poly.translate(bb.center().x(), bb.center().y());
|
||||
raster.draw(poly);
|
||||
|
||||
a = poly.area() / (scaled<double>(1.) * scaled(1.));
|
||||
ra = raster_white_area(raster);
|
||||
diff = std::abs(a - ra);
|
||||
|
||||
REQUIRE(diff <= predict_error(poly, pixdim));
|
||||
|
||||
sla::RasterGrayscaleAA raster0(res, pixdim, {}, [](double) { return 0.; });
|
||||
REQUIRE(raster_pxsum(raster0) == 0);
|
||||
|
||||
raster0.draw(poly);
|
||||
ra = raster_white_area(raster);
|
||||
REQUIRE(raster_pxsum(raster0) == 0);
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("halfcone test", "[halfcone]") {
|
||||
sla::DiffBridge br{Vec3d{1., 1., 1.}, Vec3d{10., 10., 10.}, 0.25, 0.5};
|
||||
|
||||
indexed_triangle_set m = sla::get_mesh(br, 45);
|
||||
|
||||
its_merge_vertices(m);
|
||||
its_write_obj(m, "Halfcone.obj");
|
||||
}
|
||||
|
||||
TEST_CASE("Test concurrency")
|
||||
{
|
||||
std::vector<double> vals = grid(0., 100., 10.);
|
||||
|
||||
double ref = std::accumulate(vals.begin(), vals.end(), 0.);
|
||||
|
||||
double s = execution::accumulate(ex_tbb, vals.begin(), vals.end(), 0.);
|
||||
|
||||
REQUIRE(s == Approx(ref));
|
||||
}
|
||||
1
tests/sla_print/sla_print_tests_main.cpp
Normal file
1
tests/sla_print/sla_print_tests_main.cpp
Normal file
@@ -0,0 +1 @@
|
||||
#include <catch_main.hpp>
|
||||
96
tests/sla_print/sla_raycast_tests.cpp
Normal file
96
tests/sla_print/sla_raycast_tests.cpp
Normal file
@@ -0,0 +1,96 @@
|
||||
#include <catch2/catch.hpp>
|
||||
#include <test_utils.hpp>
|
||||
|
||||
#include <libslic3r/SLA/IndexedMesh.hpp>
|
||||
#include <libslic3r/SLA/Hollowing.hpp>
|
||||
|
||||
#include "sla_test_utils.hpp"
|
||||
|
||||
using namespace Slic3r;
|
||||
|
||||
// First do a simple test of the hole raycaster.
|
||||
TEST_CASE("Raycaster - find intersections of a line and cylinder")
|
||||
{
|
||||
sla::DrainHole hole{Vec3f(0,0,0), Vec3f(0,0,1), 5, 10};
|
||||
std::array<std::pair<float, Vec3d>, 2> out;
|
||||
Vec3f s;
|
||||
Vec3f dir;
|
||||
|
||||
// Start inside the hole and cast perpendicular to its axis.
|
||||
s = {-1.f, 0, 5.f};
|
||||
dir = {1.f, 0, 0};
|
||||
hole.get_intersections(s, dir, out);
|
||||
REQUIRE(out[0].first == Approx(-4.f));
|
||||
REQUIRE(out[1].first == Approx(6.f));
|
||||
|
||||
// Start outside and cast parallel to axis.
|
||||
s = {0, 0, -1.f};
|
||||
dir = {0, 0, 1.f};
|
||||
hole.get_intersections(s, dir, out);
|
||||
REQUIRE(std::abs(out[0].first - 1.f) < 0.001f);
|
||||
REQUIRE(std::abs(out[1].first - 11.f) < 0.001f);
|
||||
|
||||
// Start outside and cast so that entry is in base and exit on the cylinder
|
||||
s = {0, -1.f, -1.f};
|
||||
dir = {0, 1.f, 1.f};
|
||||
dir.normalize();
|
||||
hole.get_intersections(s, dir, out);
|
||||
REQUIRE(std::abs(out[0].first - std::sqrt(2.f)) < 0.001f);
|
||||
REQUIRE(std::abs(out[1].first - std::sqrt(72.f)) < 0.001f);
|
||||
}
|
||||
|
||||
#ifdef SLIC3R_HOLE_RAYCASTER
|
||||
// Create a simple scene with a 20mm cube and a big hole in the front wall
|
||||
// with 5mm radius. Then shoot rays from interesting positions and see where
|
||||
// they land.
|
||||
TEST_CASE("Raycaster with loaded drillholes", "[sla_raycast]")
|
||||
{
|
||||
// Load the cube and make it hollow.
|
||||
TriangleMesh cube = load_model("20mm_cube.obj");
|
||||
sla::HollowingConfig hcfg;
|
||||
std::unique_ptr<TriangleMesh> cube_inside = sla::generate_interior(cube, hcfg);
|
||||
REQUIRE(cube_inside);
|
||||
|
||||
// Helper bb
|
||||
auto boxbb = cube.bounding_box();
|
||||
|
||||
// Create the big 10mm long drainhole in the front wall.
|
||||
Vec3f center = boxbb.center().cast<float>();
|
||||
Vec3f p = {center.x(), 0., center.z()};
|
||||
Vec3f normal = {0.f, 1.f, 0.f};
|
||||
float radius = 5.f;
|
||||
float hole_length = 10.;
|
||||
sla::DrainHoles holes = { sla::DrainHole{p, normal, radius, hole_length} };
|
||||
|
||||
cube.merge(*cube_inside);
|
||||
|
||||
sla::IndexedMesh emesh{cube};
|
||||
emesh.load_holes(holes);
|
||||
|
||||
Vec3d s = center.cast<double>();
|
||||
// Fire from center, should hit the interior wall
|
||||
auto hit = emesh.query_ray_hit(s, {0, 1., 0.});
|
||||
REQUIRE(hit.distance() == Approx(boxbb.size().x() / 2 - hcfg.min_thickness));
|
||||
|
||||
// Fire upward from hole center, hit distance equals the radius (hits the
|
||||
// side of the hole cut.
|
||||
s.y() = hcfg.min_thickness / 2;
|
||||
hit = emesh.query_ray_hit(s, {0, 0., 1.});
|
||||
REQUIRE(hit.distance() == Approx(radius));
|
||||
|
||||
// Fire from outside, hit the back side of the cube interior
|
||||
s.y() = -1.;
|
||||
hit = emesh.query_ray_hit(s, {0, 1., 0.});
|
||||
REQUIRE(hit.distance() == Approx(boxbb.max.y() - hcfg.min_thickness - s.y()));
|
||||
|
||||
// Fire downwards from above the hole cylinder. Has to go through the cyl.
|
||||
// as it was not there.
|
||||
s = center.cast<double>();
|
||||
s.z() = boxbb.max.z() - hcfg.min_thickness - 1.;
|
||||
hit = emesh.query_ray_hit(s, {0, 0., -1.});
|
||||
REQUIRE(hit.distance() == Approx(s.z() - boxbb.min.z() - hcfg.min_thickness));
|
||||
|
||||
// Check for support tree correctness
|
||||
test_support_model_collision("20mm_cube.obj", {}, hcfg, holes);
|
||||
}
|
||||
#endif
|
||||
141
tests/sla_print/sla_supptgen_tests.cpp
Normal file
141
tests/sla_print/sla_supptgen_tests.cpp
Normal file
@@ -0,0 +1,141 @@
|
||||
#include <catch2/catch.hpp>
|
||||
#include <test_utils.hpp>
|
||||
|
||||
#include <libslic3r/ExPolygon.hpp>
|
||||
#include <libslic3r/BoundingBox.hpp>
|
||||
|
||||
#include "sla_test_utils.hpp"
|
||||
|
||||
namespace Slic3r { namespace sla {
|
||||
|
||||
TEST_CASE("Overhanging point should be supported", "[SupGen]") {
|
||||
|
||||
// Pyramid with 45 deg slope
|
||||
TriangleMesh mesh = make_pyramid(10.f, 10.f);
|
||||
mesh.rotate_y(float(PI));
|
||||
mesh.WriteOBJFile("Pyramid.obj");
|
||||
|
||||
sla::SupportPoints pts = calc_support_pts(mesh);
|
||||
|
||||
// The overhang, which is the upside-down pyramid's edge
|
||||
Vec3f overh{0., 0., -10.};
|
||||
|
||||
REQUIRE(!pts.empty());
|
||||
|
||||
float dist = (overh - pts.front().pos).norm();
|
||||
|
||||
for (const auto &pt : pts)
|
||||
dist = std::min(dist, (overh - pt.pos).norm());
|
||||
|
||||
// Should require exactly one support point at the overhang
|
||||
REQUIRE(pts.size() > 0);
|
||||
REQUIRE(dist < 1.f);
|
||||
}
|
||||
|
||||
double min_point_distance(const sla::SupportPoints &pts)
|
||||
{
|
||||
sla::PointIndex index;
|
||||
|
||||
for (size_t i = 0; i < pts.size(); ++i)
|
||||
index.insert(pts[i].pos.cast<double>(), i);
|
||||
|
||||
auto d = std::numeric_limits<double>::max();
|
||||
index.foreach([&d, &index](const sla::PointIndexEl &el) {
|
||||
auto res = index.nearest(el.first, 2);
|
||||
for (const sla::PointIndexEl &r : res)
|
||||
if (r.second != el.second)
|
||||
d = std::min(d, (el.first - r.first).norm());
|
||||
});
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
TEST_CASE("Overhanging horizontal surface should be supported", "[SupGen]") {
|
||||
double width = 10., depth = 10., height = 1.;
|
||||
|
||||
TriangleMesh mesh = make_cube(width, depth, height);
|
||||
mesh.translate(0., 0., 5.); // lift up
|
||||
mesh.WriteOBJFile("Cuboid.obj");
|
||||
|
||||
sla::SupportPointGenerator::Config cfg;
|
||||
sla::SupportPoints pts = calc_support_pts(mesh, cfg);
|
||||
|
||||
double mm2 = width * depth;
|
||||
|
||||
REQUIRE(!pts.empty());
|
||||
REQUIRE(pts.size() * cfg.support_force() > mm2 * cfg.tear_pressure());
|
||||
REQUIRE(min_point_distance(pts) >= cfg.minimal_distance);
|
||||
}
|
||||
|
||||
template<class M> auto&& center_around_bb(M &&mesh)
|
||||
{
|
||||
auto bb = mesh.bounding_box();
|
||||
mesh.translate(-bb.center().template cast<float>());
|
||||
|
||||
return std::forward<M>(mesh);
|
||||
}
|
||||
|
||||
TEST_CASE("Overhanging edge should be supported", "[SupGen]") {
|
||||
float width = 10.f, depth = 10.f, height = 5.f;
|
||||
|
||||
TriangleMesh mesh = make_prism(width, depth, height);
|
||||
mesh.rotate_y(float(PI)); // rotate on its back
|
||||
mesh.translate(0., 0., height);
|
||||
mesh.WriteOBJFile("Prism.obj");
|
||||
|
||||
sla::SupportPointGenerator::Config cfg;
|
||||
sla::SupportPoints pts = calc_support_pts(mesh, cfg);
|
||||
|
||||
Linef3 overh{ {0.f, -depth / 2.f, 0.f}, {0.f, depth / 2.f, 0.f}};
|
||||
|
||||
// Get all the points closer that 1 mm to the overhanging edge:
|
||||
sla::SupportPoints overh_pts; overh_pts.reserve(pts.size());
|
||||
|
||||
std::copy_if(pts.begin(), pts.end(), std::back_inserter(overh_pts),
|
||||
[&overh](const sla::SupportPoint &pt){
|
||||
return line_alg::distance_to(overh, Vec3d{pt.pos.cast<double>()}) < 1.;
|
||||
});
|
||||
|
||||
REQUIRE(overh_pts.size() * cfg.support_force() > overh.length() * cfg.tear_pressure());
|
||||
double ddiff = min_point_distance(pts) - cfg.minimal_distance;
|
||||
REQUIRE(ddiff > - 0.1 * cfg.minimal_distance);
|
||||
}
|
||||
|
||||
TEST_CASE("Hollowed cube should be supported from the inside", "[SupGen][Hollowed]") {
|
||||
TriangleMesh mesh = make_cube(20., 20., 20.);
|
||||
|
||||
hollow_mesh(mesh, HollowingConfig{});
|
||||
|
||||
mesh.WriteOBJFile("cube_hollowed.obj");
|
||||
|
||||
auto bb = mesh.bounding_box();
|
||||
auto h = float(bb.max.z() - bb.min.z());
|
||||
Vec3f mv = bb.center().cast<float>() - Vec3f{0.f, 0.f, 0.5f * h};
|
||||
mesh.translate(-mv);
|
||||
|
||||
sla::SupportPointGenerator::Config cfg;
|
||||
sla::SupportPoints pts = calc_support_pts(mesh, cfg);
|
||||
sla::remove_bottom_points(pts, mesh.bounding_box().min.z() + EPSILON);
|
||||
|
||||
REQUIRE(!pts.empty());
|
||||
}
|
||||
|
||||
TEST_CASE("Two parallel plates should be supported", "[SupGen][Hollowed]")
|
||||
{
|
||||
double width = 20., depth = 20., height = 1.;
|
||||
|
||||
TriangleMesh mesh = center_around_bb(make_cube(width + 5., depth + 5., height));
|
||||
TriangleMesh mesh_high = center_around_bb(make_cube(width, depth, height));
|
||||
mesh_high.translate(0., 0., 10.); // lift up
|
||||
mesh.merge(mesh_high);
|
||||
|
||||
mesh.WriteOBJFile("parallel_plates.obj");
|
||||
|
||||
sla::SupportPointGenerator::Config cfg;
|
||||
sla::SupportPoints pts = calc_support_pts(mesh, cfg);
|
||||
sla::remove_bottom_points(pts, mesh.bounding_box().min.z() + EPSILON);
|
||||
|
||||
REQUIRE(!pts.empty());
|
||||
}
|
||||
|
||||
}} // namespace Slic3r::sla
|
||||
437
tests/sla_print/sla_test_utils.cpp
Normal file
437
tests/sla_print/sla_test_utils.cpp
Normal file
@@ -0,0 +1,437 @@
|
||||
#include "sla_test_utils.hpp"
|
||||
#include "libslic3r/TriangleMeshSlicer.hpp"
|
||||
#include "libslic3r/SLA/AGGRaster.hpp"
|
||||
|
||||
#include <iomanip>
|
||||
|
||||
void test_support_model_collision(const std::string &obj_filename,
|
||||
const sla::SupportTreeConfig &input_supportcfg,
|
||||
const sla::HollowingConfig &hollowingcfg,
|
||||
const sla::DrainHoles &drainholes)
|
||||
{
|
||||
SupportByproducts byproducts;
|
||||
|
||||
sla::SupportTreeConfig supportcfg = input_supportcfg;
|
||||
|
||||
// Set head penetration to a small negative value which should ensure that
|
||||
// the supports will not touch the model body.
|
||||
supportcfg.head_penetration_mm = -0.15;
|
||||
|
||||
test_supports(obj_filename, supportcfg, hollowingcfg, drainholes, byproducts);
|
||||
|
||||
// Slice the support mesh given the slice grid of the model.
|
||||
std::vector<ExPolygons> support_slices =
|
||||
byproducts.supporttree.slice(byproducts.slicegrid, CLOSING_RADIUS);
|
||||
|
||||
// The slices originate from the same slice grid so the numbers must match
|
||||
|
||||
bool support_mesh_is_empty =
|
||||
byproducts.supporttree.retrieve_mesh(sla::MeshType::Pad).empty() &&
|
||||
byproducts.supporttree.retrieve_mesh(sla::MeshType::Support).empty();
|
||||
|
||||
if (support_mesh_is_empty)
|
||||
REQUIRE(support_slices.empty());
|
||||
else
|
||||
REQUIRE(support_slices.size() == byproducts.model_slices.size());
|
||||
|
||||
bool notouch = true;
|
||||
for (size_t n = 0; notouch && n < support_slices.size(); ++n) {
|
||||
const ExPolygons &sup_slice = support_slices[n];
|
||||
const ExPolygons &mod_slice = byproducts.model_slices[n];
|
||||
|
||||
Polygons intersections = intersection(sup_slice, mod_slice);
|
||||
|
||||
double pinhead_r = scaled(input_supportcfg.head_front_radius_mm);
|
||||
|
||||
// TODO:: make it strict without a threshold of PI * pihead_radius ^ 2
|
||||
notouch = notouch && area(intersections) < PI * pinhead_r * pinhead_r;
|
||||
}
|
||||
|
||||
/*if (!notouch) */export_failed_case(support_slices, byproducts);
|
||||
|
||||
REQUIRE(notouch);
|
||||
}
|
||||
|
||||
void export_failed_case(const std::vector<ExPolygons> &support_slices, const SupportByproducts &byproducts)
|
||||
{
|
||||
for (size_t n = 0; n < support_slices.size(); ++n) {
|
||||
const ExPolygons &sup_slice = support_slices[n];
|
||||
const ExPolygons &mod_slice = byproducts.model_slices[n];
|
||||
Polygons intersections = intersection(sup_slice, mod_slice);
|
||||
|
||||
std::stringstream ss;
|
||||
if (!intersections.empty()) {
|
||||
ss << byproducts.obj_fname << std::setprecision(4) << n << ".svg";
|
||||
SVG svg(ss.str());
|
||||
svg.draw(sup_slice, "green");
|
||||
svg.draw(mod_slice, "blue");
|
||||
svg.draw(intersections, "red");
|
||||
svg.Close();
|
||||
}
|
||||
}
|
||||
|
||||
indexed_triangle_set its;
|
||||
byproducts.supporttree.retrieve_full_mesh(its);
|
||||
TriangleMesh m{its};
|
||||
m.merge(byproducts.input_mesh);
|
||||
m.WriteOBJFile((Catch::getResultCapture().getCurrentTestName() + "_" +
|
||||
byproducts.obj_fname).c_str());
|
||||
}
|
||||
|
||||
void test_supports(const std::string &obj_filename,
|
||||
const sla::SupportTreeConfig &supportcfg,
|
||||
const sla::HollowingConfig &hollowingcfg,
|
||||
const sla::DrainHoles &drainholes,
|
||||
SupportByproducts &out)
|
||||
{
|
||||
using namespace Slic3r;
|
||||
TriangleMesh mesh = load_model(obj_filename);
|
||||
|
||||
REQUIRE_FALSE(mesh.empty());
|
||||
|
||||
if (hollowingcfg.enabled) {
|
||||
sla::InteriorPtr interior = sla::generate_interior(mesh, hollowingcfg);
|
||||
REQUIRE(interior);
|
||||
mesh.merge(TriangleMesh{sla::get_mesh(*interior)});
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
out.slicegrid = grid(float(gnd), float(zmax), layer_h);
|
||||
out.model_slices = slice_mesh_ex(mesh.its, out.slicegrid, CLOSING_RADIUS);
|
||||
sla::cut_drainholes(out.model_slices, out.slicegrid, CLOSING_RADIUS, drainholes, []{});
|
||||
|
||||
// Create the special index-triangle mesh with spatial indexing which
|
||||
// is the input of the support point and support mesh generators
|
||||
sla::IndexedMesh emesh{mesh};
|
||||
|
||||
#ifdef SLIC3R_HOLE_RAYCASTER
|
||||
if (hollowingcfg.enabled)
|
||||
emesh.load_holes(drainholes);
|
||||
#endif
|
||||
|
||||
// TODO: do the cgal hole cutting...
|
||||
|
||||
// Create the support point generator
|
||||
sla::SupportPointGenerator::Config autogencfg;
|
||||
autogencfg.head_diameter = float(2 * supportcfg.head_front_radius_mm);
|
||||
sla::SupportPointGenerator point_gen{emesh, autogencfg, [] {}, [](int) {}};
|
||||
|
||||
point_gen.seed(0); // Make the test repeatable
|
||||
point_gen.execute(out.model_slices, out.slicegrid);
|
||||
|
||||
// Get the calculated support points.
|
||||
std::vector<sla::SupportPoint> support_points = point_gen.output();
|
||||
|
||||
int validityflags = ASSUME_NO_REPAIR;
|
||||
|
||||
// If there is no elevation, support points shall be removed from the
|
||||
// bottom of the object.
|
||||
if (std::abs(supportcfg.object_elevation_mm) < EPSILON) {
|
||||
sla::remove_bottom_points(support_points, zmin + supportcfg.base_height_mm);
|
||||
} else {
|
||||
// Should be support points at least on the bottom of the model
|
||||
REQUIRE_FALSE(support_points.empty());
|
||||
|
||||
// Also the support mesh should not be empty.
|
||||
validityflags |= ASSUME_NO_EMPTY;
|
||||
}
|
||||
|
||||
// Generate the actual support tree
|
||||
sla::SupportTreeBuilder treebuilder;
|
||||
sla::SupportableMesh sm{emesh, support_points, supportcfg};
|
||||
sla::SupportTreeBuildsteps::execute(treebuilder, sm);
|
||||
|
||||
check_support_tree_integrity(treebuilder, supportcfg);
|
||||
|
||||
TriangleMesh output_mesh{treebuilder.retrieve_mesh(sla::MeshType::Support)};
|
||||
|
||||
check_validity(output_mesh, validityflags);
|
||||
|
||||
// Quick check if the dimensions and placement of supports are correct
|
||||
auto obb = output_mesh.bounding_box();
|
||||
|
||||
double allowed_zmin = zmin - supportcfg.object_elevation_mm;
|
||||
|
||||
if (std::abs(supportcfg.object_elevation_mm) < EPSILON)
|
||||
allowed_zmin = zmin - 2 * supportcfg.head_back_radius_mm;
|
||||
|
||||
REQUIRE(obb.min.z() >= Approx(allowed_zmin));
|
||||
REQUIRE(obb.max.z() <= Approx(zmax));
|
||||
|
||||
// Move out the support tree into the byproducts, we can examine it further
|
||||
// in various tests.
|
||||
out.obj_fname = std::move(obj_filename);
|
||||
out.supporttree = std::move(treebuilder);
|
||||
out.input_mesh = std::move(mesh);
|
||||
}
|
||||
|
||||
void check_support_tree_integrity(const sla::SupportTreeBuilder &stree,
|
||||
const sla::SupportTreeConfig &cfg)
|
||||
{
|
||||
double gnd = stree.ground_level;
|
||||
double H1 = cfg.max_solo_pillar_height_mm;
|
||||
double H2 = cfg.max_dual_pillar_height_mm;
|
||||
|
||||
for (const sla::Head &head : stree.heads()) {
|
||||
REQUIRE((!head.is_valid() || head.pillar_id != sla::SupportTreeNode::ID_UNSET ||
|
||||
head.bridge_id != sla::SupportTreeNode::ID_UNSET));
|
||||
}
|
||||
|
||||
for (const sla::Pillar &pillar : stree.pillars()) {
|
||||
if (std::abs(pillar.endpoint().z() - gnd) < EPSILON) {
|
||||
double h = pillar.height;
|
||||
|
||||
if (h > H1) REQUIRE(pillar.links >= 1);
|
||||
else if(h > H2) { REQUIRE(pillar.links >= 2); }
|
||||
}
|
||||
|
||||
REQUIRE(pillar.links <= cfg.pillar_cascade_neighbors);
|
||||
REQUIRE(pillar.bridges <= cfg.max_bridges_on_pillar);
|
||||
}
|
||||
|
||||
double max_bridgelen = 0.;
|
||||
auto chck_bridge = [&cfg](const sla::Bridge &bridge, double &max_brlen) {
|
||||
Vec3d n = bridge.endp - bridge.startp;
|
||||
double d = sla::distance(n);
|
||||
max_brlen = std::max(d, max_brlen);
|
||||
|
||||
double z = n.z();
|
||||
double polar = std::acos(z / d);
|
||||
double slope = -polar + PI / 2.;
|
||||
REQUIRE(std::abs(slope) >= cfg.bridge_slope - EPSILON);
|
||||
};
|
||||
|
||||
for (auto &bridge : stree.bridges()) chck_bridge(bridge, max_bridgelen);
|
||||
REQUIRE(max_bridgelen <= Approx(cfg.max_bridge_length_mm));
|
||||
|
||||
max_bridgelen = 0;
|
||||
for (auto &bridge : stree.crossbridges()) chck_bridge(bridge, max_bridgelen);
|
||||
|
||||
double md = cfg.max_pillar_link_distance_mm / std::cos(-cfg.bridge_slope);
|
||||
REQUIRE(max_bridgelen <= md);
|
||||
}
|
||||
|
||||
void test_pad(const std::string &obj_filename, const sla::PadConfig &padcfg, PadByproducts &out)
|
||||
{
|
||||
REQUIRE(padcfg.validate().empty());
|
||||
|
||||
TriangleMesh mesh = load_model(obj_filename);
|
||||
|
||||
REQUIRE_FALSE(mesh.empty());
|
||||
|
||||
// Create pad skeleton only from the model
|
||||
Slic3r::sla::pad_blueprint(mesh.its, out.model_contours);
|
||||
|
||||
test_concave_hull(out.model_contours);
|
||||
|
||||
REQUIRE_FALSE(out.model_contours.empty());
|
||||
|
||||
// Create the pad geometry for the model contours only
|
||||
indexed_triangle_set out_its;
|
||||
Slic3r::sla::create_pad({}, out.model_contours, out_its, padcfg);
|
||||
out.mesh = TriangleMesh{out_its};
|
||||
|
||||
check_validity(out.mesh);
|
||||
|
||||
auto bb = out.mesh.bounding_box();
|
||||
REQUIRE(bb.max.z() - bb.min.z() == Approx(padcfg.full_height()));
|
||||
}
|
||||
|
||||
static void _test_concave_hull(const Polygons &hull, const ExPolygons &polys)
|
||||
{
|
||||
REQUIRE(polys.size() >=hull.size());
|
||||
|
||||
double polys_area = 0;
|
||||
for (const ExPolygon &p : polys) polys_area += p.area();
|
||||
|
||||
double cchull_area = 0;
|
||||
for (const Slic3r::Polygon &p : hull) cchull_area += p.area();
|
||||
|
||||
REQUIRE(cchull_area >= Approx(polys_area));
|
||||
|
||||
size_t cchull_holes = 0;
|
||||
for (const Slic3r::Polygon &p : hull)
|
||||
cchull_holes += p.is_clockwise() ? 1 : 0;
|
||||
|
||||
REQUIRE(cchull_holes == 0);
|
||||
|
||||
Polygons intr = diff(to_polygons(polys), hull);
|
||||
REQUIRE(intr.empty());
|
||||
}
|
||||
|
||||
void test_concave_hull(const ExPolygons &polys) {
|
||||
sla::PadConfig pcfg;
|
||||
|
||||
Slic3r::sla::ConcaveHull cchull{polys, pcfg.max_merge_dist_mm, []{}};
|
||||
|
||||
_test_concave_hull(cchull.polygons(), polys);
|
||||
|
||||
coord_t delta = scaled(pcfg.brim_size_mm + pcfg.wing_distance());
|
||||
ExPolygons wafflex = sla::offset_waffle_style_ex(cchull, delta);
|
||||
Polygons waffl = sla::offset_waffle_style(cchull, delta);
|
||||
|
||||
_test_concave_hull(to_polygons(wafflex), polys);
|
||||
_test_concave_hull(waffl, polys);
|
||||
}
|
||||
|
||||
//FIXME this functionality is gone after TriangleMesh refactoring to get rid of admesh.
|
||||
void check_validity(const TriangleMesh &input_mesh, int flags)
|
||||
{
|
||||
/*
|
||||
TriangleMesh mesh{input_mesh};
|
||||
|
||||
if (flags & ASSUME_NO_EMPTY) {
|
||||
REQUIRE_FALSE(mesh.empty());
|
||||
} else if (mesh.empty())
|
||||
return; // If it can be empty and it is, there is nothing left to do.
|
||||
|
||||
bool do_update_shared_vertices = false;
|
||||
mesh.repair(do_update_shared_vertices);
|
||||
|
||||
if (flags & ASSUME_NO_REPAIR) {
|
||||
REQUIRE_FALSE(mesh.repaired());
|
||||
}
|
||||
|
||||
if (flags & ASSUME_MANIFOLD) {
|
||||
if (!mesh.is_manifold()) mesh.WriteOBJFile("non_manifold.obj");
|
||||
REQUIRE(mesh.is_manifold());
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
void check_raster_transformations(sla::RasterBase::Orientation o, sla::RasterBase::TMirroring mirroring)
|
||||
{
|
||||
double disp_w = 120., disp_h = 68.;
|
||||
sla::RasterBase::Resolution res{2560, 1440};
|
||||
sla::RasterBase::PixelDim pixdim{disp_w / res.width_px, disp_h / res.height_px};
|
||||
|
||||
auto bb = BoundingBox({0, 0}, {scaled(disp_w), scaled(disp_h)});
|
||||
sla::RasterBase::Trafo trafo{o, mirroring};
|
||||
trafo.center_x = bb.center().x();
|
||||
trafo.center_y = bb.center().y();
|
||||
double gamma = 1.;
|
||||
|
||||
sla::RasterGrayscaleAAGammaPower raster{res, pixdim, trafo, gamma};
|
||||
|
||||
// create box of size 32x32 pixels (not 1x1 to avoid antialiasing errors)
|
||||
coord_t pw = 32 * coord_t(std::ceil(scaled<double>(pixdim.w_mm)));
|
||||
coord_t ph = 32 * coord_t(std::ceil(scaled<double>(pixdim.h_mm)));
|
||||
ExPolygon box;
|
||||
box.contour.points = {{-pw, -ph}, {pw, -ph}, {pw, ph}, {-pw, ph}};
|
||||
|
||||
double tr_x = scaled<double>(20.), tr_y = tr_x;
|
||||
|
||||
box.translate(tr_x, tr_y);
|
||||
ExPolygon expected_box = box;
|
||||
|
||||
// Now calculate the position of the translated box according to output
|
||||
// trafo.
|
||||
if (o == sla::RasterBase::Orientation::roPortrait) expected_box.rotate(PI / 2.);
|
||||
|
||||
if (mirroring[X])
|
||||
for (auto &p : expected_box.contour.points) p.x() = -p.x();
|
||||
|
||||
if (mirroring[Y])
|
||||
for (auto &p : expected_box.contour.points) p.y() = -p.y();
|
||||
|
||||
raster.draw(box);
|
||||
|
||||
Point expected_coords = expected_box.contour.bounding_box().center();
|
||||
double rx = unscaled(expected_coords.x() + bb.center().x()) / pixdim.w_mm;
|
||||
double ry = unscaled(expected_coords.y() + bb.center().y()) / pixdim.h_mm;
|
||||
auto w = size_t(std::floor(rx));
|
||||
auto h = res.height_px - size_t(std::floor(ry));
|
||||
|
||||
REQUIRE((w < res.width_px && h < res.height_px));
|
||||
|
||||
auto px = raster.read_pixel(w, h);
|
||||
|
||||
if (px != FullWhite) {
|
||||
std::fstream outf("out.png", std::ios::out);
|
||||
|
||||
outf << raster.encode(sla::PNGRasterEncoder());
|
||||
}
|
||||
|
||||
REQUIRE(px == FullWhite);
|
||||
}
|
||||
|
||||
ExPolygon square_with_hole(double v)
|
||||
{
|
||||
ExPolygon poly;
|
||||
coord_t V = scaled(v / 2.);
|
||||
|
||||
poly.contour.points = {{-V, -V}, {V, -V}, {V, V}, {-V, V}};
|
||||
poly.holes.emplace_back();
|
||||
V = V / 2;
|
||||
poly.holes.front().points = {{-V, V}, {V, V}, {V, -V}, {-V, -V}};
|
||||
return poly;
|
||||
}
|
||||
|
||||
long raster_pxsum(const sla::RasterGrayscaleAA &raster)
|
||||
{
|
||||
auto res = raster.resolution();
|
||||
long a = 0;
|
||||
|
||||
for (size_t x = 0; x < res.width_px; ++x)
|
||||
for (size_t y = 0; y < res.height_px; ++y)
|
||||
a += raster.read_pixel(x, y);
|
||||
|
||||
return a;
|
||||
}
|
||||
|
||||
double raster_white_area(const sla::RasterGrayscaleAA &raster)
|
||||
{
|
||||
if (raster.resolution().pixels() == 0) return std::nan("");
|
||||
|
||||
auto res = raster.resolution();
|
||||
double a = 0;
|
||||
|
||||
for (size_t x = 0; x < res.width_px; ++x)
|
||||
for (size_t y = 0; y < res.height_px; ++y) {
|
||||
auto px = raster.read_pixel(x, y);
|
||||
a += pixel_area(px, raster.pixel_dimensions());
|
||||
}
|
||||
|
||||
return a;
|
||||
}
|
||||
|
||||
double predict_error(const ExPolygon &p, const sla::RasterBase::PixelDim &pd)
|
||||
{
|
||||
auto lines = p.lines();
|
||||
double pix_err = pixel_area(FullWhite, pd) / 2.;
|
||||
|
||||
// Worst case is when a line is parallel to the shorter axis of one pixel,
|
||||
// when the line will be composed of the max number of pixels
|
||||
double pix_l = std::min(pd.h_mm, pd.w_mm);
|
||||
|
||||
double error = 0.;
|
||||
for (auto &l : lines)
|
||||
error += (unscaled(l.length()) / pix_l) * pix_err;
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
sla::SupportPoints calc_support_pts(
|
||||
const TriangleMesh & mesh,
|
||||
const sla::SupportPointGenerator::Config &cfg)
|
||||
{
|
||||
// Prepare the slice grid and the slices
|
||||
auto bb = cast<float>(mesh.bounding_box());
|
||||
std::vector<float> heights = grid(bb.min.z(), bb.max.z(), 0.1f);
|
||||
std::vector<ExPolygons> slices = slice_mesh_ex(mesh.its, heights, CLOSING_RADIUS);
|
||||
|
||||
// Prepare the support point calculator
|
||||
sla::IndexedMesh emesh{mesh};
|
||||
sla::SupportPointGenerator spgen{emesh, cfg, []{}, [](int){}};
|
||||
|
||||
// Calculate the support points
|
||||
spgen.seed(0);
|
||||
spgen.execute(slices, heights);
|
||||
|
||||
return spgen.output();
|
||||
}
|
||||
192
tests/sla_print/sla_test_utils.hpp
Normal file
192
tests/sla_print/sla_test_utils.hpp
Normal file
@@ -0,0 +1,192 @@
|
||||
#ifndef SLA_TEST_UTILS_HPP
|
||||
#define SLA_TEST_UTILS_HPP
|
||||
|
||||
#include <catch2/catch.hpp>
|
||||
#include <test_utils.hpp>
|
||||
|
||||
// Debug
|
||||
#include <fstream>
|
||||
#include <unordered_set>
|
||||
|
||||
#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/SupportTreeBuildsteps.hpp"
|
||||
#include "libslic3r/SLA/SupportPointGenerator.hpp"
|
||||
#include "libslic3r/SLA/AGGRaster.hpp"
|
||||
#include "libslic3r/SLA/ConcaveHull.hpp"
|
||||
#include "libslic3r/MTUtils.hpp"
|
||||
|
||||
#include "libslic3r/SVG.hpp"
|
||||
#include "libslic3r/Format/OBJ.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;
|
||||
sla::SupportTreeBuilder supporttree;
|
||||
TriangleMesh input_mesh;
|
||||
};
|
||||
|
||||
const constexpr float CLOSING_RADIUS = 0.005f;
|
||||
|
||||
void check_support_tree_integrity(const sla::SupportTreeBuilder &stree,
|
||||
const sla::SupportTreeConfig &cfg);
|
||||
|
||||
void test_supports(const std::string &obj_filename,
|
||||
const sla::SupportTreeConfig &supportcfg,
|
||||
const sla::HollowingConfig &hollowingcfg,
|
||||
const sla::DrainHoles &drainholes,
|
||||
SupportByproducts &out);
|
||||
|
||||
inline void test_supports(const std::string &obj_filename,
|
||||
const sla::SupportTreeConfig &supportcfg,
|
||||
SupportByproducts &out)
|
||||
{
|
||||
sla::HollowingConfig hcfg;
|
||||
hcfg.enabled = false;
|
||||
test_supports(obj_filename, supportcfg, hcfg, {}, out);
|
||||
}
|
||||
|
||||
inline void test_supports(const std::string &obj_filename,
|
||||
const sla::SupportTreeConfig &supportcfg = {})
|
||||
{
|
||||
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,
|
||||
const sla::SupportTreeConfig &input_supportcfg,
|
||||
const sla::HollowingConfig &hollowingcfg,
|
||||
const sla::DrainHoles &drainholes);
|
||||
|
||||
inline void test_support_model_collision(
|
||||
const std::string &obj_filename,
|
||||
const sla::SupportTreeConfig &input_supportcfg = {})
|
||||
{
|
||||
sla::HollowingConfig hcfg;
|
||||
hcfg.enabled = false;
|
||||
test_support_model_collision(obj_filename, input_supportcfg, hcfg, {});
|
||||
}
|
||||
|
||||
// Test pair hash for 'nums' random number pairs.
|
||||
template <class I, class II> void test_pairhash()
|
||||
{
|
||||
const constexpr size_t nums = 1000;
|
||||
I A[nums] = {0}, B[nums] = {0};
|
||||
std::unordered_set<I> CH;
|
||||
std::unordered_map<II, std::pair<I, I>> ints;
|
||||
|
||||
std::random_device rd;
|
||||
std::mt19937 gen(rd());
|
||||
|
||||
const I Ibits = int(sizeof(I) * CHAR_BIT);
|
||||
const II IIbits = int(sizeof(II) * CHAR_BIT);
|
||||
|
||||
int bits = IIbits / 2 < Ibits ? Ibits / 2 : Ibits;
|
||||
if (std::is_signed<I>::value) bits -= 1;
|
||||
const I Imin = 0;
|
||||
const I Imax = I(std::pow(2., bits) - 1);
|
||||
|
||||
std::uniform_int_distribution<I> dis(Imin, Imax);
|
||||
|
||||
for (size_t i = 0; i < nums;) {
|
||||
I a = dis(gen);
|
||||
if (CH.find(a) == CH.end()) { CH.insert(a); A[i] = a; ++i; }
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < nums;) {
|
||||
I b = dis(gen);
|
||||
if (CH.find(b) == CH.end()) { CH.insert(b); B[i] = b; ++i; }
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < nums; ++i) {
|
||||
I a = A[i], b = B[i];
|
||||
|
||||
REQUIRE(a != b);
|
||||
|
||||
II hash_ab = sla::pairhash<I, II>(a, b);
|
||||
II hash_ba = sla::pairhash<I, II>(b, a);
|
||||
REQUIRE(hash_ab == hash_ba);
|
||||
|
||||
auto it = ints.find(hash_ab);
|
||||
|
||||
if (it != ints.end()) {
|
||||
REQUIRE((
|
||||
(it->second.first == a && it->second.second == b) ||
|
||||
(it->second.first == b && it->second.second == a)
|
||||
));
|
||||
} else
|
||||
ints[hash_ab] = std::make_pair(a, b);
|
||||
}
|
||||
}
|
||||
|
||||
// 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; }
|
||||
|
||||
void check_raster_transformations(sla::RasterBase::Orientation o,
|
||||
sla::RasterBase::TMirroring mirroring);
|
||||
|
||||
ExPolygon square_with_hole(double v);
|
||||
|
||||
inline double pixel_area(TPixel px, const sla::RasterBase::PixelDim &pxdim)
|
||||
{
|
||||
return (pxdim.h_mm * pxdim.w_mm) * px * 1. / (FullWhite - FullBlack);
|
||||
}
|
||||
|
||||
double raster_white_area(const sla::RasterGrayscaleAA &raster);
|
||||
long raster_pxsum(const sla::RasterGrayscaleAA &raster);
|
||||
|
||||
double predict_error(const ExPolygon &p, const sla::RasterBase::PixelDim &pd);
|
||||
|
||||
sla::SupportPoints calc_support_pts(
|
||||
const TriangleMesh & mesh,
|
||||
const sla::SupportPointGenerator::Config &cfg = {});
|
||||
|
||||
#endif // SLA_TEST_UTILS_HPP
|
||||
Reference in New Issue
Block a user