Giter Club home page Giter Club logo

pembroider's Issues

Experiments with Hatch and stitch Lengths & suggestions for better fills

Experiments with altering stitch length! and hatch

2020-06-08_16h51_07
2020-06-08_17h21_21

For fills I think it would be beneficial to make the thread stops on alternating layers as far from each other as possible (Like these yellow dots I've drawn in) or at least not very close to the thread stops on neighbor lines - the magenta dots in here are where the stitches start and stop and the yellow is a suggestion for how to make the fill a little better
2020-06-08_17h21_51

so the threads look more like this - this seems to be how other machine embroideries get their fills effectively.

2020-06-08_17h22_22
2020-06-08_17h22_30

other wise it creates valleys in the fill (highlighted in red below) that alter the shape - i think this skewed the circle since it causes the fabric to stretch and is harder on the fabric and more likely to deform or break it since its poking a lot of holes right next to each other instead of spacing them out more
2020-06-08_17h13_22

Also did some tests with outlines, the one on the left has a lower hatch value and the stitch length on both is the same and is the same as the width of the border, decreasing hatch and increasing stitch_length definitely help things look better

2020-06-08_17h20_24

Problems with raster hatching

Hi @LingDong- ,

This issue is demonstrated in the new example,
https://github.com/CreativeInquiry/PEmbroider/tree/master/examples/PEmbroider_bitmap_image_1

There are several problems:

  1. There's a weird aliasing on raster hatches in PARALLEL and CROSS modes, as can be seen in the upper two embroideries in the screenshot below. The aliasing is proportional to the stitch length.
  2. When using CONCENTRIC or SPIRAL hatch modes, larger values of hatchSpacing reveal the problem, that the outer edge of the shape is not currently being stitched. This is visible in the middle embroidery on the lower row. The outside edge should not be omitted from the CONCENTRIC hatch.
  3. Currently, strokes are not working at all in raster rendering. The lower right embroidery is totally wrong; it should have a stroke and no fill.

Screen Shot 2020-06-13 at 1 37 12 AM

Code for the lower right embroidery is:

  E.stroke(0, 0, 0); 
  E.noFill(); 
  E.strokeWeight(5); 
  E.STROKE_MODE = PEmbroiderGraphics.TANGENT;
  E.STROKE_SPACING = 4;
  E.hatchRaster(PG, 500, 250);

Feature request: add stitch points directly

Hi @LingDong- ,
There has been a request to have the ability to add stitch points directly, within the user's Processing sketch itself. Basically, some users want extremely precise control over where the stitches go. One example is for artistic effects; another example is a CS professor who wants to assign their students to have the problem of designing a stitch-placing algorithm (without having to recompile PEmbroider). Or, perhaps they just don't like where our algorithm has placed the stitches.

The command would have syntax like E.stitch(x,y);

Can it be done? (Does it already exist?)

Errors with shape culling

Shape culling needs some attention, please, as demonstrated by the example, PEmbroider_shape_culling.

Currently, small turds from culled shapes are sporadically left in the scene. As small as these isolated stitches are, they can cause major headaches later when the TSP is run. Below you can see screenshots of PEmbroider_shape_culling, with and without the TSP visualization.

Screen Shot 2020-06-14 at 3 47 34 AM

Screen Shot 2020-06-14 at 3 48 44 AM

A close look also shows that some stitches are culled prematurely, instead of being culled precisely; see magnification below. Perhaps its a related issue. Is culling currently using raster internals?

Untitled

strokeMode (ANGLED)

A feature request, inspired by some embroidery graphics I've seen:

E.strokeMode(PEmbroiderGraphics.ANGLED); E.strokeAngle(radians(45));

IMG_8700

This will not work for large angles, but could be attractive for angles ±45°. It might require raster rendering to cope with appropriate cropping.

Option for no overlap of fill and stroke

Is there a way to eliminate overlap of stroke and fill on a singular shape from a bitmap? This is achievable with shapes through culling:

E.beginCull();
  
  E.noStroke();
  E.fill(0,0,0);
  E.circle(100, 100, 100); 
  
  E.noFill();
  E.stroke(255, 255, 0); // yellow stroke
  E.circle(100, 100, 100); 
  
  E.endCull();

(culling v not culling)

2020-06-19_20h47_472020-06-19_20h48_14

but does not work with images

E.beginCull();
  
  E.noStroke();
  E.fill(0,0,0);
  E.image(myImage, 0, 0); 
  
  E.noFill();
  E.stroke(255, 255, 0); // yellow stroke
  E.image(myImage, 0, 0); 
  E.endCull();

2020-06-19_20h49_05

Might be usefull and more legible to have something like 'E.Fill_Stroke_Overlap(false); ' to call function instead of making multiple instances of the same element

Clamp ranges on property setters

It should be impossible to set a stitch length which is zero or negative.
Other properties with setter functions should impose reasonable safeties as well.

NaN's in the optimizer...

The following code is in PEmbroider_bitmap_image_1.pde, rendering the broken heart image:

  // Draw fat parallel stroke only; no fill.   
  E.noFill(); 
  E.stroke(0, 0, 0); 
  E.setStitch(2, 30, 1.0);
  E.strokeWeight(16); 
  E.strokeSpacing(4);
  E.strokeMode(PEmbroiderGraphics.PERPENDICULAR);
  E.image(myImage, 500, 250);

This code is producing the following worrisome output in the optimizer:

[PEmbroider Optimize] Input:NaN
[PEmbroider Optimize] Trial:0	NN:Infinity	2-Opt:2224.5767
[PEmbroider Optimize] Trial:1	NN:Infinity	2-Opt:2224.5767
[PEmbroider Optimize] Trial:2	NN:Infinity	2-Opt:2247.809
[PEmbroider Optimize] Trial:3	NN:Infinity	2-Opt:2275.2676
[PEmbroider Optimize] Trial:4	NN:Infinity	2-Opt:2301.788
[PEmbroider Optimize] Final:2224.5767
[PEmbroider Writer] BASENAME :/Users/golan/Desktop/PEmbroider-Uber/PEmbroider/examples/PEmbroider_bitmap_image_1/PEmbroider_bitmap_image_1
[PEmbroider Writer] EXTENSION:vp3
[PEmbroider Writer] Color count: 1
[PEmbroider Writer] Written!

Results from Shapes

Shapes_Merging
image

Shapes
image

Shapes Culling
image

Shapes Hatching 1
image
image

Shapes Hatching 2
Pre Cleanup
image

Post Cleanup (vaguely impossible for vec and perlin) there are way to many overlapping stitches that the pattern gets lost
image

Shapes Hatching 3
(had already posted this but here it is again so its all in one place)
2020-06-19_21h29_45
2020-06-19_21h29_58

End angle is incorrect for arc()

@LingDong- ,
There's an error with the end-angle for the arc() function; it should be about 10 degrees bigger. This rendering is supposed to be an arc with 1.5xPI radians (3/4 of a circle):

Screen Shot 2020-06-14 at 9 57 04 PM

How big is a unit?

@tatyanade , could you kindly do some Internet research and/or some actual tests, to reckon the number of embroidery-units-per-inch (at least, for our Viking Jade 35 machine)? I don't know whether a stitch length of 50 is really long or not, and I don't know how big a circle with diameter 100 will actually appear. Maybe embroider a units ruler?

Add optional numTrials argument to E.optimize()?

I'm seeing some VERY long optimization times (on the order of minutes) for large/complex designs. Let's pass in an optional argument for the number of optimization trials, (default 3) so that I can decide to do a quick test, OR to let it run overnight, etc.

Refactor hatchSpineVF() to remove hatch spacing argument

Currently, calling hatchSpineVF has a second argument, which is the hatch spacing:
PEmbroiderHatchSpine.hatchSpineVF(myImage, 3.0);
This argument should be removed, and hatchSpineVF should instead use the current hatchSpacing() setting.

Single line Embroidery

I think it would be beneficial to implement a small repeat stitch at the beginning and end of each line

When using a sewing machine for sewing, when you reach the end of a stitch, you go over the same spot a few times (reverse then go forward again) so that the thread is effectively tied and it does not unravel when you snip the extra thread.
you can see this in a few spots on the ruler in #17 and the image below where I did a test on some lines - even just going over the last stitch one time helped a lot,
image
You can see the bottom version has unraveled in a few places but the top hasn't - I manually went over the last stitch one time, but it should work and look something like this (but with all the stitches having the same Y values) - I'll manually test this out
image

another issue is that lines intersecting at one point don't appear to intersect unless both lines stop at the intersection:

image

you can see the top vertical line seems to be floating about the horizontal line, but if the horizontal line had a stitch start and stop at the intersection there would be no way for it to move out of the way.

Errors rendering image contours with thin strokes

This bug report concerns the Example, PEmbroider_bitmap_image_2, which is tracing the Processing.org logo.

Things look fine with E.strokeWeight(2); E.strokeMode(PEmbroiderGraphics.TANGENT);:
Screen Shot 2020-06-17 at 11 48 14 PM

However, there is a strange error with E.strokeWeight(2); E.strokeMode(PEmbroiderGraphics.PERPENDICULAR);:
Screen Shot 2020-06-17 at 11 48 32 PM

And with E.strokeWeight(1); E.strokeMode(PEmbroiderGraphics.TANGENT);, one of the shapes is omitted altogether:
Screen Shot 2020-06-17 at 11 49 14 PM

Errors rendering lines

Hi @LingDong- ,
See the example, PEmbroider_lines_1. Issues include:

  • lines with a strokeWeight of exactly 2.0 are not rendered.
  • strokeCap(SQUARE) is not currently working for strokeMode(PERPENDICULAR); it renders with round endcaps. However, strokeCap(SQUARE) is working correctly for strokeMode(TANGENT).
  • something funny is going on with the round endcaps of thick lines. The two ends of the line should not look different. It looks like you're maybe drawing a full circle instead of a semicircle?

PEmbroider_lines_1

Confusion regarding strokeSpacing, hatchSpacing, stitchLength scaling w/transforms?

I may be overthinking this, but: Below are two circles, both drawn with hatchSpacing(10) and PARALLEL hatch, but in the second case, I have scaled the world by 0.5. (code is below). The stitch length is being scaled, as is the hatch spacing:

Screen Shot 2020-06-17 at 11 33 31 PM

Here's another case, where I'm using CONCENTRIC hatch, and scaling non-uniformly. In this case, the stitch length is NOT being scaled, but the hatch spacing is:

Screen Shot 2020-06-17 at 11 38 00 PM

A few thoughts:

  • At the very least, some consistency here would probably be good.
  • It might be nice for the user to be able to decide if (independently) stitchLength, hatchSpacing, and strokeSpacing scale with other graphics transforms. They would (or would-not) scale independently from the "art" itself (e.g. just the circles). This suggestion loosely inspired by the "Scale Strokes & Effects" checkbox in Adobe Illustrator, which allows these things to be coupled or de-coupled:

Screen Shot 2020-06-17 at 11 43 40 PM

@LingDong- , @tatyanade , what is your opinion of this question?

import processing.embroider.*;
void setup() {
  noLoop(); 
  size (800, 600);
  PEmbroiderGraphics E = new PEmbroiderGraphics(this, width, height);

  E.beginDraw(); 
  E.clear();
  E.noStroke();
  E.fill(0, 0, 0);
  E.ellipseMode(CENTER); 
  E.hatchMode(PEmbroiderGraphics.PARALLEL); 
  E.hatchSpacing(10); 

  E.circle(200, 200, 200); 

  E.pushMatrix();
  E.translate(400, 200); 
  E.scale(0.5, 0.5); 
  E.circle(0, 0, 200); 
  E.popMatrix(); 

  E.visualize();//true, true, true
}

HATCH_SPARSITY does not affect thick strokes

Hi @LingDong- ,

HATCH_SPARSITY currently does not affect the rendering of thick strokes. Either it should, or there should be a separate STROKE_HATCH_SPARSITY property (and maybe also a FILL_HATCH_SPARSITY which maps to the usual HATCH_SPARSITY or both.)

Screen Shot 2020-06-05 at 9 32 02 PM

Problem rendering near sharp concavities with hatchSpine()

When using the (admittedly experimental) PEmbroiderHatchSpine.hatchSpine(), sometimes hatching voids are produced in the vicinity of sharp concave contours. This can be seen in the PEmbroider_bitmap_image_1 example, below:

Untitled

I can think of some ugly hacks for dealing with this, just wanted to document the problem for the moment.

Don't put long connective TSP stitches underneath hatching

So, this might be a tough one: A problem is the long TSP connective stitches being sewn UNDERNEATH a hatch. You can see that in this picture:

Screen Shot 2020-06-07 at 11 29 34 PM

It is essentially impossible to remove those long connectors later, if they are sewn under a hatch. But they can be quite visible, which is the (aesthetic) problem. Can you imagine any way to avoid this?

One way Lingdong can think of is to add it as an optimization goal to the TSP: minimize number of crossing between connective stitches and real stitches. But: how to optimize for that parallel to the TSP goals yet, other than simply doing a lot more trials and pick the best one?

Please add .EXP, .JEF, and .XXX file export

Hi @LingDong- ,
I have started to announce PEmbroider on Twitter and there is a strong positive response. We made good choices by selecting .PES and .DST. But there are a few people who would like to help us do testing, whose machines only support other formats. Could you please add support for .EXP, .JEF, and .XXX? Once we do this, we should have all of the necessary formats covered. Here's code for the three formats:

https://github.com/EmbroidePy/EmbroideryIO/blob/master/core/src/main/java/org/embroideryio/embroideryio/ExpWriter.java
https://github.com/EmbroidePy/EmbroideryIO/blob/master/core/src/main/java/org/embroideryio/embroideryio/JefWriter.java
https://github.com/EmbroidePy/EmbroideryIO/blob/master/core/src/main/java/org/embroideryio/embroideryio/XxxWriter.java

The .XXX format is for Singer sewing machines. It seems inappropriate, but it is true.

The online viewer at https://htmtopdf.herokuapp.com/embroidery/ is able to handle all of these formats, for output verification.

Thank you!
Golan

stitchwise-TSP vs. objectwise-TSP?

@LingDong- , I see some opportunities in which the TSP solver could have a behavior which, though less "optimal" in one sense, might be more user-friendly in another.

Let's call an "object", a cluster of related stitches. For example: all of the stitches inside some polygon. Sometimes, when rendering several different objects, the TSP will render half of an object; jump to another object; and then (eventually) return to complete the remainder of the first object.

From a user's perspective, it might make more sense to complete each object individually. More precisely, to:

  • to complete each object, in isolation unto itself, in an optimal way, with TSP, and,
  • then to complete the collection of all objects, in an optimal order.

Is this an option that would be easy to add to the TSP solver?

Please support .PES format

Hi @LingDong- , could you please add support for the .PES embroidery format. Some folks who want to help test have a Brother PE800 machine, for which this is the best format.
Thank you!
Golan

Matrix transform issue, in

Got a good one for you, @LingDong-
I made an example based on this recursive tree by Dan Shiffman:
https://processing.org/examples/tree.html
This example is located in examples/gallery/PEmbroider_tree/PEmbroider_tree.pde.

When rendered with Processing, it looks like this:
Screen Shot 2020-06-20 at 12 09 50 AM

When rendered with PEmbroider (adding E. before all graphics calls), it looks like:
Screen Shot 2020-06-20 at 12 09 15 AM

Please debug?

Things to rename :(

@LingDong-

Please rename:
HATCH_SPARSITY → HATCH_SPACING
STROKE_SPARSITY → STROKE_SPACING
NORMAL → PERPENDICULAR

Thanks!
Golan

Remaining bits of Processing compatibility: arc(), square(), PShape/SVG

Hi Lingdong,
For thoroughness and compatibility with Processing, could you please add the following to PEmbroider:

This is more complex, but could you also add support for loading SVG files. Ideally this would use Processing's PShape code: https://processing.org/reference/PShape.html

Here is the code for a sample SVG to get you started, the rubber duck:

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
	 width="107.59px" height="107.59px" viewBox="0 0 107.59 107.59" style="enable-background:new 0 0 107.59 107.59;"
	 xml:space="preserve">
<g>
	<g>
		<path id="path5050" d="M96.264,34.699c-3.347-2.532-2.761,11.526-21.229,13.686c-6.061,0.707-11.467,0.123-16.271-1.017
			c-3.056-0.717-3.266-2.931-1.117-5.208c4.146-4.382,6.692-10.292,6.692-16.804c0-13.518-10.953-24.47-24.467-24.47
			c-9.802,0-18.25,5.758-22.158,14.075c-1.331,2.842-4.267,4.793-7.355,4.272C4.308,18.213,0,18.525,0,24.396
			c0,5.9,7.381,11.777,16.339,16.008c2.835,1.335,2.868,3.211,0.267,4.966C7.755,51.313,1.925,61.412,1.925,72.876
			c0,18.295,14.928,31.224,33.129,33.126c25.834,2.701,56.48-1.725,68.054-24.964C111.389,64.409,107.671,43.343,96.264,34.699"/>
	</g>
</g>
</svg>

Screen Shot 2020-06-14 at 4 34 59 PM

Although it's outside the official Processing spec, it would also be cool to add Alexandre B A Villares' "arcVertex":

new PEmbroiderGraphics width height

2020-06-19_19h51_06 2020-06-19_19h51_16

There is weird machine behavior if you make the width height in E = new PEmbroiderGraphics(this, width, height); smaller than the canvas dimensions; same file above viewed on 80x80 and 240x150; it has all the stitch information regardless of it going off canvas (didn't try running on the 80x80 in case it acts weirdly)

is there any reason to have the user manually set the dimensions for the output instead of having it match the canvas automatically?

Spiraling

When I call
E.setStitch(10,30,0); E.hatchMode(SPIRAL); E.hatchSpacing(8); E.rect(350, 350, 100, 100);

image

With the inner corners becoming slanted instead of keeping the shape at right angles

a lot less noticable with a stitch length of 40, but you can see it a bit towards the center
image

Also spiraling for circles gets a bit funky depending on stitch length ; this is circle with E.setStitch(10,40,0)
2020-06-19_18h53_57

verses E.setStitch(10,30,0), both with hatch spacing of 4.
2020-06-19_18h55_26

smaller stitch length looks better but im not sure why there would only be one inconsistently lengthen stitch with length 40

I think the circle spiral issue is not as much of a concern (or possibly not a concern at all, easy for the user to fix on their own) but for rectangle spiraling I think special attention should be payed to the inner corners guaranteeing a stitch point at least for more noticeable (non-central) corners

Color Based Optimization

image

Was doing this small test to see what order the colors would go - strokes are all the same color and fill is a different color but all the fills are the same. The second column is STROKE_OVER_FILL and the 3rd is FILL_OVER_STROKE. This is how it ran: It did the stroke for 1, then had me switch colors, did the fill for 2, had me switch color, did the stroke for 2 and 3, had me switch, did the fills for 3 and 4, had me switch, did the stroke for 5, had me switch, did the fill for 6, had me switch and did the stroke for 6 and 7, then i switched thread for the last time to cover the fill for 7 and 8. meaning i load the thread 8 individual times

Would be a lot less hassle if it does something more like strokes for 1,5,3,4, then having me switch to the color for the fill and doing the fill for 2, 3, 4, 6, 7, 8, then switching back to do the remaining stroke_over_fill strokes for 2 and 6

this would conflict with #35 stitch-wise TSP (since its currently acting object based) but is definitely a lot more user friendly to be able to optimize the embroidery so that you change out the thread the least amount of possible times

results for example Text_1 through 3

Test 1
image
(this above image was before the stroke staggering, redid below with some changes)
image

And a sample to see the difference in Fill first vs Stroke first, stroke first looks a lot better:
image

Text 2
image
fill is a bit sparse with these, will redo with 2 colors and stroke first

Text 3
image
still has stray threads to clean up but some of them are barely legible so I will reprint this example with larger font size

Error with Greek Hershey font

The code:

E.textFont(PEmbroiderFont.GREEK_SIMPLEX);
E.text("Ξεσκεπαζω την ψυχοφθορα βδελυγμια.", 50, 50);

Produces an error:
ArrayIndexOutOfBoundsException: 894

Bitmap Results

Here's the first run; Ill finesse some of the values and re-embroider
2020-06-14_21h57_04

Got an error with this one:
2020-06-14_21h57_44

I cant embroider this; whenever I try to open the file on the machine it tells me "Embroidery too large', which is a peculiar error that I don't believe has anything to do with physical size so I'd assume the file contains to much information?

2020-06-14_21h56_45
For the parallel strokes, would it be possible to implement a staggering similar to the offset on fill so that the thread ends are not right next to each other?

2020-06-14_21h56_32
Dense concentric hatch warps the fabric at three points, will see if this goes away with adjusting value

2020-06-14_21h56_37
2020-06-14_21h56_55
2020-06-14_21h56_15
2020-06-14_21h56_24

Disabling resampling of straight lines (e.g. for AxiDraw output)

Another idea for the PEmbroider library... a modification that removes stitch-down points that break up lines that are otherwise straight. The goal would be to reuse the hatching code for something like an AxiDraw plotter, where there’s no need to make individual “stitches” in a long straight line.

IMG_8629

This could take the form of something like noResample() or resample(true/false).

Registration point for type is not working as expected

This type was set with the registration point (0,0). It is located at the incorrect position and should behave just like regular Processing.

Screen Shot 2020-06-06 at 6 53 38 PM

Here's the code:


import processing.embroider.*;
PEmbroiderGraphics E;

void setup() {
  noLoop(); 
  size (600, 400);
  PFont myFont = createFont("Helvetica-Bold", 100);

  E = new PEmbroiderGraphics(this, width, height);
  String outputFilePath = sketchPath("PEmbroider_text.vp3");
  E.setPath(outputFilePath); 

  E.beginDraw(); 
  E.clear();

  E.hatchMode(PEmbroiderGraphics.PARALLEL);
  E.strokeMode(PEmbroiderGraphics.PERPENDICULAR);
  E.hatchSpacing(4);
  E.strokeSpacing(4);
  
  E.textFont(myFont);
  E.fill(0);
  E.strokeWeight(12);
  E.textSize(250);
  E.text("ABC", 0, 0);

  //-----------------------
  E.visualize();
  //E.optimize(); // slow, but very good and important
  //E.endDraw(); // write out the file
}

hatchMode(AUTO)

The orientation of parallel or satin strokes should be perpendicular to major axis of an arbitrary polygon, using hatchMode(AUTO).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.