Fixed missing layers of Lightning infill.

This commit is contained in:
Lukáš Hejl 2022-04-29 08:08:10 +02:00
parent 8d0dd13144
commit dfb7fbbd10
3 changed files with 16 additions and 33 deletions

View File

@ -6,6 +6,7 @@
#include "DistanceField.hpp"
#include "TreeNode.hpp"
#include "../../ClipperUtils.hpp"
#include "../../Geometry.hpp"
#include "Utils.hpp"
@ -271,6 +272,7 @@ void Layer::reconnectRoots
}
}
#if 0
/*!
* Moves the point \p from onto the nearest polygon or leaves the point as-is, when the comb boundary is not within the root of \p max_dist2 distance.
* Given a \p distance more than zero, the point will end up inside, and conversely outside.
@ -398,6 +400,7 @@ static unsigned int moveInside(const Polygons& polygons, Point& from, int distan
}
return static_cast<unsigned int>(-1);
}
#endif
// Returns 'added someting'.
Polylines Layer::convertToLines(const Polygons& limit_to_outline, const coord_t line_width) const
@ -405,31 +408,11 @@ Polylines Layer::convertToLines(const Polygons& limit_to_outline, const coord_t
if (tree_roots.empty())
return {};
Polygons result_lines;
for (const auto& tree : tree_roots) {
// If even the furthest location in the tree is inside the polygon, the entire tree must be inside of the polygon.
// (Don't take the root as that may be on the edge and cause rounding errors to register as 'outside'.)
constexpr coord_t epsilon = 5;
Point should_be_inside = tree->getLocation();
moveInside(limit_to_outline, should_be_inside, epsilon, epsilon * epsilon);
if (inside(limit_to_outline, should_be_inside))
tree->convertToPolylines(result_lines, line_width);
}
Polylines result_lines;
for (const auto &tree : tree_roots)
tree->convertToPolylines(result_lines, line_width);
// TODO: allow for polylines!
Polylines split_lines;
for (Polygon &line : result_lines) {
if (line.size() <= 1)
continue;
Point last = line[0];
for (size_t point_idx = 1; point_idx < line.size(); point_idx++) {
Point here = line[point_idx];
split_lines.push_back({ last, here });
last = here;
}
}
return split_lines;
return intersection_pl(result_lines, limit_to_outline);
}
} // namespace Slic3r::Lightning

View File

@ -343,16 +343,16 @@ coord_t Node::prune(const coord_t& pruning_distance)
return max_distance_pruned;
}
void Node::convertToPolylines(Polygons& output, const coord_t line_width) const
void Node::convertToPolylines(Polylines &output, const coord_t line_width) const
{
Polygons result;
Polylines result;
result.emplace_back();
convertToPolylines(0, result);
removeJunctionOverlap(result, line_width);
append(output, std::move(result));
}
void Node::convertToPolylines(size_t long_line_idx, Polygons& output) const
void Node::convertToPolylines(size_t long_line_idx, Polylines &output) const
{
if (m_children.empty()) {
output[long_line_idx].points.push_back(m_p);
@ -372,12 +372,12 @@ void Node::convertToPolylines(size_t long_line_idx, Polygons& output) const
}
}
void Node::removeJunctionOverlap(Polygons& result_lines, const coord_t line_width) const
void Node::removeJunctionOverlap(Polylines &result_lines, const coord_t line_width) const
{
const coord_t reduction = line_width / 2; // TODO make configurable?
size_t res_line_idx = 0;
while (res_line_idx < result_lines.size()) {
Polygon &polyline = result_lines[res_line_idx];
Polyline &polyline = result_lines[res_line_idx];
if (polyline.size() <= 1) {
polyline = std::move(result_lines.back());
result_lines.pop_back();
@ -387,7 +387,7 @@ void Node::removeJunctionOverlap(Polygons& result_lines, const coord_t line_widt
coord_t to_be_reduced = reduction;
Point a = polyline.back();
for (int point_idx = int(polyline.size()) - 2; point_idx >= 0; point_idx--) {
const Point b = polyline[point_idx];
const Point b = polyline.points[point_idx];
const Point ab = b - a;
const auto ab_len = coord_t(ab.cast<double>().norm());
if (ab_len >= to_be_reduced) {

View File

@ -239,7 +239,7 @@ public:
*
* \param output all branches in this tree connected into polylines
*/
void convertToPolylines(Polygons& output, coord_t line_width) const;
void convertToPolylines(Polylines &output, coord_t line_width) const;
/*! If this was ever a direct child of the root, it'll have a previous grounding location.
*
@ -258,9 +258,9 @@ protected:
* \param long_line a reference to a polyline in \p output which to continue building on in the recursion
* \param output all branches in this tree connected into polylines
*/
void convertToPolylines(size_t long_line_idx, Polygons& output) const;
void convertToPolylines(size_t long_line_idx, Polylines &output) const;
void removeJunctionOverlap(Polygons& polylines, coord_t line_width) const;
void removeJunctionOverlap(Polylines &polylines, coord_t line_width) const;
bool m_is_root;
Point m_p;