Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve outline accuracy and reduce z-seam wobble by not discarding so many points #757

Closed

Conversation

1 participant
@smartavionics
Copy link
Contributor

smartavionics commented May 2, 2018

A user on the forum was having problems with a wobbly z-seam and I have been looking into it. As far as I can tell, the problem is caused by the simplify() method discarding points that it really shouldn't do if the z-seam is to stand much chance of being straight. That method has two criteria to decide whether a point in a polygon outline can be removed while still preserving the shape of the polygon. (1) distance of the point from the points before and after and (2) distance of the point from the line that joins the before and after points (error distance).

One of the changes in this PR is to not use the error distance criteria when simplifying the outline polygons. This is enough to vastly improve the location of the z-seam, here's a couple of images that show the difference, first, the results for the original code:

screenshot_2018-05-02_14-22-05

and now the results for the PR code:

screenshot_2018-05-02_14-20-24

One downside of not throwing away points is that for models that have a lot of points, the slicing time is going to increase. If this PR is deemed unacceptably slow then one solution would be to introduce another setting that can go with Maximum Resolution (BTW, shouldn't this be called Minimum Resolution as it is specifying the min size of a line segment?) that can specify the max allowed error distance and that could be used to reduce the numbers of points.

Another change in this PR is that I modified the simplify() code so that it no longer accesses elements of a vector using invalid iterators. It may be that the original code does work OK but it can't be guaranteed to do so.

smartavionics added some commits May 2, 2018

Use only smallest_line_segment_squared to determine min line length.
Before, it used the minimum of smallest_line_segment_squared and allowed_error_distance_squared.
To me, that makes no sense and as I want to be able to set allowed_error_distance_squared
to zero to disable the filtering of lines based on error distance, the min line length has
to be able to be specified.
Rework code that removed vector elements while iterators were still p…
…ointing at later elements.

C++ standard says that after a vector element is erased, all iterators & pointers that
reference elements after the erased element are invalidated.
When simplifying the polygons, don't discard points based on error di…
…stance, just line length.

The problem with discarding points that can be removed without exceeding a max error distance
is that it can introduce big errors in the position of the z-seam. Also, meshfix_maximum_resolution
is advertised as "the minimum size of a line segment" and so that value really shouldn't be
used as the maximum error value - I suggest that a separate setting should be used for the
max error value if that is required.
Remove call to simplify() when generating insets as the outline has a…
…lready been simplified().

In Slicer::makePolygons(), the polygons are simplified using the user's desired resolution
so it's better not to simplify here and, potentially, throw away detail the user wanted to
keep.
@smartavionics

This comment has been minimized.

Copy link
Contributor Author

smartavionics commented May 2, 2018

Yes, this PR does have a bad effect on slicing speed when the model has a lot of outlines but, then again, it does actually produce a more accurate result. Here's a complex part sliced with the same resolution (0.04) with and without the error distance criteria.

When using the error distance criteria (original code) the slice took around 35 seconds and the output looked like this:

screenshot_2018-05-02_15-56-36

Look closely at that image and you can see some really bad outlines have been created.

When not using the error distance criteria the slice took around 180 seconds (much longer) but the output quality is noticeably improved:

screenshot_2018-05-02_15-55-08

The fidelity of the outlines is much improved. I know which one I would rather print.

@smartavionics

This comment has been minimized.

Copy link
Contributor Author

smartavionics commented May 2, 2018

Damn, pressed the wrong button, reopened!

@smartavionics smartavionics reopened this May 2, 2018

@smartavionics

This comment has been minimized.

Copy link
Contributor Author

smartavionics commented May 2, 2018

However, playing more with the Maximum Resolution setting, you can trade off slicing time with output fidelity. With a resolution of 0.25mm, the slicing time is around 66 seconds and the output still looks much better than the result obtained with this PR so I think that perhaps the slowdown is acceptable given that the user can adjust the resolution.

screenshot_2018-05-02_16-13-59

@smartavionics smartavionics changed the title Simplify mods to reduce z-seam wobble Improve outline accuracy and reduce z-seam wobble by not discarding so many points May 2, 2018

@smartavionics

This comment has been minimized.

Copy link
Contributor Author

smartavionics commented May 2, 2018

Hmm, not sure now about this one, going to think about it some more...

@smartavionics smartavionics deleted the smartavionics:mb-simplify-fixes branch May 3, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.