From 320f964847a45c785fcf2f727380b7b830809eb5 Mon Sep 17 00:00:00 2001 From: tamasmeszaros Date: Tue, 30 Jul 2019 14:24:42 +0200 Subject: [PATCH] Fixing zero elevation bug when concave hull overlap was not detected. Backported from tm_perf_optims --- src/libslic3r/MTUtils.hpp | 10 ++++++++++ src/libslic3r/SLA/SLABasePool.cpp | 9 ++++----- src/libslic3r/SLA/SLABasePool.hpp | 3 +++ src/libslic3r/SLA/SLASupportTree.cpp | 20 +++++++++++++++----- 4 files changed, 32 insertions(+), 10 deletions(-) diff --git a/src/libslic3r/MTUtils.hpp b/src/libslic3r/MTUtils.hpp index 1fef4b475..212752883 100644 --- a/src/libslic3r/MTUtils.hpp +++ b/src/libslic3r/MTUtils.hpp @@ -320,6 +320,9 @@ using FloatingOnly = enable_if_t::value, O>; template using ScaledCoordOnly = enable_if_t::value, O>; +template +using IntegerOnly = enable_if_t::value, O>; + template using ArithmeticOnly = enable_if_t::value, O>; @@ -384,6 +387,13 @@ unscaled(const Eigen::Matrix &v) noexcept return v.template cast() * SCALING_FACTOR; } +template inline std::vector reserve_vector(size_t capacity) +{ + std::vector ret; + ret.reserve(capacity); + return ret; +} + } // namespace Slic3r #endif // MTUTILS_HPP diff --git a/src/libslic3r/SLA/SLABasePool.cpp b/src/libslic3r/SLA/SLABasePool.cpp index 4ce84ba02..53dfef404 100644 --- a/src/libslic3r/SLA/SLABasePool.cpp +++ b/src/libslic3r/SLA/SLABasePool.cpp @@ -591,8 +591,7 @@ inline Point centroid(const Polygon& poly) { /// with explicit bridges. Bridges are generated from each shape's centroid /// to the center of the "scene" which is the centroid calculated from the shape /// centroids (a star is created...) -Polygons concave_hull(const Polygons& polys, double max_dist_mm = 50, - ThrowOnCancel throw_on_cancel = [](){}) +Polygons concave_hull(const Polygons& polys, double maxd_mm, ThrowOnCancel thr) { namespace bgi = boost::geometry::index; using SpatElement = std::pair; @@ -600,7 +599,7 @@ Polygons concave_hull(const Polygons& polys, double max_dist_mm = 50, if(polys.empty()) return Polygons(); - const double max_dist = scaled(max_dist_mm); + const double max_dist = scaled(maxd_mm); Polygons punion = unify(polys); // could be redundant @@ -624,10 +623,10 @@ Polygons concave_hull(const Polygons& polys, double max_dist_mm = 50, idx = 0; std::transform(centroids.begin(), centroids.end(), std::back_inserter(punion), - [¢roids, &ctrindex, cc, max_dist, &idx, throw_on_cancel] + [¢roids, &ctrindex, cc, max_dist, &idx, thr] (const Point& c) { - throw_on_cancel(); + thr(); double dx = x(c) - x(cc), dy = y(c) - y(cc); double l = std::sqrt(dx * dx + dy * dy); double nx = dx / l, ny = dy / l; diff --git a/src/libslic3r/SLA/SLABasePool.hpp b/src/libslic3r/SLA/SLABasePool.hpp index 67b9ccdcb..eec426bbf 100644 --- a/src/libslic3r/SLA/SLABasePool.hpp +++ b/src/libslic3r/SLA/SLABasePool.hpp @@ -41,6 +41,9 @@ void breakstick_holes(ExPolygon &poly, double stick_width, double penetration = 0.0); +Polygons concave_hull(const Polygons& polys, double max_dist_mm = 50, + ThrowOnCancel throw_on_cancel = [](){}); + struct PoolConfig { double min_wall_thickness_mm = 2; double min_wall_height_mm = 5; diff --git a/src/libslic3r/SLA/SLASupportTree.cpp b/src/libslic3r/SLA/SLASupportTree.cpp index 4751dad6c..d89836cb9 100644 --- a/src/libslic3r/SLA/SLASupportTree.cpp +++ b/src/libslic3r/SLA/SLASupportTree.cpp @@ -618,15 +618,25 @@ struct Pad { } } + ExPolygons concaveh = offset_ex( + concave_hull(basep, pcfg.max_merge_distance_mm, thr), + scaled(pcfg.min_wall_thickness_mm)); + // Punching the breaksticks across the offsetted polygon perimeters - ExPolygons pad_stickholes; pad_stickholes.reserve(modelbase.size()); + auto pad_stickholes = reserve_vector(modelbase.size()); for(auto& poly : modelbase_offs) { + bool overlap = false; + for (const ExPolygon &p : concaveh) + overlap = overlap || poly.overlaps(p); + + auto bb = poly.contour.bounding_box(); + bb.offset(scaled(pcfg.min_wall_thickness_mm)); + std::vector qres = - bindex.query(poly.contour.bounding_box(), - BoxIndex::qtIntersects); - - if (!qres.empty()) { + bindex.query(bb, BoxIndex::qtIntersects); + + if (!qres.empty() || overlap) { // The model silhouette polygon 'poly' HAS an intersection // with the support silhouettes. Include this polygon