Ultimaker / CuraEngine

Powerful, fast and robust engine for converting 3D models into g-code instructions for 3D printers. It is part of the larger open source project Cura.
https://ultimaker.com/en/products/cura-software
GNU Affero General Public License v3.0
1.67k stars 880 forks source link

CURA 10724 smooth operator #1891

Closed jellespijker closed 1 year ago

jellespijker commented 1 year ago

Problem

The simplification of polygons sometimes leaves small segments with large differences in angles compared to the segments before and after them. This occurs because the simplification algorithm is over-constrained, and the solution space doesn't diverge to an optimal point, but to a plateau. This means that smaller segments won't be filtered out since doing so would violate other criteria, such as removing too much area, etc.

Printers with Marlin 1.x seem to handle the resulting toolpaths better than smooth motion planners such as Klipper. These printers see a sudden change in direction and will try to adhere to the requested toolpath as much as possible. Because that toolpath is now suddenly requesting a change in direction (for a very short length), the head will slow down to make the corner, but the extrusion process can't adjust at the same speed, resulting in over-extrusion at that spot.

Fix

Since we can reasonably assume that such a sudden change in toolpath direction over a short distance, compared to the direction of the toolpath before and after, does not belong to the actual intended shape of the sliced model, we can adjust the polygons in favour of the intent and smooth motion printers.

We loop over each closed polygon, which is used to generate the Aranche toolpaths, and examine 3 segments (4 points) each time: AB -> BC -> CD. Sudden small segments BC (< maximum resolution) that deviate more than a certain angle compared to a fluid motion angle (wall transition angle) between the preceding segment AB or subsequent CD are smoothed out. This is done by either shifting point B or C towards A or D by half the maximum resolution's distance or removing them altogether if there is no room to shift them.

It also introduces some concepts and std::get functions which can be used to obtain coordinates from different Point and Junction types by either specifying the index or letter: X, Y or x, y, z

Peek 2023-06-30 16-45

TODO:

Type of change

How Has This Been Tested?

Test Configuration:

Checklist:

github-actions[bot] commented 1 year ago

Unit Test Results

26 tests  +1   25 :heavy_check_mark: ±0   13s :stopwatch: +3s   1 suites ±0     0 :zzz: ±0    1 files   ±0     1 :x: +1 

For more details on these failures, see this check.

Results for commit d7fd7183. ± Comparison against base commit 1926285e.

:recycle: This comment has been updated with latest results.