CreativeInquiry / PEmbroider

Embroidery Library for Processing
Other
443 stars 28 forks source link

make each font character it's own shape to optimize #84

Closed stephanschulz closed 3 years ago

stephanschulz commented 3 years ago

I notice when using PEmbroider_text_1 example with text longer than just the example "a" that my machine jumps between different characters during stitching. This means it leave characters unfinished, jumps to somethings else and comes back later to the same character. I think it would be great is each character / letter gets treated as a single unit which needs to be completed before going to the next one. This would avoid too many looses threads between each shape that needs to be manually removed after.

2020-08-02 08 50 36

Love the library :)

golanlevin commented 3 years ago

@LingDong- , this is a good suggestion for optimization, i.e. treating each character as a single unit of optimization.

LingDong- commented 3 years ago

Potentially expensive but still doable:

Text currently works by rasterizing the whole sentence onto Processing canvas and generate pattern for all characters in one pass.

If each character needs to be optimized individually, the naïve solution is to rasterize each character individually and generate pattern for each. However we'll lose all kerning info which gives ugly-looking results for any non-monospace fonts.

A better solution is to rasterize whole sentence, re-vectorize by tracing the outlines (e.g. with findContours), and then rasterize each of the characters again. However when tracing, there's no way to know which blob belongs to which character, (e.g. the ï in previous paragraph has 3 blobs), so we can only optimize per-blob and not per-character. Which still seems to be a pretty good approximation to the given goal.

However there'll definitely be a bunch of overhead and loss of precision when vectorizing and rasterizing back and forth.

LingDong- commented 3 years ago

@golanlevin @stephanschulz Feature added: 0e73c6312da7d900410ff00e4d46e464f038e133

Toggled by experimental option:

E.TEXT_OPTIMIZE_PER_CHAR = true;

Example: examples/PEmbroider_otimize_per_char

Screen Shot 2020-08-04 at 10 10 04 PM
stephanschulz commented 3 years ago

can't wait to try it on my machine.

I notice that the build in machine fonts lay down an under-structure before doing the many fancy looking things. Probably also helps to stabilize the fabric.

Screen Shot 2020-08-04 at 10 13 47 PM Screen Shot 2020-08-04 at 10 13 38 PM Screen Shot 2020-08-04 at 10 13 24 PM
LingDong- commented 3 years ago

Hard to judge just from the photos, but I think they're used to avoid the "jumps". They hide the "walks" beneath the stitches, so each character can be drawn in 1 stroke.

PEmrboider has a similar feature! It's called hatchMode(SATIN). I think our library the job better the what's shown in the photographs because ours seems more efficient with the walks :)

But maybe they're there for a different purpose -- I don't know because I haven't actually stitched anything myself

Here's an example of my algorithm:

Screen Shot 2020-08-04 at 10 33 55 PM
stephanschulz commented 3 years ago

We should totally consult a textile artist / someone that actually knows this stuff. I will ask my aunt :) I don't thinks it's just an efficiency path stitch they do. I watched my machine for a while (better than TV) and it seems intentional. here a super slow res video https://www.dropbox.com/s/yak8sgndy6tbygm/big-iPhone-cell.3gp?dl=0

golanlevin commented 3 years ago

@stephanschulz , there are folks in the Slack who are serious embroidery professionals, also Processing-literate, I recommend you ask there. Our community manager @tatyanade also knows a bunch and is available to help through the end of August, please send questions her way! I hope you get to try out Lingdong's hatchMode(SATIN) mode, it's pretty awesome.

@LingDong- , we should probably make E.TEXT_OPTIMIZE_PER_CHAR = true; the default.