Fix slow cancellation of rasterization step

fixes #6253
This commit is contained in:
tamasmeszaros 2021-04-08 14:35:58 +02:00
parent e8af080346
commit 08ca5b29f0
2 changed files with 19 additions and 9 deletions

View file

@ -390,16 +390,25 @@ public:
virtual void apply(const SLAPrinterConfig &cfg) = 0;
// Fn have to be thread safe: void(sla::RasterBase& raster, size_t lyrid);
template<class Fn> void draw_layers(size_t layer_num, Fn &&drawfn)
template<class Fn, class CancelFn, class EP = ExecutionTBB>
void draw_layers(
size_t layer_num,
Fn && drawfn,
CancelFn cancelfn = []() { return false; },
const EP & ep = {})
{
m_layers.resize(layer_num);
sla::ccr::for_each(size_t(0), m_layers.size(),
[this, &drawfn] (size_t idx) {
sla::EncodedRaster& enc = m_layers[idx];
auto rst = create_raster();
drawfn(*rst, idx);
enc = rst->encode(get_encoder());
});
execution::for_each(
ep, size_t(0), m_layers.size(),
[this, &drawfn, &cancelfn](size_t idx) {
if (cancelfn()) return;
sla::EncodedRaster &enc = m_layers[idx];
auto rst = create_raster();
drawfn(*rst, idx);
enc = rst->encode(get_encoder());
},
execution::max_concurrency(ep));
}
};

View file

@ -1093,7 +1093,8 @@ void SLAPrint::Steps::rasterize()
if(canceled()) return;
// Print all the layers in parallel
m_print->m_printer->draw_layers(m_print->m_printer_input.size(), lvlfn);
m_print->m_printer->draw_layers(m_print->m_printer_input.size(), lvlfn,
[this]() { return canceled(); }, ex_tbb);
}
std::string SLAPrint::Steps::label(SLAPrintObjectStep step)