Skip to content

Commit

Permalink
Merge branch '5.9' into CURA-12234_combing-over-top-surface
Browse files Browse the repository at this point in the history
HellAholic authored Nov 11, 2024
2 parents 3c73ce8 + aa9b651 commit 2ba2e24
Showing 4 changed files with 19 additions and 8 deletions.
5 changes: 4 additions & 1 deletion include/PathOrderOptimizer.h
Original file line number Diff line number Diff line change
@@ -740,7 +740,10 @@ class PathOrderOptimizer

if (path.force_start_index_.has_value()) // Actually handles EZSeamType::USER_SPECIFIED
{
main_criterion.criterion = std::make_shared<DistanceScoringCriterion>(points, points.at(path.force_start_index_.value()));
// Use a much smaller distance divider because we want points around the forced points to be filtered out very easily
constexpr double distance_divider = 1.0;
constexpr auto distance_type = DistanceScoringCriterion::DistanceType::Euclidian;
main_criterion.criterion = std::make_shared<DistanceScoringCriterion>(points, points.at(path.force_start_index_.value()), distance_type, distance_divider);
}
else
{
12 changes: 11 additions & 1 deletion include/utils/scoring/DistanceScoringCriterion.h
Original file line number Diff line number Diff line change
@@ -30,8 +30,18 @@ class DistanceScoringCriterion : public ScoringCriterion
const Point2LL& target_pos_;
const DistanceType distance_type_;

/*!
* Fixed divider for shortest distances computation. The divider should be set so that the minimum encountered
* distance gives a score very close to 1.0, and a medium-far distance gives a score close to 0.5
*/
const double distance_divider_;

public:
explicit DistanceScoringCriterion(const PointsSet& points, const Point2LL& target_pos, DistanceType distance_type = DistanceType::Euclidian);
explicit DistanceScoringCriterion(
const PointsSet& points,
const Point2LL& target_pos,
DistanceType distance_type = DistanceType::Euclidian,
const double distance_divider = 20.0);

virtual double computeScore(const size_t candidate_index) const override;
};
1 change: 1 addition & 0 deletions src/LayerPlan.cpp
Original file line number Diff line number Diff line change
@@ -2751,6 +2751,7 @@ void LayerPlan::writeGCode(GCodeExport& gcode)
gcode.writeTravel(current_position, extruder.settings_.get<Velocity>("speed_z_hop"));

// Prevent the final travel(s) from resetting to the 'previous' layer height.
path.z_offset = final_travel_z_ - z_;
gcode.setZ(final_travel_z_);
}
for (size_t point_idx = 0; point_idx + 1 < path.points.size(); point_idx++)
9 changes: 3 additions & 6 deletions src/utils/scoring/DistanceScoringCriterion.cpp
Original file line number Diff line number Diff line change
@@ -9,21 +9,18 @@
namespace cura
{

DistanceScoringCriterion::DistanceScoringCriterion(const PointsSet& points, const Point2LL& target_pos, DistanceType distance_type)
DistanceScoringCriterion::DistanceScoringCriterion(const PointsSet& points, const Point2LL& target_pos, DistanceType distance_type, const double distance_divider)
: points_(points)
, target_pos_(target_pos)
, distance_type_(distance_type)
, distance_divider_(distance_divider)
{
}

double DistanceScoringCriterion::computeScore(const size_t candidate_index) const
{
const Point2LL& candidate_position = points_.at(candidate_index);

// Fixed divider for shortest distances computation. The divider should be set so that the minimum encountered
// distance gives a score very close to 1.0, and a medium-far distance gives a score close to 0.5
constexpr double distance_divider = 20.0;

double distance = 0.0;
switch (distance_type_)
{
@@ -40,7 +37,7 @@ double DistanceScoringCriterion::computeScore(const size_t candidate_index) cons
}

// Use reciprocal function to normalize distance score decreasingly
return 1.0 / (1.0 + (distance / distance_divider));
return 1.0 / (1.0 + (distance / distance_divider_));
}

} // namespace cura

0 comments on commit 2ba2e24

Please sign in to comment.