2019-10-02 12:55:02 +00:00
|
|
|
#include <unordered_set>
|
|
|
|
#include <unordered_map>
|
|
|
|
#include <random>
|
2021-03-19 09:01:50 +00:00
|
|
|
#include <numeric>
|
2020-12-10 07:40:08 +00:00
|
|
|
#include <cstdint>
|
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
|
|
|
|
2021-05-17 18:25:59 +00:00
|
|
|
#include <libslic3r/TriangleMeshSlicer.hpp>
|
2020-07-16 09:49:30 +00:00
|
|
|
#include <libslic3r/SLA/SupportTreeMesher.hpp>
|
2022-05-25 13:12:22 +00:00
|
|
|
#include <libslic3r/BranchingTree/PointCloud.hpp>
|
2020-07-16 09:49:30 +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");
|
|
|
|
|
2022-05-11 10:08:32 +00:00
|
|
|
AABBMesh emesh{mesh};
|
2020-01-14 09:41:42 +00:00
|
|
|
|
2020-06-25 11:58:51 +00:00
|
|
|
sla::SupportTreeConfig supportcfg;
|
2020-01-14 09:41:42 +00:00
|
|
|
sla::SupportPointGenerator::Config autogencfg;
|
|
|
|
autogencfg.head_diameter = float(2 * supportcfg.head_front_radius_mm);
|
|
|
|
sla::SupportPointGenerator point_gen{emesh, autogencfg, [] {}, [](int) {}};
|
2021-05-17 18:25:59 +00:00
|
|
|
|
2020-01-14 09:41:42 +00:00
|
|
|
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);
|
2021-05-18 13:05:23 +00:00
|
|
|
std::vector<ExPolygons> slices = slice_mesh_ex(mesh.its, slicegrid, CLOSING_RADIUS);
|
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){
|
2020-12-10 07:40:08 +00:00
|
|
|
int64_t chksum = 0;
|
2020-01-14 09:41:42 +00:00
|
|
|
for (auto &pt : pts) {
|
|
|
|
auto p = scaled(pt.pos);
|
|
|
|
chksum += p.x() + p.y() + p.z();
|
|
|
|
}
|
|
|
|
|
|
|
|
return chksum;
|
|
|
|
};
|
|
|
|
|
2020-12-10 07:40:08 +00:00
|
|
|
int64_t checksum = get_chksum(point_gen.output());
|
2020-01-14 09:41:42 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2022-05-11 10:08:32 +00:00
|
|
|
TEST_CASE("DefaultSupports::ElevatedSupportGeometryIsValid", "[SLASupportGeneration]") {
|
2020-06-25 11:58:51 +00:00
|
|
|
sla::SupportTreeConfig supportcfg;
|
2020-09-21 06:45:28 +00:00
|
|
|
supportcfg.object_elevation_mm = 10.;
|
2019-11-04 13:33:29 +00:00
|
|
|
|
2020-09-21 06:45:28 +00:00
|
|
|
for (auto fname : SUPPORT_TEST_MODELS) test_supports(fname, supportcfg);
|
2019-09-24 13:24:47 +00:00
|
|
|
}
|
|
|
|
|
2022-05-11 10:08:32 +00:00
|
|
|
TEST_CASE("DefaultSupports::FloorSupportGeometryIsValid", "[SLASupportGeneration]") {
|
2020-06-25 11:58:51 +00:00
|
|
|
sla::SupportTreeConfig supportcfg;
|
2019-09-24 13:24:47 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2022-05-11 10:08:32 +00:00
|
|
|
TEST_CASE("DefaultSupports::ElevatedSupportsDoNotPierceModel", "[SLASupportGeneration]") {
|
2020-06-25 11:58:51 +00:00
|
|
|
sla::SupportTreeConfig supportcfg;
|
2022-05-11 10:08:32 +00:00
|
|
|
supportcfg.object_elevation_mm = 10.;
|
|
|
|
|
2019-09-24 13:24:47 +00:00
|
|
|
for (auto fname : SUPPORT_TEST_MODELS)
|
|
|
|
test_support_model_collision(fname, supportcfg);
|
|
|
|
}
|
|
|
|
|
2022-05-11 10:08:32 +00:00
|
|
|
TEST_CASE("DefaultSupports::FloorSupportsDoNotPierceModel", "[SLASupportGeneration]") {
|
2019-11-04 13:33:29 +00:00
|
|
|
|
2020-06-25 11:58:51 +00:00
|
|
|
sla::SupportTreeConfig supportcfg;
|
2019-10-03 14:15:11 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2022-05-09 13:32:57 +00:00
|
|
|
//TEST_CASE("BranchingSupports::ElevatedSupportGeometryIsValid", "[SLASupportGeneration][Branching]") {
|
2022-05-11 10:08:32 +00:00
|
|
|
// sla::SupportTreeConfig supportcfg;
|
|
|
|
// supportcfg.object_elevation_mm = 10.;
|
2022-05-09 13:32:57 +00:00
|
|
|
// supportcfg.tree_type = sla::SupportTreeType::Branching;
|
2022-05-11 10:08:32 +00:00
|
|
|
|
|
|
|
// for (auto fname : SUPPORT_TEST_MODELS) test_supports(fname, supportcfg);
|
|
|
|
//}
|
|
|
|
|
2022-05-09 13:32:57 +00:00
|
|
|
//TEST_CASE("BranchingSupports::FloorSupportGeometryIsValid", "[SLASupportGeneration][Branching]") {
|
2022-05-11 10:08:32 +00:00
|
|
|
// sla::SupportTreeConfig supportcfg;
|
|
|
|
// supportcfg.object_elevation_mm = 0;
|
2022-05-09 13:32:57 +00:00
|
|
|
// supportcfg.tree_type = sla::SupportTreeType::Branching;
|
2022-05-11 10:08:32 +00:00
|
|
|
|
|
|
|
// for (auto &fname: SUPPORT_TEST_MODELS) test_supports(fname, supportcfg);
|
|
|
|
//}
|
|
|
|
|
2022-06-03 15:01:30 +00:00
|
|
|
bool is_outside_support_cone(const Vec3f &supp, const Vec3f &pt, float angle)
|
|
|
|
{
|
|
|
|
Vec3d D = (pt - supp).cast<double>();
|
|
|
|
double dot_sq = -D.z() * std::abs(-D.z());
|
|
|
|
|
|
|
|
return dot_sq <
|
|
|
|
D.squaredNorm() * std::cos(angle) * std::abs(std::cos(angle));
|
|
|
|
}
|
|
|
|
|
2022-05-25 13:12:22 +00:00
|
|
|
TEST_CASE("BranchingSupports::MergePointFinder", "[SLASupportGeneration][Branching]") {
|
|
|
|
SECTION("Identical points have the same merge point") {
|
|
|
|
Vec3f a{0.f, 0.f, 0.f}, b = a;
|
2022-06-20 14:52:59 +00:00
|
|
|
auto slope = float(PI / 4.);
|
2022-05-25 13:12:22 +00:00
|
|
|
|
|
|
|
auto mergept = branchingtree::find_merge_pt(a, b, slope);
|
|
|
|
|
|
|
|
REQUIRE(bool(mergept));
|
|
|
|
REQUIRE((*mergept - b).norm() < EPSILON);
|
|
|
|
REQUIRE((*mergept - a).norm() < EPSILON);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ^ Z
|
|
|
|
// | a *
|
|
|
|
// |
|
|
|
|
// | b * <= mergept
|
|
|
|
SECTION("Points at different heights have the lower point as mergepoint") {
|
|
|
|
Vec3f a{0.f, 0.f, 0.f}, b = {0.f, 0.f, -1.f};
|
2022-06-20 14:52:59 +00:00
|
|
|
auto slope = float(PI / 4.);
|
2022-05-25 13:12:22 +00:00
|
|
|
|
|
|
|
auto mergept = branchingtree::find_merge_pt(a, b, slope);
|
|
|
|
|
|
|
|
REQUIRE(bool(mergept));
|
2022-06-29 10:35:43 +00:00
|
|
|
REQUIRE((*mergept - b).squaredNorm() < 2 * EPSILON);
|
2022-05-25 13:12:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// -|---------> X
|
|
|
|
// a b
|
|
|
|
// * *
|
|
|
|
// * <= mergept
|
|
|
|
SECTION("Points at different X have mergept in the middle at lower Z") {
|
|
|
|
Vec3f a{0.f, 0.f, 0.f}, b = {1.f, 0.f, 0.f};
|
2022-06-20 14:52:59 +00:00
|
|
|
auto slope = float(PI / 4.);
|
2022-05-25 13:12:22 +00:00
|
|
|
|
|
|
|
auto mergept = branchingtree::find_merge_pt(a, b, slope);
|
|
|
|
|
|
|
|
REQUIRE(bool(mergept));
|
|
|
|
|
|
|
|
// Distance of mergept should be equal from both input points
|
|
|
|
float D = std::abs((*mergept - b).squaredNorm() - (*mergept - a).squaredNorm());
|
|
|
|
|
|
|
|
REQUIRE(D < EPSILON);
|
2022-06-03 15:01:30 +00:00
|
|
|
REQUIRE(!is_outside_support_cone(a, *mergept, slope));
|
|
|
|
REQUIRE(!is_outside_support_cone(b, *mergept, slope));
|
2022-05-25 13:12:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// -|---------> Y
|
|
|
|
// a b
|
|
|
|
// * *
|
|
|
|
// * <= mergept
|
|
|
|
SECTION("Points at different Y have mergept in the middle at lower Z") {
|
|
|
|
Vec3f a{0.f, 0.f, 0.f}, b = {0.f, 1.f, 0.f};
|
2022-06-20 14:52:59 +00:00
|
|
|
auto slope = float(PI / 4.);
|
2022-05-25 13:12:22 +00:00
|
|
|
|
|
|
|
auto mergept = branchingtree::find_merge_pt(a, b, slope);
|
|
|
|
|
|
|
|
REQUIRE(bool(mergept));
|
|
|
|
|
|
|
|
// Distance of mergept should be equal from both input points
|
|
|
|
float D = std::abs((*mergept - b).squaredNorm() - (*mergept - a).squaredNorm());
|
|
|
|
|
|
|
|
REQUIRE(D < EPSILON);
|
2022-06-03 15:01:30 +00:00
|
|
|
REQUIRE(!is_outside_support_cone(a, *mergept, slope));
|
|
|
|
REQUIRE(!is_outside_support_cone(b, *mergept, slope));
|
2022-05-25 13:12:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("Points separated by less than critical angle have the lower point as mergept") {
|
2022-06-29 10:35:43 +00:00
|
|
|
Vec3f a{-1.f, -1.f, -1.f}, b = {-1.5f, -1.5f, -2.f};
|
2022-06-20 14:52:59 +00:00
|
|
|
auto slope = float(PI / 4.);
|
2022-05-25 13:12:22 +00:00
|
|
|
|
|
|
|
auto mergept = branchingtree::find_merge_pt(a, b, slope);
|
|
|
|
|
|
|
|
REQUIRE(bool(mergept));
|
2022-06-29 10:35:43 +00:00
|
|
|
REQUIRE((*mergept - b).norm() < 2 * EPSILON);
|
2022-05-25 13:12:22 +00:00
|
|
|
}
|
2022-06-29 13:48:45 +00:00
|
|
|
|
|
|
|
// -|----------------------------> Y
|
|
|
|
// a b
|
|
|
|
// * * <= mergept *
|
|
|
|
//
|
|
|
|
SECTION("Points at same height have mergepoint in the middle if critical angle is zero ") {
|
|
|
|
Vec3f a{-1.f, -1.f, -1.f}, b = {-1.5f, -1.5f, -1.f};
|
|
|
|
auto slope = EPSILON;
|
|
|
|
|
|
|
|
auto mergept = branchingtree::find_merge_pt(a, b, slope);
|
|
|
|
|
|
|
|
REQUIRE(bool(mergept));
|
|
|
|
Vec3f middle = (b + a) / 2.;
|
|
|
|
REQUIRE((*mergept - middle).norm() < 4 * EPSILON);
|
|
|
|
}
|
2022-05-25 13:12:22 +00:00
|
|
|
}
|
|
|
|
|
2022-05-09 13:32:57 +00:00
|
|
|
TEST_CASE("BranchingSupports::ElevatedSupportsDoNotPierceModel", "[SLASupportGeneration][Branching]") {
|
2022-05-11 10:08:32 +00:00
|
|
|
|
|
|
|
sla::SupportTreeConfig supportcfg;
|
|
|
|
supportcfg.object_elevation_mm = 10.;
|
2022-05-09 13:32:57 +00:00
|
|
|
supportcfg.tree_type = sla::SupportTreeType::Branching;
|
2022-05-11 10:08:32 +00:00
|
|
|
|
|
|
|
for (auto fname : SUPPORT_TEST_MODELS)
|
|
|
|
test_support_model_collision(fname, supportcfg);
|
|
|
|
}
|
|
|
|
|
2022-05-09 13:32:57 +00:00
|
|
|
TEST_CASE("BranchingSupports::FloorSupportsDoNotPierceModel", "[SLASupportGeneration][Branching]") {
|
2022-05-11 10:08:32 +00:00
|
|
|
|
|
|
|
sla::SupportTreeConfig supportcfg;
|
|
|
|
supportcfg.object_elevation_mm = 0;
|
2022-05-09 13:32:57 +00:00
|
|
|
supportcfg.tree_type = sla::SupportTreeType::Branching;
|
2022-05-11 10:08:32 +00:00
|
|
|
|
|
|
|
for (auto fname : SUPPORT_TEST_MODELS)
|
|
|
|
test_support_model_collision(fname, supportcfg);
|
|
|
|
}
|
|
|
|
|
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
|
2022-01-12 12:54:18 +00:00
|
|
|
sla::Resolution res{2560, 1440};
|
|
|
|
sla::PixelDim pixdim{120. / res.width_px, 68. / res.height_px};
|
2019-11-04 13:33:29 +00:00
|
|
|
|
2020-04-13 10:31:37 +00:00
|
|
|
sla::RasterGrayscaleAAGammaPower raster(res, pixdim, {}, 1.);
|
2019-10-04 12:47:02 +00:00
|
|
|
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]") {
|
2020-04-13 10:31:37 +00:00
|
|
|
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};
|
2019-11-04 13:33:29 +00:00
|
|
|
|
2019-10-01 11:27:58 +00:00
|
|
|
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.;
|
2022-01-12 12:54:18 +00:00
|
|
|
sla::Resolution res{2560, 1440};
|
|
|
|
sla::PixelDim pixdim{disp_w / res.width_px, disp_h / res.height_px};
|
2019-11-04 13:33:29 +00:00
|
|
|
|
2020-04-13 10:31:37 +00:00
|
|
|
double gamma = 1.;
|
|
|
|
sla::RasterGrayscaleAAGammaPower raster(res, pixdim, {}, gamma);
|
2019-10-01 11:27:58 +00:00
|
|
|
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));
|
2020-04-13 10:31:37 +00:00
|
|
|
|
|
|
|
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);
|
2019-09-24 13:24:47 +00:00
|
|
|
}
|
2019-11-04 13:33:29 +00:00
|
|
|
|
2020-07-16 09:49:30 +00:00
|
|
|
|
|
|
|
TEST_CASE("halfcone test", "[halfcone]") {
|
|
|
|
sla::DiffBridge br{Vec3d{1., 1., 1.}, Vec3d{10., 10., 10.}, 0.25, 0.5};
|
|
|
|
|
2021-05-21 12:08:05 +00:00
|
|
|
indexed_triangle_set m = sla::get_mesh(br, 45);
|
2020-07-16 09:49:30 +00:00
|
|
|
|
2021-05-21 12:08:05 +00:00
|
|
|
its_merge_vertices(m);
|
|
|
|
its_write_obj(m, "Halfcone.obj");
|
2020-07-16 09:49:30 +00:00
|
|
|
}
|
2020-08-31 16:53:44 +00:00
|
|
|
|
|
|
|
TEST_CASE("Test concurrency")
|
|
|
|
{
|
|
|
|
std::vector<double> vals = grid(0., 100., 10.);
|
|
|
|
|
|
|
|
double ref = std::accumulate(vals.begin(), vals.end(), 0.);
|
|
|
|
|
2021-03-18 08:38:21 +00:00
|
|
|
double s = execution::accumulate(ex_tbb, vals.begin(), vals.end(), 0.);
|
2020-08-31 16:53:44 +00:00
|
|
|
|
|
|
|
REQUIRE(s == Approx(ref));
|
|
|
|
}
|