Slight code cleanup

This commit is contained in:
Lukas Matena 2020-08-12 12:58:23 +02:00
parent 97bc092cce
commit 6db1e5ab8f
2 changed files with 6 additions and 14 deletions

View file

@ -121,8 +121,8 @@ public:
// Height of the extrusion, used for visualization purposes. // Height of the extrusion, used for visualization purposes.
float height; float height;
ExtrusionPath(ExtrusionRole role) : mm3_per_mm(-1), width(-1), height(-1), m_role(role) {}; ExtrusionPath(ExtrusionRole role) : mm3_per_mm(-1), width(-1), height(-1), m_role(role) {}
ExtrusionPath(ExtrusionRole role, double mm3_per_mm, float width, float height) : mm3_per_mm(mm3_per_mm), width(width), height(height), m_role(role) {}; ExtrusionPath(ExtrusionRole role, double mm3_per_mm, float width, float height) : mm3_per_mm(mm3_per_mm), width(width), height(height), m_role(role) {}
ExtrusionPath(const ExtrusionPath& rhs) : polyline(rhs.polyline), mm3_per_mm(rhs.mm3_per_mm), width(rhs.width), height(rhs.height), m_role(rhs.m_role) {} ExtrusionPath(const ExtrusionPath& rhs) : polyline(rhs.polyline), mm3_per_mm(rhs.mm3_per_mm), width(rhs.width), height(rhs.height), m_role(rhs.m_role) {}
ExtrusionPath(ExtrusionPath&& rhs) : polyline(std::move(rhs.polyline)), mm3_per_mm(rhs.mm3_per_mm), width(rhs.width), height(rhs.height), m_role(rhs.m_role) {} ExtrusionPath(ExtrusionPath&& rhs) : polyline(std::move(rhs.polyline)), mm3_per_mm(rhs.mm3_per_mm), width(rhs.width), height(rhs.height), m_role(rhs.m_role) {}
ExtrusionPath(const Polyline &polyline, const ExtrusionPath &rhs) : polyline(polyline), mm3_per_mm(rhs.mm3_per_mm), width(rhs.width), height(rhs.height), m_role(rhs.m_role) {} ExtrusionPath(const Polyline &polyline, const ExtrusionPath &rhs) : polyline(polyline), mm3_per_mm(rhs.mm3_per_mm), width(rhs.width), height(rhs.height), m_role(rhs.m_role) {}

View file

@ -2463,7 +2463,7 @@ plot(p2.subs(r,0.2).subs(z,1.), (x, -1, 3), adaptive=False, nb_of_points=400)
} }
} }
static Points::iterator project_point_to_polygon_and_insert(Polygon &polygon, const Point &pt, double eps) static Points::const_iterator project_point_to_polygon_and_insert(Polygon &polygon, const Point &pt, double eps)
{ {
assert(polygon.points.size() >= 2); assert(polygon.points.size() >= 2);
if (polygon.points.size() <= 1) if (polygon.points.size() <= 1)
@ -2651,7 +2651,7 @@ std::string GCode::extrude_loop(ExtrusionLoop loop, std::string description, dou
// Insert a projection of last_pos into the polygon. // Insert a projection of last_pos into the polygon.
size_t last_pos_proj_idx; size_t last_pos_proj_idx;
{ {
Points::iterator it = project_point_to_polygon_and_insert(polygon, last_pos, 0.1 * nozzle_r); auto it = project_point_to_polygon_and_insert(polygon, last_pos, 0.1 * nozzle_r);
last_pos_proj_idx = it - polygon.points.begin(); last_pos_proj_idx = it - polygon.points.begin();
} }
@ -2671,11 +2671,9 @@ std::string GCode::extrude_loop(ExtrusionLoop loop, std::string description, dou
if (was_clockwise) if (was_clockwise)
ccwAngle = - ccwAngle; ccwAngle = - ccwAngle;
float penalty = 0; float penalty = 0;
// if (ccwAngle <- float(PI/3.))
if (ccwAngle <- float(0.6 * PI)) if (ccwAngle <- float(0.6 * PI))
// Sharp reflex vertex. We love that, it hides the seam perfectly. // Sharp reflex vertex. We love that, it hides the seam perfectly.
penalty = 0.f; penalty = 0.f;
// else if (ccwAngle > float(PI/3.))
else if (ccwAngle > float(0.6 * PI)) else if (ccwAngle > float(0.6 * PI))
// Seams on sharp convex vertices are more visible than on reflex vertices. // Seams on sharp convex vertices are more visible than on reflex vertices.
penalty = penaltyConvexVertex; penalty = penaltyConvexVertex;
@ -2688,7 +2686,6 @@ std::string GCode::extrude_loop(ExtrusionLoop loop, std::string description, dou
penalty = penaltyConvexVertex + (penaltyFlatSurface - penaltyConvexVertex) * bspline_kernel(ccwAngle * float(PI * 2. / 3.)); penalty = penaltyConvexVertex + (penaltyFlatSurface - penaltyConvexVertex) * bspline_kernel(ccwAngle * float(PI * 2. / 3.));
} }
// Give a negative penalty for points close to the last point or the prefered seam location. // Give a negative penalty for points close to the last point or the prefered seam location.
//float dist_to_last_pos_proj = last_pos_proj.distance_to(polygon.points[i]);
float dist_to_last_pos_proj = (i < last_pos_proj_idx) ? float dist_to_last_pos_proj = (i < last_pos_proj_idx) ?
std::min(lengths[last_pos_proj_idx] - lengths[i], lengths.back() - lengths[last_pos_proj_idx] + lengths[i]) : std::min(lengths[last_pos_proj_idx] - lengths[i], lengths.back() - lengths[last_pos_proj_idx] + lengths[i]) :
std::min(lengths[i] - lengths[last_pos_proj_idx], lengths.back() - lengths[i] + lengths[last_pos_proj_idx]); std::min(lengths[i] - lengths[last_pos_proj_idx], lengths.back() - lengths[i] + lengths[last_pos_proj_idx]);
@ -2708,14 +2705,10 @@ std::string GCode::extrude_loop(ExtrusionLoop loop, std::string description, dou
// Signed distance is positive outside the object, negative inside the object. // Signed distance is positive outside the object, negative inside the object.
// The point is considered at an overhang, if it is more than nozzle radius // The point is considered at an overhang, if it is more than nozzle radius
// outside of the lower layer contour. // outside of the lower layer contour.
#ifdef NDEBUG // to suppress unused variable warning in release mode [[maybe_unused]] bool found = (*lower_layer_edge_grid)->signed_distance(p, search_r, dist);
(*lower_layer_edge_grid)->signed_distance(p, search_r, dist);
#else
bool found = (*lower_layer_edge_grid)->signed_distance(p, search_r, dist);
#endif
// If the approximate Signed Distance Field was initialized over lower_layer_edge_grid, // If the approximate Signed Distance Field was initialized over lower_layer_edge_grid,
// then the signed distnace shall always be known. // then the signed distnace shall always be known.
assert(found); assert(found);
penalties[i] += extrudate_overlap_penalty(float(nozzle_r), penaltyOverhangHalf, float(dist)); penalties[i] += extrudate_overlap_penalty(float(nozzle_r), penaltyOverhangHalf, float(dist));
} }
} }
@ -2723,7 +2716,6 @@ std::string GCode::extrude_loop(ExtrusionLoop loop, std::string description, dou
// Find a point with a minimum penalty. // Find a point with a minimum penalty.
size_t idx_min = std::min_element(penalties.begin(), penalties.end()) - penalties.begin(); size_t idx_min = std::min_element(penalties.begin(), penalties.end()) - penalties.begin();
// if (seam_position == spAligned)
// For all (aligned, nearest, rear) seams: // For all (aligned, nearest, rear) seams:
{ {
// Very likely the weight of idx_min is very close to the weight of last_pos_proj_idx. // Very likely the weight of idx_min is very close to the weight of last_pos_proj_idx.