mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-12-10 15:28:45 -07:00
Prototype 1 - slowdown extended to detect curled edges and further reduce speed
First prototype of the code submitted.
This commit is contained in:
parent
19ca3ee715
commit
a2ac701645
3 changed files with 58 additions and 8 deletions
|
|
@ -234,6 +234,7 @@ namespace AABBTreeLines {
|
||||||
return found_lines;
|
return found_lines;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// return 1 if true, -1 if false, 0 for point on contour (or if cannot be determined)
|
// return 1 if true, -1 if false, 0 for point on contour (or if cannot be determined)
|
||||||
template <typename LineType, typename TreeType, typename VectorType>
|
template <typename LineType, typename TreeType, typename VectorType>
|
||||||
inline int point_outside_closed_contours(const std::vector<LineType>& lines, const TreeType& tree, const VectorType& point)
|
inline int point_outside_closed_contours(const std::vector<LineType>& lines, const TreeType& tree, const VectorType& point)
|
||||||
|
|
@ -352,7 +353,7 @@ namespace AABBTreeLines {
|
||||||
|
|
||||||
std::vector<size_t> all_lines_in_radius(const Vec<2, typename LineType::Scalar>& point, Floating radius)
|
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 cast<Floating>()
|
||||||
}
|
}
|
||||||
|
|
||||||
template <bool sorted>
|
template <bool sorted>
|
||||||
|
|
|
||||||
|
|
@ -272,6 +272,7 @@ public:
|
||||||
{
|
{
|
||||||
size_t speed_sections_count = std::min(overlaps.values.size(), speeds.values.size());
|
size_t speed_sections_count = std::min(overlaps.values.size(), speeds.values.size());
|
||||||
std::vector<std::pair<float, float>> speed_sections;
|
std::vector<std::pair<float, float>> speed_sections;
|
||||||
|
|
||||||
for (size_t i = 0; i < speed_sections_count; i++) {
|
for (size_t i = 0; i < speed_sections_count; i++) {
|
||||||
float distance = path.width * (1.0 - (overlaps.get_at(i) / 100.0));
|
float distance = path.width * (1.0 - (overlaps.get_at(i) / 100.0));
|
||||||
float speed = speeds.get_at(i).percent ? (ext_perimeter_speed * speeds.get_at(i).value / 100.0) : speeds.get_at(i).value;
|
float speed = speeds.get_at(i).percent ? (ext_perimeter_speed * speeds.get_at(i).value / 100.0) : speeds.get_at(i).value;
|
||||||
|
|
@ -302,6 +303,54 @@ public:
|
||||||
const ExtendedPoint &curr = extended_points[i];
|
const ExtendedPoint &curr = extended_points[i];
|
||||||
const ExtendedPoint &next = extended_points[i + 1 < extended_points.size() ? i + 1 : i];
|
const ExtendedPoint &next = extended_points[i + 1 < extended_points.size() ? i + 1 : i];
|
||||||
|
|
||||||
|
// The following code artifically increases the distance to provide slowdown for extrusions that are over curled lines
|
||||||
|
float artificial_distance_to_curled_lines = 0.0;
|
||||||
|
const double dist_limit = 10.0 * path.width;
|
||||||
|
{
|
||||||
|
Vec2d middle = 0.5 * (curr.position + next.position);
|
||||||
|
auto line_indices = prev_curled_extrusions[current_object].all_lines_in_radius(Point::new_scale(middle), scale_(dist_limit));
|
||||||
|
if (!line_indices.empty()) {
|
||||||
|
double len = (next.position - curr.position).norm();
|
||||||
|
// For long lines, there is a problem with the additional slowdown. If by accident, there is small curled line near the middle of this long line
|
||||||
|
// The whole segment gets slower unnecesarily. For these long lines, we do additional check whether it is worth slowing down.
|
||||||
|
// NOTE that this is still quite rough approximation, e.g. we are still checking lines only near the middle point
|
||||||
|
// TODO maybe split the lines into smaller segments before running this alg? but can be demanding, and GCode will be huge
|
||||||
|
if (len > 8) {
|
||||||
|
Vec2d dir = Vec2d(next.position - curr.position) / len;
|
||||||
|
Vec2d right = Vec2d(-dir.y(), dir.x());
|
||||||
|
|
||||||
|
Polygon box_of_influence = {
|
||||||
|
scaled(Vec2d(curr.position + right * dist_limit)),
|
||||||
|
scaled(Vec2d(next.position + right * dist_limit)),
|
||||||
|
scaled(Vec2d(next.position - right * dist_limit)),
|
||||||
|
scaled(Vec2d(curr.position - right * dist_limit)),
|
||||||
|
};
|
||||||
|
|
||||||
|
double projected_lengths_sum = 0;
|
||||||
|
for (size_t idx : line_indices) {
|
||||||
|
const CurledLine &line = prev_curled_extrusions[current_object].get_line(idx);
|
||||||
|
Lines inside = intersection_ln({{line.a, line.b}}, {box_of_influence});
|
||||||
|
if (inside.empty())
|
||||||
|
continue;
|
||||||
|
double projected_length = abs(dir.dot(unscaled(Vec2d((inside.back().b - inside.back().a).cast<double>()))));
|
||||||
|
projected_lengths_sum += projected_length;
|
||||||
|
}
|
||||||
|
if (projected_lengths_sum < 0.4 * len) {
|
||||||
|
line_indices.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t idx : line_indices) {
|
||||||
|
const CurledLine &line = prev_curled_extrusions[current_object].get_line(idx);
|
||||||
|
float distance_from_curled = unscaled(line_alg::distance_to(line, Point::new_scale(middle)));
|
||||||
|
float dist = path.width * (1.0 - (distance_from_curled / dist_limit)) *
|
||||||
|
(1.0 - (distance_from_curled / dist_limit)) *
|
||||||
|
(line.curled_height / (path.height * 10.0f)); // max_curled_height_factor from SupportSpotGenerator
|
||||||
|
artificial_distance_to_curled_lines = std::max(artificial_distance_to_curled_lines, dist);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
auto calculate_speed = [&speed_sections, &original_speed](float distance) {
|
auto calculate_speed = [&speed_sections, &original_speed](float distance) {
|
||||||
float final_speed;
|
float final_speed;
|
||||||
if (distance <= speed_sections.front().first) {
|
if (distance <= speed_sections.front().first) {
|
||||||
|
|
@ -321,9 +370,13 @@ public:
|
||||||
return final_speed;
|
return final_speed;
|
||||||
};
|
};
|
||||||
|
|
||||||
float extrusion_speed = std::min(calculate_speed(curr.distance), calculate_speed(next.distance));
|
float old_extrusion_speed = std::min(calculate_speed(curr.distance), calculate_speed(next.distance));
|
||||||
|
float extrusion_speed = std::min(calculate_speed(curr.distance+artificial_distance_to_curled_lines), calculate_speed(next.distance+artificial_distance_to_curled_lines));
|
||||||
float overlap = std::min(1 - curr.distance * width_inv, 1 - next.distance * width_inv);
|
float overlap = std::min(1 - curr.distance * width_inv, 1 - next.distance * width_inv);
|
||||||
|
|
||||||
|
if(artificial_distance_to_curled_lines>0 ) printf("Found curls\n"); // Temporary debug messages
|
||||||
|
if(old_extrusion_speed>extrusion_speed ) printf("Reduced speed. Original: %f, New: %f\n",old_extrusion_speed,extrusion_speed); // Temporary debug messages
|
||||||
|
|
||||||
processed_points.push_back({ scaled(curr.position), extrusion_speed, overlap });
|
processed_points.push_back({ scaled(curr.position), extrusion_speed, overlap });
|
||||||
}
|
}
|
||||||
return processed_points;
|
return processed_points;
|
||||||
|
|
|
||||||
|
|
@ -175,7 +175,6 @@ void estimate_malformations(LayerPtrs &layers, const Params ¶ms)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const ExtrusionLine &line : current_layer_lines) {
|
for (const ExtrusionLine &line : current_layer_lines) {
|
||||||
if (line.curled_up_height > params.curling_tolerance_limit) {
|
if (line.curled_up_height > params.curling_tolerance_limit) {
|
||||||
l->curled_lines.push_back(CurledLine{Point::new_scale(line.a), Point::new_scale(line.b), line.curled_up_height});
|
l->curled_lines.push_back(CurledLine{Point::new_scale(line.a), Point::new_scale(line.b), line.curled_up_height});
|
||||||
|
|
@ -184,9 +183,6 @@ void estimate_malformations(LayerPtrs &layers, const Params ¶ms)
|
||||||
|
|
||||||
prev_layer_lines = LD{current_layer_lines};
|
prev_layer_lines = LD{current_layer_lines};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue