|
@@ -629,13 +629,13 @@ Points getFrontier(Polylines& polylines, const Point& p1, const Point& p2, const
|
|
|
/// return the connected polylines in polylines_out. Can output polygons (stored as polylines with first_point = last_point).
|
|
|
/// complexity: worst: N(infill_ordered.points) x N(boundary.points)
|
|
|
/// typical: N(infill_ordered) x ( N(boundary.points) + N(infill_ordered.points) )
|
|
|
-void connect_infill(const Polylines& infill_ordered, const ExPolygon& boundary, Polylines& polylines_out, const double spacing, const FillParams& params) {
|
|
|
+void connect_infill(const Polylines& infill_ordered, const ExPolygon& boundary, Polylines& polylines_out, const coord_t spacing, const FillParams& params) {
|
|
|
|
|
|
//TODO: fallback to the quick & dirty old algorithm when n(points) is too high.
|
|
|
Polylines polylines_frontier = to_polylines(((Polygons)boundary));
|
|
|
|
|
|
Polylines polylines_blocker;
|
|
|
- coord_t clip_size = scale_(spacing) * 2;
|
|
|
+ coord_t clip_size = (spacing) * 2;
|
|
|
for (const Polyline& polyline : infill_ordered) {
|
|
|
if (polyline.length() > 2.01 * clip_size) {
|
|
|
polylines_blocker.push_back(polyline);
|
|
@@ -655,8 +655,8 @@ void connect_infill(const Polylines& infill_ordered, const ExPolygon& boundary,
|
|
|
Points& pts_end = polylines_connected_first.back().points;
|
|
|
const Point& last_point = pts_end.back();
|
|
|
const Point& first_point = polyline.points.front();
|
|
|
- if (last_point.distance_to(first_point) < scale_(spacing) * 10) {
|
|
|
- Points pts_frontier = getFrontier(polylines_frontier, last_point, first_point, scale_(spacing), polylines_blocker, scale_(ideal_length) * 2);
|
|
|
+ if (last_point.distance_to(first_point) < (spacing) * 10) {
|
|
|
+ Points pts_frontier = getFrontier(polylines_frontier, last_point, first_point, (spacing), polylines_blocker, (ideal_length) * 2);
|
|
|
if (!pts_frontier.empty()) {
|
|
|
// The lines can be connected.
|
|
|
pts_end.insert(pts_end.end(), pts_frontier.begin(), pts_frontier.end());
|
|
@@ -681,7 +681,7 @@ void connect_infill(const Polylines& infill_ordered, const ExPolygon& boundary,
|
|
|
const Point& first_point = polyline.points.front();
|
|
|
|
|
|
Polylines before = polylines_frontier;
|
|
|
- Points pts_frontier = getFrontier(polylines_frontier, last_point, first_point, scale_(spacing), polylines_blocker);
|
|
|
+ Points pts_frontier = getFrontier(polylines_frontier, last_point, first_point, (spacing), polylines_blocker);
|
|
|
if (!pts_frontier.empty()) {
|
|
|
// The lines can be connected.
|
|
|
pts_end.insert(pts_end.end(), pts_frontier.begin(), pts_frontier.end());
|
|
@@ -718,7 +718,7 @@ void connect_infill(const Polylines& infill_ordered, const ExPolygon& boundary,
|
|
|
Points pts_frontier = getFrontier(polylines_frontier,
|
|
|
switch_id1 ? polylines_connected[idx1].first_point() : polylines_connected[idx1].last_point(),
|
|
|
switch_id2 ? polylines_connected[min_idx].last_point() : polylines_connected[min_idx].first_point(),
|
|
|
- scale_(spacing), polylines_blocker);
|
|
|
+ (spacing), polylines_blocker);
|
|
|
if (!pts_frontier.empty()) {
|
|
|
if (switch_id1) polylines_connected[idx1].reverse();
|
|
|
if (switch_id2) polylines_connected[min_idx].reverse();
|
|
@@ -732,7 +732,7 @@ void connect_infill(const Polylines& infill_ordered, const ExPolygon& boundary,
|
|
|
|
|
|
//try to create some loops if possible
|
|
|
for (Polyline& polyline : polylines_connected) {
|
|
|
- Points pts_frontier = getFrontier(polylines_frontier, polyline.last_point(), polyline.first_point(), scale_(spacing), polylines_blocker);
|
|
|
+ Points pts_frontier = getFrontier(polylines_frontier, polyline.last_point(), polyline.first_point(), (spacing), polylines_blocker);
|
|
|
if (!pts_frontier.empty()) {
|
|
|
polyline.points.insert(polyline.points.end(), pts_frontier.begin(), pts_frontier.end());
|
|
|
polyline.points.insert(polyline.points.begin(), polyline.points.back());
|
|
@@ -1053,7 +1053,7 @@ namespace PrusaSimpleConnect {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- void connect_infill(Polylines &&infill_ordered, const ExPolygon &boundary_src, Polylines &polylines_out, const double spacing, const FillParams ¶ms)
|
|
|
+ void connect_infill(Polylines &&infill_ordered, const ExPolygon &boundary_src, Polylines &polylines_out, const coord_t spacing, const FillParams ¶ms)
|
|
|
{
|
|
|
assert(!infill_ordered.empty());
|
|
|
assert(!boundary_src.contour.points.empty());
|
|
@@ -1132,16 +1132,16 @@ namespace PrusaSimpleConnect {
|
|
|
|
|
|
// Mark the points and segments of split boundary as consumed if they are very close to some of the infill line.
|
|
|
{
|
|
|
- // @supermerill used 2. * scale_(spacing)
|
|
|
- const double clip_distance = 3. * scale_(spacing);
|
|
|
- const double distance_colliding = 1.1 * scale_(spacing);
|
|
|
+ // @supermerill used 2. * (spacing)
|
|
|
+ const double clip_distance = 3. * (spacing);
|
|
|
+ const double distance_colliding = 1.1 * (spacing);
|
|
|
mark_boundary_segments_touching_infill(boundary, boundary_data, bbox, infill_ordered, clip_distance, distance_colliding);
|
|
|
}
|
|
|
|
|
|
// Connection from end of one infill line to the start of another infill line.
|
|
|
- //const float length_max = scale_(spacing);
|
|
|
- // const float length_max = scale_((2. / params.density) * spacing);
|
|
|
- const coord_t length_max = scale_((1000. / params.density) * spacing);
|
|
|
+ //const float length_max = (spacing);
|
|
|
+ // const float length_max = ((2. / params.density) * spacing);
|
|
|
+ const coord_t length_max = ((1000. / params.density) * spacing);
|
|
|
std::vector<size_t> merged_with(infill_ordered.size());
|
|
|
for (size_t i = 0; i < merged_with.size(); ++i)
|
|
|
merged_with[i] = i;
|
|
@@ -2169,7 +2169,7 @@ void mark_boundary_segments_touching_infill(
|
|
|
assert(validate_boundary_intersections(boundary_intersections));
|
|
|
}
|
|
|
|
|
|
-void connect_infill(Polylines&& infill_ordered, const ExPolygon& boundary_src, Polylines& polylines_out, const double spacing, const FillParams& params)
|
|
|
+void connect_infill(Polylines&& infill_ordered, const ExPolygon& boundary_src, Polylines& polylines_out, const coord_t spacing, const FillParams& params)
|
|
|
{
|
|
|
assert(!boundary_src.contour.points.empty());
|
|
|
auto polygons_src = reserve_vector<const Polygon*>(boundary_src.holes.size() + 1);
|
|
@@ -2182,7 +2182,7 @@ void connect_infill(Polylines&& infill_ordered, const ExPolygon& boundary_src, P
|
|
|
connect_infill(std::move(infill_ordered), polygons_src, get_extents(boundary_src.contour), polylines_out, spacing, params);
|
|
|
}
|
|
|
|
|
|
-void connect_infill(Polylines&& infill_ordered, const Polygons& boundary_src, const BoundingBox& bbox, Polylines& polylines_out, const double spacing, const FillParams& params)
|
|
|
+void connect_infill(Polylines&& infill_ordered, const Polygons& boundary_src, const BoundingBox& bbox, Polylines& polylines_out, const coord_t spacing, const FillParams& params)
|
|
|
{
|
|
|
auto polygons_src = reserve_vector<const Polygon*>(boundary_src.size());
|
|
|
for (const Polygon& polygon : boundary_src)
|
|
@@ -2285,7 +2285,7 @@ static inline void mark_boundary_segments_overlapping_infill(
|
|
|
// Infill lines, either completely inside the boundary, or touching the boundary.
|
|
|
const Polylines &infill,
|
|
|
// Spacing (width) of the infill lines.
|
|
|
- const double spacing)
|
|
|
+ const coord_t spacing)
|
|
|
{
|
|
|
for (ContourIntersectionPoint &cp : graph.map_infill_end_point_to_boundary) {
|
|
|
const Points &contour = graph.boundary[cp.contour_idx];
|
|
@@ -2360,7 +2360,7 @@ static inline void mark_boundary_segments_overlapping_infill(
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-BoundaryInfillGraph create_boundary_infill_graph(const Polylines &infill_ordered, const std::vector<const Polygon*> &boundary_src, const BoundingBox &bbox, const double spacing)
|
|
|
+BoundaryInfillGraph create_boundary_infill_graph(const Polylines &infill_ordered, const std::vector<const Polygon*> &boundary_src, const BoundingBox &bbox, const coord_t spacing)
|
|
|
{
|
|
|
BoundaryInfillGraph out;
|
|
|
out.boundary.assign(boundary_src.size(), Points());
|
|
@@ -2484,12 +2484,12 @@ BoundaryInfillGraph create_boundary_infill_graph(const Polylines &infill_ordered
|
|
|
|
|
|
// Mark the points and segments of split out.boundary as consumed if they are very close to some of the infill line.
|
|
|
{
|
|
|
- // @supermerill used 2. * scale_(spacing)
|
|
|
- const double clip_distance = 1.7 * scale_(spacing);
|
|
|
+ // @supermerill used 2. * (spacing)
|
|
|
+ const double clip_distance = 1.7 * (spacing);
|
|
|
// Allow a bit of overlap. This value must be slightly higher than the overlap of FillAdaptive, otherwise
|
|
|
// the anchors of the adaptive infill will mask the other side of the perimeter line.
|
|
|
// (see connect_lines_using_hooks() in FillAdaptive.cpp)
|
|
|
- const double distance_colliding = 0.8 * scale_(spacing);
|
|
|
+ const double distance_colliding = 0.8 * (spacing);
|
|
|
mark_boundary_segments_touching_infill(out.boundary, out.boundary_params, boundary_intersection_points, bbox, infill_ordered, clip_distance, distance_colliding);
|
|
|
}
|
|
|
}
|
|
@@ -2497,7 +2497,7 @@ BoundaryInfillGraph create_boundary_infill_graph(const Polylines &infill_ordered
|
|
|
return out;
|
|
|
}
|
|
|
|
|
|
-void connect_infill(Polylines &&infill_ordered, const std::vector<const Polygon*> &boundary_src, const BoundingBox &bbox, Polylines &polylines_out, const double spacing, const FillParams ¶ms)
|
|
|
+void connect_infill(Polylines &&infill_ordered, const std::vector<const Polygon*> &boundary_src, const BoundingBox &bbox, Polylines &polylines_out, const coord_t spacing, const FillParams ¶ms)
|
|
|
{
|
|
|
assert(! infill_ordered.empty());
|
|
|
assert(params.anchor_length >= 0.);
|
|
@@ -2544,13 +2544,13 @@ void connect_infill(Polylines &&infill_ordered, const std::vector<const Polygon*
|
|
|
return std::numeric_limits<size_t>::max();
|
|
|
};
|
|
|
|
|
|
- const double line_half_width = 0.5 * scale_(spacing);
|
|
|
+ const double line_half_width = 0.5 * (spacing);
|
|
|
|
|
|
#if 0
|
|
|
// Connection from end of one infill line to the start of another infill line.
|
|
|
- //const double length_max = scale_(spacing);
|
|
|
-// const auto length_max = double(scale_((2. / params.density) * spacing));
|
|
|
- const auto length_max = double(scale_((1000. / params.density) * spacing));
|
|
|
+ //const double length_max = (spacing);
|
|
|
+// const auto length_max = double(((2. / params.density) * spacing));
|
|
|
+ const auto length_max = double(((1000. / params.density) * spacing));
|
|
|
struct ConnectionCost {
|
|
|
ConnectionCost(size_t idx_first, double cost, bool reversed) : idx_first(idx_first), cost(cost), reversed(reversed) {}
|
|
|
size_t idx_first;
|
|
@@ -2745,7 +2745,7 @@ void connect_infill(Polylines &&infill_ordered, const std::vector<const Polygon*
|
|
|
|
|
|
// Extend the infill lines along the perimeters, this is mainly useful for grid aligned support, where a perimeter line may be nearly
|
|
|
// aligned with the infill lines.
|
|
|
-static inline void base_support_extend_infill_lines(Polylines &infill, BoundaryInfillGraph &graph, const double spacing, const FillParams ¶ms)
|
|
|
+static inline void base_support_extend_infill_lines(Polylines &infill, BoundaryInfillGraph &graph, const coord_t line_spacing, const FillParams ¶ms)
|
|
|
{
|
|
|
/*
|
|
|
// Backup the source lines.
|
|
@@ -2753,8 +2753,6 @@ static inline void base_support_extend_infill_lines(Polylines &infill, BoundaryI
|
|
|
lines.reserve(linfill.size());
|
|
|
std::transform(infill.begin(), infill.end(), std::back_inserter(lines), [](const Polyline &pl) { assert(pl.size() == 2); return Line(pl.points.begin(), pl.points.end()); });
|
|
|
*/
|
|
|
-
|
|
|
- const double line_spacing = scale_(spacing) / params.density;
|
|
|
// Maximum deviation perpendicular to the infill line to allow merging as a continuation of the same infill line.
|
|
|
const auto dist_max_x = coord_t(line_spacing * 0.33);
|
|
|
// Minimum length of the arc away from the infill end point to allow merging as a continuation of the same infill line.
|
|
@@ -3114,7 +3112,7 @@ static double evaluate_support_arch_cost(const Polyline &pl)
|
|
|
}
|
|
|
|
|
|
// Costs for prev / next arch of each infill line end point.
|
|
|
-static inline std::vector<SupportArcCost> evaluate_support_arches(Polylines &infill, BoundaryInfillGraph &graph, const double spacing, const FillParams ¶ms)
|
|
|
+static inline std::vector<SupportArcCost> evaluate_support_arches(Polylines &infill, BoundaryInfillGraph &graph, const FillParams ¶ms)
|
|
|
{
|
|
|
std::vector<SupportArcCost> arches(graph.map_infill_end_point_to_boundary.size() * 2);
|
|
|
|
|
@@ -3160,13 +3158,15 @@ static inline std::vector<SupportArcCost> evaluate_support_arches(Polylines &inf
|
|
|
} // end namespace FakePerimeterConnect
|
|
|
|
|
|
// Both the poly_with_offset and polylines_out are rotated, so the infill lines are strictly vertical.
|
|
|
-void Fill::connect_base_support(Polylines &&infill_ordered, const std::vector<const Polygon*> &boundary_src, const BoundingBox &bbox, Polylines &polylines_out, const double spacing, const FillParams ¶ms)
|
|
|
+void Fill::connect_base_support(Polylines &&infill_ordered, const std::vector<const Polygon*> &boundary_src, const BoundingBox &bbox, Polylines &polylines_out, const coord_t line_spacing, const FillParams ¶ms)
|
|
|
{
|
|
|
// assert(! infill_ordered.empty());
|
|
|
assert(params.anchor_length >= 0.);
|
|
|
assert(params.anchor_length_max >= 0.01f);
|
|
|
assert(params.anchor_length_max >= params.anchor_length);
|
|
|
|
|
|
+ coord_t spacing = line_spacing * params.density;
|
|
|
+
|
|
|
FakePerimeterConnect::BoundaryInfillGraph graph = FakePerimeterConnect::create_boundary_infill_graph(infill_ordered, boundary_src, bbox, spacing);
|
|
|
|
|
|
#ifdef INFILL_DEBUG_OUTPUT
|
|
@@ -3175,15 +3175,14 @@ void Fill::connect_base_support(Polylines &&infill_ordered, const std::vector<co
|
|
|
export_partial_infill_to_svg(debug_out_path("connect_base_support-initial-%03d.svg", iRun), graph, infill_ordered, polylines_out);
|
|
|
#endif // INFILL_DEBUG_OUTPUT
|
|
|
|
|
|
- const double line_half_width = 0.5 * scale_(spacing);
|
|
|
- const double line_spacing = ((params.max_sparse_infill_spacing > 0) ? params.max_sparse_infill_spacing : spacing) / params.density;
|
|
|
+ const double line_half_width = 0.5 * spacing;
|
|
|
const double min_arch_length = 1.3 * line_spacing;
|
|
|
const double trim_length = line_half_width * 0.3;
|
|
|
|
|
|
// After mark_boundary_segments_touching_infill() marks boundary segments overlapping trimmed infill lines,
|
|
|
// there are possibly some very short boundary segments unmarked, but overlapping the untrimmed infill lines fully.
|
|
|
// Mark those short boundary segments.
|
|
|
- mark_boundary_segments_overlapping_infill(graph, infill_ordered, scale_(spacing));
|
|
|
+ mark_boundary_segments_overlapping_infill(graph, infill_ordered, spacing);
|
|
|
|
|
|
#ifdef INFILL_DEBUG_OUTPUT
|
|
|
export_partial_infill_to_svg(debug_out_path("connect_base_support-marked-%03d.svg", iRun), graph, infill_ordered, polylines_out);
|
|
@@ -3239,7 +3238,7 @@ void Fill::connect_base_support(Polylines &&infill_ordered, const std::vector<co
|
|
|
export_partial_infill_to_svg(debug_out_path("connect_base_support-excess-%03d.svg", iRun), graph, infill_ordered, polylines_out);
|
|
|
#endif // INFILL_DEBUG_OUTPUT
|
|
|
|
|
|
- base_support_extend_infill_lines(infill_ordered, graph, spacing, params);
|
|
|
+ base_support_extend_infill_lines(infill_ordered, graph, line_spacing, params);
|
|
|
|
|
|
#ifdef INFILL_DEBUG_OUTPUT
|
|
|
export_partial_infill_to_svg(debug_out_path("connect_base_support-extended-%03d.svg", iRun), graph, infill_ordered, polylines_out);
|
|
@@ -3376,7 +3375,7 @@ void Fill::connect_base_support(Polylines &&infill_ordered, const std::vector<co
|
|
|
export_partial_infill_to_svg(debug_out_path("connect_base_support-vertical-%03d.svg", iRun), graph, infill_ordered, polylines_out);
|
|
|
#endif // INFILL_DEBUG_OUTPUT
|
|
|
|
|
|
- const std::vector<FakePerimeterConnect::SupportArcCost> arches = FakePerimeterConnect::evaluate_support_arches(infill_ordered, graph, spacing, params);
|
|
|
+ const std::vector<FakePerimeterConnect::SupportArcCost> arches = FakePerimeterConnect::evaluate_support_arches(infill_ordered, graph, params);
|
|
|
static const double cost_low = line_spacing * 1.3;
|
|
|
static const double cost_high = line_spacing * 2.;
|
|
|
static const double cost_veryhigh = line_spacing * 3.;
|
|
@@ -3615,16 +3614,16 @@ void Fill::connect_base_support(Polylines &&infill_ordered, const std::vector<co
|
|
|
polylines_out.emplace_back(std::move(pl));
|
|
|
}
|
|
|
|
|
|
-void Fill::connect_base_support(Polylines &&infill_ordered, const Polygons &boundary_src, const BoundingBox &bbox, Polylines &polylines_out, const double spacing, const FillParams ¶ms)
|
|
|
+void Fill::connect_base_support(Polylines &&infill_ordered, const Polygons &boundary_src, const BoundingBox &bbox, Polylines &polylines_out, const coord_t line_spacing, const FillParams ¶ms)
|
|
|
{
|
|
|
auto polygons_src = reserve_vector<const Polygon*>(boundary_src.size());
|
|
|
for (const Polygon &polygon : boundary_src)
|
|
|
polygons_src.emplace_back(&polygon);
|
|
|
|
|
|
- connect_base_support(std::move(infill_ordered), polygons_src, bbox, polylines_out, spacing, params);
|
|
|
+ connect_base_support(std::move(infill_ordered), polygons_src, bbox, polylines_out, line_spacing, params);
|
|
|
}
|
|
|
|
|
|
-void Fill::connect_infill(Polylines&& infill_ordered, const ExPolygon& boundary, Polylines& polylines_out, const double spacing, const FillParams& params) {
|
|
|
+void Fill::connect_infill(Polylines&& infill_ordered, const ExPolygon& boundary, Polylines& polylines_out, const coord_t spacing, const FillParams& params) {
|
|
|
if (params.anchor_length_max == 0) {
|
|
|
PrusaSimpleConnect::connect_infill(std::move(infill_ordered), boundary, polylines_out, spacing, params);
|
|
|
} else {
|
|
@@ -3632,7 +3631,7 @@ void Fill::connect_infill(Polylines&& infill_ordered, const ExPolygon& boundary,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void Fill::connect_infill(Polylines&& infill_ordered, const ExPolygon& boundary, const Polygons& polygons_src, Polylines& polylines_out, const double spacing, const FillParams& params) {
|
|
|
+void Fill::connect_infill(Polylines&& infill_ordered, const ExPolygon& boundary, const Polygons& polygons_src, Polylines& polylines_out, const coord_t spacing, const FillParams& params) {
|
|
|
if (params.anchor_length_max == 0) {
|
|
|
PrusaSimpleConnect::connect_infill(std::move(infill_ordered), boundary, polylines_out, spacing, params);
|
|
|
} else {
|