mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-14 18:27:58 -06:00
Refactoring of EdgeGrid to accept an segment to segment visitor.
WIP: PolygonTrimmer to trim skirt & brim with polygons stored in EdgeGrid.
This commit is contained in:
parent
668a8cd2ea
commit
dc3a0a0ab3
6 changed files with 272 additions and 152 deletions
56
src/libslic3r/PolygonTrimmer.cpp
Normal file
56
src/libslic3r/PolygonTrimmer.cpp
Normal file
|
@ -0,0 +1,56 @@
|
|||
#include "PolygonTrimmer.hpp"
|
||||
#include "EdgeGrid.hpp"
|
||||
#include "Geometry.hpp"
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
TrimmedLoop trim_loop(const Polygon &loop, const EdgeGrid::Grid &grid)
|
||||
{
|
||||
assert(! loop.empty());
|
||||
assert(loop.size() >= 2);
|
||||
|
||||
TrimmedLoop out;
|
||||
|
||||
if (loop.size() >= 2) {
|
||||
size_t cnt = loop.points.size();
|
||||
|
||||
struct Visitor {
|
||||
Visitor(const EdgeGrid::Grid &grid, const Slic3r::Point *pt_prev, const Slic3r::Point *pt_this) : grid(grid), pt_prev(pt_prev), pt_this(pt_this) {}
|
||||
|
||||
void operator()(coord_t iy, coord_t ix) {
|
||||
// Called with a row and colum of the grid cell, which is intersected by a line.
|
||||
auto cell_data_range = grid.cell_data_range(iy, ix);
|
||||
for (auto it_contour_and_segment = cell_data_range.first; it_contour_and_segment != cell_data_range.second; ++ it_contour_and_segment) {
|
||||
// End points of the line segment and their vector.
|
||||
auto segment = grid.segment(*it_contour_and_segment);
|
||||
if (Geometry::segments_intersect(segment.first, segment.second, *pt_prev, *pt_this)) {
|
||||
// The two segments intersect. Add them to the output.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const EdgeGrid::Grid &grid;
|
||||
const Slic3r::Point *pt_this;
|
||||
const Slic3r::Point *pt_prev;
|
||||
} visitor(grid, &loop.points.back(), nullptr);
|
||||
|
||||
for (const Point &pt_this : loop.points) {
|
||||
visitor.pt_this = &pt_this;
|
||||
grid.visit_cells_intersecting_line(*visitor.pt_prev, pt_this, visitor);
|
||||
visitor.pt_prev = &pt_this;
|
||||
}
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
std::vector<TrimmedLoop> trim_loops(const Polygons &loops, const EdgeGrid::Grid &grid)
|
||||
{
|
||||
std::vector<TrimmedLoop> out;
|
||||
out.reserve(loops.size());
|
||||
for (const Polygon &loop : loops)
|
||||
out.emplace_back(trim_loop(loop, grid));
|
||||
return out;
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue