Skip to content

Commit 7876d03

Browse files
committed
Merge remote-tracking branch 'origin/5.9'
2 parents 4774868 + 7a327d4 commit 7876d03

34 files changed

+1359
-646
lines changed

CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ set(engine_SRCS # Except main.cpp.
6363
src/Mold.cpp
6464
src/multiVolumes.cpp
6565
src/path_ordering.cpp
66+
src/PathAdapter.cpp
6667
src/Preheat.cpp
6768
src/PrimeTower/PrimeTower.cpp
6869
src/PrimeTower/PrimeTowerNormal.cpp
@@ -156,6 +157,12 @@ set(engine_SRCS # Except main.cpp.
156157
src/utils/VoxelUtils.cpp
157158
src/utils/MixedPolylineStitcher.cpp
158159

160+
src/utils/scoring/BestElementFinder.cpp
161+
src/utils/scoring/CornerScoringCriterion.cpp
162+
src/utils/scoring/DistanceScoringCriterion.cpp
163+
src/utils/scoring/ExclusionAreaScoringCriterion.cpp
164+
src/utils/scoring/RandomScoringCriterion.cpp
165+
159166
src/geometry/Point2LL.cpp
160167
src/geometry/Point3LL.cpp
161168
src/geometry/Polygon.cpp

benchmark/scoring_benchmark.h

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// Copyright (c) 2024 UltiMaker
2+
// CuraEngine is released under the terms of the AGPLv3 or higher
3+
4+
#ifndef CURAENGINE_SCORING_BENCHMARK_H
5+
#define CURAENGINE_SCORING_BENCHMARK_H
6+
7+
#include <benchmark/benchmark.h>
8+
9+
#include "geometry/PointsSet.h"
10+
#include "utils/scoring/BestElementFinder.h"
11+
#include "utils/scoring/CornerScoringCriterion.h"
12+
#include "utils/scoring/DistanceScoringCriterion.h"
13+
14+
namespace cura
15+
{
16+
class ScoringTestFixture : public benchmark::Fixture
17+
{
18+
public:
19+
PointsSet points;
20+
21+
void SetUp(const ::benchmark::State& state) override
22+
{
23+
points.resize(state.range(0));
24+
constexpr double radius = 5000.0;
25+
26+
for (size_t i = 0; i < points.size(); ++i)
27+
{
28+
const double angle = (i * std::numbers::pi * 2.0) / points.size();
29+
points[i] = Point2LL(std::cos(angle) * radius, std::sin(angle) * radius);
30+
}
31+
}
32+
33+
void TearDown(const ::benchmark::State& state) override
34+
{
35+
}
36+
};
37+
38+
BENCHMARK_DEFINE_F(ScoringTestFixture, ScoringTest_WorstCase)(benchmark::State& st)
39+
{
40+
for (auto _ : st)
41+
{
42+
BestElementFinder best_element_finder;
43+
44+
// Pass 1 : find corners
45+
BestElementFinder::CriteriaPass main_criteria_pass;
46+
main_criteria_pass.outsider_delta_threshold = 0.05;
47+
48+
BestElementFinder::WeighedCriterion main_criterion;
49+
main_criterion.criterion = std::make_shared<CornerScoringCriterion>(points, EZSeamCornerPrefType::Z_SEAM_CORNER_PREF_WEIGHTED);
50+
main_criteria_pass.criteria.push_back(main_criterion);
51+
52+
best_element_finder.appendCriteriaPass(main_criteria_pass);
53+
54+
// Pass 2 : fallback to distance calculation
55+
BestElementFinder::CriteriaPass fallback_criteria_pass;
56+
BestElementFinder::WeighedCriterion fallback_criterion;
57+
fallback_criterion.criterion = std::make_shared<DistanceScoringCriterion>(points, Point2LL(1000, 0));
58+
59+
fallback_criteria_pass.criteria.push_back(fallback_criterion);
60+
best_element_finder.appendCriteriaPass(fallback_criteria_pass);
61+
62+
best_element_finder.findBestElement(points.size());
63+
}
64+
}
65+
66+
BENCHMARK_REGISTER_F(ScoringTestFixture, ScoringTest_WorstCase)->Arg(10000)->Unit(benchmark::kMillisecond);
67+
68+
BENCHMARK_REGISTER_F(ScoringTestFixture, ScoringTest_WorstCase)->Arg(1000)->Unit(benchmark::kMillisecond);
69+
70+
BENCHMARK_REGISTER_F(ScoringTestFixture, ScoringTest_WorstCase)->Arg(10)->Unit(benchmark::kMillisecond);
71+
72+
} // namespace cura
73+
#endif // CURAENGINE_SCORING_BENCHMARK_H

conandata.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ requirements:
55
requirements_arcus:
66
- "arcus/5.4.1"
77
requirements_plugins:
8-
- "curaengine_grpc_definitions/0.2.1"
8+
- "curaengine_grpc_definitions/0.3.0"
99
requirements_cura_resources:
1010
- "cura_resources/(latest)@ultimaker/testing"

include/ExtruderPlan.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ class ExtruderPlan
191191
/*!
192192
* @return distance between p0 and p1 as well as the time spend on the segment
193193
*/
194-
std::pair<double, double> getPointToPointTime(const Point3LL& p0, const Point3LL& p1, const GCodePath& path);
194+
std::pair<double, double> getPointToPointTime(const Point3LL& p0, const Point3LL& p1, const GCodePath& path) const;
195195

196196
/*!
197197
* Compute naive time estimates (without accounting for slow down at corners etc.) and naive material estimates.

include/LayerPlan.h

Lines changed: 126 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ class Comb;
3838
class SliceDataStorage;
3939
class LayerPlanBuffer;
4040

41+
template<typename PathType>
42+
class PathAdapter;
43+
4144
/*!
4245
* The LayerPlan class stores multiple moves that are planned.
4346
*
@@ -57,20 +60,27 @@ class LayerPlan : public NoCopy
5760
#endif
5861

5962
public:
60-
// 'AdjustCoasting'; because split-up paths from the same extruder (with no travel moves between them) should count as the same path w.r.t. coasting.
61-
enum class AdjustCoasting
62-
{
63-
AsNormal,
64-
CoastEntirePath,
65-
ContinueCoasting
66-
};
67-
6863
const PathConfigStorage configs_storage_; //!< The line configs for this layer for each feature type
6964
const coord_t z_;
7065
coord_t final_travel_z_;
7166
bool mode_skip_agressive_merge_; //!< Whether to give every new path the 'skip_agressive_merge_hint' property (see GCodePath); default is false.
7267

7368
private:
69+
// Indicates how coasting should be processed on the given path.
70+
enum class ApplyCoasting
71+
{
72+
NoCoasting, // Do not apply coasting on this path, extrude it normally
73+
CoastEntirePath, // Fully coast this path, i.e. replace it by travel moves
74+
PartialCoasting // Extrude the first part of the path and coast the end
75+
};
76+
77+
struct PathCoasting
78+
{
79+
ApplyCoasting apply_coasting{ ApplyCoasting::NoCoasting };
80+
size_t coasting_start_index{ 0 };
81+
Point3LL coasting_start_pos;
82+
};
83+
7484
const SliceDataStorage& storage_; //!< The polygon data obtained from FffPolygonProcessor
7585
const LayerIndex layer_nr_; //!< The layer number of this layer plan
7686
const bool is_initial_layer_; //!< Whether this is the first layer (which might be raft)
@@ -393,16 +403,21 @@ class LayerPlan : public NoCopy
393403
* \param spiralize Whether to gradually increase the z height from the normal layer height to the height of the next layer over this polygon
394404
* \param flow_ratio The ratio with which to multiply the extrusion amount
395405
* \param always_retract Whether to force a retraction when moving to the start of the polygon (used for outer walls)
406+
* \param scarf_seam Indicates whether we may use a scarf seam for the path
407+
* \param smooth_speed Indicates whether we may use a speed gradient for the path
396408
*/
397409
void addPolygon(
398410
const Polygon& polygon,
399411
int startIdx,
400412
const bool reverse,
413+
const Settings& settings,
401414
const GCodePathConfig& config,
402415
coord_t wall_0_wipe_dist = 0,
403416
bool spiralize = false,
404417
const Ratio& flow_ratio = 1.0_r,
405-
bool always_retract = false);
418+
bool always_retract = false,
419+
bool scarf_seam = false,
420+
bool smooth_speed = false);
406421

407422
/*!
408423
* Add polygons to the gcode with optimized order.
@@ -431,17 +446,22 @@ class LayerPlan : public NoCopy
431446
* \param reverse_order Adds polygons in reverse order.
432447
* \param start_near_location Start optimising the path near this location.
433448
* If unset, this causes it to start near the last planned location.
449+
* \param scarf_seam Indicates whether we may use a scarf seam for the path
450+
* \param smooth_speed Indicates whether we may use a speed gradient for the path
434451
*/
435452
void addPolygonsByOptimizer(
436453
const Shape& polygons,
437454
const GCodePathConfig& config,
455+
const Settings& settings,
438456
const ZSeamConfig& z_seam_config = ZSeamConfig(),
439457
coord_t wall_0_wipe_dist = 0,
440458
bool spiralize = false,
441459
const Ratio flow_ratio = 1.0_r,
442460
bool always_retract = false,
443461
bool reverse_order = false,
444-
const std::optional<Point2LL> start_near_location = std::optional<Point2LL>());
462+
const std::optional<Point2LL> start_near_location = std::optional<Point2LL>(),
463+
bool scarf_seam = false,
464+
bool smooth_acceleration = false);
445465

446466
/*!
447467
* Add a single line that is part of a wall to the gcode.
@@ -525,6 +545,8 @@ class LayerPlan : public NoCopy
525545
* polyline).
526546
* \param is_reversed Whether to print this wall in reverse direction.
527547
* \param is_linked_path Whether the path is a continuation off the previous path
548+
* \param scarf_seam Indicates whether we may use a scarf seam for the path
549+
* \param smooth_speed Indicates whether we may use a speed gradient for the path
528550
*/
529551
void addWall(
530552
const ExtrusionLine& wall,
@@ -699,28 +721,6 @@ class LayerPlan : public NoCopy
699721
*/
700722
bool makeRetractSwitchRetract(unsigned int extruder_plan_idx, unsigned int path_idx);
701723

702-
/*!
703-
* Writes a path to GCode and performs coasting, or returns false if it did nothing.
704-
*
705-
* Coasting replaces the last piece of an extruded path by move commands and uses the oozed material to lay down lines.
706-
*
707-
* \param gcode The gcode to write the planned paths to.
708-
* \param extruder_plan_idx The index of the current extruder plan.
709-
* \param path_idx The index into LayerPlan::paths for the next path to be
710-
* written to GCode.
711-
* \param layer_thickness The height of the current layer.
712-
* \param insertTempOnTime A function that inserts temperature changes at a given time.
713-
* \param coasting_adjust Paths can be split up, so we need to know when to continue coasting from last, or even coast the entire path.
714-
* \return Whether any GCode has been written for the path.
715-
*/
716-
bool writePathWithCoasting(
717-
GCodeExport& gcode,
718-
const size_t extruder_plan_idx,
719-
const size_t path_idx,
720-
const coord_t layer_thickness,
721-
const std::function<void(const double, const int64_t)> insertTempOnTime,
722-
const std::pair<AdjustCoasting, double> coasting_adjust);
723-
724724
/*!
725725
* Applying speed corrections for minimal layer times and determine the fanSpeed.
726726
*
@@ -834,20 +834,34 @@ class LayerPlan : public NoCopy
834834
PrintFeatureType feature,
835835
bool update_extrusion_offset = false);
836836

837+
/*!
838+
* \brief Alias for a function definition that adds an extrusion segment
839+
* \param start The start position of the segment
840+
* \param end The end position of the segment
841+
* \param speed_factor The speed factor to be applied when extruding this specific segment (relative to nominal speed for the entire path)
842+
* \param flow_ratio The flow ratio to be applied when extruding this specific segment (relative to nominal flow for the entire path)
843+
* \param line_width_ratio The line width ratio to be applied when extruding this specific segment (relative to nominal line width for the entire path)
844+
* \param distance_to_bridge_start The calculate distance to the next bridge start, which may be irrelevant in some cases
845+
*/
846+
using AddExtrusionSegmentFunction = std::function<void(
847+
const Point3LL& start,
848+
const Point3LL& end,
849+
const Ratio& speed_factor,
850+
const Ratio& flow_ratio,
851+
const Ratio& line_width_ratio,
852+
const coord_t distance_to_bridge_start)>;
853+
837854
/*!
838855
* \brief Add a wall to the gcode with optimized order, but split into pieces in order to facilitate the scarf seam and/or speed gradient.
856+
* \tparam PathType The type of path to be processed, either ExtrusionLine or some subclass of Polyline
839857
* \param wall The full wall to be added
840858
* \param wall_length The pre-calculated full wall length
841859
* \param start_idx The index of the point where to start printing the wall
842860
* \param direction The direction along which to print the wall, which should be 1 or -1
843861
* \param max_index The last index to be used when iterating over the wall segments
844-
* \param settings The settings which should apply to this wall added to the layer plan
845862
* \param default_config The config with which to print the wall lines that are not spanning a bridge or are exposed to air
846-
* \param roofing_config The config with which to print the wall lines that are exposed to air
847-
* \param bridge_config The config with which to print the wall lines that are spanning a bridge
848863
* \param flow_ratio The ratio with which to multiply the extrusion amount
849-
* \param line_width_ratio The line width ratio to be applied
850-
* \param non_bridge_line_volume A pseudo-volume that is derived from the print speed and flow of the non-bridge lines that have preceded this lin
864+
* \param nominal_line_width The nominal line width for the wall
851865
* \param min_bridge_line_len The minimum line width to allow an extrusion move to be processed as a bridge move
852866
* \param always_retract Whether to force a retraction when moving to the start of the polygon (used for outer walls)
853867
* \param is_small_feature Indicates whether the wall is so small that it should be processed differently
@@ -864,26 +878,26 @@ class LayerPlan : public NoCopy
864878
* \param end_speed_ratio The ratio of the top speed to be applied when finishing a segment
865879
* \param decelerate_length The pre-calculated length of the deceleration phase
866880
* \param is_scarf_closure Indicates whether this function is called to make the scarf closure (overlap over the first scarf pass) or the normal first pass of the wall
881+
* \param compute_distance_to_bridge_start Whether we should compute the distance to start of bridge. This is
882+
* possible only if PathType is ExtrusionLine and will be ignored otherwise.
883+
* \param func_add_segment The function to be called to actually add an extrusion segment with the given parameters
867884
*/
885+
template<class PathType>
868886
void addSplitWall(
869-
const ExtrusionLine& wall,
887+
const PathAdapter<PathType>& wall,
870888
const coord_t wall_length,
871-
size_t start_idx,
872-
const int direction,
889+
const size_t start_idx,
873890
const size_t max_index,
874-
const Settings& settings,
891+
const int direction,
875892
const GCodePathConfig& default_config,
876-
const GCodePathConfig& roofing_config,
877-
const GCodePathConfig& bridge_config,
878-
const double flow_ratio,
879-
const Ratio line_width_ratio,
880-
double& non_bridge_line_volume,
881-
const coord_t min_bridge_line_len,
882893
const bool always_retract,
883894
const bool is_small_feature,
884895
Ratio small_feature_speed_factor,
885896
const coord_t max_area_deviation,
886897
const auto max_resolution,
898+
const double flow_ratio,
899+
const coord_t nominal_line_width,
900+
const coord_t min_bridge_line_len,
887901
const auto scarf_seam_length,
888902
const auto scarf_seam_start_ratio,
889903
const auto scarf_split_distance,
@@ -893,7 +907,71 @@ class LayerPlan : public NoCopy
893907
const coord_t accelerate_length,
894908
const Ratio end_speed_ratio,
895909
const coord_t decelerate_length,
896-
const bool is_scarf_closure);
910+
const bool is_scarf_closure,
911+
const bool compute_distance_to_bridge_start,
912+
const AddExtrusionSegmentFunction& func_add_segment);
913+
914+
/*!
915+
* \brief Add a wall to the gcode with optimized order, possibly adding a scarf seam / speed gradient according to settings
916+
* \tparam PathType The type of path to be processed, either ExtrusionLine or some subclass of Polyline
917+
* \param wall The full wall to be added
918+
* \param start_idx The index of the point where to start printing the wall
919+
* \param settings The settings which should apply to this wall added to the layer plan
920+
* \param default_config The config with which to print the wall lines that are not spanning a bridge or are exposed to air
921+
* \param flow_ratio The ratio with which to multiply the extrusion amount
922+
* \param always_retract Whether to force a retraction when moving to the start of the polygon (used for outer walls)
923+
* \param is_closed Indicates whether the path is closed (or open)
924+
* \param is_reversed Indicates if the path is to be processed backwards
925+
* \param is_candidate_small_feature Indicates whether the path should be tested for being treated as a smell feature
926+
* \param scarf_seam Indicates whether we may use a scarf seam for the path
927+
* \param smooth_speed Indicates whether we may use a speed gradient for the path
928+
* \param func_add_segment The function to be called to actually add an extrusion segment with the given parameters
929+
*/
930+
template<class PathType>
931+
void addWallWithScarfSeam(
932+
const PathAdapter<PathType>& wall,
933+
size_t start_idx,
934+
const Settings& settings,
935+
const GCodePathConfig& default_config,
936+
const double flow_ratio,
937+
bool always_retract,
938+
const bool is_closed,
939+
const bool is_reversed,
940+
const bool is_candidate_small_feature,
941+
const bool scarf_seam,
942+
const bool smooth_speed,
943+
const AddExtrusionSegmentFunction& func_add_segment);
944+
945+
/*!
946+
* Pre-calculates the coasting to be applied on the paths
947+
*
948+
* \param extruder_settings The current extruder settings
949+
* \param paths The current set of paths to be written to GCode
950+
* \param current_position The last position set in the gcode writer
951+
* \return The list of coasting settings to be applied on the paths. It will always have the same size as paths.
952+
*/
953+
std::vector<PathCoasting> calculatePathsCoasting(const Settings& extruder_settings, const std::vector<GCodePath>& paths, const Point3LL& current_position) const;
954+
955+
/*!
956+
* Writes a path to GCode and performs coasting, or returns false if it did nothing.
957+
*
958+
* Coasting replaces the last piece of an extruded path by move commands and uses the oozed material to lay down lines.
959+
*
960+
* \param gcode The gcode to write the planned paths to.
961+
* \param extruder_plan_idx The index of the current extruder plan.
962+
* \param path_idx The index into LayerPlan::paths for the next path to be
963+
* written to GCode.
964+
* \param layer_thickness The height of the current layer.
965+
* \param insertTempOnTime A function that inserts temperature changes at a given time.
966+
* \param path_coasting The actual coasting to be applied to the path.
967+
* \return Whether any GCode has been written for the path.
968+
*/
969+
bool writePathWithCoasting(
970+
GCodeExport& gcode,
971+
const size_t extruder_plan_idx,
972+
const size_t path_idx,
973+
const std::function<void(const double, const int64_t)> insertTempOnTime,
974+
const PathCoasting& path_coasting);
897975

898976
/*!
899977
* \brief Helper function to calculate the distance from the start of the current wall line to the first bridge segment

0 commit comments

Comments
 (0)