Skip to content

Commit a6450b0

Browse files
committed
Fix non-straight user-defined seam
CURA-12264 With a high-definition model, the new vertex created especially for the seam is quite close to the other points of its former segment. So the two other vertices would end up at good enough outsiders for the distance criterion. Now the distance factor of the criterion is a setting, so that in this specific case we can change the value to give more weight to the specific vertex and less to others, even if very close.
1 parent 7a327d4 commit a6450b0

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

include/PathOrderOptimizer.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,10 @@ class PathOrderOptimizer
740740

741741
if (path.force_start_index_.has_value()) // Actually handles EZSeamType::USER_SPECIFIED
742742
{
743-
main_criterion.criterion = std::make_shared<DistanceScoringCriterion>(points, points.at(path.force_start_index_.value()));
743+
// Use a much smaller distance divider because we want points around the forced points to be filtered out very easily
744+
constexpr double distance_divider = 1.0;
745+
constexpr auto distance_type = DistanceScoringCriterion::DistanceType::Euclidian;
746+
main_criterion.criterion = std::make_shared<DistanceScoringCriterion>(points, points.at(path.force_start_index_.value()), distance_type, distance_divider);
744747
}
745748
else
746749
{

include/utils/scoring/DistanceScoringCriterion.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,18 @@ class DistanceScoringCriterion : public ScoringCriterion
3030
const Point2LL& target_pos_;
3131
const DistanceType distance_type_;
3232

33+
/*!
34+
* Fixed divider for shortest distances computation. The divider should be set so that the minimum encountered
35+
* distance gives a score very close to 1.0, and a medium-far distance gives a score close to 0.5
36+
*/
37+
const double distance_divider_;
38+
3339
public:
34-
explicit DistanceScoringCriterion(const PointsSet& points, const Point2LL& target_pos, DistanceType distance_type = DistanceType::Euclidian);
40+
explicit DistanceScoringCriterion(
41+
const PointsSet& points,
42+
const Point2LL& target_pos,
43+
DistanceType distance_type = DistanceType::Euclidian,
44+
const double distance_divider = 20.0);
3545

3646
virtual double computeScore(const size_t candidate_index) const override;
3747
};

src/utils/scoring/DistanceScoringCriterion.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,18 @@
99
namespace cura
1010
{
1111

12-
DistanceScoringCriterion::DistanceScoringCriterion(const PointsSet& points, const Point2LL& target_pos, DistanceType distance_type)
12+
DistanceScoringCriterion::DistanceScoringCriterion(const PointsSet& points, const Point2LL& target_pos, DistanceType distance_type, const double distance_divider)
1313
: points_(points)
1414
, target_pos_(target_pos)
1515
, distance_type_(distance_type)
16+
, distance_divider_(distance_divider)
1617
{
1718
}
1819

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

23-
// Fixed divider for shortest distances computation. The divider should be set so that the minimum encountered
24-
// distance gives a score very close to 1.0, and a medium-far distance gives a score close to 0.5
25-
constexpr double distance_divider = 20.0;
26-
2724
double distance = 0.0;
2825
switch (distance_type_)
2926
{
@@ -40,7 +37,7 @@ double DistanceScoringCriterion::computeScore(const size_t candidate_index) cons
4037
}
4138

4239
// Use reciprocal function to normalize distance score decreasingly
43-
return 1.0 / (1.0 + (distance / distance_divider));
40+
return 1.0 / (1.0 + (distance / distance_divider_));
4441
}
4542

4643
} // namespace cura

0 commit comments

Comments
 (0)