This commit is contained in:
Filip Sykala - NTB T15p 2023-01-10 14:10:40 +01:00
commit 9c1f4ef5d3
7 changed files with 34 additions and 20 deletions

View File

@ -14,7 +14,7 @@
#include "../../../clipper/clipper_z.hpp" #include "../../../clipper/clipper_z.hpp"
namespace Slic3r { namespace Slic3r {
class ThickPolyline; struct ThickPolyline;
} }
namespace Slic3r::Arachne namespace Slic3r::Arachne

View File

@ -320,7 +320,9 @@ void ExPolygon::medial_axis(double min_width, double max_width, Polylines* polyl
{ {
ThickPolylines tp; ThickPolylines tp;
this->medial_axis(min_width, max_width, &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 Lines ExPolygon::lines() const

View File

@ -498,6 +498,7 @@ void MedialAxis::build(ThickPolylines* polylines)
polyline.width.emplace_back(seed_edge_data.width_end); polyline.width.emplace_back(seed_edge_data.width_end);
// Grow the polyline in a forward direction. // Grow the polyline in a forward direction.
this->process_edge_neighbors(&*seed_edge, &polyline); this->process_edge_neighbors(&*seed_edge, &polyline);
assert(polyline.width.size() == polyline.points.size() * 2 - 2);
// Grow the polyline in a backward direction. // Grow the polyline in a backward direction.
reverse_polyline.clear(); 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.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.width.insert(polyline.width.begin(), reverse_polyline.width.rbegin(), reverse_polyline.width.rend());
polyline.endpoints.first = reverse_polyline.endpoints.second; polyline.endpoints.first = reverse_polyline.endpoints.second;
assert(polyline.width.size() == polyline.points.size() * 2 - 2); assert(polyline.width.size() == polyline.points.size() * 2 - 2);
// Prevent loop endpoints from being extended. // Prevent loop endpoints from being extended.
@ -538,7 +538,9 @@ void MedialAxis::build(Polylines* polylines)
{ {
ThickPolylines tp; ThickPolylines tp;
this->build(&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) void MedialAxis::process_edge_neighbors(const VD::edge_type *edge, ThickPolyline* polyline)

View File

@ -497,15 +497,18 @@ void Layer::make_perimeters()
} else { } else {
SurfaceCollection new_slices; 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. // 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. // Merge slices (surfaces) according to number of extra perimeters.
for (uint32_t region_id : layer_region_ids) { for (uint32_t region_id : layer_region_ids) {
LayerRegion &layerm = *m_regions[region_id]; LayerRegion &layerm = *m_regions[region_id];
for (const Surface &surface : layerm.slices()) for (const Surface &surface : layerm.slices())
surfaces_to_merge.emplace_back(&surface); surfaces_to_merge.emplace_back(&surface);
if (layerm.region().config().fill_density > layerm_config->region().config().fill_density) if (layerm.region().config().fill_density > layerm_config->region().config().fill_density) {
layerm_config = &layerm; 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; }); 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();) { for (size_t i = 0; i < surfaces_to_merge.size();) {
@ -525,7 +528,7 @@ void Layer::make_perimeters()
} }
// make perimeters // make perimeters
layerm_config->make_perimeters(new_slices, perimeter_and_gapfill_ranges, fill_expolygons, fill_expolygons_ranges); 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);
} }
} }
} }

View File

@ -10,7 +10,7 @@
namespace Slic3r { namespace Slic3r {
class Polyline; class Polyline;
class ThickPolyline; struct ThickPolyline;
typedef std::vector<Polyline> Polylines; typedef std::vector<Polyline> Polylines;
typedef std::vector<ThickPolyline> ThickPolylines; typedef std::vector<ThickPolyline> 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. // Returns index of a segment of a polyline and foot point of pt on polyline.
std::pair<int, Point> foot_pt(const Points &polyline, const Point &pt); std::pair<int, Point> foot_pt(const Points &polyline, const Point &pt);
class ThickPolyline : public Polyline { struct ThickPolyline {
public: ThickPolyline() = default;
ThickPolyline() : endpoints(std::make_pair(false, false)) {}
ThickLines thicklines() const; 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() { void reverse() {
Polyline::reverse(); std::reverse(this->points.begin(), this->points.end());
std::reverse(this->width.begin(), this->width.end()); std::reverse(this->width.begin(), this->width.end());
std::swap(this->endpoints.first, this->endpoints.second); std::swap(this->endpoints.first, this->endpoints.second);
} }
void clip_end(double distance); void clip_end(double distance);
std::vector<coordf_t> width; Points points;
std::pair<bool,bool> endpoints; std::vector<coordf_t> width;
std::pair<bool,bool> endpoints { false, false };
}; };
inline ThickPolylines to_thick_polylines(Polylines &&polylines, const coordf_t width) inline ThickPolylines to_thick_polylines(Polylines &&polylines, const coordf_t width)

View File

@ -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) 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) for (const ThickPolyline &pl : polylines)
this->draw((Polyline)*it, stroke, stroke_width); 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) void SVG::draw(const ThickPolylines &thickpolylines, const std::string &fill, const std::string &stroke, coordf_t stroke_width)

View File

@ -617,9 +617,8 @@ std::tuple<ObjectPart, float> 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) { 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);
} }
} }