Parallelize PrintObject::process_external_surfaces()

This commit is contained in:
bubnikv 2017-03-07 17:43:43 +01:00
parent 109013bed7
commit 65c024f7cf
3 changed files with 29 additions and 40 deletions

View file

@ -22,7 +22,8 @@ class LayerRegion
friend class Layer; friend class Layer;
public: public:
Layer* layer(); Layer* layer() { return this->_layer; }
const Layer* layer() const { return this->_layer; }
PrintRegion* region() { return this->_region; } PrintRegion* region() { return this->_region; }
const PrintRegion* region() const { return this->_region; } const PrintRegion* region() const { return this->_region; }
@ -76,8 +77,8 @@ class LayerRegion
Layer *_layer; Layer *_layer;
PrintRegion *_region; PrintRegion *_region;
LayerRegion(Layer *layer, PrintRegion *region); LayerRegion(Layer *layer, PrintRegion *region) : _layer(layer), _region(region) {}
~LayerRegion(); ~LayerRegion() {}
}; };

View file

@ -14,22 +14,6 @@
namespace Slic3r { namespace Slic3r {
LayerRegion::LayerRegion(Layer *layer, PrintRegion *region)
: _layer(layer),
_region(region)
{
}
LayerRegion::~LayerRegion()
{
}
Layer*
LayerRegion::layer()
{
return this->_layer;
}
Flow Flow
LayerRegion::flow(FlowRole role, bool bridge, double width) const LayerRegion::flow(FlowRole role, bool bridge, double width) const
{ {
@ -134,26 +118,26 @@ LayerRegion::process_external_surfaces(const Layer* lower_layer)
// bottom_polygons are used to trim inflated top surfaces. // bottom_polygons are used to trim inflated top surfaces.
fill_boundaries.reserve(number_polygons(surfaces)); fill_boundaries.reserve(number_polygons(surfaces));
bool has_infill = this->region()->config.fill_density.value > 0.; bool has_infill = this->region()->config.fill_density.value > 0.;
for (Surfaces::iterator surface = this->fill_surfaces.surfaces.begin(); surface != this->fill_surfaces.surfaces.end(); ++surface) { for (const Surface &surface : this->fill_surfaces.surfaces) {
if (surface->surface_type == stTop) { if (surface.surface_type == stTop) {
// Collect the top surfaces, inflate them and trim them by the bottom surfaces. // Collect the top surfaces, inflate them and trim them by the bottom surfaces.
// This gives the priority to bottom surfaces. // This gives the priority to bottom surfaces.
surfaces_append(top, offset_ex(surface->expolygon, float(margin), EXTERNAL_SURFACES_OFFSET_PARAMETERS), *surface); surfaces_append(top, offset_ex(surface.expolygon, float(margin), EXTERNAL_SURFACES_OFFSET_PARAMETERS), surface);
} else if (surface->surface_type == stBottom || (surface->surface_type == stBottomBridge && lower_layer == NULL)) { } else if (surface.surface_type == stBottom || (surface.surface_type == stBottomBridge && lower_layer == NULL)) {
// Grown by 3mm. // Grown by 3mm.
surfaces_append(bottom, offset_ex(surface->expolygon, float(margin), EXTERNAL_SURFACES_OFFSET_PARAMETERS), *surface); surfaces_append(bottom, offset_ex(surface.expolygon, float(margin), EXTERNAL_SURFACES_OFFSET_PARAMETERS), surface);
} else if (surface->surface_type == stBottomBridge) { } else if (surface.surface_type == stBottomBridge) {
if (! surface->empty()) if (! surface.empty())
bridges.push_back(*surface); bridges.push_back(surface);
} }
bool internal_surface = surface->surface_type != stTop && ! surface->is_bottom(); bool internal_surface = surface.surface_type != stTop && ! surface.is_bottom();
if (has_infill || surface->surface_type != stInternal) { if (has_infill || surface.surface_type != stInternal) {
if (internal_surface) if (internal_surface)
// Make a copy as the following line uses the move semantics. // Make a copy as the following line uses the move semantics.
internal.push_back(*surface); internal.push_back(surface);
polygons_append(fill_boundaries, STDMOVE(surface->expolygon)); polygons_append(fill_boundaries, STDMOVE(surface.expolygon));
} else if (internal_surface) } else if (internal_surface)
internal.push_back(STDMOVE(*surface)); internal.push_back(STDMOVE(surface));
} }
} }

View file

@ -526,15 +526,19 @@ PrintObject::process_external_surfaces()
BOOST_LOG_TRIVIAL(info) << "Processing external surfaces..."; BOOST_LOG_TRIVIAL(info) << "Processing external surfaces...";
FOREACH_REGION(this->_print, region) { FOREACH_REGION(this->_print, region) {
size_t region_id = region - this->_print->regions.begin(); int region_id = int(region - this->_print->regions.begin());
FOREACH_LAYER(this, layer_it) { BOOST_LOG_TRIVIAL(debug) << "Processing external surfaces for region " << region_id << " in parallel - start";
const Layer* lower_layer = (layer_it == this->layers.begin()) tbb::parallel_for(
? NULL tbb::blocked_range<size_t>(0, this->layers.size()),
: *(layer_it-1); [this, region_id](const tbb::blocked_range<size_t>& range) {
BOOST_LOG_TRIVIAL(trace) << "Processing external surface, layer" << (*layer_it)->print_z; for (size_t layer_idx = range.begin(); layer_idx < range.end(); ++ layer_idx) {
(*layer_it)->get_region(region_id)->process_external_surfaces(lower_layer); // BOOST_LOG_TRIVIAL(trace) << "Processing external surface, layer" << this->layers[layer_idx]->print_z;
} this->layers[layer_idx]->get_region(region_id)->process_external_surfaces((layer_idx == 0) ? NULL : this->layers[layer_idx - 1]);
}
}
);
BOOST_LOG_TRIVIAL(debug) << "Processing external surfaces for region " << region_id << " in parallel - end";
} }
} }