Smoothen the curled height estimations and slowdown

This commit is contained in:
PavelMikus 2023-04-11 13:01:31 +02:00 committed by Pavel Mikuš
parent 6e40e061f6
commit da6b972a79
4 changed files with 69 additions and 24 deletions

View file

@ -347,7 +347,7 @@ public:
std::vector<size_t> all_lines_in_radius(const Vec<2, typename LineType::Scalar> &point, Floating radius)
{
return all_lines_in_radius(this->lines, this->tree, point, radius * radius);
return AABBTreeLines::all_lines_in_radius(this->lines, this->tree, point, radius * radius);
}
template<bool sorted> std::vector<std::pair<Vec<2, Scalar>, size_t>> intersections_with_line(const LineType &line) const

View file

@ -3036,7 +3036,7 @@ std::string GCode::_extrude(const ExtrusionPath &path, const std::string_view de
EXTRUDER_CONFIG(filament_max_volumetric_speed) / path.mm3_per_mm);
}
new_points = m_extrusion_quality_estimator.estimate_extrusion_quality(path, overhangs_with_speeds, overhang_w_fan_speeds,
new_points = m_extrusion_quality_estimator.estimate_speed_from_extrusion_quality(path, overhangs_with_speeds, overhang_w_fan_speeds,
m_writer.extruder()->id(), external_perim_reference_speed,
speed);
variable_speed_or_fan_speed = std::any_of(new_points.begin(), new_points.end(),

View file

@ -101,13 +101,10 @@ public:
struct ExtendedPoint
{
ExtendedPoint(Vec2d position, float distance = 0.0, size_t nearest_prev_layer_line = size_t(-1), float curvature = 0.0)
: position(position), distance(distance), nearest_prev_layer_line(nearest_prev_layer_line), curvature(curvature)
{}
Vec2d position;
float distance;
size_t nearest_prev_layer_line;
Vec2d nearest_prev_layer_point;
float curvature;
};
@ -132,6 +129,7 @@ std::vector<ExtendedPoint> estimate_points_properties(const std::vector<P>
auto [distance, nearest_line, x] = unscaled_prev_layer.template distance_from_lines_extra<SIGNED_DISTANCE>(start_point.position.cast<AABBScalar>());
start_point.distance = distance + boundary_offset;
start_point.nearest_prev_layer_line = nearest_line;
start_point.nearest_prev_layer_point = x.template cast<double>();
points.push_back(start_point);
}
for (size_t i = 1; i < input_points.size(); i++) {
@ -139,13 +137,19 @@ std::vector<ExtendedPoint> estimate_points_properties(const std::vector<P>
auto [distance, nearest_line, x] = unscaled_prev_layer.template distance_from_lines_extra<SIGNED_DISTANCE>(next_point.position.cast<AABBScalar>());
next_point.distance = distance + boundary_offset;
next_point.nearest_prev_layer_line = nearest_line;
next_point.nearest_prev_layer_point = x.template cast<double>();
if (ADD_INTERSECTIONS &&
((points.back().distance > boundary_offset + EPSILON) != (next_point.distance > boundary_offset + EPSILON))) {
const ExtendedPoint &prev_point = points.back();
auto intersections = unscaled_prev_layer.template intersections_with_line<true>(L{prev_point.position.cast<AABBScalar>(), next_point.position.cast<AABBScalar>()});
for (const auto &intersection : intersections) {
points.emplace_back(intersection.first.template cast<double>(), boundary_offset, intersection.second);
ExtendedPoint p{};
p.position = intersection.first.template cast<double>();
p.distance = boundary_offset;
p.nearest_prev_layer_line = intersection.second;
p.nearest_prev_layer_point = p.position;
points.push_back(p);
}
}
points.push_back(next_point);
@ -171,12 +175,22 @@ std::vector<ExtendedPoint> estimate_points_properties(const std::vector<P>
if (t0 < 1.0) {
auto p0 = curr.position + t0 * (next.position - curr.position);
auto [p0_dist, p0_near_l, p0_x] = unscaled_prev_layer.template distance_from_lines_extra<SIGNED_DISTANCE>(p0.cast<AABBScalar>());
new_points.push_back(ExtendedPoint{p0, float(p0_dist + boundary_offset), p0_near_l});
ExtendedPoint new_p{};
new_p.position = p0;
new_p.distance = float(p0_dist + boundary_offset);
new_p.nearest_prev_layer_line = p0_near_l;
new_p.nearest_prev_layer_point = p0_x.template cast<double>();
new_points.push_back(new_p);
}
if (t1 > 0.0) {
auto p1 = curr.position + t1 * (next.position - curr.position);
auto [p1_dist, p1_near_l, p1_x] = unscaled_prev_layer.template distance_from_lines_extra<SIGNED_DISTANCE>(p1.cast<AABBScalar>());
new_points.push_back(ExtendedPoint{p1, float(p1_dist + boundary_offset), p1_near_l});
ExtendedPoint new_p{};
new_p.position = p1;
new_p.distance = float(p1_dist + boundary_offset);
new_p.nearest_prev_layer_line = p1_near_l;
new_p.nearest_prev_layer_point = p1_x.template cast<double>();
new_points.push_back(new_p);
}
}
}
@ -200,7 +214,12 @@ std::vector<ExtendedPoint> estimate_points_properties(const std::vector<P>
Vec2d pos = curr.position * (1.0 - j * t) + next.position * (j * t);
auto [p_dist, p_near_l,
p_x] = unscaled_prev_layer.template distance_from_lines_extra<SIGNED_DISTANCE>(pos.cast<AABBScalar>());
new_points.push_back(ExtendedPoint{pos, float(p_dist + boundary_offset), p_near_l});
ExtendedPoint new_p{};
new_p.position = pos;
new_p.distance = float(p_dist + boundary_offset);
new_p.nearest_prev_layer_line = p_near_l;
new_p.nearest_prev_layer_point = p_x.template cast<double>();
new_points.push_back(new_p);
}
}
new_points.push_back(points.back());
@ -301,10 +320,12 @@ public:
auto [distance_from_curled, line_idx,
p] = prev_curled_extrusions[current_object].distance_from_lines_extra<false>(Point::new_scale(ep.position));
if (distance_from_curled < scale_(2.0 * path.width)) {
float articifally_increased_distance = path.width *
prev_curled_extrusions[current_object].get_line(line_idx).curled_height /
(path.height * 10.0f); // max_curled_height_factor from SupportSpotGenerator
ep.distance = std::max(ep.distance, articifally_increased_distance);
float artificially_increased_distance = path.width *
(1.0 - (unscaled(distance_from_curled) / (2.0 * path.width)) *
(unscaled(distance_from_curled) / (2.0 * path.width))) *
(prev_curled_extrusions[current_object].get_line(line_idx).curled_height /
(path.height * 10.0f)); // max_curled_height_factor from SupportSpotGenerator
ep.distance = std::max(ep.distance, artificially_increased_distance);
}
}

View file

@ -13,6 +13,7 @@
#include "PrintBase.hpp"
#include "PrintConfig.hpp"
#include "Tesselate.hpp"
#include "Utils.hpp"
#include "libslic3r.h"
#include "tbb/parallel_for.h"
#include "tbb/blocked_range.h"
@ -247,6 +248,32 @@ float estimate_curled_up_height(
return curled_up_height;
}
std::tuple<float, float> get_bottom_extrusions_quality_and_curling(const LD &prev_layer_lines, const ExtendedPoint &curr_point)
{
if (prev_layer_lines.get_lines().empty()) {
return {1.0,0.0};
}
const ExtrusionLine nearest_prev_layer_line = prev_layer_lines.get_line(curr_point.nearest_prev_layer_line);
float quality = nearest_prev_layer_line.form_quality;
float curling = nearest_prev_layer_line.curled_up_height;
if ((curr_point.nearest_prev_layer_point.cast<float>() - nearest_prev_layer_line.a).squaredNorm() < 0.1) {
const auto& prev_line = prev_layer_lines.get_line(prev_idx_modulo(curr_point.nearest_prev_layer_line, prev_layer_lines.get_lines().size()));
if ((curr_point.nearest_prev_layer_point.cast<float>() - prev_line.b).squaredNorm() < 0.1) {
quality = 0.5 * (quality + prev_line.form_quality);
curling = 0.5 * (curling + prev_line.curled_up_height);
}
} else if ((curr_point.nearest_prev_layer_point.cast<float>() - nearest_prev_layer_line.b).squaredNorm() < 0.1) {
const auto &next_line = prev_layer_lines.get_line(
next_idx_modulo(curr_point.nearest_prev_layer_line, prev_layer_lines.get_lines().size()));
if ((curr_point.nearest_prev_layer_point.cast<float>() - next_line.a).squaredNorm() < 0.1) {
quality = 0.5 * (quality + next_line.form_quality);
curling = 0.5 * (curling + next_line.curled_up_height);
}
}
return {quality, curling};
}
std::vector<ExtrusionLine> check_extrusion_entity_stability(const ExtrusionEntity *entity,
const LayerRegion *layer_region,
const LD &prev_layer_lines,
@ -335,9 +362,7 @@ std::vector<ExtrusionLine> check_extrusion_entity_stability(const ExtrusionEntit
float line_len = (prev_point.position - curr_point.position).norm();
ExtrusionLine line_out{prev_point.position.cast<float>(), curr_point.position.cast<float>(), line_len, entity};
const ExtrusionLine nearest_prev_layer_line = prev_layer_lines.get_lines().size() > 0 ?
prev_layer_lines.get_line(curr_point.nearest_prev_layer_line) :
ExtrusionLine{};
auto [prev_layer_quality, prev_layer_curling] = get_bottom_extrusions_quality_and_curling(prev_layer_lines, curr_point);
// correctify the distance sign using slice polygons
float sign = (prev_layer_boundary.distance_from_lines<true>(curr_point.position) + 0.5f * flow_width) < 0.0f ? -1.0f : 1.0f;
@ -362,7 +387,7 @@ std::vector<ExtrusionLine> check_extrusion_entity_stability(const ExtrusionEntit
}
} else if (curr_point.distance > flow_width * 0.8f) {
bridged_distance += line_len;
line_out.form_quality = nearest_prev_layer_line.form_quality - 0.3f;
line_out.form_quality = prev_layer_quality - 0.3f;
if (line_out.form_quality < 0 && bridged_distance > max_bridge_len) {
line_out.support_point_generated = potential_cause;
line_out.form_quality = 0.5f;
@ -373,7 +398,7 @@ std::vector<ExtrusionLine> check_extrusion_entity_stability(const ExtrusionEntit
}
line_out.curled_up_height = estimate_curled_up_height(curr_point, layer_region->layer()->height, flow_width,
nearest_prev_layer_line.curled_up_height, params);
prev_layer_curling, params);
lines_out.push_back(line_out);
}
@ -1082,6 +1107,7 @@ void estimate_supports_malformations(SupportLayerPtrs &layers, float flow_width,
ExtrusionLine line_out{i > 0 ? annotated_points[i - 1].position.cast<float>() : curr_point.position.cast<float>(),
curr_point.position.cast<float>(), line_len, extrusion};
auto [prev_layer_quality, prev_layer_curling] = get_bottom_extrusions_quality_and_curling(prev_layer_lines, curr_point);
const ExtrusionLine nearest_prev_layer_line = prev_layer_lines.get_lines().size() > 0 ?
prev_layer_lines.get_line(curr_point.nearest_prev_layer_line) :
ExtrusionLine{};
@ -1094,7 +1120,7 @@ void estimate_supports_malformations(SupportLayerPtrs &layers, float flow_width,
}
line_out.curled_up_height = estimate_curled_up_height(curr_point, l->height, flow_width,
nearest_prev_layer_line.curled_up_height, params);
prev_layer_curling, params);
current_layer_lines.push_back(line_out);
}
@ -1158,16 +1184,14 @@ void estimate_malformations(LayerPtrs &layers, const Params &params)
ExtrusionLine line_out{i > 0 ? annotated_points[i - 1].position.cast<float>() : curr_point.position.cast<float>(),
curr_point.position.cast<float>(), line_len, extrusion};
const ExtrusionLine nearest_prev_layer_line = prev_layer_lines.get_lines().size() > 0 ?
prev_layer_lines.get_line(curr_point.nearest_prev_layer_line) :
ExtrusionLine{};
auto [prev_layer_quality, prev_layer_curling] = get_bottom_extrusions_quality_and_curling(prev_layer_lines, curr_point);
float sign = (prev_layer_boundary.distance_from_lines<true>(curr_point.position) + 0.5f * flow_width) < 0.0f ? -1.0f :
1.0f;
curr_point.distance *= sign;
line_out.curled_up_height = estimate_curled_up_height(curr_point, layer_region->layer()->height, flow_width,
nearest_prev_layer_line.curled_up_height, params);
prev_layer_curling, params);
current_layer_lines.push_back(line_out);
}