LingDong- / skeleton-tracing

A new algorithm for retrieving topological skeleton as a set of polylines from binary images
https://skeleton-tracing.netlify.app
MIT License
504 stars 65 forks source link

How to sort polylines for most optimal total path? #19

Open stephanschulz opened 2 years ago

stephanschulz commented 2 years ago

Hey I was wondering if you can suggest a good way to sort the resulting polyline vector from polylines = ofxTraceSkeleton::trace(im); in such a way that a xy plotter could draw the most efficient path through all of the polylines? Currently the order is all jumbled.

Dec-15-2021 18-38-42 Here is a small test I did in OpenFrameworks.

I am sure you have already done something like this for https://github.com/CreativeInquiry/PEmbroider

Thanks a bunch.

msurguy commented 2 years ago

@stephanschulz I'd suggest you use something like Vpype which has sorting, simplification and other features that make your SVG output CNC machine friendly: https://vpype.readthedocs.io/en/stable/reference.html#linesort

stephanschulz commented 2 years ago

Thank you, I will check it out. I have a feeling axidraw uses something similar in their reordering call: https://axidraw.com/doc/py_api/#reordering I was hoping to do the reordering inside OpenFrameworks to avoid using external libraries. In any case your advice @msurguy will be very helpful.

msurguy commented 2 years ago

@stephanschulz I think you can call CLI command after SVG generation, call vpype to optimize and wait for the result. You'll save yourself a lot of headache. https://openframeworks.cc/learning/08_other/system/