Fixing zero elevation bug when concave hull overlap was not detected.

Backported from tm_perf_optims
This commit is contained in:
tamasmeszaros 2019-07-30 14:24:42 +02:00
parent 7f33e23fbb
commit 320f964847
4 changed files with 32 additions and 10 deletions

View file

@ -320,6 +320,9 @@ using FloatingOnly = enable_if_t<std::is_floating_point<T>::value, O>;
template<class T, class O = T> template<class T, class O = T>
using ScaledCoordOnly = enable_if_t<is_scaled_coord<T>::value, O>; using ScaledCoordOnly = enable_if_t<is_scaled_coord<T>::value, O>;
template<class T, class O = T>
using IntegerOnly = enable_if_t<std::is_integral<T>::value, O>;
template<class T, class O = T> template<class T, class O = T>
using ArithmeticOnly = enable_if_t<std::is_arithmetic<T>::value, O>; using ArithmeticOnly = enable_if_t<std::is_arithmetic<T>::value, O>;
@ -384,6 +387,13 @@ unscaled(const Eigen::Matrix<Tin, N, EigenArgs...> &v) noexcept
return v.template cast<Tout>() * SCALING_FACTOR; return v.template cast<Tout>() * SCALING_FACTOR;
} }
template<class T> inline std::vector<T> reserve_vector(size_t capacity)
{
std::vector<T> ret;
ret.reserve(capacity);
return ret;
}
} // namespace Slic3r } // namespace Slic3r
#endif // MTUTILS_HPP #endif // MTUTILS_HPP

View file

@ -591,8 +591,7 @@ inline Point centroid(const Polygon& poly) {
/// with explicit bridges. Bridges are generated from each shape's centroid /// 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 /// to the center of the "scene" which is the centroid calculated from the shape
/// centroids (a star is created...) /// centroids (a star is created...)
Polygons concave_hull(const Polygons& polys, double max_dist_mm = 50, Polygons concave_hull(const Polygons& polys, double maxd_mm, ThrowOnCancel thr)
ThrowOnCancel throw_on_cancel = [](){})
{ {
namespace bgi = boost::geometry::index; namespace bgi = boost::geometry::index;
using SpatElement = std::pair<Point, unsigned>; using SpatElement = std::pair<Point, unsigned>;
@ -600,7 +599,7 @@ Polygons concave_hull(const Polygons& polys, double max_dist_mm = 50,
if(polys.empty()) return Polygons(); 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 Polygons punion = unify(polys); // could be redundant
@ -624,10 +623,10 @@ Polygons concave_hull(const Polygons& polys, double max_dist_mm = 50,
idx = 0; idx = 0;
std::transform(centroids.begin(), centroids.end(), std::transform(centroids.begin(), centroids.end(),
std::back_inserter(punion), std::back_inserter(punion),
[&centroids, &ctrindex, cc, max_dist, &idx, throw_on_cancel] [&centroids, &ctrindex, cc, max_dist, &idx, thr]
(const Point& c) (const Point& c)
{ {
throw_on_cancel(); thr();
double dx = x(c) - x(cc), dy = y(c) - y(cc); double dx = x(c) - x(cc), dy = y(c) - y(cc);
double l = std::sqrt(dx * dx + dy * dy); double l = std::sqrt(dx * dx + dy * dy);
double nx = dx / l, ny = dy / l; double nx = dx / l, ny = dy / l;

View file

@ -41,6 +41,9 @@ void breakstick_holes(ExPolygon &poly,
double stick_width, double stick_width,
double penetration = 0.0); double penetration = 0.0);
Polygons concave_hull(const Polygons& polys, double max_dist_mm = 50,
ThrowOnCancel throw_on_cancel = [](){});
struct PoolConfig { struct PoolConfig {
double min_wall_thickness_mm = 2; double min_wall_thickness_mm = 2;
double min_wall_height_mm = 5; double min_wall_height_mm = 5;

View file

@ -618,15 +618,25 @@ struct Pad {
} }
} }
ExPolygons concaveh = offset_ex(
concave_hull(basep, pcfg.max_merge_distance_mm, thr),
scaled<float>(pcfg.min_wall_thickness_mm));
// Punching the breaksticks across the offsetted polygon perimeters // Punching the breaksticks across the offsetted polygon perimeters
ExPolygons pad_stickholes; pad_stickholes.reserve(modelbase.size()); auto pad_stickholes = reserve_vector<ExPolygon>(modelbase.size());
for(auto& poly : modelbase_offs) { for(auto& poly : modelbase_offs) {
std::vector<BoxIndexEl> qres = bool overlap = false;
bindex.query(poly.contour.bounding_box(), for (const ExPolygon &p : concaveh)
BoxIndex::qtIntersects); overlap = overlap || poly.overlaps(p);
if (!qres.empty()) { auto bb = poly.contour.bounding_box();
bb.offset(scaled<float>(pcfg.min_wall_thickness_mm));
std::vector<BoxIndexEl> qres =
bindex.query(bb, BoxIndex::qtIntersects);
if (!qres.empty() || overlap) {
// The model silhouette polygon 'poly' HAS an intersection // The model silhouette polygon 'poly' HAS an intersection
// with the support silhouettes. Include this polygon // with the support silhouettes. Include this polygon