Skip to content

Commit

Permalink
bugfix, remove \t, prusa3d#4640
Browse files Browse the repository at this point in the history
  • Loading branch information
supermerill committed Dec 10, 2018
1 parent 6643d78 commit 137c99c
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 24 deletions.
2 changes: 1 addition & 1 deletion xs/src/libslic3r/ExPolygon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ ExPolygon::remove_point_too_near(const coord_t tolerance) {
void
ExPolygon::medial_axis(const ExPolygon &bounds, double max_width, double min_width, ThickPolylines* polylines, double height, bool stop_at_min_width) const {
Slic3r::MedialAxis ma(*this, bounds, max_width, min_width, height);
ma.stop_at_min_width = stop_at_min_width;
ma.stop_at_min_width = stop_at_min_width;
ma.build(polylines);
}

Expand Down
60 changes: 40 additions & 20 deletions xs/src/libslic3r/MedialAxis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,13 +301,14 @@ remove_point_too_near(ThickPolyline* to_reduce)
to_reduce->points.erase(to_reduce->points.begin() + id);
to_reduce->width.erase(to_reduce->width.begin() + id);
newdist = to_reduce->points[id].distance_to(to_reduce->points[id - 1]);
//if you removed a point, it check if the next one isn't too near from the previous one.
// if not, it bypass it.
if (newdist > smallest) {
++id;
}
}
//go to next one
//if you removed a point, it check if the next one isn't too near from the previous one.
// if not, it byepass it.
if (newdist > smallest) {
++id;
}
else ++id;
}
}

Expand Down Expand Up @@ -620,26 +621,45 @@ MedialAxis::extends_line(ThickPolyline& polyline, const ExPolygons& anchors, con
line.a = *(polyline.points.begin() + first_idx);
}
// prevent the line from touching on the other side, otherwise intersection() might return that solution
if (polyline.points.size() == 2) line.a = line.midpoint();
if (polyline.points.size() == 2 && this->expolygon.contains(line.midpoint())) line.a = line.midpoint();

line.extend_end(max_width);
Point new_back;
if (this->expolygon.contour.has_boundary_point(polyline.points.back())) {
new_back = polyline.points.back();
} else {
//TODO: verify also for holes.
(void)this->expolygon.contour.first_intersection(line, &new_back);
bool finded = this->expolygon.contour.first_intersection(line, &new_back);
//verify also for holes.
Point new_back_temp;
for (Polygon hole : this->expolygon.holes) {
if (hole.first_intersection(line, &new_back_temp)) {
if (!finded || line.a.distance_to(new_back_temp) < line.a.distance_to(new_back)) {
finded = true;
new_back = new_back_temp;
}
}
}
// safety check if no intersection
if (new_back.x == 0 && new_back.y == 0) new_back = line.b;
if (!finded) new_back = line.b;

polyline.points.push_back(new_back);
polyline.width.push_back(polyline.width.back());
}
Point new_bound;
//TODO: verify also for holes.
(void)bounds.contour.first_intersection(line, &new_bound);
bool finded = bounds.contour.first_intersection(line, &new_bound);
//verify also for holes.
Point new_bound_temp;
for (Polygon hole : bounds.holes) {
if (hole.first_intersection(line, &new_bound_temp)) {
if (!finded || line.a.distance_to(new_bound_temp) < line.a.distance_to(new_bound)) {
finded = true;
new_bound = new_bound_temp;
}
}
}
// safety check if no intersection
if (new_bound.x == 0 && new_bound.y == 0) {
if (!finded) {
if (line.b.coincides_with_epsilon(polyline.points.back())) return;
//check if we don't over-shoot inside us
bool is_in_anchor = false;
Expand Down Expand Up @@ -1363,7 +1383,7 @@ MedialAxis::build(ThickPolylines* polylines_out)
// Loop through all returned polylines in order to extend their endpoints to the
// expolygon boundaries (if done here, it may be cut later if not thick enough)
if (stop_at_min_width) {
const ExPolygons anchors = offset2_ex(to_polygons(diff_ex(this->bounds, this->expolygon)), -SCALED_RESOLUTION, SCALED_RESOLUTION);
const ExPolygons anchors = offset2_ex(to_polygons(diff_ex(this->bounds, this->expolygon)), -SCALED_RESOLUTION, SCALED_RESOLUTION);
for (size_t i = 0; i < pp.size(); ++i) {
ThickPolyline& polyline = pp[i];
extends_line(polyline, anchors, min_width);
Expand Down Expand Up @@ -1398,14 +1418,14 @@ MedialAxis::build(ThickPolylines* polylines_out)
// Loop through all returned polylines in order to extend their endpoints to the
// expolygon boundaries
if (!stop_at_min_width) {
const ExPolygons anchors = offset2_ex(to_polygons(diff_ex(this->bounds, this->expolygon)), -SCALED_RESOLUTION, SCALED_RESOLUTION);
for (size_t i = 0; i < pp.size(); ++i) {
ThickPolyline& polyline = pp[i];
extends_line(polyline, anchors, min_width);
polyline.reverse();
extends_line(polyline, anchors, min_width);
}
}
const ExPolygons anchors = offset2_ex(to_polygons(diff_ex(this->bounds, this->expolygon)), -SCALED_RESOLUTION, SCALED_RESOLUTION);
for (size_t i = 0; i < pp.size(); ++i) {
ThickPolyline& polyline = pp[i];
extends_line(polyline, anchors, min_width);
polyline.reverse();
extends_line(polyline, anchors, min_width);
}
}
//{
// stringstream stri;
// stri << "medial_axis_5_expand_" << id << ".svg";
Expand Down
2 changes: 1 addition & 1 deletion xs/src/libslic3r/MedialAxis.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace Slic3r {
public:
Lines lines; //lines is here only to avoid appassing it in argument of amny method. Initialized in polyline_from_voronoi.
ExPolygon expolygon;
const ExPolygon& surface;
const ExPolygon& bounds;
const double max_width;
Expand Down
8 changes: 6 additions & 2 deletions xs/src/libslic3r/PerimeterGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ PerimeterGenerator::process()
if (half_thins.size() > 0) {
no_thin_zone = diff(last, to_polygons(offset_ex(half_thins, (float)(min_width / 2) - SCALED_EPSILON)), true);
}
ExPolygons thin_zones_extruded;
// compute a bit of overlap to anchor thin walls inside the print.
for (ExPolygon &half_thin : half_thins) {
//growing back the polygon
Expand All @@ -145,17 +146,20 @@ PerimeterGenerator::process()
for (ExPolygon &bound : bounds) {
if (!intersection_ex(thin[0], bound).empty()) {
//be sure it's not too small to extrude reliably
thin[0].remove_point_too_near(SCALED_RESOLUTION);
thin[0].remove_point_too_near(SCALED_RESOLUTION);
if (thin[0].area() > min_width*(ext_pwidth + ext_pspacing2)) {
bound.remove_point_too_near(SCALED_RESOLUTION);
bound.remove_point_too_near(SCALED_RESOLUTION);
// the maximum thickness of our thin wall area is equal to the minimum thickness of a single loop
thin[0].medial_axis(bound, ext_pwidth + ext_pspacing2, min_width,
&thin_walls, this->layer_height);
thin_zones_extruded.emplace_back(thin[0]);
}
break;
}
}
}
// recompute the next onion, to be sure to not miss any small areas that can't be extruded by thin_walls
offsets = to_polygons(diff_ex(offset_ex(last, -(float)(ext_pwidth / 2)), thin_zones_extruded, true));
#ifdef DEBUG
printf(" %zu thin walls detected\n", thin_walls.size());
#endif
Expand Down

0 comments on commit 137c99c

Please sign in to comment.