CreativeInquiry / PEmbroider

Embroidery Library for Processing
Other
442 stars 28 forks source link

Problems with raster hatching #14

Closed golanlevin closed 4 years ago

golanlevin commented 4 years ago

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);
golanlevin commented 4 years ago

Lower right heart should look like this:

IMG_8688

LingDong- commented 4 years ago

Fixed in : 666e5762f9500a21c4681febe3f64ce1d45d6ae7

Turns out the chunky looking parallel and concentric hatching is not due to the new resampling method. It is because we’re using the raster mode, which has a step. It goes a step, check if it is outside of the polygon, and go another step, etc. The step is automatically set to 1/4 of stitch length based on my random guess. In your image the stitch length is huge. I now set the step to 1 for all situations. Slow but works

BTW, image() also works for PImages directly, no need to render them to PGraphics first. However, since currently the image needs to be inverted, I kept the PGraphics in the example, so that I can use PG.filter(INVERT); Maybe we can add an option to toggle "inverted" mode for images?

Screen Shot 2020-06-13 at 2 38 26 AM
golanlevin commented 4 years ago

OK. We still have the issue, that

When using CONCENTRIC hatch mode, 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.

Perhaps this can be a setting — something like, E.INCLUDE_STROKE_IN_CONCENTRIC_HATCH = true;

LingDong- commented 4 years ago

@golanlevin

Now fixed: 43a5b3209e940a558b8981d4988ca136d7470bc2

It will automatically add a stroke if fill is concentric and no stroke has been specified.

golanlevin commented 4 years ago

Thanks, @LingDong- . I'm not certain if SPIRAL mode also needs the same fix or not, but I'll close this for now.