diff --git a/src/libslic3r/MTUtils.hpp b/src/libslic3r/MTUtils.hpp index 7e91ace32..ee70f535d 100644 --- a/src/libslic3r/MTUtils.hpp +++ b/src/libslic3r/MTUtils.hpp @@ -5,6 +5,9 @@ #include // for std::lock_guard #include // for std::function #include // for std::forward +#include +#include +#include namespace Slic3r { @@ -182,6 +185,57 @@ public: inline bool empty() const { return size() == 0; } }; +template +struct remove_cvref +{ + using type = + typename std::remove_cv::type>::type; +}; + +template +using remove_cvref_t = typename remove_cvref::type; + +template class C, class T> +class Container: public C> { +public: + explicit Container(size_t count, T&& initval): + C>(count, initval) {} +}; + +template using DefaultContainer = std::vector; + +/// Exactly like Matlab https://www.mathworks.com/help/matlab/ref/linspace.html +template class C = DefaultContainer> +inline C> linspace(const T &start, const T &stop, const I &n) +{ + Container vals(n, T()); + T stride = (stop - start) / n; + + size_t i = 0; + std::generate(vals.begin(), vals.end(), [&i, start, stride] { + return start + i++ * stride; + }); + + return vals; +} + +/// A set of equidistant values starting from 'start' (inclusive), ending +/// in the closest multiple of 'stride' less than or equal to 'end' and +/// leaving 'stride' space between each value. +/// Very similar to Matlab [start:stride:end] notation. +template class C = DefaultContainer> +inline C> grid(const T &start, const T &stop, const T &stride) +{ + Container vals(size_t(std::ceil((stop - start) / stride)), T()); + + int i = 0; + std::generate(vals.begin(), vals.end(), [&i, start, stride] { + return start + i++ * stride; + }); + + return vals; +} + } #endif // MTUTILS_HPP diff --git a/src/libslic3r/SLA/SLASupportTree.cpp b/src/libslic3r/SLA/SLASupportTree.cpp index c38ff34e1..cfb5c2e74 100644 --- a/src/libslic3r/SLA/SLASupportTree.cpp +++ b/src/libslic3r/SLA/SLASupportTree.cpp @@ -9,6 +9,7 @@ #include "SLASpatIndex.hpp" #include "SLABasePool.hpp" +#include #include #include @@ -559,7 +560,7 @@ struct Pad { Pad() = default; - Pad(const TriangleMesh& object_support_mesh, + Pad(const TriangleMesh& support_mesh, const ExPolygons& modelbase, double ground_level, const PoolConfig& pcfg) : @@ -576,9 +577,11 @@ struct Pad { // Get a sample for the pad from the support mesh { ExPolygons platetmp; - float plateZ = float(get_pad_fullheight(pcfg) + EPSILON); - base_plate(object_support_mesh, platetmp, plateZ, 0.1f, thr); + float zstart = float(zlevel); + float zend = zstart + float(get_pad_fullheight(pcfg) + EPSILON); + + base_plate(support_mesh, platetmp, grid(zstart, zend, 0.1f), thr); // We don't need no... holes control... for (const ExPolygon &bp : platetmp)