Parallelized the slow discover_vertical_shells()

This commit is contained in:
bubnikv 2017-03-08 14:54:04 +01:00
parent f200781436
commit 798bca561b

View File

@ -579,8 +579,6 @@ PrintObject::discover_vertical_shells()
BOOST_LOG_TRIVIAL(info) << "Discovering vertical shells...";
const SurfaceType surfaces_bottom[2] = { stBottom, stBottomBridge };
for (size_t idx_region = 0; idx_region < this->_print->regions.size(); ++ idx_region) {
PROFILE_BLOCK(discover_vertical_shells_region);
@ -593,11 +591,20 @@ PrintObject::discover_vertical_shells()
if (n_extra_top_layers + n_extra_bottom_layers == 0)
// Zero or 1 layer, there is no additional vertical wall thickness enforced.
continue;
BOOST_LOG_TRIVIAL(debug) << "Discovering vertical shells for region " << idx_region << " in parallel - start";
//FIXME Improve the heuristics for a grain size.
size_t grain_size = std::max(this->layers.size() / 16, size_t(1));
tbb::parallel_for(
tbb::blocked_range<size_t>(0, this->layers.size(), grain_size),
[this, idx_region, n_extra_top_layers, n_extra_bottom_layers](const tbb::blocked_range<size_t>& range) {
// printf("discover_vertical_shells from %d to %d\n", range.begin(), range.end());
// Cyclic buffers of pre-calculated offsetted top/bottom surfaces.
//FIXME these caches could be maintained per thread of the thread loop.
std::vector<DiscoverVerticalShellsCacheEntry> cache_top_regions(n_extra_top_layers, DiscoverVerticalShellsCacheEntry());
std::vector<DiscoverVerticalShellsCacheEntry> cache_bottom_regions(n_extra_bottom_layers, DiscoverVerticalShellsCacheEntry());
for (size_t idx_layer = 0; idx_layer < this->layers.size(); ++ idx_layer)
{
const SurfaceType surfaces_bottom[2] = { stBottom, stBottomBridge };
for (size_t idx_layer = range.begin(); idx_layer < range.end(); ++ idx_layer) {
PROFILE_BLOCK(discover_vertical_shells_region_layer);
#ifdef SLIC3R_DEBUG_SLICE_PROCESSING
@ -606,7 +613,7 @@ PrintObject::discover_vertical_shells()
#endif /* SLIC3R_DEBUG_SLICE_PROCESSING */
Layer *layer = this->layers[idx_layer];
LayerRegion *layerm = layer->get_region(idx_region);
LayerRegion *layerm = layer->regions[idx_region];
#ifdef SLIC3R_DEBUG_SLICE_PROCESSING
layerm->export_region_slices_to_svg_debug("4_discover_vertical_shells-initial");
@ -841,6 +848,8 @@ PrintObject::discover_vertical_shells()
layerm->fill_surfaces.append(new_internal_void, stInternalVoid);
layerm->fill_surfaces.append(new_internal_solid, stInternalSolid);
} // for each layer
});
BOOST_LOG_TRIVIAL(debug) << "Discovering vertical shells for region " << idx_region << " in parallel - end";
#ifdef SLIC3R_DEBUG_SLICE_PROCESSING
for (size_t idx_layer = 0; idx_layer < this->layers.size(); ++idx_layer) {