LaserWeb / LaserWeb4

Collaborative effort on the next version of LaserWeb / CNCWeb
GNU Affero General Public License v3.0
706 stars 191 forks source link

Potrace (Bitmap to vector) #275

Closed ghost closed 7 years ago

ghost commented 7 years ago

We had Potrace.js in LW3

Users miss this feature in LW4.

Sure we could say - "do your tracing in Inkscape" ...

jorgerobles commented 7 years ago

@openhardwarecoza I see more useful render vector as bitmap. There are packages (commercial or free) equal or superior to potrace.

cojarbi commented 7 years ago

LW is all grown up but what will make it popular is its easy of use and "solution provider"

If that is taking a bitmap and converting it to raster just to add some edge marking around the bitmap i say, go for it.

I would go as far as letting the user add some basic shaped like squares to cut out an image for example

jorgerobles commented 7 years ago

LW is all grown up but what will make it popular is its easy of use and "solution provider"

I've seen tall castles crumble to ground by the weight of their flags. -- :smile: (sounds like a chinese proverb?)

If that is taking a bitmap and converting it to raster just to add some edge marking around the bitmap i say, go for it.

@cojarbi It would overcome also some performance issues. Too tight vectors consumes more power than a bitmap

cprezzi commented 7 years ago

I think before we add bitmap tracing, we should extend image manipulation (brighness, contrast...) to have a (real time) preview. ;) For a good tracing result, the user should at least be able to optimize the picture in brightness & contrast before the tracing is started.

jorgerobles commented 7 years ago

@tbfleming get realtime raster filter output is feasible but some background needed:

jorgerobles commented 7 years ago

@openhardwarecoza speaking of Potrace, what would be the flow? Will be a new type of operation, or work as a tool on selected bitmaps? The former could be a natural way to do, the later needs some heavy UI.

I'm ok to implement as long users are aware of their drawbacks: I've got some background on vector design and know quality vector shapes needs tweaking (reordering, simplification, etc.), and stray points could wreak havoc on Gcode generation and playing (that segment setting...).

cojarbi commented 7 years ago

Maybe adding some basic tools to adjust contrast and similar would help?

How would the operation type work: I select the file, choose Trace and then it creates another instance of the file in the tree and removes the operation?

jorgerobles commented 7 years ago

Work in progress https://github.com/LaserWeb/LaserWeb4/tree/image_editor

@tbfleming applying transform2d of traced image makes the traced vector go far away. What I'm missing?

image

jorgerobles commented 7 years ago

@tbfleming I've managed to put the traced on 0,0 with transforms, but cannot figure how to translate to doc origin :|

tbfleming commented 7 years ago

@jorgerobles : These variables and fields in loadSvg live in SVG space, not in WPos space: parentMat, combinedMat, point.x, point.y, x, and y. transform2d lives in WPos space.

The push in this code converts to WPos space:

for (let point of path.points) {
    let x = (combinedMat[0] * point.x + combinedMat[2] * point.y) / pxPerInch * 25.4 + combinedMat[4];
    let y = (combinedMat[1] * point.x + combinedMat[3] * point.y) / pxPerInch * 25.4 + combinedMat[5];
    p.push(viewBoxDeltaX + x, viewBoxDeltaY - y);
}

You need to apply transform2d to the converted point; don't pass it in as parentMat.

jorgerobles commented 7 years ago

Any suggestion before closing?