From 0b1ccb87081671ef2142de52b8a06768533d492c Mon Sep 17 00:00:00 2001 From: wintergua Date: Wed, 15 Mar 2023 09:21:20 +0800 Subject: [PATCH] ENH: improve the efficiency of grouping volumes during brim generation the processes are parallized via tbb the patch 12311 ENH: remove trim_overlap should be used Change-Id: I226dc171daadebd81b8d3ae013b08c71b91fb392 (cherry picked from commit eaa2e7997a59f43175d5af430269127471e40cbb) --- src/libslic3r/PrintObjectSlice.cpp | 37 ++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/src/libslic3r/PrintObjectSlice.cpp b/src/libslic3r/PrintObjectSlice.cpp index 2a33241e1..2194fc98a 100644 --- a/src/libslic3r/PrintObjectSlice.cpp +++ b/src/libslic3r/PrintObjectSlice.cpp @@ -451,20 +451,33 @@ static std::vector> slices_to_regions( bool doesVolumeIntersect(VolumeSlices& vs1, VolumeSlices& vs2) { if (vs1.volume_id == vs2.volume_id) return true; + // two volumes in the same object should have same number of layers, otherwise the slicing is incorrect. if (vs1.slices.size() != vs2.slices.size()) return false; - for (int i = 0; i != vs1.slices.size(); ++i) { + auto& vs1s = vs1.slices; + auto& vs2s = vs2.slices; + bool is_intersect = false; - if (vs1.slices[i].empty()) continue; - if (!vs2.slices[i].empty() && !intersection_ex(vs1.slices[i], vs2.slices[i]).empty()) return true; - if (i + 1 != vs2.slices.size() && !vs2.slices[i + 1].empty()) { - if (!intersection_ex(vs1.slices[i], vs2.slices[i + 1]).empty()) return true; - } - if (i - 1 >= 0 && !vs2.slices[i - 1].empty()) { - if (!intersection_ex(vs1.slices[i], vs2.slices[i - 1]).empty()) return true; - } - } - return false; + tbb::parallel_for(tbb::blocked_range(0, vs1s.size()), + [&vs1s, &vs2s, &is_intersect](const tbb::blocked_range& range) { + for (auto i = range.begin(); i != range.end(); ++i) { + if (vs1s[i].empty()) continue; + + if (overlaps(vs1s[i], vs2s[i])) { + is_intersect = true; + break; + } + if (i + 1 != vs2s.size() && overlaps(vs1s[i], vs2s[i + 1])) { + is_intersect = true; + break; + } + if (i - 1 >= 0 && overlaps(vs1s[i], vs2s[i - 1])) { + is_intersect = true; + break; + } + } + }); + return is_intersect; } //BBS: grouping the volumes of an object according to their connection relationship @@ -744,7 +757,7 @@ void PrintObject::slice() m_layers = new_layers(this, generate_object_layers(m_slicing_params, layer_height_profile)); this->slice_volumes(); m_print->throw_if_canceled(); -#if 0 +#if 1 // Fix the model. //FIXME is this the right place to do? It is done repeateadly at the UI and now here at the backend. std::string warning = fix_slicing_errors(this, m_layers, [this](){ m_print->throw_if_canceled(); });