turn off curvature estimator for extrusion quality control, improve the logic of the estimator.

This commit is contained in:
PavelMikus 2022-11-24 12:40:59 +01:00 committed by Pavel Mikuš
parent 0fdb545b55
commit bdc58c617b
2 changed files with 14 additions and 24 deletions

View File

@ -2705,7 +2705,6 @@ std::string GCode::extrude_multi_path(ExtrusionMultiPath multipath, const std::s
std::string GCode::extrude_entity(const ExtrusionEntity &entity, const std::string_view description, double speed)
{
m_extrusion_quality_estimator.reset_for_next_extrusion();
if (const ExtrusionPath* path = dynamic_cast<const ExtrusionPath*>(&entity))
return this->extrude_path(*path, description, speed);
else if (const ExtrusionMultiPath* multipath = dynamic_cast<const ExtrusionMultiPath*>(&entity))

View File

@ -44,7 +44,7 @@ public:
{
if (total_distance <= 0.0) { return 0.0; }
return total_curvature / std::min(total_distance, window_size);
return total_curvature / std::max(total_distance, window_size);
}
void reset()
@ -64,6 +64,7 @@ class CurvatureEstimator
public:
void add_point(float distance, float angle)
{
if (distance < EPSILON) return;
for (SlidingWindowCurvatureAccumulator &slider : sliders) { slider.add_point(distance, angle); }
}
float get_curvature()
@ -82,7 +83,6 @@ class ExtrusionQualityEstimator
{
AABBTreeLines::LinesDistancer<Linef> prev_layer_boundary;
AABBTreeLines::LinesDistancer<Linef> next_layer_boundary;
CurvatureEstimator cestim{};
public:
void prepare_for_new_layer(const std::vector<const Layer *> &layers)
@ -97,12 +97,10 @@ public:
next_layer_boundary = AABBTreeLines::LinesDistancer<Linef>{std::move(layer_lines)};
}
void reset_for_next_extrusion() { cestim.reset(); }
std::vector<float> estimate_extrusion_quality(const ExtrusionPath &path)
{
float flow_width = path.width;
float min_malformation_dist = 0.2 * flow_width;
float min_malformation_dist = 0.0 * flow_width;
float max_malformation_dist = 1.1 * flow_width;
float worst_malformation_dist = 0.5 * (min_malformation_dist + max_malformation_dist);
@ -113,34 +111,27 @@ public:
std::vector<float> point_qualities(points.size(), 1.0);
for (size_t point_idx = 0; point_idx < points.size(); ++point_idx) {
Vec2f b = points[point_idx];
const Vec2f &p = points[point_idx];
double dist_from_prev_layer = prev_layer_boundary.signed_distance_from_lines(b.cast<double>()) + flow_width * 0.5f;
double dist_from_prev_layer = prev_layer_boundary.signed_distance_from_lines(p.cast<double>()) + flow_width * 0.5f;
if (dist_from_prev_layer < min_malformation_dist) continue;
Vec2f a = points[point_idx > 0 ? point_idx - 1 : point_idx];
Vec2f c = points[point_idx < points.size() - 1 ? point_idx + 1 : point_idx];
float basic_distance_quality = 0.5f * fmin(1.0f, (1.0f - (dist_from_prev_layer - min_malformation_dist) /
(max_malformation_dist - min_malformation_dist)));
float curling_distance_quality = 0.5f * fmin(1.0f, std::abs(dist_from_prev_layer - worst_malformation_dist) /
(worst_malformation_dist - min_malformation_dist));
const Vec2f v1 = b - a;
const Vec2f v2 = c - b;
float curr_angle = angle(v1, v2);
cestim.add_point(v1.norm(), curr_angle);
float distance_quality = std::min(1.0, std::abs(dist_from_prev_layer - worst_malformation_dist) /
(worst_malformation_dist - min_malformation_dist));
// Curvature is 1 / R, where is radius of the touching sphere
// if the radius of the touching sphere is greater than 10 mm, dont lower quality, for sharper corners do lower the quality of the point
float curvature_value = std::abs(cestim.get_curvature()) * 10.0f;
curvature_value = std::max(curvature_value, 1.0f);
distance_quality /= curvature_value;
float distance_quality = basic_distance_quality + curling_distance_quality;
point_qualities[point_idx] = distance_quality;
}
if (points.size() > 1) { point_qualities[0] = point_qualities[1]; }
for (size_t point_idx = 1; point_idx < points.size(); ++point_idx) {
point_qualities[point_idx - 1] = std::max(point_qualities[point_idx - 1], point_qualities[point_idx]);
}
return point_qualities;
}
};