diff --git a/src/libnest2d/include/libnest2d/backends/clipper/geometries.hpp b/src/libnest2d/include/libnest2d/backends/clipper/geometries.hpp index 15eeb57b8..232668f61 100644 --- a/src/libnest2d/include/libnest2d/backends/clipper/geometries.hpp +++ b/src/libnest2d/include/libnest2d/backends/clipper/geometries.hpp @@ -331,8 +331,15 @@ inline std::vector clipper_execute( auto processPoly = [&retv, &processHole](ClipperLib::PolyNode *pptr) { PolygonImpl poly; - poly.Contour.swap(pptr->Contour); auto front_p = poly.Contour.front(); - poly.Contour.emplace_back(std::move(front_p)); + poly.Contour.swap(pptr->Contour); + + assert(!pptr->IsHole()); + + if(pptr->IsOpen()) { + auto front_p = poly.Contour.front(); + poly.Contour.emplace_back(front_p); + } + for(auto h : pptr->Childs) { processHole(h, poly); } retv.push_back(poly); }; @@ -340,8 +347,14 @@ inline std::vector clipper_execute( processHole = [&processPoly](ClipperLib::PolyNode *pptr, PolygonImpl& poly) { poly.Holes.emplace_back(std::move(pptr->Contour)); - auto front_p = poly.Holes.back().front(); - poly.Holes.back().emplace_back(std::move(front_p)); + + assert(pptr->IsHole()); + + if(pptr->IsOpen()) { + auto front_p = poly.Holes.back().front(); + poly.Holes.back().emplace_back(front_p); + } + for(auto c : pptr->Childs) processPoly(c); }; diff --git a/src/libslic3r/Rasterizer/Rasterizer.cpp b/src/libslic3r/Rasterizer/Rasterizer.cpp index ab584821f..496a584a2 100644 --- a/src/libslic3r/Rasterizer/Rasterizer.cpp +++ b/src/libslic3r/Rasterizer/Rasterizer.cpp @@ -71,16 +71,41 @@ public: clear(); } - template inline void draw(const Geometry &poly) { + void draw(const ExPolygon &poly) { agg::rasterizer_scanline_aa<> ras; agg::scanline_p8 scanlines; - auto&& path = to_path(poly); + auto&& path = to_path(poly.contour); if(m_o == Origin::TOP_LEFT) flipy(path); ras.add_path(path); + for(auto h : poly.holes) { + auto&& holepath = to_path(h); + if(m_o == Origin::TOP_LEFT) flipy(holepath); + ras.add_path(holepath); + } + + agg::render_scanlines(ras, scanlines, m_renderer); + } + + void draw(const ClipperLib::Polygon &poly) { + agg::rasterizer_scanline_aa<> ras; + agg::scanline_p8 scanlines; + + auto&& path = to_path(poly.Contour); + + if(m_o == Origin::TOP_LEFT) flipy(path); + + ras.add_path(path); + + for(auto h : poly.Holes) { + auto&& holepath = to_path(h); + if(m_o == Origin::TOP_LEFT) flipy(holepath); + ras.add_path(holepath); + } + agg::render_scanlines(ras, scanlines, m_renderer); } @@ -186,14 +211,12 @@ void Raster::clear() void Raster::draw(const ExPolygon &expoly) { - m_impl->draw(expoly.contour); - for(auto& h : expoly.holes) m_impl->draw(h); + m_impl->draw(expoly); } void Raster::draw(const ClipperLib::Polygon &poly) { - m_impl->draw(poly.Contour); - for(auto& h : poly.Holes) m_impl->draw(h); + m_impl->draw(poly); } void Raster::save(std::ostream& stream, Compression comp) diff --git a/src/libslic3r/SLAPrint.cpp b/src/libslic3r/SLAPrint.cpp index a5aa826c9..424881491 100644 --- a/src/libslic3r/SLAPrint.cpp +++ b/src/libslic3r/SLAPrint.cpp @@ -1084,9 +1084,15 @@ void SLAPrint::process() SpinMutex mutex; using Lock = std::lock_guard; -// for (PrintLayer& layer : m_printer_input) - auto printlayerfn = [this, get_all_polygons, polyunion, polydiff, areafn, area_fill, display_area, exp_time, init_exp_time, fast_tilt, slow_tilt, delta_fade_time, - &mutex, &models_volume, &supports_volume, &estim_time, &slow_layers, &fast_layers, &fade_layer_time](size_t sliced_layer_cnt) + // Going to parallel: + auto printlayerfn = [this, + // functions and read only vars + get_all_polygons, polyunion, polydiff, areafn, + area_fill, display_area, exp_time, init_exp_time, fast_tilt, slow_tilt, delta_fade_time, + + // write vars + &mutex, &models_volume, &supports_volume, &estim_time, &slow_layers, + &fast_layers, &fade_layer_time](size_t sliced_layer_cnt) { PrintLayer& layer = m_printer_input[sliced_layer_cnt]; @@ -1141,9 +1147,9 @@ void SLAPrint::process() } if(!supports_polygons.empty()) { - /*if(model_polygons.empty()) */supports_polygons = polyunion(supports_polygons); - /*else */ if(!model_polygons.empty())supports_polygons = polydiff(supports_polygons, model_polygons); - // allegedly, union of subject is done withing the diff + if(model_polygons.empty()) supports_polygons = polyunion(supports_polygons); + else supports_polygons = polydiff(supports_polygons, model_polygons); + // allegedly, union of subject is done withing the diff according to the pftPositive polyFillType } double layer_support_area = 0; @@ -1190,8 +1196,9 @@ void SLAPrint::process() } }; - for(size_t i = 0; i < m_printer_input.size(); ++i) printlayerfn(i); -// tbb::parallel_for(0, m_printer_input.size(), printlayerfn); + // sequential version for debugging: + // for(size_t i = 0; i < m_printer_input.size(); ++i) printlayerfn(i); + tbb::parallel_for(0, m_printer_input.size(), printlayerfn); m_print_statistics.support_used_material = supports_volume * SCALING_FACTOR * SCALING_FACTOR; m_print_statistics.objects_used_material = models_volume * SCALING_FACTOR * SCALING_FACTOR;