From 7cb3007558731b0bcd09fd2bea4b7d2fceea2316 Mon Sep 17 00:00:00 2001 From: Vojtech Bubnik Date: Tue, 10 Jan 2023 12:18:06 +0100 Subject: [PATCH 1/4] Fixed ThickPolyline clear(), which did not clear widths. Fixed by refactoring ThickPolyline to compose Polyline instead of being derived of it. --- src/libslic3r/Arachne/utils/ExtrusionLine.hpp | 2 +- src/libslic3r/ExPolygon.cpp | 4 +++- src/libslic3r/Geometry/MedialAxis.cpp | 6 +++-- src/libslic3r/Polyline.hpp | 22 +++++++++++++------ src/libslic3r/SVG.cpp | 4 ++-- 5 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/libslic3r/Arachne/utils/ExtrusionLine.hpp b/src/libslic3r/Arachne/utils/ExtrusionLine.hpp index 7ac1a3c4c..c0c5e7db1 100644 --- a/src/libslic3r/Arachne/utils/ExtrusionLine.hpp +++ b/src/libslic3r/Arachne/utils/ExtrusionLine.hpp @@ -14,7 +14,7 @@ #include "../../../clipper/clipper_z.hpp" namespace Slic3r { -class ThickPolyline; +struct ThickPolyline; } namespace Slic3r::Arachne diff --git a/src/libslic3r/ExPolygon.cpp b/src/libslic3r/ExPolygon.cpp index 8dc0ff547..dc991e46d 100644 --- a/src/libslic3r/ExPolygon.cpp +++ b/src/libslic3r/ExPolygon.cpp @@ -320,7 +320,9 @@ void ExPolygon::medial_axis(double min_width, double max_width, Polylines* polyl { ThickPolylines tp; this->medial_axis(min_width, max_width, &tp); - polylines->insert(polylines->end(), tp.begin(), tp.end()); + polylines->reserve(polylines->size() + tp.size()); + for (auto &pl : tp) + polylines->emplace_back(pl.points); } Lines ExPolygon::lines() const diff --git a/src/libslic3r/Geometry/MedialAxis.cpp b/src/libslic3r/Geometry/MedialAxis.cpp index c92796f41..4f614169c 100644 --- a/src/libslic3r/Geometry/MedialAxis.cpp +++ b/src/libslic3r/Geometry/MedialAxis.cpp @@ -498,6 +498,7 @@ void MedialAxis::build(ThickPolylines* polylines) polyline.width.emplace_back(seed_edge_data.width_end); // Grow the polyline in a forward direction. this->process_edge_neighbors(&*seed_edge, &polyline); + assert(polyline.width.size() == polyline.points.size() * 2 - 2); // Grow the polyline in a backward direction. reverse_polyline.clear(); @@ -505,7 +506,6 @@ void MedialAxis::build(ThickPolylines* polylines) polyline.points.insert(polyline.points.begin(), reverse_polyline.points.rbegin(), reverse_polyline.points.rend()); polyline.width.insert(polyline.width.begin(), reverse_polyline.width.rbegin(), reverse_polyline.width.rend()); polyline.endpoints.first = reverse_polyline.endpoints.second; - assert(polyline.width.size() == polyline.points.size() * 2 - 2); // Prevent loop endpoints from being extended. @@ -538,7 +538,9 @@ void MedialAxis::build(Polylines* polylines) { ThickPolylines tp; this->build(&tp); - polylines->insert(polylines->end(), tp.begin(), tp.end()); + polylines->reserve(polylines->size() + tp.size()); + for (auto &pl : tp) + polylines->emplace_back(pl.points); } void MedialAxis::process_edge_neighbors(const VD::edge_type *edge, ThickPolyline* polyline) diff --git a/src/libslic3r/Polyline.hpp b/src/libslic3r/Polyline.hpp index bee5e51ba..8ca8e4f16 100644 --- a/src/libslic3r/Polyline.hpp +++ b/src/libslic3r/Polyline.hpp @@ -10,7 +10,7 @@ namespace Slic3r { class Polyline; -class ThickPolyline; +struct ThickPolyline; typedef std::vector Polylines; typedef std::vector ThickPolylines; @@ -160,20 +160,28 @@ bool remove_degenerate(Polylines &polylines); // Returns index of a segment of a polyline and foot point of pt on polyline. std::pair foot_pt(const Points &polyline, const Point &pt); -class ThickPolyline : public Polyline { -public: - ThickPolyline() : endpoints(std::make_pair(false, false)) {} +struct ThickPolyline { + ThickPolyline() = default; ThickLines thicklines() const; + + const Point& first_point() const { return this->points.front(); } + const Point& last_point() const { return this->points.back(); } + bool is_valid() const { return this->points.size() >= 2; } + double length() const { return Slic3r::length(this->points); } + + void clear() { this->points.clear(); this->width.clear(); } + void reverse() { - Polyline::reverse(); + std::reverse(this->points.begin(), this->points.end()); std::reverse(this->width.begin(), this->width.end()); std::swap(this->endpoints.first, this->endpoints.second); } void clip_end(double distance); - std::vector width; - std::pair endpoints; + Points points; + std::vector width; + std::pair endpoints { false, false }; }; inline ThickPolylines to_thick_polylines(Polylines &&polylines, const coordf_t width) diff --git a/src/libslic3r/SVG.cpp b/src/libslic3r/SVG.cpp index d4088089b..4770334de 100644 --- a/src/libslic3r/SVG.cpp +++ b/src/libslic3r/SVG.cpp @@ -179,8 +179,8 @@ void SVG::draw(const ThickLines &thicklines, const std::string &fill, const std: void SVG::draw(const ThickPolylines &polylines, const std::string &stroke, coordf_t stroke_width) { - for (ThickPolylines::const_iterator it = polylines.begin(); it != polylines.end(); ++it) - this->draw((Polyline)*it, stroke, stroke_width); + for (const ThickPolyline &pl : polylines) + this->draw(Polyline(pl.points), stroke, stroke_width); } void SVG::draw(const ThickPolylines &thickpolylines, const std::string &fill, const std::string &stroke, coordf_t stroke_width) From 1912b834b19968f114c9f0ed41895fb30ab5e35b Mon Sep 17 00:00:00 2001 From: Vojtech Bubnik Date: Tue, 10 Jan 2023 12:18:47 +0100 Subject: [PATCH 2/4] Fixed a typo in SupportSpotsGenerator, where thin fills were pulled from an incorrect region. --- src/libslic3r/SupportSpotsGenerator.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libslic3r/SupportSpotsGenerator.cpp b/src/libslic3r/SupportSpotsGenerator.cpp index 07055576a..ecca5ac5c 100644 --- a/src/libslic3r/SupportSpotsGenerator.cpp +++ b/src/libslic3r/SupportSpotsGenerator.cpp @@ -619,7 +619,7 @@ std::tuple build_object_part_from_slice(const LayerSlice &sli } const LayerRegion *thin_fill_region = layer->get_region(island.fill_region_id); for (const auto &thin_fill_idx : island.thin_fills) { - add_extrusions_to_object(thin_fill_region->thin_fills().entities[thin_fill_idx], perimeter_region); + add_extrusions_to_object(perimeter_region->thin_fills().entities[thin_fill_idx], perimeter_region); } } From 25dffb9c2f00c9bc52adea508c7c93815ca2e6ba Mon Sep 17 00:00:00 2001 From: Vojtech Bubnik Date: Tue, 10 Jan 2023 12:37:05 +0100 Subject: [PATCH 3/4] Fix of slicing with modifiers after recent refactoring - sorting infills into islands. --- src/libslic3r/Layer.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/libslic3r/Layer.cpp b/src/libslic3r/Layer.cpp index 35b4a331a..37a24b54c 100644 --- a/src/libslic3r/Layer.cpp +++ b/src/libslic3r/Layer.cpp @@ -497,15 +497,18 @@ void Layer::make_perimeters() } else { SurfaceCollection new_slices; // Use the region with highest infill rate, as the make_perimeters() function below decides on the gap fill based on the infill existence. - LayerRegion *layerm_config = m_regions[layer_region_ids.front()]; - { + uint32_t region_id_config = layer_region_ids.front(); + LayerRegion* layerm_config = m_regions[region_id_config]; + { // Merge slices (surfaces) according to number of extra perimeters. for (uint32_t region_id : layer_region_ids) { LayerRegion &layerm = *m_regions[region_id]; for (const Surface &surface : layerm.slices()) surfaces_to_merge.emplace_back(&surface); - if (layerm.region().config().fill_density > layerm_config->region().config().fill_density) - layerm_config = &layerm; + if (layerm.region().config().fill_density > layerm_config->region().config().fill_density) { + region_id_config = region_id; + layerm_config = &layerm; + } } std::sort(surfaces_to_merge.begin(), surfaces_to_merge.end(), [](const Surface *l, const Surface *r){ return l->extra_perimeters < r->extra_perimeters; }); for (size_t i = 0; i < surfaces_to_merge.size();) { @@ -525,7 +528,7 @@ void Layer::make_perimeters() } // make perimeters layerm_config->make_perimeters(new_slices, perimeter_and_gapfill_ranges, fill_expolygons, fill_expolygons_ranges); - this->sort_perimeters_into_islands(new_slices, region_id, perimeter_and_gapfill_ranges, std::move(fill_expolygons), fill_expolygons_ranges, layer_region_ids); + this->sort_perimeters_into_islands(new_slices, region_id_config, perimeter_and_gapfill_ranges, std::move(fill_expolygons), fill_expolygons_ranges, layer_region_ids); } } } From 6f20c68c8d8d5ffeaac2dea67fc9e87e0aa1709e Mon Sep 17 00:00:00 2001 From: Vojtech Bubnik Date: Tue, 10 Jan 2023 12:37:44 +0100 Subject: [PATCH 4/4] Follow-up to 1912b834b19968f114c9f0ed41895fb30ab5e35b Fixed a typo in SupportSpotsGenerator, where thin fills were pulled from an incorrect region. --- src/libslic3r/SupportSpotsGenerator.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libslic3r/SupportSpotsGenerator.cpp b/src/libslic3r/SupportSpotsGenerator.cpp index ecca5ac5c..3d061269a 100644 --- a/src/libslic3r/SupportSpotsGenerator.cpp +++ b/src/libslic3r/SupportSpotsGenerator.cpp @@ -617,7 +617,6 @@ std::tuple build_object_part_from_slice(const LayerSlice &sli } } } - const LayerRegion *thin_fill_region = layer->get_region(island.fill_region_id); for (const auto &thin_fill_idx : island.thin_fills) { add_extrusions_to_object(perimeter_region->thin_fills().entities[thin_fill_idx], perimeter_region); }