Clipper optimization:

1) Removed the already commented-out scaling / unscaling when doing
   "safe offsetting"
2) Removed some of the "safe offsetting" at calls where it never was used.
3) Reworked Clipper & ClipperUtils to pass Polygons / ExPolygons / Surfaces
   as input parameters without conversion to ClipperLib::Paths. This
   should save a lot of memory allocation and copying.
4) Reworked conversions from ClipperLib::Paths & PolyTree to Polygons /
   ExPolygons to use the move operator to avoid many unnecessary allocations.
5) Reworked some "union with safe ofsetting" to "offset_ex", which should
   be cheaper.
This commit is contained in:
Vojtech Bubnik 2021-04-30 11:49:57 +02:00
parent b327314b02
commit 9fbba855ef
15 changed files with 616 additions and 722 deletions

View file

@ -42,9 +42,10 @@ Point ConcaveHull::centroid(const Points &pp)
// As it shows, the current offset_ex in ClipperUtils hangs if used in jtRound
// mode
static ClipperLib::Paths fast_offset(const ClipperLib::Paths &paths,
coord_t delta,
ClipperLib::JoinType jointype)
template<typename PolygonsProvider>
static ClipperLib::Paths fast_offset(PolygonsProvider &&paths,
coord_t delta,
ClipperLib::JoinType jointype)
{
using ClipperLib::ClipperOffset;
using ClipperLib::etClosedPolygon;
@ -61,7 +62,7 @@ static ClipperLib::Paths fast_offset(const ClipperLib::Paths &paths,
return {};
}
offs.AddPaths(paths, jointype, etClosedPolygon);
offs.AddPaths(std::forward<PolygonsProvider>(paths), jointype, etClosedPolygon);
Paths result;
offs.Execute(result, static_cast<double>(delta));
@ -157,11 +158,9 @@ ExPolygons ConcaveHull::to_expolygons() const
ExPolygons offset_waffle_style_ex(const ConcaveHull &hull, coord_t delta)
{
ClipperLib::Paths paths = Slic3rMultiPoints_to_ClipperPaths(hull.polygons());
paths = fast_offset(paths, 2 * delta, ClipperLib::jtRound);
paths = fast_offset(paths, -delta, ClipperLib::jtRound);
ExPolygons ret = ClipperPaths_to_Slic3rExPolygons(paths);
for (ExPolygon &p : ret) p.holes = {};
ExPolygons ret = ClipperPaths_to_Slic3rExPolygons(
fast_offset(fast_offset(ClipperUtils::PolygonsProvider(hull.polygons()), 2 * delta, ClipperLib::jtRound), -delta, ClipperLib::jtRound));
for (ExPolygon &p : ret) p.holes.clear();
return ret;
}