CreativeInquiry / PEmbroider

Embroidery Library for Processing
Other
443 stars 28 forks source link

satin hatching does not catch all polygons #99

Open stephanschulz opened 3 years ago

stephanschulz commented 3 years ago

I have many .png images which I all want to be executed with E.SATIN But depending on the size of these images not all polygon shaped images get hatched. Here the resulting file with the missing shapes circled. polarbear_2020_9_6_9_23_23 this shows all the different shapes that should be executed.

Screen Shot 2020-09-06 at 9 29 44 AM

Is it possible that the satin hatch get overwhelmed with too many shapes?

thx

LingDong- commented 3 years ago

Hi @stephanschulz , I'm wondering what is your input to SATIN? Is the input polygons vertices, or binary images? Is each color input separately to SATIN, or is each polygon input separately to SATIN, or are they given all at the same time? Do the missing parts share the same color, and of what color should they actually be? What does gray values of the second grayscale image indicate, do they correspond to the colors of the first image?

Thanks and sorry for so many questions, but I need the info to pinpoint the problem :)

stephanschulz commented 3 years ago

Embroider_test.zip

LingDong- commented 3 years ago
Screen Shot 2020-09-07 at 5 22 58 PM
import java.io.*;
import processing.embroider.*;
PEmbroiderGraphics E;

void setup(){
  size(800,800);
  background(0);

  E = new PEmbroiderGraphics(this);

  String[] filenames = new File(dataPath("")).list(new FilenameFilter() {
    public boolean accept(File dir, String name) {
        return name.toLowerCase().endsWith(".png");
    }
  });

  for (int i = 0; i < filenames.length; i++){
    println("working on layer "+i+" ...");
    PImage img = loadImage(dataPath(filenames[i]));
    img.resize(width,height);

    E.noStroke();
    E.fill((int)random(100,255),(int)random(100,255),(int)random(100,255));
    E.hatchSpacing(5);
    E.hatchMode(E.SATIN);
    E.image(img,0,0);

  }

  E.visualize(true,false,false);

}
stephanschulz commented 3 years ago

as soon as I add

  E.optimize();
  E.visualize(true, false, false);
  E.printStats();
  E.endDraw(); // write out the file

to your code I see the problem again

LingDong- commented 3 years ago

fixed: 7099df3c873b20ec5cf8851e5a8b2418acf800aa

btw, optimize shouldn't be used with SATIN, since it might flip the order of the centerline and the hatch, see https://github.com/CreativeInquiry/PEmbroider/issues/82

golanlevin commented 3 years ago

@stephanschulz also, be aware that beginOptimize()/endOptimize() does exist, in case you need to combine SATIN with other stuff.

stephanschulz commented 3 years ago

thanks for the tips.

I saw E.optimize(); being used in the PEmbroider_satin_hatching_2 example. But now I know better.

thanks.