Skip to content

Commit

Permalink
Merge branch '5.9' into CURA-12265_the-wiping-movement-goes-in-the-wr…
Browse files Browse the repository at this point in the history
…ong-direction
  • Loading branch information
wawanbreton authored Nov 8, 2024
2 parents 3e7f35a + c4ce927 commit fd222be
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
5 changes: 4 additions & 1 deletion include/PathOrderOptimizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
12 changes: 11 additions & 1 deletion include/utils/scoring/DistanceScoringCriterion.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
9 changes: 3 additions & 6 deletions src/utils/scoring/DistanceScoringCriterion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_)
{
Expand All @@ -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 fd222be

Please sign in to comment.