mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-10-20 06:01:16 +00:00
Optimize travel: exact/refined path chaining, object tours, and joined infill lines (#16492)
* Shorten the travel between extrusion paths chain_and_reorder_extrusion_entities() builds the print order of the infill, ironing and support paths of a region from the nozzle position. It took the greedy chain, which leaves its longest joins for last; it now shortens it: - Up to eight paths, chain_segments_exact() finds the shortest chain over every order and allowed reversal, by dynamic programming over the subsets of paths, with a fixed start and a free end. - Longer chains are refined by local search: 2-opt, or-opt of up to three paths, and moving a run of any length next to the nozzle to the front, each tried only toward the 32 end points nearest a link, which come from a uniform grid. A move is applied only if it shortens the chain, so the result is never longer than the greedy one. - A nearest-next chain is built too, and refined and used instead when it is already shorter than the refined greedy chain, which happens when the greedy chain sweeps away from the nozzle and has to come back with a long jump. The shared greedy chaining also chains two to four segments exactly, which covers the islands of a layer and the loops of a perimeter collection. Paths that cannot reverse, such as Grid's, are only reordered, and collections that keep their order are left alone. The overload without a start point keeps the greedy chain. Co-authored-by: Tobias Gloth <tobias.gloth@3dsystems.com> * Order objects and islands along shorter tours Objects under print_order Default, and the tour of islands across objects, are visited in the same order on every layer, so chain_points_with_postprocessing() orders them as a closed tour. Up to ten points, tsp_exact_cycle() finds the shortest tour by dynamic programming over subsets, starting at the point nearest the start point when one is given. Larger sets add or-opt to the existing 2-opt and crossing removal: runs of up to three points move next to one of the eight points nearest an end of the run, reversed or not, and crossing removal runs last so no crossing is left. Snake ordering is unchanged; Best of strategies gets the shorter Default tour as a candidate. * Join infill lines into fewer paths Every separate infill path costs a travel to it, so the fill generators now leave fewer of them: - connect_infill() pairs the line ends along each wall in the order that joins the most lines: besides shortest arc first, it replays arcs of about the same length taken along each contour, forwards and backwards, including the last pass that joins neighboring open ends, and keeps the order that joins the most. Regular patterns no longer leave loose ends where the pairs along a wall fall out of step, and multiline copies print out and back. - Ends whose anchors would meet are joined along the wall instead, up to two anchors and a line width apart. - An unpaired end anchors toward the nearest open end of another path, where the next path usually starts, instead of the side with more free wall. With multiline infill, an anchor toward a copy of the same line stops short of the copy instead of printing over it. - Last, sparse infill lines whose ends are at most two line spacings apart are joined with a straight piece, shortest first, without closing a loop or crossing a line; with anchors off this is the only joining. Copies of neighboring multiline groups are joined at the same side, and lines that cannot reverse only join end to start. * Describe the travel optimization design How the extrusion chains, the object and island tours and the infill line joining shorten the travel, and why each part is built the way it is. --------- Co-authored-by: Tobias Gloth <tobias.gloth@3dsystems.com>
This commit is contained in:
1 parent
cdb9bb57ae
commit
69193d5681
11 files changed
+1316
-29
No files matched your search
@@ -1719,9 +1719,10 @@ TEST_CASE("Smoothing multiline lightning infill keeps its outlines connected", "
|
||||
const SparseInfillShape smooth = shape_for("100%");
|
||||
|
||||
REQUIRE(sharp.path_count > 0);
|
||||
// Smoothing should leave the loop count about where it was; uncapping the smoothing reach, the
|
||||
// regression this guards against, adds about 10%.
|
||||
const size_t allowed_extra = sharp.path_count / 50; // 2%
|
||||
// Smoothing should leave the path count about where it was; uncapping the smoothing reach, the
|
||||
// regression this guards against, adds a quarter to a third. Outline ends next to each other are
|
||||
// joined into one path, so a few loops more or less are a larger share of the count.
|
||||
const size_t allowed_extra = sharp.path_count / 10; // 10%
|
||||
REQUIRE(smooth.path_count <= sharp.path_count + allowed_extra);
|
||||
// The outlines are still rounded.
|
||||
REQUIRE(smooth.point_count > sharp.point_count);
|
||||
@@ -2353,3 +2354,66 @@ TEST_CASE("Adaptive TPMS anchors match the printed infill", "[Fill][InternalBrid
|
||||
max_distance = std::max(max_distance, printed_tree.distance_from_lines<false>(point));
|
||||
CHECK(unscale<double>(max_distance) <= 0.012);
|
||||
}
|
||||
|
||||
TEST_CASE("Infill lines whose ends are next to each other join into one path", "[Fill]")
|
||||
{
|
||||
// An out-and-back pair 1 mm apart, as multiline infill leaves, and a line 19 mm away.
|
||||
Polylines lines { Polyline(Point::new_scale(0., 0.), Point::new_scale(10., 0.)), Polyline(Point::new_scale(0., 1.), Point::new_scale(10., 1.)),
|
||||
Polyline(Point::new_scale(0., 20.), Point::new_scale(10., 20.)) };
|
||||
join_close_ends(lines, scale_(1.5), true);
|
||||
|
||||
REQUIRE(lines.size() == 2);
|
||||
const auto joined = std::find_if(lines.begin(), lines.end(), [](const Polyline &pl) { return pl.size() == 4; });
|
||||
REQUIRE(joined != lines.end());
|
||||
// Both lines plus the 1 mm between them, joined at one end only, as joining the other end too would close a loop.
|
||||
CHECK_THAT(unscale<double>(joined->length()), Catch::Matchers::WithinAbs(21., 1e-6));
|
||||
CHECK(joined->first_point() != joined->last_point());
|
||||
}
|
||||
|
||||
TEST_CASE("Joined infill lines print each line once", "[Fill]")
|
||||
{
|
||||
// The middle line comes first and both of its ends get joined, so the group has to be walked from an outer line.
|
||||
Polylines lines { Polyline(Point::new_scale(0., 0.), Point::new_scale(10., 0.)), Polyline(Point::new_scale(0., 1.), Point::new_scale(10., 1.)),
|
||||
Polyline(Point::new_scale(10., -1.), Point::new_scale(0., -1.)) };
|
||||
join_close_ends(lines, scale_(1.5), true);
|
||||
|
||||
REQUIRE(lines.size() == 1);
|
||||
CHECK(lines.front().size() == 6);
|
||||
// Three 10 mm lines and two 1 mm joins.
|
||||
CHECK_THAT(unscale<double>(lines.front().length()), Catch::Matchers::WithinAbs(32., 1e-6));
|
||||
}
|
||||
|
||||
TEST_CASE("Infill line ends are not joined across another line", "[Fill]")
|
||||
{
|
||||
// A pair 1 mm apart whose left ends have a third line running between them, which a join there would cross.
|
||||
Polylines lines { Polyline(Point::new_scale(0., 0.), Point::new_scale(10., 0.)), Polyline(Point::new_scale(0., 1.), Point::new_scale(10., 1.)),
|
||||
Polyline(Point::new_scale(-5., 0.5), Point::new_scale(5., 0.5)) };
|
||||
join_close_ends(lines, scale_(1.5), true);
|
||||
|
||||
REQUIRE(lines.size() == 2);
|
||||
const auto joined = std::find_if(lines.begin(), lines.end(), [](const Polyline &pl) { return pl.size() == 4; });
|
||||
REQUIRE(joined != lines.end());
|
||||
// Joined on the right, where nothing is in between, so the left ends stay open.
|
||||
CHECK(joined->first_point().x() == 0);
|
||||
CHECK(joined->last_point().x() == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("Infill lines that cannot reverse join only end to start", "[Fill]")
|
||||
{
|
||||
const Point a(Point::new_scale(0., 0.)), b(Point::new_scale(10., 0.)), c(Point::new_scale(10., 1.)), d(Point::new_scale(0., 1.));
|
||||
SECTION("Ends that would need a reversal stay apart") {
|
||||
Polylines lines { Polyline(a, b), Polyline(d, c) };
|
||||
join_close_ends(lines, scale_(1.5), false);
|
||||
CHECK(lines.size() == 2);
|
||||
}
|
||||
SECTION("The end of one line joins the start of the next, both kept in their direction") {
|
||||
Polylines lines { Polyline(c, d), Polyline(a, b) };
|
||||
join_close_ends(lines, scale_(1.5), false);
|
||||
REQUIRE(lines.size() == 1);
|
||||
const Points &points = lines.front().points;
|
||||
REQUIRE(points.size() == 4);
|
||||
auto position = [&points](const Point &p) { return std::find(points.begin(), points.end(), p) - points.begin(); };
|
||||
CHECK(position(a) < position(b));
|
||||
CHECK(position(c) < position(d));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user