Fix path sorting

This commit is contained in:
Pavel Mikus 2023-04-25 18:30:52 +02:00 committed by Pavel Mikuš
parent ebbbb1505c
commit aa85d050fe
3 changed files with 118 additions and 142 deletions

View file

@ -4,6 +4,7 @@
#include "AABBTreeLines.hpp"
#include "Algorithm/PathSorting.hpp"
#include "BoundingBox.hpp"
#include "ExPolygon.hpp"
#include "FillEnsuring.hpp"
#include "KDTreeIndirect.hpp"
@ -322,14 +323,14 @@ ThickPolylines FillEnsuring::fill_surface_arachne(const Surface *surface, const
}
// gaps_for_additional_filling = opening_ex(gaps_for_additional_filling, 0.3 * scaled_spacing);
// BoundingBox bbox = get_extents(filled_area);
// bbox.offset(scale_(1.));
// ::Slic3r::SVG svg(debug_out_path(("surface" + std::to_string(surface->area())).c_str()).c_str(), bbox);
// svg.draw(to_lines(filled_area), "red", scale_(0.4));
// svg.draw(to_lines(reconstructed_area), "blue", scale_(0.3));
// svg.draw(to_lines(gaps_for_additional_filling), "green", scale_(0.2));
// svg.draw(vertical_lines, "black", scale_(0.1));
// svg.Close();
BoundingBox bbox = get_extents(filled_area);
bbox.offset(scale_(1.));
::Slic3r::SVG svg(debug_out_path(("surface" + std::to_string(surface->area())).c_str()).c_str(), bbox);
svg.draw(to_lines(filled_area), "red", scale_(0.4));
svg.draw(to_lines(reconstructed_area), "blue", scale_(0.3));
svg.draw(to_lines(gaps_for_additional_filling), "green", scale_(0.2));
svg.draw(vertical_lines, "black", scale_(0.1));
svg.Close();
for (ExPolygon &ex_poly : gaps_for_additional_filling) {
Point bbox_size = ex_poly.contour.bounding_box().size();
@ -447,8 +448,6 @@ ThickPolylines FillEnsuring::fill_surface_arachne(const Surface *surface, const
}
}
rotate_thick_polylines(thick_polylines_out, cos(-aligning_angle), sin(-aligning_angle));
thick_polylines_out.erase(std::remove_if(thick_polylines_out.begin(), thick_polylines_out.end(),
[scaled_spacing](const ThickPolyline &tp) {
return tp.length() < scaled_spacing &&
@ -457,17 +456,22 @@ ThickPolylines FillEnsuring::fill_surface_arachne(const Surface *surface, const
}),
thick_polylines_out.end());
Algorithm::sort_paths(thick_polylines_out.begin(), thick_polylines_out.end(), thick_polylines_out.begin(), scaled_spacing * 2,
[](const ThickPolyline &tp) {
Lines ls;
Point prev = tp.first_point();
for (size_t i = 1; i < tp.points.size(); i++) {
ls.emplace_back(prev, tp.points[i]);
prev = ls.back().b;
}
return ls;
});
std::sort(thick_polylines_out.begin(), thick_polylines_out.end(), [](const ThickPolyline &left, const ThickPolyline &right) {
return BoundingBox(left.points).min.x() < BoundingBox(right.points).min.x();
});
Algorithm::sort_paths(thick_polylines_out.begin(), thick_polylines_out.end(), bb.min, scaled_spacing * 1.2, [](const ThickPolyline
&tp) {
Lines ls;
Point prev = tp.first_point();
for (size_t i = 1; i < tp.points.size(); i++) {
ls.emplace_back(prev, tp.points[i]);
prev = ls.back().b;
}
return ls;
});
rotate_thick_polylines(thick_polylines_out, cos(-aligning_angle), sin(-aligning_angle));
return thick_polylines_out;
}