Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CURA-12264 Fix seam alignment #2167

Merged
merged 1 commit into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading