Skip to content

Commit

Permalink
adaptive elpehant foot compensation, fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
bubnikv committed Nov 1, 2019
1 parent f60fbec commit a72ac57
Show file tree
Hide file tree
Showing 16 changed files with 715 additions and 52 deletions.
2 changes: 2 additions & 0 deletions src/libslic3r/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ add_library(libslic3r STATIC
Config.hpp
EdgeGrid.cpp
EdgeGrid.hpp
ElephantFootCompensation.cpp
ElephantFootCompensation.hpp
ExPolygon.cpp
ExPolygon.hpp
ExPolygonCollection.cpp
Expand Down
16 changes: 16 additions & 0 deletions src/libslic3r/ClipperUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1060,6 +1060,22 @@ ClipperLib::Path mittered_offset_path_scaled(const Points &contour, const std::v
}
}

#if 0
{
ClipperLib::Path polytmp(out);
unscaleClipperPolygon(polytmp);
Slic3r::Polygon offsetted = ClipperPath_to_Slic3rPolygon(polytmp);
BoundingBox bbox = get_extents(contour);
bbox.merge(get_extents(offsetted));
static int iRun = 0;
SVG svg(debug_out_path("mittered_offset_path_scaled-%d.svg", iRun ++).c_str(), bbox);
svg.draw_outline(Polygon(contour), "blue", scale_(0.01));
svg.draw_outline(offsetted, "red", scale_(0.01));
svg.draw(contour, "blue", scale_(0.03));
svg.draw((Points)offsetted, "blue", scale_(0.03));
}
#endif

return out;
}

Expand Down
6 changes: 5 additions & 1 deletion src/libslic3r/EdgeGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,11 @@ void EdgeGrid::Grid::create_from_m_contours(coord_t resolution)
Visitor(std::vector<std::pair<size_t, size_t>> &cell_data, std::vector<Cell> &cells, size_t cols) :
cell_data(cell_data), cells(cells), cols(cols), i(0), j(0) {}

void operator()(coord_t iy, coord_t ix) { cell_data[cells[iy*cols + ix].end++] = std::pair<size_t, size_t>(i, j); }
inline bool operator()(coord_t iy, coord_t ix) {
cell_data[cells[iy*cols + ix].end++] = std::pair<size_t, size_t>(i, j);
// Continue traversing the grid along the edge.
return true;
}

std::vector<std::pair<size_t, size_t>> &cell_data;
std::vector<Cell> &cells;
Expand Down
19 changes: 12 additions & 7 deletions src/libslic3r/EdgeGrid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class Grid
void create(const ExPolygons &expolygons, coord_t resolution);
void create(const ExPolygonCollection &expolygons, coord_t resolution);

const std::vector<const Slic3r::Points*>& contours() const { return m_contours; }

#if 0
// Test, whether the edges inside the grid intersect with the polygons provided.
bool intersect(const MultiPoint &polyline, bool closed);
Expand Down Expand Up @@ -77,7 +79,7 @@ class Grid
std::vector<std::pair<ContourEdge, ContourEdge>> intersecting_edges() const;
bool has_intersecting_edges() const;

template<typename FUNCTION> void visit_cells_intersecting_line(Slic3r::Point p1, Slic3r::Point p2, FUNCTION func) const
template<typename VISITOR> void visit_cells_intersecting_line(Slic3r::Point p1, Slic3r::Point p2, VISITOR &visitor) const
{
// End points of the line segment.
p1(0) -= m_bbox.min(0);
Expand All @@ -94,8 +96,7 @@ class Grid
assert(ixb >= 0 && size_t(ixb) < m_cols);
assert(iyb >= 0 && size_t(iyb) < m_rows);
// Account for the end points.
func(iy, ix);
if (ix == ixb && iy == iyb)
if (! visitor(iy, ix) || (ix == ixb && iy == iyb))
// Both ends fall into the same cell.
return;
// Raster the centeral part of the line.
Expand Down Expand Up @@ -125,7 +126,8 @@ class Grid
ey = int64_t(dx) * m_resolution;
iy += 1;
}
func(iy, ix);
if (! visitor(iy, ix))
return;
} while (ix != ixb || iy != iyb);
}
else {
Expand All @@ -143,7 +145,8 @@ class Grid
ey = int64_t(dx) * m_resolution;
iy -= 1;
}
func(iy, ix);
if (! visitor(iy, ix))
return;
} while (ix != ixb || iy != iyb);
}
}
Expand All @@ -165,7 +168,8 @@ class Grid
ey = int64_t(dx) * m_resolution;
iy += 1;
}
func(iy, ix);
if (! visitor(iy, ix))
return;
} while (ix != ixb || iy != iyb);
}
else {
Expand Down Expand Up @@ -197,7 +201,8 @@ class Grid
ey = int64_t(dx) * m_resolution;
iy -= 1;
}
func(iy, ix);
if (! visitor(iy, ix))
return;
} while (ix != ixb || iy != iyb);
}
}
Expand Down
Loading

0 comments on commit a72ac57

Please sign in to comment.