use tbb::scallable_allocator for Polygons and ExPolygon::holes
to better scale on multiple threads
This commit is contained in:
Vojtech Bubnik 2023-04-20 14:30:52 +02:00
parent 9cde96993e
commit b67ad6434d
12 changed files with 28 additions and 27 deletions

View File

@ -281,7 +281,7 @@ enum EdgeSide { esLeft = 1, esRight = 2};
OutPt *Prev;
};
using OutPts = std::vector<OutPt, tbb::scalable_allocator<OutPt>>;
using OutPts = std::vector<OutPt, Allocator<OutPt>>;
struct OutRec;
struct Join {

View File

@ -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<Polygon> 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) {

View File

@ -133,21 +133,21 @@ namespace ClipperUtils {
const std::vector<PathType> &m_paths;
};
template<typename MultiPointType>
template<typename MultiPointsType>
class MultiPointsProvider {
public:
MultiPointsProvider(const std::vector<MultiPointType> &multipoints) : m_multipoints(multipoints) {}
MultiPointsProvider(const MultiPointsType &multipoints) : m_multipoints(multipoints) {}
struct iterator : public PathsProviderIteratorBase {
public:
explicit iterator(typename std::vector<MultiPointType>::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<MultiPointType>::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<MultiPointType> &m_multipoints;
const MultiPointsType &m_multipoints;
};
using PolygonsProvider = MultiPointsProvider<Polygon>;
using PolylinesProvider = MultiPointsProvider<Polyline>;
using PolygonsProvider = MultiPointsProvider<Polygons>;
using PolylinesProvider = MultiPointsProvider<Polylines>;
struct ExPolygonProvider {
ExPolygonProvider(const ExPolygon &expoly) : m_expoly(expoly) {}

View File

@ -269,7 +269,7 @@ Polyline JPSPathFinder::find_path(const Point &p0, const Point &p1)
using QNode = astar::QNode<JPSTracer<Pixel, decltype(cell_query)>>;
std::unordered_map<size_t, QNode> astar_cache{};
std::vector<Pixel, tbb::scalable_allocator<Pixel>> out_path;
std::vector<Pixel, PointsAllocator<Pixel>> out_path;
std::vector<decltype(tracer)::Node> 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<Pixel, tbb::scalable_allocator<Pixel>> tmp_path;
std::vector<Pixel, PointsAllocator<Pixel>> 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());

View File

@ -52,7 +52,9 @@ using Vec2d = Eigen::Matrix<double, 2, 1, Eigen::DontAlign>;
using Vec3d = Eigen::Matrix<double, 3, 1, Eigen::DontAlign>;
using Vec4d = Eigen::Matrix<double, 4, 1, Eigen::DontAlign>;
using Points = std::vector<Point, tbb::scalable_allocator<Point>>;
template<typename BaseType>
using PointsAllocator = tbb::scalable_allocator<BaseType>;
using Points = std::vector<Point, PointsAllocator<Point>>;
using PointPtrs = std::vector<Point*>;
using PointConstPtrs = std::vector<const Point*>;
using Points3 = std::vector<Vec3crd>;
@ -60,7 +62,7 @@ using Pointfs = std::vector<Vec2d>;
using Vec2ds = std::vector<Vec2d>;
using Pointf3s = std::vector<Vec3d>;
using VecOfPoints = std::vector<Points, tbb::scalable_allocator<Points>>;
using VecOfPoints = std::vector<Points, PointsAllocator<Points>>;
using Matrix2f = Eigen::Matrix<float, 2, 2, Eigen::DontAlign>;
using Matrix2d = Eigen::Matrix<double, 2, 2, Eigen::DontAlign>;

View File

@ -12,9 +12,9 @@
namespace Slic3r {
class Polygon;
using Polygons = std::vector<Polygon>;
using PolygonPtrs = std::vector<Polygon*>;
using ConstPolygonPtrs = std::vector<const Polygon*>;
using Polygons = std::vector<Polygon, PointsAllocator<Polygon>>;
using PolygonPtrs = std::vector<Polygon*, PointsAllocator<Polygon*>>;
using ConstPolygonPtrs = std::vector<const Polygon*, PointsAllocator<const Polygon*>>;
// Returns true if inside. Returns border_result if on boundary.
bool contains(const Polygon& polygon, const Point& p, bool border_result = true);

View File

@ -6,6 +6,8 @@
#include <cmath>
#include <string>
#include <libslic3r/Point.hpp>
struct indexed_triangle_set;
namespace Slic3r {
@ -13,7 +15,7 @@ namespace Slic3r {
class ExPolygon;
class Polygon;
using ExPolygons = std::vector<ExPolygon>;
using Polygons = std::vector<Polygon>;
using Polygons = std::vector<Polygon, PointsAllocator<Polygon>>;
namespace sla {

View File

@ -4,6 +4,7 @@
#include <vector>
#include <memory>
#include <libslic3r/Polygon.hpp>
#include <libslic3r/ExPolygon.hpp>
#include <libslic3r/AABBMesh.hpp>
@ -14,9 +15,6 @@
namespace Slic3r {
using Polygons = std::vector<Polygon>;
using ExPolygons = std::vector<ExPolygon>;
namespace sla {
struct SupportTreeConfig

View File

@ -8,13 +8,11 @@
#include <utility>
#include <vector>
#include <oneapi/tbb/scalable_allocator.h>
namespace Slic3r {
namespace ClipperLib {
class PolyNode;
using PolyNodes = std::vector<PolyNode*, tbb::scalable_allocator<PolyNode*>>;
using PolyNodes = std::vector<PolyNode*, PointsAllocator<PolyNode*>>;
}
class ExPolygon;

View File

@ -14,7 +14,7 @@ namespace Slic3r {
class TriangleMesh;
class Polygon;
using Polygons = std::vector<Polygon>;
using Polygons = std::vector<Polygon, PointsAllocator<Polygon>>;
class BuildVolume;
namespace GUI {

View File

@ -183,7 +183,8 @@ static void update_arrangepoly_slaprint(arrangement::ArrangePolygon &ret,
trafo_instance = trafo_instance * po.trafo().cast<float>().inverse();
auto polys = reserve_vector<Polygon>(3);
Polygons polys;
polys.reserve(3);
auto zlvl = -po.get_elevation();
if (omesh) {

View File

@ -308,8 +308,8 @@ SCENARIO("Various Clipper operations - t/clipper.t", "[ClipperUtils]") {
}
}
template<e_ordering o = e_ordering::OFF, class P, class Tree>
double polytree_area(const Tree &tree, std::vector<P> *out)
template<e_ordering o = e_ordering::OFF, class P, class P_Alloc, class Tree>
double polytree_area(const Tree &tree, std::vector<P, P_Alloc> *out)
{
traverse_pt<o>(tree, out);