mirror of
https://git.mirrors.martin98.com/https://github.com/slic3r/Slic3r.git
synced 2025-08-17 15:25:53 +08:00
Multithreading dense_infill
This commit is contained in:
parent
0f897eeaa3
commit
05c03d7120
@ -1797,11 +1797,12 @@ void Print::process()
|
|||||||
{
|
{
|
||||||
name_tbb_thread_pool_threads();
|
name_tbb_thread_pool_threads();
|
||||||
bool something_done = !is_step_done_unguarded(psBrim);
|
bool something_done = !is_step_done_unguarded(psBrim);
|
||||||
|
|
||||||
BOOST_LOG_TRIVIAL(info) << "Starting the slicing process." << log_memory_info();
|
BOOST_LOG_TRIVIAL(info) << "Starting the slicing process." << log_memory_info();
|
||||||
for (PrintObject *obj : m_objects)
|
for (PrintObject *obj : m_objects)
|
||||||
obj->make_perimeters();
|
obj->make_perimeters();
|
||||||
this->set_status(70, L("Infilling layers"));
|
this->set_status(70, L("Infilling layers"));
|
||||||
|
//note: as object seems to be sliced independantly, it's maybe possible to add a tbb parallel_loop with simple partitioner on infill,
|
||||||
|
// as prepare_infill has some function not //
|
||||||
for (PrintObject *obj : m_objects)
|
for (PrintObject *obj : m_objects)
|
||||||
obj->infill();
|
obj->infill();
|
||||||
for (PrintObject *obj : m_objects)
|
for (PrintObject *obj : m_objects)
|
||||||
|
@ -1155,26 +1155,37 @@ namespace Slic3r {
|
|||||||
const float COEFF_SPLIT = 1.5;
|
const float COEFF_SPLIT = 1.5;
|
||||||
|
|
||||||
for (const PrintRegion* region : this->m_print->regions()) {
|
for (const PrintRegion* region : this->m_print->regions()) {
|
||||||
LayerRegion* previousOne = NULL;
|
|
||||||
//count how many surface there are on each one
|
//count how many surface there are on each one
|
||||||
if (region->config().infill_dense.getBool() && region->config().fill_density < 40) {
|
if (region->config().infill_dense.getBool() && region->config().fill_density < 40) {
|
||||||
for (size_t idx_layer = this->layers().size() - 1; idx_layer < this->layers().size(); --idx_layer) {
|
std::vector<LayerRegion*> layeridx2lregion;
|
||||||
LayerRegion* layerm = NULL;
|
std::vector<Surfaces> new_surfaces; //surface store, as you can't modify them when working in //
|
||||||
|
// store the LayerRegion on which we are working
|
||||||
|
layeridx2lregion.resize(this->layers().size(), nullptr);
|
||||||
|
new_surfaces.resize(this->layers().size(), Surfaces{});
|
||||||
|
for (size_t idx_layer = 0; idx_layer < this->layers().size(); ++idx_layer) {
|
||||||
|
LayerRegion* layerm = nullptr;
|
||||||
for (LayerRegion* lregion : this->layers()[idx_layer]->regions()) {
|
for (LayerRegion* lregion : this->layers()[idx_layer]->regions()) {
|
||||||
if (lregion->region() == region) {
|
if (lregion->region() == region) {
|
||||||
layerm = lregion;
|
layerm = lregion;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (layerm == NULL) {
|
if (layerm != nullptr)
|
||||||
previousOne = NULL;
|
layeridx2lregion[idx_layer] = layerm;
|
||||||
|
}
|
||||||
|
// run in parallel, it's a costly thing.
|
||||||
|
tbb::parallel_for(tbb::blocked_range<size_t>(0, this->layers().size()-1),
|
||||||
|
[this, &layeridx2lregion, &new_surfaces, region, COEFF_SPLIT](const tbb::blocked_range<size_t>& range) {
|
||||||
|
for (size_t idx_layer = range.begin(); idx_layer < range.end(); ++idx_layer) {
|
||||||
|
// we our LayerRegion and the one on top
|
||||||
|
LayerRegion* layerm = layeridx2lregion[idx_layer];
|
||||||
|
const LayerRegion* previousOne = nullptr;
|
||||||
|
previousOne = layeridx2lregion[idx_layer + 1];
|
||||||
|
if (layerm == nullptr || previousOne == nullptr) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (previousOne == NULL) {
|
Surfaces &surfs_to_add = new_surfaces[idx_layer];
|
||||||
previousOne = layerm;
|
// check all surfaces to cover
|
||||||
continue;
|
|
||||||
}
|
|
||||||
Surfaces surfs_to_add;
|
|
||||||
for (Surface& surface : layerm->fill_surfaces.surfaces) {
|
for (Surface& surface : layerm->fill_surfaces.surfaces) {
|
||||||
surface.maxNbSolidLayersOnTop = -1;
|
surface.maxNbSolidLayersOnTop = -1;
|
||||||
if (!surface.has_fill_solid()) {
|
if (!surface.has_fill_solid()) {
|
||||||
@ -1188,7 +1199,7 @@ namespace Slic3r {
|
|||||||
for (const ExPolygon& surf_with_overlap : surfs_with_overlap) {
|
for (const ExPolygon& surf_with_overlap : surfs_with_overlap) {
|
||||||
ExPolygons sparse_polys = { surf_with_overlap };
|
ExPolygons sparse_polys = { surf_with_overlap };
|
||||||
//find the surface which intersect with the smallest maxNb possible
|
//find the surface which intersect with the smallest maxNb possible
|
||||||
for (Surface& upp : previousOne->fill_surfaces.surfaces) {
|
for (const Surface& upp : previousOne->fill_surfaces.surfaces) {
|
||||||
if (upp.has_fill_solid()) {
|
if (upp.has_fill_solid()) {
|
||||||
// i'm using intersection_ex because the result different than
|
// i'm using intersection_ex because the result different than
|
||||||
// upp.expolygon.overlaps(surf.expolygon) or surf.expolygon.overlaps(upp.expolygon)
|
// upp.expolygon.overlaps(surf.expolygon) or surf.expolygon.overlaps(upp.expolygon)
|
||||||
@ -1208,7 +1219,7 @@ namespace Slic3r {
|
|||||||
if (layerm->region()->config().infill_dense_algo.value == dfaEnlarged
|
if (layerm->region()->config().infill_dense_algo.value == dfaEnlarged
|
||||||
|| (layerm->region()->config().infill_dense_algo.value == dfaAutoOrEnlarged && surf_with_overlap_area <= area_intersect * COEFF_SPLIT)) {
|
|| (layerm->region()->config().infill_dense_algo.value == dfaAutoOrEnlarged && surf_with_overlap_area <= area_intersect * COEFF_SPLIT)) {
|
||||||
//expand the area a bit
|
//expand the area a bit
|
||||||
intersect = offset_ex(intersect, double(scale_(layerm->region()->config().external_infill_margin.get_abs_value(
|
intersect = offset_ex(intersect, (scaled(layerm->region()->config().external_infill_margin.get_abs_value(
|
||||||
region->config().perimeters == 0 ? 0 : (layerm->flow(frExternalPerimeter).width + layerm->flow(frPerimeter).spacing() * (region->config().perimeters - 1))))));
|
region->config().perimeters == 0 ? 0 : (layerm->flow(frExternalPerimeter).width + layerm->flow(frPerimeter).spacing() * (region->config().perimeters - 1))))));
|
||||||
} else if (layerm->region()->config().infill_dense_algo.value == dfaAutoNotFull
|
} else if (layerm->region()->config().infill_dense_algo.value == dfaAutoNotFull
|
||||||
|| layerm->region()->config().infill_dense_algo.value == dfaAutomatic) {
|
|| layerm->region()->config().infill_dense_algo.value == dfaAutomatic) {
|
||||||
@ -1307,8 +1318,14 @@ namespace Slic3r {
|
|||||||
surfs_to_add.insert(surfs_to_add.begin(), surf_to_add.begin(), surf_to_add.end());
|
surfs_to_add.insert(surfs_to_add.begin(), surf_to_add.begin(), surf_to_add.end());
|
||||||
} else surfs_to_add.emplace_back(std::move(surface));
|
} else surfs_to_add.emplace_back(std::move(surface));
|
||||||
}
|
}
|
||||||
layerm->fill_surfaces.surfaces = std::move(surfs_to_add);
|
//layerm->fill_surfaces.surfaces = std::move(surfs_to_add);
|
||||||
previousOne = layerm;
|
}
|
||||||
|
});
|
||||||
|
// now set the new surfaces
|
||||||
|
for (size_t idx_layer = 0; idx_layer < this->layers().size() - 1; ++idx_layer) {
|
||||||
|
LayerRegion* lr = layeridx2lregion[idx_layer];
|
||||||
|
if(lr != nullptr && layeridx2lregion[idx_layer + 1] != nullptr)
|
||||||
|
lr->fill_surfaces.surfaces = new_surfaces[idx_layer];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user