Follow-up to 9cde96993e
use tbb::scallable_allocator for Polygons and ExPolygon::holes to better scale on multiple threads
This commit is contained in:
parent
9cde96993e
commit
b67ad6434d
@ -281,7 +281,7 @@ enum EdgeSide { esLeft = 1, esRight = 2};
|
|||||||
OutPt *Prev;
|
OutPt *Prev;
|
||||||
};
|
};
|
||||||
|
|
||||||
using OutPts = std::vector<OutPt, tbb::scalable_allocator<OutPt>>;
|
using OutPts = std::vector<OutPt, Allocator<OutPt>>;
|
||||||
|
|
||||||
struct OutRec;
|
struct OutRec;
|
||||||
struct Join {
|
struct Join {
|
||||||
|
@ -341,7 +341,7 @@ void removeSmallAreas(Polygons &thiss, const double min_area_size, const bool re
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// For each polygon, computes the signed area, move small outlines at the end of the vector and keep pointer on small holes
|
// 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;) {
|
for (auto it = thiss.begin(); it < new_end;) {
|
||||||
if (double area = ClipperLib::Area(to_path(*it)); fabs(area) < min_area_size) {
|
if (double area = ClipperLib::Area(to_path(*it)); fabs(area) < min_area_size) {
|
||||||
if (area >= 0) {
|
if (area >= 0) {
|
||||||
|
@ -133,21 +133,21 @@ namespace ClipperUtils {
|
|||||||
const std::vector<PathType> &m_paths;
|
const std::vector<PathType> &m_paths;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename MultiPointType>
|
template<typename MultiPointsType>
|
||||||
class MultiPointsProvider {
|
class MultiPointsProvider {
|
||||||
public:
|
public:
|
||||||
MultiPointsProvider(const std::vector<MultiPointType> &multipoints) : m_multipoints(multipoints) {}
|
MultiPointsProvider(const MultiPointsType &multipoints) : m_multipoints(multipoints) {}
|
||||||
|
|
||||||
struct iterator : public PathsProviderIteratorBase {
|
struct iterator : public PathsProviderIteratorBase {
|
||||||
public:
|
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; }
|
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 m_it == rhs.m_it; }
|
||||||
bool operator!=(const iterator &rhs) const { return !(*this == rhs); }
|
bool operator!=(const iterator &rhs) const { return !(*this == rhs); }
|
||||||
const Points& operator++(int) { return (m_it ++)->points; }
|
const Points& operator++(int) { return (m_it ++)->points; }
|
||||||
iterator& operator++() { ++ m_it; return *this; }
|
iterator& operator++() { ++ m_it; return *this; }
|
||||||
private:
|
private:
|
||||||
typename std::vector<MultiPointType>::const_iterator m_it;
|
typename MultiPointsType::const_iterator m_it;
|
||||||
};
|
};
|
||||||
|
|
||||||
iterator cbegin() const { return iterator(m_multipoints.begin()); }
|
iterator cbegin() const { return iterator(m_multipoints.begin()); }
|
||||||
@ -157,11 +157,11 @@ namespace ClipperUtils {
|
|||||||
size_t size() const { return m_multipoints.size(); }
|
size_t size() const { return m_multipoints.size(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const std::vector<MultiPointType> &m_multipoints;
|
const MultiPointsType &m_multipoints;
|
||||||
};
|
};
|
||||||
|
|
||||||
using PolygonsProvider = MultiPointsProvider<Polygon>;
|
using PolygonsProvider = MultiPointsProvider<Polygons>;
|
||||||
using PolylinesProvider = MultiPointsProvider<Polyline>;
|
using PolylinesProvider = MultiPointsProvider<Polylines>;
|
||||||
|
|
||||||
struct ExPolygonProvider {
|
struct ExPolygonProvider {
|
||||||
ExPolygonProvider(const ExPolygon &expoly) : m_expoly(expoly) {}
|
ExPolygonProvider(const ExPolygon &expoly) : m_expoly(expoly) {}
|
||||||
|
@ -269,7 +269,7 @@ Polyline JPSPathFinder::find_path(const Point &p0, const Point &p1)
|
|||||||
using QNode = astar::QNode<JPSTracer<Pixel, decltype(cell_query)>>;
|
using QNode = astar::QNode<JPSTracer<Pixel, decltype(cell_query)>>;
|
||||||
|
|
||||||
std::unordered_map<size_t, QNode> astar_cache{};
|
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;
|
std::vector<decltype(tracer)::Node> out_nodes;
|
||||||
|
|
||||||
if (!astar::search_route(tracer, {start, {0, 0}}, std::back_inserter(out_nodes), astar_cache)) {
|
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));
|
svg.draw(scaled_point(start), "green", scale_(0.4));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::vector<Pixel, tbb::scalable_allocator<Pixel>> tmp_path;
|
std::vector<Pixel, PointsAllocator<Pixel>> tmp_path;
|
||||||
tmp_path.reserve(out_path.size());
|
tmp_path.reserve(out_path.size());
|
||||||
// Some path found, reverse and remove points that do not change direction
|
// Some path found, reverse and remove points that do not change direction
|
||||||
std::reverse(out_path.begin(), out_path.end());
|
std::reverse(out_path.begin(), out_path.end());
|
||||||
|
@ -52,7 +52,9 @@ using Vec2d = Eigen::Matrix<double, 2, 1, Eigen::DontAlign>;
|
|||||||
using Vec3d = Eigen::Matrix<double, 3, 1, Eigen::DontAlign>;
|
using Vec3d = Eigen::Matrix<double, 3, 1, Eigen::DontAlign>;
|
||||||
using Vec4d = Eigen::Matrix<double, 4, 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 PointPtrs = std::vector<Point*>;
|
||||||
using PointConstPtrs = std::vector<const Point*>;
|
using PointConstPtrs = std::vector<const Point*>;
|
||||||
using Points3 = std::vector<Vec3crd>;
|
using Points3 = std::vector<Vec3crd>;
|
||||||
@ -60,7 +62,7 @@ using Pointfs = std::vector<Vec2d>;
|
|||||||
using Vec2ds = std::vector<Vec2d>;
|
using Vec2ds = std::vector<Vec2d>;
|
||||||
using Pointf3s = std::vector<Vec3d>;
|
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 Matrix2f = Eigen::Matrix<float, 2, 2, Eigen::DontAlign>;
|
||||||
using Matrix2d = Eigen::Matrix<double, 2, 2, Eigen::DontAlign>;
|
using Matrix2d = Eigen::Matrix<double, 2, 2, Eigen::DontAlign>;
|
||||||
|
@ -12,9 +12,9 @@
|
|||||||
namespace Slic3r {
|
namespace Slic3r {
|
||||||
|
|
||||||
class Polygon;
|
class Polygon;
|
||||||
using Polygons = std::vector<Polygon>;
|
using Polygons = std::vector<Polygon, PointsAllocator<Polygon>>;
|
||||||
using PolygonPtrs = std::vector<Polygon*>;
|
using PolygonPtrs = std::vector<Polygon*, PointsAllocator<Polygon*>>;
|
||||||
using ConstPolygonPtrs = std::vector<const Polygon*>;
|
using ConstPolygonPtrs = std::vector<const Polygon*, PointsAllocator<const Polygon*>>;
|
||||||
|
|
||||||
// Returns true if inside. Returns border_result if on boundary.
|
// Returns true if inside. Returns border_result if on boundary.
|
||||||
bool contains(const Polygon& polygon, const Point& p, bool border_result = true);
|
bool contains(const Polygon& polygon, const Point& p, bool border_result = true);
|
||||||
|
@ -6,6 +6,8 @@
|
|||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include <libslic3r/Point.hpp>
|
||||||
|
|
||||||
struct indexed_triangle_set;
|
struct indexed_triangle_set;
|
||||||
|
|
||||||
namespace Slic3r {
|
namespace Slic3r {
|
||||||
@ -13,7 +15,7 @@ namespace Slic3r {
|
|||||||
class ExPolygon;
|
class ExPolygon;
|
||||||
class Polygon;
|
class Polygon;
|
||||||
using ExPolygons = std::vector<ExPolygon>;
|
using ExPolygons = std::vector<ExPolygon>;
|
||||||
using Polygons = std::vector<Polygon>;
|
using Polygons = std::vector<Polygon, PointsAllocator<Polygon>>;
|
||||||
|
|
||||||
namespace sla {
|
namespace sla {
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
#include <libslic3r/Polygon.hpp>
|
||||||
#include <libslic3r/ExPolygon.hpp>
|
#include <libslic3r/ExPolygon.hpp>
|
||||||
#include <libslic3r/AABBMesh.hpp>
|
#include <libslic3r/AABBMesh.hpp>
|
||||||
|
|
||||||
@ -14,9 +15,6 @@
|
|||||||
|
|
||||||
namespace Slic3r {
|
namespace Slic3r {
|
||||||
|
|
||||||
using Polygons = std::vector<Polygon>;
|
|
||||||
using ExPolygons = std::vector<ExPolygon>;
|
|
||||||
|
|
||||||
namespace sla {
|
namespace sla {
|
||||||
|
|
||||||
struct SupportTreeConfig
|
struct SupportTreeConfig
|
||||||
|
@ -8,13 +8,11 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <oneapi/tbb/scalable_allocator.h>
|
|
||||||
|
|
||||||
namespace Slic3r {
|
namespace Slic3r {
|
||||||
|
|
||||||
namespace ClipperLib {
|
namespace ClipperLib {
|
||||||
class PolyNode;
|
class PolyNode;
|
||||||
using PolyNodes = std::vector<PolyNode*, tbb::scalable_allocator<PolyNode*>>;
|
using PolyNodes = std::vector<PolyNode*, PointsAllocator<PolyNode*>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
class ExPolygon;
|
class ExPolygon;
|
||||||
|
@ -14,7 +14,7 @@ namespace Slic3r {
|
|||||||
|
|
||||||
class TriangleMesh;
|
class TriangleMesh;
|
||||||
class Polygon;
|
class Polygon;
|
||||||
using Polygons = std::vector<Polygon>;
|
using Polygons = std::vector<Polygon, PointsAllocator<Polygon>>;
|
||||||
class BuildVolume;
|
class BuildVolume;
|
||||||
|
|
||||||
namespace GUI {
|
namespace GUI {
|
||||||
|
@ -183,7 +183,8 @@ static void update_arrangepoly_slaprint(arrangement::ArrangePolygon &ret,
|
|||||||
|
|
||||||
trafo_instance = trafo_instance * po.trafo().cast<float>().inverse();
|
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();
|
auto zlvl = -po.get_elevation();
|
||||||
|
|
||||||
if (omesh) {
|
if (omesh) {
|
||||||
|
@ -308,8 +308,8 @@ SCENARIO("Various Clipper operations - t/clipper.t", "[ClipperUtils]") {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<e_ordering o = e_ordering::OFF, class P, class Tree>
|
template<e_ordering o = e_ordering::OFF, class P, class P_Alloc, class Tree>
|
||||||
double polytree_area(const Tree &tree, std::vector<P> *out)
|
double polytree_area(const Tree &tree, std::vector<P, P_Alloc> *out)
|
||||||
{
|
{
|
||||||
traverse_pt<o>(tree, out);
|
traverse_pt<o>(tree, out);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user