mirror of
https://git.mirrors.martin98.com/https://github.com/slic3r/Slic3r.git
synced 2025-08-01 04:31:58 +08:00
fix commit 5a5ea5
This commit is contained in:
parent
773e059c39
commit
59747ac40c
@ -499,7 +499,7 @@ MedialAxis::fusion_curve(ThickPolylines &pp)
|
|||||||
|
|
||||||
//check my length is small
|
//check my length is small
|
||||||
coord_t length = (coord_t)polyline.length();
|
coord_t length = (coord_t)polyline.length();
|
||||||
if (length > max_width) continue;
|
if (length > this->max_width) continue;
|
||||||
|
|
||||||
size_t closest_point_idx = this->expolygon.contour.closest_point_index(polyline.points.back());
|
size_t closest_point_idx = this->expolygon.contour.closest_point_index(polyline.points.back());
|
||||||
|
|
||||||
@ -604,7 +604,7 @@ MedialAxis::remove_bits(ThickPolylines &pp)
|
|||||||
|
|
||||||
//check my length is small
|
//check my length is small
|
||||||
coordf_t length = polyline.length();
|
coordf_t length = polyline.length();
|
||||||
if (length > coordf_t(max_width) * 1.5) {
|
if (length > coordf_t(this->max_width) * 1.5) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -631,11 +631,11 @@ MedialAxis::remove_bits(ThickPolylines &pp)
|
|||||||
if (nb_better_than_me < 2) continue;
|
if (nb_better_than_me < 2) continue;
|
||||||
|
|
||||||
//check if the length of the polyline is small vs width of the other lines
|
//check if the length of the polyline is small vs width of the other lines
|
||||||
coord_t max_width = 0;
|
coord_t local_max_width = 0;
|
||||||
for (int i = 0; i < crosspoint.size(); i++) {
|
for (int i = 0; i < crosspoint.size(); i++) {
|
||||||
max_width = std::max(max_width, pp[crosspoint[i]].width[0]);
|
local_max_width = std::max(local_max_width, pp[crosspoint[i]].width[0]);
|
||||||
}
|
}
|
||||||
if (length > coordf_t(max_width + min_width))
|
if (length > coordf_t(local_max_width + min_width))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
//delete the now unused polyline
|
//delete the now unused polyline
|
||||||
@ -665,7 +665,7 @@ MedialAxis::fusion_corners(ThickPolylines &pp)
|
|||||||
|
|
||||||
//check my length is small
|
//check my length is small
|
||||||
coord_t length = (coord_t)polyline.length();
|
coord_t length = (coord_t)polyline.length();
|
||||||
if (length > max_width) continue;
|
if (length > this->max_width) continue;
|
||||||
|
|
||||||
// look if other end is a cross point with multiple other branch
|
// look if other end is a cross point with multiple other branch
|
||||||
std::vector<size_t> crosspoint;
|
std::vector<size_t> crosspoint;
|
||||||
@ -764,7 +764,7 @@ MedialAxis::extends_line(ThickPolyline& polyline, const ExPolygons& anchors, con
|
|||||||
// prevent the line from touching on the other side, otherwise intersection() might return that solution
|
// prevent the line from touching on the other side, otherwise intersection() might return that solution
|
||||||
if (polyline.points.size() == 2 && this->expolygon.contains(line.midpoint())) line.a = line.midpoint();
|
if (polyline.points.size() == 2 && this->expolygon.contains(line.midpoint())) line.a = line.midpoint();
|
||||||
|
|
||||||
line.extend_end((double)max_width);
|
line.extend_end((double)this->max_width);
|
||||||
Point new_back;
|
Point new_back;
|
||||||
if (this->expolygon.contour.has_boundary_point(polyline.points.back())) {
|
if (this->expolygon.contour.has_boundary_point(polyline.points.back())) {
|
||||||
new_back = polyline.points.back();
|
new_back = polyline.points.back();
|
||||||
@ -842,14 +842,14 @@ MedialAxis::extends_line(ThickPolyline& polyline, const ExPolygons& anchors, con
|
|||||||
}*/
|
}*/
|
||||||
// find anchor
|
// find anchor
|
||||||
Point best_anchor;
|
Point best_anchor;
|
||||||
coordf_t shortest_dist = (coordf_t)max_width;
|
coordf_t shortest_dist = (coordf_t)this->max_width;
|
||||||
for (const ExPolygon& a : anchors) {
|
for (const ExPolygon& a : anchors) {
|
||||||
Point p_maybe_inside = a.contour.centroid();
|
Point p_maybe_inside = a.contour.centroid();
|
||||||
coordf_t test_dist = new_bound.distance_to(p_maybe_inside) + new_back.distance_to(p_maybe_inside);
|
coordf_t test_dist = new_bound.distance_to(p_maybe_inside) + new_back.distance_to(p_maybe_inside);
|
||||||
//if (test_dist < max_width / 2 && (test_dist < shortest_dist || shortest_dist < 0)) {
|
//if (test_dist < max_width / 2 && (test_dist < shortest_dist || shortest_dist < 0)) {
|
||||||
double angle_test = new_back.ccw_angle(p_maybe_inside, line.a);
|
double angle_test = new_back.ccw_angle(p_maybe_inside, line.a);
|
||||||
if (angle_test > PI) angle_test = 2 * PI - angle_test;
|
if (angle_test > PI) angle_test = 2 * PI - angle_test;
|
||||||
if (test_dist < max_width && test_dist<shortest_dist && abs(angle_test) > PI / 2) {
|
if (test_dist < (coordf_t)this->max_width && test_dist<shortest_dist && abs(angle_test) > PI / 2) {
|
||||||
shortest_dist = test_dist;
|
shortest_dist = test_dist;
|
||||||
best_anchor = p_maybe_inside;
|
best_anchor = p_maybe_inside;
|
||||||
}
|
}
|
||||||
@ -859,7 +859,7 @@ MedialAxis::extends_line(ThickPolyline& polyline, const ExPolygons& anchors, con
|
|||||||
p_obj.x() /= 2;
|
p_obj.x() /= 2;
|
||||||
p_obj.y() /= 2;
|
p_obj.y() /= 2;
|
||||||
Line l2 = Line(new_back, p_obj);
|
Line l2 = Line(new_back, p_obj);
|
||||||
l2.extend_end((double)max_width);
|
l2.extend_end((coordf_t)this->max_width);
|
||||||
(void)bounds->contour.first_intersection(l2, &new_bound);
|
(void)bounds->contour.first_intersection(l2, &new_bound);
|
||||||
}
|
}
|
||||||
if (new_bound.coincides_with_epsilon(new_back))
|
if (new_bound.coincides_with_epsilon(new_back))
|
||||||
@ -936,10 +936,10 @@ MedialAxis::main_fusion(ThickPolylines& pp)
|
|||||||
if (
|
if (
|
||||||
((polyline.points.back().distance_to(other.points.back())
|
((polyline.points.back().distance_to(other.points.back())
|
||||||
+ (polyline.width.back() + other.width.back()) / 4)
|
+ (polyline.width.back() + other.width.back()) / 4)
|
||||||
> max_width*1.05))
|
> this->max_width *1.05))
|
||||||
continue;
|
continue;
|
||||||
// test if the lines are not too different in length.
|
// test if the lines are not too different in length.
|
||||||
if (abs(polyline.length() - other.length()) > max_width) continue;
|
if (abs(polyline.length() - other.length()) > (coordf_t)this->max_width) continue;
|
||||||
|
|
||||||
|
|
||||||
//test if we don't merge with something too different and without any relevance.
|
//test if we don't merge with something too different and without any relevance.
|
||||||
@ -955,7 +955,7 @@ MedialAxis::main_fusion(ThickPolylines& pp)
|
|||||||
// << (abs(polyline.length()*coeffSizePolyI - other.length()*coeffSizeOtherJ) > max_width / 2)
|
// << (abs(polyline.length()*coeffSizePolyI - other.length()*coeffSizeOtherJ) > max_width / 2)
|
||||||
// << (abs(polyline.length()*coeffSizePolyI - other.length()*coeffSizeOtherJ) > max_width)
|
// << (abs(polyline.length()*coeffSizePolyI - other.length()*coeffSizeOtherJ) > max_width)
|
||||||
// << "\n";
|
// << "\n";
|
||||||
if (abs(polyline.length()*coeffSizePolyI - other.length()*coeffSizeOtherJ) > max_width / 2) continue;
|
if (abs(polyline.length()*coeffSizePolyI - other.length()*coeffSizeOtherJ) > (coordf_t)(this->max_width / 2)) continue;
|
||||||
|
|
||||||
|
|
||||||
//compute angle to see if it's better than previous ones (straighter = better).
|
//compute angle to see if it's better than previous ones (straighter = better).
|
||||||
@ -1111,8 +1111,8 @@ MedialAxis::main_fusion(ThickPolylines& pp)
|
|||||||
//std::cout << "width:" << polyline.width[idx_point] << " = " << value_from_current_width << " + " << value_from_dist
|
//std::cout << "width:" << polyline.width[idx_point] << " = " << value_from_current_width << " + " << value_from_dist
|
||||||
// << " (<" << max_width << " && " << (bounds.contour.closest_point(polyline.points[idx_point])->distance_to(polyline.points[idx_point]) * 2.1)<<")\n";
|
// << " (<" << max_width << " && " << (bounds.contour.closest_point(polyline.points[idx_point])->distance_to(polyline.points[idx_point]) * 2.1)<<")\n";
|
||||||
//failsafes
|
//failsafes
|
||||||
if (polyline.width[idx_point] > max_width)
|
if (polyline.width[idx_point] > this->max_width)
|
||||||
polyline.width[idx_point] = max_width;
|
polyline.width[idx_point] = this->max_width;
|
||||||
//failsafe: try to not go out of the radius of the section, take the width of the merging point for that. (and with some offset)
|
//failsafe: try to not go out of the radius of the section, take the width of the merging point for that. (and with some offset)
|
||||||
coord_t main_branch_width = pp[biggest_main_branch_id].width.front();
|
coord_t main_branch_width = pp[biggest_main_branch_id].width.front();
|
||||||
coordf_t main_branch_dist = pp[biggest_main_branch_id].points.front().distance_to(polyline.points[idx_point]);
|
coordf_t main_branch_dist = pp[biggest_main_branch_id].points.front().distance_to(polyline.points[idx_point]);
|
||||||
@ -1249,7 +1249,7 @@ MedialAxis::remove_too_thin_extrusion(ThickPolylines& pp)
|
|||||||
changes = true;
|
changes = true;
|
||||||
}
|
}
|
||||||
//remove points and bits that comes from a "main line"
|
//remove points and bits that comes from a "main line"
|
||||||
if (polyline.points.size() < 2 || (changes && polyline.length() < max_width && polyline.points.size() ==2)) {
|
if (polyline.points.size() < 2 || (changes && polyline.length() < this->max_width && polyline.points.size() ==2)) {
|
||||||
//remove self if too small
|
//remove self if too small
|
||||||
pp.erase(pp.begin() + i);
|
pp.erase(pp.begin() + i);
|
||||||
--i;
|
--i;
|
||||||
@ -1468,17 +1468,15 @@ MedialAxis::remove_too_short_polylines(ThickPolylines& pp, const coord_t min_siz
|
|||||||
// know how long will the endpoints be extended since it depends on polygon thickness
|
// know how long will the endpoints be extended since it depends on polygon thickness
|
||||||
// which is variable - extension will be <= max_width/2 on each side)
|
// which is variable - extension will be <= max_width/2 on each side)
|
||||||
if ((polyline.endpoints.first || polyline.endpoints.second)) {
|
if ((polyline.endpoints.first || polyline.endpoints.second)) {
|
||||||
coordf_t max_width = max_width / 2;
|
coordf_t local_max_width = this->max_width / 2;
|
||||||
for (coordf_t w : polyline.width)
|
for (coordf_t w : polyline.width)
|
||||||
max_width = std::max(max_width, w);
|
local_max_width = std::max(local_max_width, w);
|
||||||
if(polyline.length() < max_width) {
|
if(polyline.length() < local_max_width) {
|
||||||
if (shortest_size > polyline.length()) {
|
if (shortest_size > polyline.length()) {
|
||||||
shortest_size = polyline.length();
|
shortest_size = polyline.length();
|
||||||
shortest_idx = i;
|
shortest_idx = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (shortest_idx < pp.size()) {
|
if (shortest_idx < pp.size()) {
|
||||||
@ -1490,14 +1488,14 @@ MedialAxis::remove_too_short_polylines(ThickPolylines& pp, const coord_t min_siz
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
MedialAxis::check_width(ThickPolylines& pp, coord_t max_width, std::string msg)
|
MedialAxis::check_width(ThickPolylines& pp, coord_t local_max_width, std::string msg)
|
||||||
{
|
{
|
||||||
//remove empty polyline
|
//remove empty polyline
|
||||||
int nb = 0;
|
int nb = 0;
|
||||||
for (size_t i = 0; i < pp.size(); ++i) {
|
for (size_t i = 0; i < pp.size(); ++i) {
|
||||||
for (size_t j = 0; j < pp[i].width.size(); ++j) {
|
for (size_t j = 0; j < pp[i].width.size(); ++j) {
|
||||||
if (pp[i].width[j] > coord_t(max_width * 1.01)) {
|
if (pp[i].width[j] > coord_t(local_max_width * 1.01)) {
|
||||||
BOOST_LOG_TRIVIAL(error) << "Error " << msg << " width " << unscaled(pp[i].width[j]) << "(" << i << ":" << j << ") > " << unscaled(max_width) << "\n";
|
BOOST_LOG_TRIVIAL(error) << "Error " << msg << " width " << unscaled(pp[i].width[j]) << "(" << i << ":" << j << ") > " << unscaled(local_max_width) << "\n";
|
||||||
nb++;
|
nb++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user