FIX: fail to use tbb

1.this cause slice become very slow

jira:NONE

Signed-off-by: xun.zhang <xun.zhang@bambulab.com>
Change-Id: Ied3ffe74533c1f822780fdc3a20af4ff657c1853
This commit is contained in:
xun.zhang 2024-10-12 22:10:08 +08:00 committed by Lane.Wei
parent bca344b31c
commit 4fc54affdf
1 changed files with 1 additions and 30 deletions

View File

@ -1904,21 +1904,15 @@ void PrintObject::bridge_over_infill()
const LayerRegion *region; const LayerRegion *region;
double bridge_angle; double bridge_angle;
}; };
constexpr bool BRIDGE_INFILL_USE_TBB = true;
std::map<size_t, std::vector<CandidateSurface>> surfaces_by_layer; std::map<size_t, std::vector<CandidateSurface>> surfaces_by_layer;
// SECTION to gather and filter surfaces for expanding, and then cluster them by layer // SECTION to gather and filter surfaces for expanding, and then cluster them by layer
{ {
tbb::concurrent_vector<CandidateSurface> candidate_surfaces; tbb::concurrent_vector<CandidateSurface> candidate_surfaces;
#if BRIDGE_INFILL_USE_TBB
tbb::parallel_for(tbb::blocked_range<size_t>(0, this->layers().size()), [po = static_cast<const PrintObject *>(this), tbb::parallel_for(tbb::blocked_range<size_t>(0, this->layers().size()), [po = static_cast<const PrintObject *>(this),
&candidate_surfaces](tbb::blocked_range<size_t> r) { &candidate_surfaces](tbb::blocked_range<size_t> r) {
for (size_t lidx = r.begin(); lidx < r.end(); lidx++) { for (size_t lidx = r.begin(); lidx < r.end(); lidx++) {
#else
for(size_t lidx=0;lidx<this->layers().size();++lidx){
auto po = static_cast<const PrintObject*>(this);
#endif
const Layer *layer = po->get_layer(lidx); const Layer *layer = po->get_layer(lidx);
if (layer->lower_layer == nullptr) { if (layer->lower_layer == nullptr) {
continue; continue;
@ -1981,9 +1975,7 @@ void PrintObject::bridge_over_infill()
} }
} }
} }
#if BRIDGE_INFILL_USE_TBB
}); });
#endif
for (const CandidateSurface &c : candidate_surfaces) { for (const CandidateSurface &c : candidate_surfaces) {
surfaces_by_layer[c.layer_index].push_back(c); surfaces_by_layer[c.layer_index].push_back(c);
@ -2009,14 +2001,9 @@ void PrintObject::bridge_over_infill()
backup_surfaces[lidx] = {}; backup_surfaces[lidx] = {};
} }
#if BRIDGE_INFILL_USE_TBB
tbb::parallel_for(tbb::blocked_range<size_t>(0, this->layers().size()), [po = this, &backup_surfaces, tbb::parallel_for(tbb::blocked_range<size_t>(0, this->layers().size()), [po = this, &backup_surfaces,
&surfaces_by_layer](tbb::blocked_range<size_t> r) { &surfaces_by_layer](tbb::blocked_range<size_t> r) {
for (size_t lidx = r.begin(); lidx < r.end(); lidx++) { for (size_t lidx = r.begin(); lidx < r.end(); lidx++) {
#else
for(size_t lidx=0;lidx<this->layers().size();++lidx){
auto po = this;
#endif
if (surfaces_by_layer.find(lidx) == surfaces_by_layer.end()) if (surfaces_by_layer.find(lidx) == surfaces_by_layer.end())
continue; continue;
@ -2069,9 +2056,7 @@ void PrintObject::bridge_over_infill()
} }
} }
} }
#if BRIDGE_INFILL_USE_TBB
}); });
#endif
// Use the modified surfaces to generate expanded lightning anchors // Use the modified surfaces to generate expanded lightning anchors
this->m_lightning_generator = this->prepare_lightning_infill_data(); this->m_lightning_generator = this->prepare_lightning_infill_data();
@ -2467,7 +2452,6 @@ void PrintObject::bridge_over_infill()
return expanded_bridged_area; return expanded_bridged_area;
}; };
#if BRIDGE_INFILL_USE_TBB
tbb::parallel_for(tbb::blocked_range<size_t>(0, clustered_layers_for_threads.size()), [po = static_cast<const PrintObject *>(this), tbb::parallel_for(tbb::blocked_range<size_t>(0, clustered_layers_for_threads.size()), [po = static_cast<const PrintObject *>(this),
target_flow_height_factor, &surfaces_by_layer, target_flow_height_factor, &surfaces_by_layer,
&clustered_layers_for_threads, &clustered_layers_for_threads,
@ -2476,10 +2460,6 @@ void PrintObject::bridge_over_infill()
construct_anchored_polygon]( construct_anchored_polygon](
tbb::blocked_range<size_t> r) { tbb::blocked_range<size_t> r) {
for (size_t cluster_idx = r.begin(); cluster_idx < r.end(); cluster_idx++) { for (size_t cluster_idx = r.begin(); cluster_idx < r.end(); cluster_idx++) {
#else
for(size_t cluster_idx=0;cluster_idx<clustered_layers_for_threads.size();++cluster_idx){
auto po = static_cast<const PrintObject*>(this);
#endif
for (size_t job_idx = 0; job_idx < clustered_layers_for_threads[cluster_idx].size(); job_idx++) { for (size_t job_idx = 0; job_idx < clustered_layers_for_threads[cluster_idx].size(); job_idx++) {
size_t lidx = clustered_layers_for_threads[cluster_idx][job_idx]; size_t lidx = clustered_layers_for_threads[cluster_idx][job_idx];
const Layer *layer = po->get_layer(lidx); const Layer *layer = po->get_layer(lidx);
@ -2658,19 +2638,12 @@ void PrintObject::bridge_over_infill()
expanded_surfaces.clear(); expanded_surfaces.clear();
} }
} }
#if BRIDGE_INFILL_USE_TBB
}); });
#endif
BOOST_LOG_TRIVIAL(info) << "Bridge over infill - Directions and expanded surfaces computed" << log_memory_info(); BOOST_LOG_TRIVIAL(info) << "Bridge over infill - Directions and expanded surfaces computed" << log_memory_info();
#if BRIDGE_INFILL_USE_TBB
tbb::parallel_for(tbb::blocked_range<size_t>(0, this->layers().size()), [po = this, &surfaces_by_layer](tbb::blocked_range<size_t> r) { tbb::parallel_for(tbb::blocked_range<size_t>(0, this->layers().size()), [po = this, &surfaces_by_layer](tbb::blocked_range<size_t> r) {
for (size_t lidx = r.begin(); lidx < r.end(); lidx++) { for (size_t lidx = r.begin(); lidx < r.end(); lidx++) {
#else
for(size_t lidx=0;lidx<this->layers().size();++lidx){
auto po = this;
#endif
if (surfaces_by_layer.find(lidx) == surfaces_by_layer.end() && surfaces_by_layer.find(lidx + 1) == surfaces_by_layer.end()) if (surfaces_by_layer.find(lidx) == surfaces_by_layer.end() && surfaces_by_layer.find(lidx + 1) == surfaces_by_layer.end())
continue; continue;
Layer *layer = po->get_layer(lidx); Layer *layer = po->get_layer(lidx);
@ -2742,9 +2715,7 @@ void PrintObject::bridge_over_infill()
region->fill_surfaces.append(new_surfaces); region->fill_surfaces.append(new_surfaces);
} }
} }
#if BRIDGE_INFILL_USE_TBB
}); });
#endif
BOOST_LOG_TRIVIAL(info) << "Bridge over infill - End" << log_memory_info(); BOOST_LOG_TRIVIAL(info) << "Bridge over infill - End" << log_memory_info();