Merge branch 'et_world_coordinates' into fs_emboss

# Conflicts:
#	src/libslic3r/CMakeLists.txt
#	src/libslic3r/Format/3mf.cpp
#	src/libslic3r/Model.hpp
#	src/libslic3r/Technologies.hpp
#	src/slic3r/GUI/GLCanvas3D.cpp
#	src/slic3r/GUI/GUI_App.cpp
#	src/slic3r/GUI/Gizmos/GLGizmoBase.cpp
#	src/slic3r/GUI/Gizmos/GLGizmoBase.hpp
#	src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp
#	src/slic3r/GUI/Selection.cpp
#	src/slic3r/GUI/Selection.hpp
This commit is contained in:
Filip Sykala - NTB T15p 2022-07-20 13:02:07 +02:00
commit 79a7f588b9
300 changed files with 80473 additions and 59230 deletions

View file

@ -4,6 +4,7 @@ add_executable(${_TEST_NAME}_tests
test_avoid_crossing_perimeters.cpp
test_bridges.cpp
test_cooling.cpp
test_clipper.cpp
test_custom_gcode.cpp
test_data.cpp
test_data.hpp

View file

@ -0,0 +1,43 @@
#include <catch2/catch.hpp>
#include "test_data.hpp"
#include "clipper/clipper_z.hpp"
using namespace Slic3r;
// Test case for an issue with duplicity vertices (same XY coordinates but differ in Z coordinates) in Clipper 6.2.9,
// (related to https://sourceforge.net/p/polyclipping/bugs/160/) that was fixed in Clipper 6.4.2.
SCENARIO("Clipper Z", "[ClipperZ]")
{
ClipperLib_Z::Path subject;
subject.emplace_back(-2000, -1000, 10);
subject.emplace_back(-2000, 1000, 10);
subject.emplace_back( 2000, 1000, 10);
subject.emplace_back( 2000, -1000, 10);
ClipperLib_Z::Path clip;
clip.emplace_back(-1000, -2000, -5);
clip.emplace_back(-1000, 2000, -5);
clip.emplace_back( 1000, 2000, -5);
clip.emplace_back( 1000, -2000, -5);
ClipperLib_Z::Clipper clipper;
clipper.ZFillFunction([](const ClipperLib_Z::IntPoint &e1bot, const ClipperLib_Z::IntPoint &e1top, const ClipperLib_Z::IntPoint &e2bot,
const ClipperLib_Z::IntPoint &e2top, ClipperLib_Z::IntPoint &pt) {
pt.z() = 1;
});
clipper.AddPath(subject, ClipperLib_Z::ptSubject, false);
clipper.AddPath(clip, ClipperLib_Z::ptClip, true);
ClipperLib_Z::PolyTree polytree;
ClipperLib_Z::Paths paths;
clipper.Execute(ClipperLib_Z::ctIntersection, polytree, ClipperLib_Z::pftNonZero, ClipperLib_Z::pftNonZero);
ClipperLib_Z::PolyTreeToPaths(polytree, paths);
REQUIRE(paths.size() == 1);
REQUIRE(paths.front().size() == 2);
for (const ClipperLib_Z::IntPoint &pt : paths.front())
REQUIRE(pt.z() == 1);
}

View file

@ -134,6 +134,7 @@ TEST_CASE("Fill: Pattern Path Length", "[Fill]") {
for (auto density : { 0.4, 1.0 }) {
fill_params.density = density;
filler->spacing = flow.spacing();
REQUIRE(!fill_params.use_arachne); // Make this test fail when Arachne is used because this test is not ready for it.
for (auto angle : { 0.0, 45.0}) {
surface.expolygon.rotate(angle, Point(0,0));
Polylines paths = filler->fill_surface(&surface, fill_params);
@ -266,7 +267,15 @@ SCENARIO("Infill only where needed", "[Fill]")
});
auto test = [&config]() -> double {
std::string gcode = Slic3r::Test::slice({ Slic3r::Test::TestMesh::pyramid }, config);
TriangleMesh pyramid = Test::mesh(Slic3r::Test::TestMesh::pyramid);
// Arachne doesn't use "Detect thin walls," and because of this, it filters out tiny infill areas differently.
// So, for Arachne, we cut the pyramid model to achieve similar results.
if (config.opt_enum<PerimeterGeneratorType>("perimeter_generator") == Slic3r::PerimeterGeneratorType::Arachne) {
indexed_triangle_set lower{};
cut_mesh(pyramid.its, 35, nullptr, &lower);
pyramid = TriangleMesh(lower);
}
std::string gcode = Slic3r::Test::slice({ pyramid }, config);
THEN("gcode not empty") {
REQUIRE(! gcode.empty());
}
@ -541,8 +550,10 @@ bool test_if_solid_surface_filled(const ExPolygon& expolygon, double flow_spacin
fill_params.density = float(density);
fill_params.dont_adjust = false;
Surface surface(stBottom, expolygon);
Slic3r::Polylines paths = filler->fill_surface(&surface, fill_params);
Surface surface(stBottom, expolygon);
if (fill_params.use_arachne) // Make this test fail when Arachne is used because this test is not ready for it.
return false;
Slic3r::Polylines paths = filler->fill_surface(&surface, fill_params);
// check whether any part was left uncovered
Polygons grown_paths;

View file

@ -55,7 +55,11 @@ SCENARIO("Perimeter nesting", "[Perimeters]")
false, // spiral_vase
// output:
&loops, &gap_fill, &fill_surfaces);
perimeter_generator.process();
// FIXME Lukas H.: Disable this test for Arachne because it is failing and needs more investigation.
// if (config.perimeter_generator == PerimeterGeneratorType::Arachne)
// perimeter_generator.process_arachne();
// else
perimeter_generator.process_classic();
THEN("expected number of collections") {
REQUIRE(loops.entities.size() == data.expolygons.size());
@ -263,11 +267,23 @@ SCENARIO("Perimeters", "[Perimeters]")
THEN("all perimeters extruded ccw") {
REQUIRE(! has_cw_loops);
}
THEN("move inwards after completing external loop") {
REQUIRE(! has_outwards_move);
}
THEN("loops start on concave point if any") {
REQUIRE(! starts_on_convex_point);
// FIXME Lukas H.: Arachne is printing external loops before hole loops in this test case.
if (config.opt_enum<PerimeterGeneratorType>("perimeter_generator") == Slic3r::PerimeterGeneratorType::Arachne) {
THEN("move outwards after completing external loop") {
// REQUIRE(! has_outwards_move);
}
// FIXME Lukas H.: Disable this test for Arachne because it is failing and needs more investigation.
THEN("loops start on concave point if any") {
// REQUIRE(! starts_on_convex_point);
}
} else {
THEN("move inwards after completing external loop") {
REQUIRE(! has_outwards_move);
}
THEN("loops start on concave point if any") {
REQUIRE(! starts_on_convex_point);
}
}
};

View file

@ -1,6 +1,8 @@
get_filename_component(_TEST_NAME ${CMAKE_CURRENT_LIST_DIR} NAME)
add_executable(${_TEST_NAME}_tests ${_TEST_NAME}_tests_main.cpp printer_parts.cpp printer_parts.hpp)
target_link_libraries(${_TEST_NAME}_tests test_common libnest2d )
# mold linker for successful linking needs also to link TBB library and link it before libslic3r.
target_link_libraries(${_TEST_NAME}_tests test_common TBB::tbb libnest2d )
set_property(TARGET ${_TEST_NAME}_tests PROPERTY FOLDER "tests")
# catch_discover_tests(${_TEST_NAME}_tests TEST_PREFIX "${_TEST_NAME}: ")

View file

@ -7,12 +7,42 @@
using namespace Slic3r;
struct PointGridTracer {
TEST_CASE("Testing basic invariants of AStar", "[AStar]") {
struct DummyTracer {
using Node = int;
int goal = 0;
float distance(int a, int b) const { return a - b; }
float goal_heuristic(int n) const { return n == goal ? -1.f : 0.f; }
size_t unique_id(int n) const { return n; }
void foreach_reachable(int, std::function<bool(int)>) const {}
};
std::vector<int> out;
SECTION("Output is empty when source is also the destination") {
bool found = astar::search_route(DummyTracer{}, 0, std::back_inserter(out));
REQUIRE(out.empty());
REQUIRE(found);
}
SECTION("Return false when there is no route to destination") {
bool found = astar::search_route(DummyTracer{}, 1, std::back_inserter(out));
REQUIRE(!found);
REQUIRE(out.empty());
}
}
struct PointGridTracer3D {
using Node = size_t;
const PointGrid<float> &grid;
size_t final;
PointGridTracer(const PointGrid<float> &g, size_t goal) :
PointGridTracer3D(const PointGrid<float> &g, size_t goal) :
grid{g}, final{goal} {}
template<class Fn>
@ -49,14 +79,328 @@ struct PointGridTracer {
size_t unique_id(size_t n) const { return n; }
};
template<class Node, class Cmp = std::less<Node>>
bool has_duplicates(const std::vector<Node> &res, Cmp cmp = {})
{
auto cpy = res;
std::sort(cpy.begin(), cpy.end(), cmp);
auto it = std::unique(cpy.begin(), cpy.end());
return it != cpy.end();
}
TEST_CASE("astar algorithm test over 3D point grid", "[AStar]") {
auto vol = BoundingBox3Base<Vec3f>{{0.f, 0.f, 0.f}, {1.f, 1.f, 1.f}};
auto pgrid = point_grid(ex_seq, vol, {0.1f, 0.1f, 0.1f});
PointGridTracer pgt{pgrid, pgrid.point_count() - 1};
size_t target = pgrid.point_count() - 1;
PointGridTracer3D pgt{pgrid, target};
std::vector<size_t> out;
bool found = astar::search_route(pgt, size_t(0), std::back_inserter(out));
bool found = astar::search_route(pgt, 0, std::back_inserter(out));
REQUIRE(found);
REQUIRE(!out.empty());
REQUIRE(out.front() == target);
#ifndef NDEBUG
std::cout << "Route taken: ";
for (auto it = out.rbegin(); it != out.rend(); ++it) {
std::cout << "(" << pgrid.get_coord(*it).transpose() << ") ";
}
std::cout << std::endl;
#endif
REQUIRE(!has_duplicates(out)); // No duplicates in output
}
enum CellValue {ON, OFF};
struct CellGridTracer2D_AllDirs {
using Node = Vec2i;
static constexpr auto Cols = size_t(5);
static constexpr auto Rows = size_t(8);
static constexpr size_t GridSize = Cols * Rows;
const std::array<std::array<CellValue, Cols>, Rows> &grid;
Vec2i goal;
CellGridTracer2D_AllDirs(const std::array<std::array<CellValue, Cols>, Rows> &g,
const Vec2i &goal_)
: grid{g}, goal{goal_}
{}
template<class Fn>
void foreach_reachable(const Vec2i &src, Fn &&fn) const
{
auto is_inside = [](const Vec2i& v) { return v.x() >= 0 && v.x() < int(Cols) && v.y() >= 0 && v.y() < int(Rows); };
if (Vec2i crd = src + Vec2i{0, 1}; is_inside(crd) && grid[crd.y()] [crd.x()] == ON) fn(crd);
if (Vec2i crd = src + Vec2i{1, 0}; is_inside(crd) && grid[crd.y()] [crd.x()] == ON) fn(crd);
if (Vec2i crd = src + Vec2i{1, 1}; is_inside(crd) && grid[crd.y()] [crd.x()] == ON) fn(crd);
if (Vec2i crd = src + Vec2i{0, -1}; is_inside(crd) && grid[crd.y()] [crd.x()] == ON) fn(crd);
if (Vec2i crd = src + Vec2i{-1, 0}; is_inside(crd) && grid[crd.y()] [crd.x()] == ON) fn(crd);
if (Vec2i crd = src + Vec2i{-1, -1}; is_inside(crd) && grid[crd.y()] [crd.x()] == ON) fn(crd);
if (Vec2i crd = src + Vec2i{1, -1}; is_inside(crd) && grid[crd.y()] [crd.x()] == ON) fn(crd);
if (Vec2i crd = src + Vec2i{-1, 1}; is_inside(crd) && grid[crd.y()] [crd.x()] == ON) fn(crd);
}
float distance(const Vec2i & a, const Vec2i & b) const { return (a - b).squaredNorm(); }
float goal_heuristic(const Vec2i & n) const { return n == goal ? -1.f : (n - goal).squaredNorm(); }
size_t unique_id(const Vec2i & n) const { return n.y() * Cols + n.x(); }
};
struct CellGridTracer2D_Axis {
using Node = Vec2i;
static constexpr auto Cols = size_t(5);
static constexpr auto Rows = size_t(8);
static constexpr size_t GridSize = Cols * Rows;
const std::array<std::array<CellValue, Cols>, Rows> &grid;
Vec2i goal;
CellGridTracer2D_Axis(
const std::array<std::array<CellValue, Cols>, Rows> &g,
const Vec2i &goal_)
: grid{g}, goal{goal_}
{}
template<class Fn>
void foreach_reachable(const Vec2i &src, Fn &&fn) const
{
auto is_inside = [](const Vec2i& v) { return v.x() >= 0 && v.x() < int(Cols) && v.y() >= 0 && v.y() < int(Rows); };
if (Vec2i crd = src + Vec2i{0, 1}; is_inside(crd) && grid[crd.y()] [crd.x()] == ON) fn(crd);
if (Vec2i crd = src + Vec2i{0, -1}; is_inside(crd) && grid[crd.y()] [crd.x()] == ON) fn(crd);
if (Vec2i crd = src + Vec2i{1, 0}; is_inside(crd) && grid[crd.y()] [crd.x()] == ON) fn(crd);
if (Vec2i crd = src + Vec2i{-1, 0}; is_inside(crd) && grid[crd.y()] [crd.x()] == ON) fn(crd);
}
float distance(const Vec2i & a, const Vec2i & b) const { return (a - b).squaredNorm(); }
float goal_heuristic(const Vec2i &n) const
{
int manhattan_dst = std::abs(n.x() - goal.x()) +
std::abs(n.y() - goal.y());
return n == goal ? -1.f : manhattan_dst;
}
size_t unique_id(const Vec2i & n) const { return n.y() * Cols + n.x(); }
};
using TestClasses = std::tuple< CellGridTracer2D_AllDirs, CellGridTracer2D_Axis >;
TEMPLATE_LIST_TEST_CASE("Astar should avoid simple barrier", "[AStar]", TestClasses) {
std::array<std::array<CellValue, 5>, 8> grid = {{
{ON , ON , ON , ON , ON},
{ON , ON , ON , ON , ON},
{ON , ON , ON , ON , ON},
{ON , ON , ON , ON , ON},
{ON , ON , ON , ON , ON},
{ON , OFF, OFF, OFF, ON},
{ON , ON , ON , ON , ON},
{ON , ON , ON , ON , ON}
}};
Vec2i dst = {2, 0};
TestType cgt{grid, dst};
std::vector<Vec2i> out;
bool found = astar::search_route(cgt, {2, 7}, std::back_inserter(out));
REQUIRE(found);
REQUIRE(!out.empty());
REQUIRE(out.front() == dst);
REQUIRE(!has_duplicates(out, [](const Vec2i &a, const Vec2i &b) {
return a.x() == b.x() ? a.y() < b.y() : a.x() < b.x();
}));
#ifndef NDEBUG
std::cout << "Route taken: ";
for (auto it = out.rbegin(); it != out.rend(); ++it) {
std::cout << "(" << it->transpose() << ") ";
}
std::cout << std::endl;
#endif
}
TEMPLATE_LIST_TEST_CASE("Astar should manage to avoid arbitrary barriers", "[AStar]", TestClasses) {
std::array<std::array<CellValue, 5>, 8> grid = {{
{ON , ON , ON , ON , ON},
{ON , ON , ON , OFF, ON},
{OFF, OFF, ON , OFF, ON},
{ON , ON , ON , OFF, ON},
{ON , OFF, ON , OFF, ON},
{ON , OFF, ON , ON , ON},
{ON , OFF, ON , OFF, ON},
{ON , ON , ON , ON , ON}
}};
Vec2i dst = {0, 0};
TestType cgt{grid, dst};
std::vector<Vec2i> out;
bool found = astar::search_route(cgt, {0, 7}, std::back_inserter(out));
REQUIRE(found);
REQUIRE(!out.empty());
REQUIRE(out.front() == dst);
REQUIRE(!has_duplicates(out, [](const Vec2i &a, const Vec2i &b) {
return a.x() == b.x() ? a.y() < b.y() : a.x() < b.x();
}));
#ifndef NDEBUG
std::cout << "Route taken: ";
for (auto it = out.rbegin(); it != out.rend(); ++it) {
std::cout << "(" << it->transpose() << ") ";
}
std::cout << std::endl;
#endif
}
TEMPLATE_LIST_TEST_CASE("Astar should find the way out of a labyrinth", "[AStar]", TestClasses) {
std::array<std::array<CellValue, 5>, 8> grid = {{
{ON , ON , ON , ON , ON },
{ON , OFF, OFF, OFF, OFF},
{ON , ON , ON , ON , ON },
{OFF, OFF, OFF, OFF, ON },
{ON , ON , ON , ON , ON },
{ON , OFF, OFF, OFF, OFF},
{ON , ON , ON , ON , ON },
{OFF, OFF, OFF, OFF, ON }
}};
Vec2i dst = {4, 0};
TestType cgt{grid, dst};
std::vector<Vec2i> out;
bool found = astar::search_route(cgt, {4, 7}, std::back_inserter(out));
REQUIRE(found);
REQUIRE(!out.empty());
REQUIRE(out.front() == dst);
REQUIRE(!has_duplicates(out, [](const Vec2i &a, const Vec2i &b) {
return a.x() == b.x() ? a.y() < b.y() : a.x() < b.x();
}));
#ifndef NDEBUG
std::cout << "Route taken: ";
for (auto it = out.rbegin(); it != out.rend(); ++it) {
std::cout << "(" << it->transpose() << ") ";
}
std::cout << std::endl;
#endif
}
TEST_CASE("Zero heuristic function should result in dijsktra's algo", "[AStar]")
{
struct GraphTracer {
using Node = size_t;
using QNode = astar::QNode<GraphTracer>;
struct Edge
{
size_t to_id = size_t(-1);
float cost = 0.f;
bool operator <(const Edge &e) const { return to_id < e.to_id; }
};
struct ENode: public QNode {
std::vector<Edge> edges;
ENode(size_t node_id, std::initializer_list<Edge> edgelist)
: QNode{node_id}, edges(edgelist)
{}
ENode &operator=(const QNode &q)
{
assert(node == q.node);
g = q.g;
h = q.h;
parent = q.parent;
queue_id = q.queue_id;
return *this;
}
};
// Example graph from
// https://www.geeksforgeeks.org/dijkstras-shortest-path-algorithm-greedy-algo-7/?ref=lbp
std::vector<ENode> nodes = {
{0, {{1, 4.f}, {7, 8.f}}},
{1, {{0, 4.f}, {2, 8.f}, {7, 11.f}}},
{2, {{1, 8.f}, {3, 7.f}, {5, 4.f}, {8, 2.f}}},
{3, {{2, 7.f}, {4, 9.f}, {5, 14.f}}},
{4, {{3, 9.f}, {5, 10.f}}},
{5, {{2, 4.f}, {3, 14.f}, {4, 10.f}, {6, 2.f}}},
{6, {{5, 2.f}, {7, 1.f}, {8, 6.f}}},
{7, {{0, 8.f}, {1, 11.f}, {6, 1.f}, {8, 7.f}}},
{8, {{2, 2.f}, {6, 6.f}, {7, 7.f}}}
};
float distance(size_t a, size_t b) const {
float ret = std::numeric_limits<float>::infinity();
if (a < nodes.size()) {
auto it = std::lower_bound(nodes[a].edges.begin(),
nodes[a].edges.end(),
Edge{b, 0.f});
if (it != nodes[a].edges.end()) {
ret = it->cost;
}
}
return ret;
}
float goal_heuristic(size_t) const { return 0.f; }
size_t unique_id(size_t n) const { return n; }
void foreach_reachable(size_t n, std::function<bool(int)> fn) const
{
if (n < nodes.size()) {
for (const Edge &e : nodes[n].edges)
fn(e.to_id);
}
}
} graph;
std::vector<size_t> out;
// 'graph.nodes' is able to be a node cache (it simulates an associative container)
bool found = astar::search_route(graph, size_t(0), std::back_inserter(out), graph.nodes);
// But should not crash or loop infinitely.
REQUIRE(!found);
// Without a destination, there is no output. But the algorithm should halt.
REQUIRE(out.empty());
// Source node should have it's parent unset
REQUIRE(graph.nodes[0].parent == astar::Unassigned);
// All other nodes should have their parents set
for (size_t i = 1; i < graph.nodes.size(); ++i)
REQUIRE(graph.nodes[i].parent != astar::Unassigned);
std::array<float, 9> ref_distances = {0.f, 4.f, 12.f, 19.f, 21.f,
11.f, 9.f, 8.f, 14.f};
// Try to trace each node back to the source node. Each of them should
// arrive to the source within less hops than the full number of nodes.
for (size_t i = 0, k = 0; i < graph.nodes.size(); ++i, k = 0) {
GraphTracer::QNode *q = &graph.nodes[i];
REQUIRE(q->g == Approx(ref_distances[i]));
while (k++ < graph.nodes.size() && q->parent != astar::Unassigned)
q = &graph.nodes[q->parent];
REQUIRE(q->parent == astar::Unassigned);
}
}

View file

@ -31,11 +31,6 @@ static double volume(const BoundingBox3Base<Vec3f> &box)
return sz.x() * sz.y() * sz.z();
}
static double volume(const Eigen::AlignedBox<float, 3> &box)
{
return box.volume();
}
TEST_CASE("Test kdtree query for a Box", "[KDTreeIndirect]")
{
auto vol = BoundingBox3Base<Vec3f>{{0.f, 0.f, 0.f}, {10.f, 10.f, 10.f}};

View file

@ -4,6 +4,8 @@
#include "libslic3r/MutablePriorityQueue.hpp"
using namespace Slic3r;
// based on https://raw.githubusercontent.com/rollbear/prio_queue/master/self_test.cpp
// original source Copyright Björn Fahller 2015, Boost Software License, Version 1.0, http://www.boost.org/LICENSE_1_0.txt

View file

@ -5,7 +5,9 @@ add_executable(${_TEST_NAME}_tests ${_TEST_NAME}_tests_main.cpp
sla_supptgen_tests.cpp
sla_raycast_tests.cpp
sla_archive_readwrite_tests.cpp)
target_link_libraries(${_TEST_NAME}_tests test_common libslic3r)
# mold linker for successful linking needs also to link TBB library and link it before libslic3r.
target_link_libraries(${_TEST_NAME}_tests test_common TBB::tbb libslic3r)
set_property(TARGET ${_TEST_NAME}_tests PROPERTY FOLDER "tests")
if (WIN32)

View file

@ -8,7 +8,6 @@
#include <libslic3r/TriangleMeshSlicer.hpp>
#include <libslic3r/SLA/SupportTreeMesher.hpp>
#include <libslic3r/SLA/Concurrency.hpp>
namespace {
@ -43,7 +42,7 @@ TEST_CASE("Support point generator should be deterministic if seeded",
"[SLASupportGeneration], [SLAPointGen]") {
TriangleMesh mesh = load_model("A_upsidedown.obj");
sla::IndexedMesh emesh{mesh};
AABBMesh emesh{mesh};
sla::SupportTreeConfig supportcfg;
sla::SupportPointGenerator::Config autogencfg;
@ -126,33 +125,69 @@ TEST_CASE("WingedPadAroundObjectIsValid", "[SLASupportGeneration]") {
for (auto &fname : AROUND_PAD_TEST_OBJECTS) test_pad(fname, padcfg);
}
TEST_CASE("ElevatedSupportGeometryIsValid", "[SLASupportGeneration]") {
TEST_CASE("DefaultSupports::ElevatedSupportGeometryIsValid", "[SLASupportGeneration]") {
sla::SupportTreeConfig supportcfg;
supportcfg.object_elevation_mm = 10.;
for (auto fname : SUPPORT_TEST_MODELS) test_supports(fname, supportcfg);
}
TEST_CASE("FloorSupportGeometryIsValid", "[SLASupportGeneration]") {
TEST_CASE("DefaultSupports::FloorSupportGeometryIsValid", "[SLASupportGeneration]") {
sla::SupportTreeConfig supportcfg;
supportcfg.object_elevation_mm = 0;
for (auto &fname: SUPPORT_TEST_MODELS) test_supports(fname, supportcfg);
}
TEST_CASE("ElevatedSupportsDoNotPierceModel", "[SLASupportGeneration]") {
TEST_CASE("DefaultSupports::ElevatedSupportsDoNotPierceModel", "[SLASupportGeneration]") {
sla::SupportTreeConfig supportcfg;
supportcfg.object_elevation_mm = 10.;
for (auto fname : SUPPORT_TEST_MODELS)
test_support_model_collision(fname, supportcfg);
}
TEST_CASE("DefaultSupports::FloorSupportsDoNotPierceModel", "[SLASupportGeneration]") {
sla::SupportTreeConfig supportcfg;
supportcfg.object_elevation_mm = 0;
for (auto fname : SUPPORT_TEST_MODELS)
test_support_model_collision(fname, supportcfg);
}
TEST_CASE("FloorSupportsDoNotPierceModel", "[SLASupportGeneration]") {
//TEST_CASE("CleverSupports::ElevatedSupportGeometryIsValid", "[SLASupportGeneration][Clever]") {
// sla::SupportTreeConfig supportcfg;
// supportcfg.object_elevation_mm = 10.;
// supportcfg.tree_type = sla::SupportTreeType::Clever;
// for (auto fname : SUPPORT_TEST_MODELS) test_supports(fname, supportcfg);
//}
//TEST_CASE("CleverSupports::FloorSupportGeometryIsValid", "[SLASupportGeneration][Clever]") {
// sla::SupportTreeConfig supportcfg;
// supportcfg.object_elevation_mm = 0;
// supportcfg.tree_type = sla::SupportTreeType::Clever;
// for (auto &fname: SUPPORT_TEST_MODELS) test_supports(fname, supportcfg);
//}
TEST_CASE("CleverSupports::ElevatedSupportsDoNotPierceModel", "[SLASupportGeneration][Clever]") {
sla::SupportTreeConfig supportcfg;
supportcfg.object_elevation_mm = 10.;
supportcfg.tree_type = sla::SupportTreeType::Clever;
for (auto fname : SUPPORT_TEST_MODELS)
test_support_model_collision(fname, supportcfg);
}
TEST_CASE("CleverSupports::FloorSupportsDoNotPierceModel", "[SLASupportGeneration][Clever]") {
sla::SupportTreeConfig supportcfg;
supportcfg.object_elevation_mm = 0;
supportcfg.tree_type = sla::SupportTreeType::Clever;
for (auto fname : SUPPORT_TEST_MODELS)
test_support_model_collision(fname, supportcfg);
}

View file

@ -1,7 +1,7 @@
#include <catch2/catch.hpp>
#include <test_utils.hpp>
#include <libslic3r/SLA/IndexedMesh.hpp>
#include <libslic3r/AABBMesh.hpp>
#include <libslic3r/SLA/Hollowing.hpp>
#include "sla_test_utils.hpp"

View file

@ -3,6 +3,7 @@
#include <libslic3r/ExPolygon.hpp>
#include <libslic3r/BoundingBox.hpp>
#include <libslic3r/SLA/SpatIndex.hpp>
#include "sla_test_utils.hpp"

View file

@ -1,6 +1,7 @@
#include "sla_test_utils.hpp"
#include "libslic3r/TriangleMeshSlicer.hpp"
#include "libslic3r/SLA/AGGRaster.hpp"
#include "libslic3r/SLA/DefaultSupportTree.hpp"
#include <iomanip>
@ -15,14 +16,16 @@ void test_support_model_collision(const std::string &obj_filename,
// 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;
supportcfg.head_penetration_mm = -0.2;
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);
sla::slice(byproducts.supporttree.retrieve_mesh(sla::MeshType::Support),
byproducts.supporttree.retrieve_mesh(sla::MeshType::Pad),
byproducts.slicegrid, CLOSING_RADIUS, {});
// The slices originate from the same slice grid so the numbers must match
bool support_mesh_is_empty =
@ -47,13 +50,15 @@ void test_support_model_collision(const std::string &obj_filename,
notouch = notouch && area(intersections) < PI * pinhead_r * pinhead_r;
}
/*if (!notouch) */export_failed_case(support_slices, byproducts);
if (!notouch)
export_failed_case(support_slices, byproducts);
REQUIRE(notouch);
}
void export_failed_case(const std::vector<ExPolygons> &support_slices, const SupportByproducts &byproducts)
{
bool do_export_stl = false;
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];
@ -68,14 +73,18 @@ void export_failed_case(const std::vector<ExPolygons> &support_slices, const Sup
svg.draw(intersections, "red");
svg.Close();
}
do_export_stl = do_export_stl || !intersections.empty();
}
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());
if (do_export_stl) {
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,
@ -107,7 +116,7 @@ void test_supports(const std::string &obj_filename,
// 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};
AABBMesh emesh{mesh};
#ifdef SLIC3R_HOLE_RAYCASTER
if (hollowingcfg.enabled)
@ -144,10 +153,16 @@ void test_supports(const std::string &obj_filename,
// 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);
switch (sm.cfg.tree_type) {
case sla::SupportTreeType::Default: {
sla::DefaultSupportTree::execute(treebuilder, sm);
check_support_tree_integrity(treebuilder, supportcfg, sla::ground_level(sm));
break;
}
default:;
}
TriangleMesh output_mesh{treebuilder.retrieve_mesh(sla::MeshType::Support)};
check_validity(output_mesh, validityflags);
@ -171,9 +186,9 @@ void test_supports(const std::string &obj_filename,
}
void check_support_tree_integrity(const sla::SupportTreeBuilder &stree,
const sla::SupportTreeConfig &cfg)
const sla::SupportTreeConfig &cfg,
double gnd)
{
double gnd = stree.ground_level;
double H1 = cfg.max_solo_pillar_height_mm;
double H2 = cfg.max_dual_pillar_height_mm;
@ -426,7 +441,7 @@ sla::SupportPoints calc_support_pts(
std::vector<ExPolygons> slices = slice_mesh_ex(mesh.its, heights, CLOSING_RADIUS);
// Prepare the support point calculator
sla::IndexedMesh emesh{mesh};
AABBMesh emesh{mesh};
sla::SupportPointGenerator spgen{emesh, cfg, []{}, [](int){}};
// Calculate the support points

View file

@ -14,7 +14,7 @@
#include "libslic3r/TriangleMesh.hpp"
#include "libslic3r/SLA/Pad.hpp"
#include "libslic3r/SLA/SupportTreeBuilder.hpp"
#include "libslic3r/SLA/SupportTreeBuildsteps.hpp"
#include "libslic3r/SLA/SupportTreeUtils.hpp"
#include "libslic3r/SLA/SupportPointGenerator.hpp"
#include "libslic3r/SLA/AGGRaster.hpp"
#include "libslic3r/SLA/ConcaveHull.hpp"
@ -67,7 +67,8 @@ struct SupportByproducts
const constexpr float CLOSING_RADIUS = 0.005f;
void check_support_tree_integrity(const sla::SupportTreeBuilder &stree,
const sla::SupportTreeConfig &cfg);
const sla::SupportTreeConfig &cfg,
double gnd);
void test_supports(const std::string &obj_filename,
const sla::SupportTreeConfig &supportcfg,

View file

@ -4,7 +4,8 @@ add_executable(${_TEST_NAME}_tests
slic3r_jobs_tests.cpp
)
target_link_libraries(${_TEST_NAME}_tests test_common libslic3r_gui libslic3r)
# mold linker for successful linking needs also to link TBB library and link it before libslic3r.
target_link_libraries(${_TEST_NAME}_tests test_common TBB::tbb libslic3r_gui libslic3r)
if (MSVC)
target_link_libraries(${_TEST_NAME}_tests Setupapi.lib)
endif ()