mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-01 10:22:03 +08:00
Little refactoring, make the fill modifiable
This commit is contained in:
parent
801a41a352
commit
0a7c48f5fd
@ -147,9 +147,9 @@ protected:
|
||||
|
||||
virtual float _layer_angle(size_t idx) const { return (idx & 1) ? float(M_PI/2.) : 0; }
|
||||
|
||||
virtual std::pair<float, Point> _infill_direction(const Surface *surface) const;
|
||||
|
||||
public:
|
||||
virtual std::pair<float, Point> _infill_direction(const Surface *surface) const;
|
||||
static void connect_infill(Polylines &&infill_ordered, const ExPolygon &boundary, Polylines &polylines_out, const double spacing, const FillParams ¶ms);
|
||||
static void connect_infill(Polylines &&infill_ordered, const Polygons &boundary, const BoundingBox& bbox, Polylines &polylines_out, const double spacing, const FillParams ¶ms);
|
||||
static void connect_infill(Polylines &&infill_ordered, const std::vector<const Polygon*> &boundary, const BoundingBox &bbox, Polylines &polylines_out, double spacing, const FillParams ¶ms);
|
||||
|
@ -25,10 +25,9 @@
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
ThickPolylines FillEnsuring::fill_surface_arachne(const Surface *surface, const FillParams ¶ms)
|
||||
ThickPolylines make_fill_polylines(const Fill *fill, const Surface *surface, const FillParams ¶ms, bool stop_vibrations, bool fill_gaps)
|
||||
{
|
||||
assert(params.use_arachne);
|
||||
assert(this->print_config != nullptr && this->print_object_config != nullptr && this->print_region_config != nullptr);
|
||||
assert(fill->print_config != nullptr && fill->print_object_config != nullptr && fill->print_region_config != nullptr);
|
||||
|
||||
auto rotate_thick_polylines = [](ThickPolylines &tpolylines, double cos_angle, double sin_angle) {
|
||||
for (ThickPolyline &tp : tpolylines) {
|
||||
@ -46,14 +45,13 @@ ThickPolylines FillEnsuring::fill_surface_arachne(const Surface *surface, const
|
||||
(bhigh >= alow && bhigh <= ahigh);
|
||||
};
|
||||
|
||||
const coord_t scaled_spacing = scaled<coord_t>(this->spacing);
|
||||
const coord_t scaled_spacing = scaled<coord_t>(fill->spacing);
|
||||
double distance_limit_reconnection = double(scaled_spacing);
|
||||
double squared_distance_limit_reconnection = distance_limit_reconnection * distance_limit_reconnection;
|
||||
Polygons filled_area = to_polygons(surface->expolygon);
|
||||
std::pair<float, Point> rotate_vector = this->_infill_direction(surface);
|
||||
std::pair<float, Point> rotate_vector = fill->_infill_direction(surface);
|
||||
double aligning_angle = -rotate_vector.first + PI;
|
||||
polygons_rotate(filled_area, aligning_angle);
|
||||
Polygons internal_area = shrink(filled_area, 0.5 * scaled_spacing - scale_(this->overlap));
|
||||
BoundingBox bb = get_extents(filled_area);
|
||||
|
||||
const size_t n_vlines = (bb.max.x() - bb.min.x() + scaled_spacing - 1) / scaled_spacing;
|
||||
@ -65,11 +63,18 @@ ThickPolylines FillEnsuring::fill_surface_arachne(const Surface *surface, const
|
||||
vertical_lines[i].a = Point{x, y_min};
|
||||
vertical_lines[i].b = Point{x, y_max};
|
||||
}
|
||||
vertical_lines.push_back(vertical_lines.back());
|
||||
vertical_lines.back().a = Point{coord_t(bb.min.x() + n_vlines * double(scaled_spacing) + scaled_spacing * 0.5), y_min};
|
||||
vertical_lines.back().b = Point{vertical_lines.back().a.x(), y_max};
|
||||
|
||||
auto area_walls = AABBTreeLines::LinesDistancer<Line>{
|
||||
AABBTreeLines::LinesDistancer<Line> area_walls;
|
||||
if (stop_vibrations) {
|
||||
area_walls = AABBTreeLines::LinesDistancer<Line>{
|
||||
to_lines(intersection(filled_area, opening(filled_area, 2 * scaled_spacing, 3 * scaled_spacing)))};
|
||||
} else {
|
||||
area_walls = AABBTreeLines::LinesDistancer<Line>{to_lines(filled_area)};
|
||||
}
|
||||
|
||||
std::vector<std::vector<Line>> polygon_sections(n_vlines);
|
||||
|
||||
for (size_t i = 0; i < n_vlines; i++) {
|
||||
@ -86,6 +91,7 @@ ThickPolylines FillEnsuring::fill_surface_arachne(const Surface *surface, const
|
||||
}
|
||||
}
|
||||
|
||||
if (stop_vibrations) {
|
||||
struct Node
|
||||
{
|
||||
int section_idx;
|
||||
@ -159,6 +165,7 @@ ThickPolylines FillEnsuring::fill_surface_arachne(const Surface *surface, const
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t section_idx = 0; section_idx < polygon_sections.size(); section_idx++) {
|
||||
polygon_sections[section_idx].erase(std::remove_if(polygon_sections[section_idx].begin(), polygon_sections[section_idx].end(),
|
||||
@ -247,8 +254,8 @@ ThickPolylines FillEnsuring::fill_surface_arachne(const Surface *surface, const
|
||||
|
||||
reconstructed_area = closing(reconstructed_area, float(SCALED_EPSILON), float(SCALED_EPSILON));
|
||||
ExPolygons gaps_for_additional_filling = diff_ex(filled_area, reconstructed_area);
|
||||
if (this->overlap != 0) {
|
||||
gaps_for_additional_filling = offset_ex(gaps_for_additional_filling, scaled<float>(this->overlap));
|
||||
if (fill->overlap != 0) {
|
||||
gaps_for_additional_filling = offset_ex(gaps_for_additional_filling, scaled<float>(fill->overlap));
|
||||
}
|
||||
|
||||
// BoundingBox bbox = get_extents(filled_area);
|
||||
@ -274,12 +281,13 @@ ThickPolylines FillEnsuring::fill_surface_arachne(const Surface *surface, const
|
||||
}
|
||||
}
|
||||
|
||||
if (fill_gaps) {
|
||||
for (ExPolygon &ex_poly : gaps_for_additional_filling) {
|
||||
BoundingBox ex_bb = ex_poly.contour.bounding_box();
|
||||
coord_t loops_count = (std::max(ex_bb.size().x(), ex_bb.size().y()) + scaled_spacing - 1) / scaled_spacing;
|
||||
Polygons polygons = to_polygons(ex_poly);
|
||||
Arachne::WallToolPaths wall_tool_paths(polygons, scaled_spacing, scaled_spacing, loops_count, 0, params.layer_height,
|
||||
*this->print_object_config, *this->print_config);
|
||||
*fill->print_object_config, *fill->print_config);
|
||||
if (std::vector<Arachne::VariableWidthLines> loops = wall_tool_paths.getToolPaths(); !loops.empty()) {
|
||||
std::vector<const Arachne::ExtrusionLine *> all_extrusions;
|
||||
for (Arachne::VariableWidthLines &loop : loops) {
|
||||
@ -298,10 +306,21 @@ ThickPolylines FillEnsuring::fill_surface_arachne(const Surface *surface, const
|
||||
thick_polyline.start_at_index(nearest_point_index(thick_polyline.points, ex_bb.min));
|
||||
thick_polyline.clip_end(scaled_spacing * 0.5);
|
||||
}
|
||||
if (thick_polyline.is_valid() && thick_polyline.length() > 0 && thick_polyline.points.size() > 1) {
|
||||
thick_polylines.push_back(thick_polyline);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::sort(thick_polylines.begin(), thick_polylines.end(), [](const ThickPolyline &left, const ThickPolyline &right) {
|
||||
BoundingBox lbb(left.points);
|
||||
BoundingBox rbb(right.points);
|
||||
if (lbb.min.x() == rbb.min.x())
|
||||
return lbb.min.y() < rbb.min.y();
|
||||
else
|
||||
return lbb.min.x() < rbb.min.x();
|
||||
});
|
||||
|
||||
// connect tiny gap fills to close colinear line
|
||||
struct EndPoint
|
||||
@ -385,18 +404,9 @@ ThickPolylines FillEnsuring::fill_surface_arachne(const Surface *surface, const
|
||||
[scaled_spacing](double w) { return w < scaled_spacing; });
|
||||
}),
|
||||
thick_polylines.end());
|
||||
}
|
||||
|
||||
std::sort(thick_polylines.begin(), thick_polylines.end(), [](const ThickPolyline &left, const ThickPolyline &right) {
|
||||
BoundingBox lbb(left.points);
|
||||
BoundingBox rbb(right.points);
|
||||
if (lbb.min.x() == rbb.min.x())
|
||||
return lbb.max.y() < rbb.max.y();
|
||||
else
|
||||
return lbb.max.x() < rbb.max.x();
|
||||
});
|
||||
|
||||
Algorithm::sort_paths(thick_polylines.begin(), thick_polylines.end(), bb.min, double(scaled_spacing) * 1.2, [](const ThickPolyline
|
||||
&tp) {
|
||||
Algorithm::sort_paths(thick_polylines.begin(), thick_polylines.end(), bb.min, double(scaled_spacing) * 1.2, [](const ThickPolyline &tp) {
|
||||
Lines ls;
|
||||
Point prev = tp.first_point();
|
||||
for (size_t i = 1; i < tp.points.size(); i++) {
|
||||
|
@ -6,13 +6,18 @@
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
class FillEnsuring : public FillRectilinear
|
||||
ThickPolylines make_fill_polylines(const Fill *fill, const Surface *surface, const FillParams ¶ms, bool stop_vibrations, bool fill_gaps);
|
||||
|
||||
class FillEnsuring : public Fill
|
||||
{
|
||||
public:
|
||||
Fill *clone() const override { return new FillEnsuring(*this); }
|
||||
~FillEnsuring() override = default;
|
||||
Polylines fill_surface(const Surface *surface, const FillParams ¶ms) override { return {}; };
|
||||
ThickPolylines fill_surface_arachne(const Surface *surface, const FillParams ¶ms) override;
|
||||
ThickPolylines fill_surface_arachne(const Surface *surface, const FillParams ¶ms) override
|
||||
{
|
||||
return make_fill_polylines(this, surface, params, true, true);
|
||||
};
|
||||
|
||||
protected:
|
||||
void fill_surface_single_arachne(const Surface &surface, const FillParams ¶ms, ThickPolylines &thick_polylines_out);
|
||||
|
Loading…
x
Reference in New Issue
Block a user