From 6323e27cdca4d3fabc2ee22d78dd7efb23adcadb Mon Sep 17 00:00:00 2001 From: tamasmeszaros Date: Thu, 15 Dec 2022 13:05:02 +0100 Subject: [PATCH] csg voxelization speedup with additional parallelism --- src/libslic3r/CSGMesh/VoxelizeCSGMesh.hpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/libslic3r/CSGMesh/VoxelizeCSGMesh.hpp b/src/libslic3r/CSGMesh/VoxelizeCSGMesh.hpp index f1fd73981..0f2e8c898 100644 --- a/src/libslic3r/CSGMesh/VoxelizeCSGMesh.hpp +++ b/src/libslic3r/CSGMesh/VoxelizeCSGMesh.hpp @@ -5,6 +5,7 @@ #include "CSGMesh.hpp" #include "libslic3r/OpenVDBUtils.hpp" +#include "libslic3r/Execution/ExecutionTBB.hpp" namespace Slic3r { namespace csg { @@ -32,11 +33,24 @@ VoxelGridPtr voxelize_csgmesh(const Range &csgrange, { VoxelGridPtr ret; + std::vector grids (csgrange.size()); + + execution::for_each(ex_tbb, size_t(0), csgrange.size(), [&](size_t csgidx) { + if (params.statusfn() && params.statusfn()(-1)) + return; + + auto it = csgrange.begin(); + std::advance(it, csgidx); + auto &csgpart = *it; + grids[csgidx] = get_voxelgrid(csgpart, params); + }, execution::max_concurrency(ex_tbb)); + + size_t csgidx = 0; for (auto &csgpart : csgrange) { if (params.statusfn() && params.statusfn()(-1)) break; - VoxelGridPtr partgrid = get_voxelgrid(csgpart, params); + auto &partgrid = grids[csgidx++]; if (!ret && get_operation(csgpart) == CSGType::Union) { ret = std::move(partgrid);