From b67ad6434d1e5b1b54a13e83ceaef4141f9ad35f Mon Sep 17 00:00:00 2001 From: Vojtech Bubnik Date: Thu, 20 Apr 2023 14:30:52 +0200 Subject: [PATCH] Follow-up to 9cde96993e9f996b44f417570ba05455472efa08 use tbb::scallable_allocator for Polygons and ExPolygon::holes to better scale on multiple threads --- src/clipper/clipper.hpp | 2 +- src/libslic3r/Arachne/WallToolPaths.cpp | 2 +- src/libslic3r/ClipperUtils.hpp | 14 +++++++------- src/libslic3r/JumpPointSearch.cpp | 4 ++-- src/libslic3r/Point.hpp | 6 ++++-- src/libslic3r/Polygon.hpp | 6 +++--- src/libslic3r/SLA/Pad.hpp | 4 +++- src/libslic3r/SLA/SupportTree.hpp | 4 +--- src/libslic3r/ShortestPath.hpp | 4 +--- src/slic3r/GUI/GLModel.hpp | 2 +- src/slic3r/GUI/Jobs/ArrangeJob.cpp | 3 ++- tests/libslic3r/test_clipper_utils.cpp | 4 ++-- 12 files changed, 28 insertions(+), 27 deletions(-) diff --git a/src/clipper/clipper.hpp b/src/clipper/clipper.hpp index a2a6712b2..1d6361653 100644 --- a/src/clipper/clipper.hpp +++ b/src/clipper/clipper.hpp @@ -281,7 +281,7 @@ enum EdgeSide { esLeft = 1, esRight = 2}; OutPt *Prev; }; - using OutPts = std::vector>; + using OutPts = std::vector>; struct OutRec; struct Join { diff --git a/src/libslic3r/Arachne/WallToolPaths.cpp b/src/libslic3r/Arachne/WallToolPaths.cpp index dd2cda271..1c69fa9ac 100644 --- a/src/libslic3r/Arachne/WallToolPaths.cpp +++ b/src/libslic3r/Arachne/WallToolPaths.cpp @@ -341,7 +341,7 @@ void removeSmallAreas(Polygons &thiss, const double min_area_size, const bool re } } else { // For each polygon, computes the signed area, move small outlines at the end of the vector and keep pointer on small holes - std::vector small_holes; + Polygons small_holes; for (auto it = thiss.begin(); it < new_end;) { if (double area = ClipperLib::Area(to_path(*it)); fabs(area) < min_area_size) { if (area >= 0) { diff --git a/src/libslic3r/ClipperUtils.hpp b/src/libslic3r/ClipperUtils.hpp index 5f495788b..aaa06107d 100644 --- a/src/libslic3r/ClipperUtils.hpp +++ b/src/libslic3r/ClipperUtils.hpp @@ -133,21 +133,21 @@ namespace ClipperUtils { const std::vector &m_paths; }; - template + template class MultiPointsProvider { public: - MultiPointsProvider(const std::vector &multipoints) : m_multipoints(multipoints) {} + MultiPointsProvider(const MultiPointsType &multipoints) : m_multipoints(multipoints) {} struct iterator : public PathsProviderIteratorBase { public: - explicit iterator(typename std::vector::const_iterator it) : m_it(it) {} + explicit iterator(typename MultiPointsType::const_iterator it) : m_it(it) {} const Points& operator*() const { return m_it->points; } bool operator==(const iterator &rhs) const { return m_it == rhs.m_it; } bool operator!=(const iterator &rhs) const { return !(*this == rhs); } const Points& operator++(int) { return (m_it ++)->points; } iterator& operator++() { ++ m_it; return *this; } private: - typename std::vector::const_iterator m_it; + typename MultiPointsType::const_iterator m_it; }; iterator cbegin() const { return iterator(m_multipoints.begin()); } @@ -157,11 +157,11 @@ namespace ClipperUtils { size_t size() const { return m_multipoints.size(); } private: - const std::vector &m_multipoints; + const MultiPointsType &m_multipoints; }; - using PolygonsProvider = MultiPointsProvider; - using PolylinesProvider = MultiPointsProvider; + using PolygonsProvider = MultiPointsProvider; + using PolylinesProvider = MultiPointsProvider; struct ExPolygonProvider { ExPolygonProvider(const ExPolygon &expoly) : m_expoly(expoly) {} diff --git a/src/libslic3r/JumpPointSearch.cpp b/src/libslic3r/JumpPointSearch.cpp index 58a656fa0..722415632 100644 --- a/src/libslic3r/JumpPointSearch.cpp +++ b/src/libslic3r/JumpPointSearch.cpp @@ -269,7 +269,7 @@ Polyline JPSPathFinder::find_path(const Point &p0, const Point &p1) using QNode = astar::QNode>; std::unordered_map astar_cache{}; - std::vector> out_path; + std::vector> out_path; std::vector out_nodes; if (!astar::search_route(tracer, {start, {0, 0}}, std::back_inserter(out_nodes), astar_cache)) { @@ -308,7 +308,7 @@ Polyline JPSPathFinder::find_path(const Point &p0, const Point &p1) svg.draw(scaled_point(start), "green", scale_(0.4)); #endif - std::vector> tmp_path; + std::vector> tmp_path; tmp_path.reserve(out_path.size()); // Some path found, reverse and remove points that do not change direction std::reverse(out_path.begin(), out_path.end()); diff --git a/src/libslic3r/Point.hpp b/src/libslic3r/Point.hpp index 72c739395..b482129cf 100644 --- a/src/libslic3r/Point.hpp +++ b/src/libslic3r/Point.hpp @@ -52,7 +52,9 @@ using Vec2d = Eigen::Matrix; using Vec3d = Eigen::Matrix; using Vec4d = Eigen::Matrix; -using Points = std::vector>; +template +using PointsAllocator = tbb::scalable_allocator; +using Points = std::vector>; using PointPtrs = std::vector; using PointConstPtrs = std::vector; using Points3 = std::vector; @@ -60,7 +62,7 @@ using Pointfs = std::vector; using Vec2ds = std::vector; using Pointf3s = std::vector; -using VecOfPoints = std::vector>; +using VecOfPoints = std::vector>; using Matrix2f = Eigen::Matrix; using Matrix2d = Eigen::Matrix; diff --git a/src/libslic3r/Polygon.hpp b/src/libslic3r/Polygon.hpp index 24a2d69f3..bf4a087b0 100644 --- a/src/libslic3r/Polygon.hpp +++ b/src/libslic3r/Polygon.hpp @@ -12,9 +12,9 @@ namespace Slic3r { class Polygon; -using Polygons = std::vector; -using PolygonPtrs = std::vector; -using ConstPolygonPtrs = std::vector; +using Polygons = std::vector>; +using PolygonPtrs = std::vector>; +using ConstPolygonPtrs = std::vector>; // Returns true if inside. Returns border_result if on boundary. bool contains(const Polygon& polygon, const Point& p, bool border_result = true); diff --git a/src/libslic3r/SLA/Pad.hpp b/src/libslic3r/SLA/Pad.hpp index 0b6149557..da09343c4 100644 --- a/src/libslic3r/SLA/Pad.hpp +++ b/src/libslic3r/SLA/Pad.hpp @@ -6,6 +6,8 @@ #include #include +#include + struct indexed_triangle_set; namespace Slic3r { @@ -13,7 +15,7 @@ namespace Slic3r { class ExPolygon; class Polygon; using ExPolygons = std::vector; -using Polygons = std::vector; +using Polygons = std::vector>; namespace sla { diff --git a/src/libslic3r/SLA/SupportTree.hpp b/src/libslic3r/SLA/SupportTree.hpp index 53fb16f6e..83814d8c5 100644 --- a/src/libslic3r/SLA/SupportTree.hpp +++ b/src/libslic3r/SLA/SupportTree.hpp @@ -4,6 +4,7 @@ #include #include +#include #include #include @@ -14,9 +15,6 @@ namespace Slic3r { -using Polygons = std::vector; -using ExPolygons = std::vector; - namespace sla { struct SupportTreeConfig diff --git a/src/libslic3r/ShortestPath.hpp b/src/libslic3r/ShortestPath.hpp index 93259fee8..1781c5188 100644 --- a/src/libslic3r/ShortestPath.hpp +++ b/src/libslic3r/ShortestPath.hpp @@ -8,13 +8,11 @@ #include #include -#include - namespace Slic3r { namespace ClipperLib { class PolyNode; - using PolyNodes = std::vector>; + using PolyNodes = std::vector>; } class ExPolygon; diff --git a/src/slic3r/GUI/GLModel.hpp b/src/slic3r/GUI/GLModel.hpp index ef4ab6d47..fbf6ed533 100644 --- a/src/slic3r/GUI/GLModel.hpp +++ b/src/slic3r/GUI/GLModel.hpp @@ -14,7 +14,7 @@ namespace Slic3r { class TriangleMesh; class Polygon; -using Polygons = std::vector; +using Polygons = std::vector>; class BuildVolume; namespace GUI { diff --git a/src/slic3r/GUI/Jobs/ArrangeJob.cpp b/src/slic3r/GUI/Jobs/ArrangeJob.cpp index 8115136a5..870957018 100644 --- a/src/slic3r/GUI/Jobs/ArrangeJob.cpp +++ b/src/slic3r/GUI/Jobs/ArrangeJob.cpp @@ -183,7 +183,8 @@ static void update_arrangepoly_slaprint(arrangement::ArrangePolygon &ret, trafo_instance = trafo_instance * po.trafo().cast().inverse(); - auto polys = reserve_vector(3); + Polygons polys; + polys.reserve(3); auto zlvl = -po.get_elevation(); if (omesh) { diff --git a/tests/libslic3r/test_clipper_utils.cpp b/tests/libslic3r/test_clipper_utils.cpp index 775796ba7..1f3bc0fdc 100644 --- a/tests/libslic3r/test_clipper_utils.cpp +++ b/tests/libslic3r/test_clipper_utils.cpp @@ -308,8 +308,8 @@ SCENARIO("Various Clipper operations - t/clipper.t", "[ClipperUtils]") { } } -template -double polytree_area(const Tree &tree, std::vector

*out) +template +double polytree_area(const Tree &tree, std::vector *out) { traverse_pt(tree, out);