Methods for flattening (managing hidden lines)

Post about using Inkscape with cutters or plotters.
oskay
Posts: 6
Joined: Tue Jul 05, 2011 4:50 pm

Methods for flattening (managing hidden lines)

Postby oskay » Tue Mar 19, 2013 12:52 pm

I use Inkscape for a number of cutter/plotter/CNC applications. I usually start with a blank page, put the lines where I want them, and have good results with the output.

However, I have recently come across a number of example cases where hidden lines are causing problems.

Here is the most basic case:
Image

In this case, the desired shape (shown on top) is that created by two overlapped white-filled circles: a circle and a crescent. But this appearance depends upon the fill to be visible. If you output this to a cutting or plotter, you won't get a circle and a crescent, you'll get the lower output instead: two crescents and a third shape where the circles overlap.

There is a sense in which this behavior is correct-- the cutter or plotter is just following the lines --but it also can be frustrating for someone who really wanted the top shape.


Now, I do know perfectly well how to use the boolean path operations in Inkscape to create the upper shape out of paths only, so that it will work well on a cutter or plotter. Again, I use Inkscape regularly, and this is how I would normally approach it. (For those who need an introduction, see this other forum post for a solution for overlapped objects.)


However, getting back to the original topic, there are certain cases where the pairwise-boolean approach is genuinely impractical. Here is one:
Image

In this case, the appearance to the plotter is again wildly different than it is on the screen. It is admittedly possible to create the upper figure without fills through several dozen boolean operations, but it is not actually a "straightforward" operation. What is actually needed is a method of removing the hidden lines, to create a "flat" vector file that includes only the lines that are intended to be drawn or cut.


The second major case is with vector clip art. A good example might be this stylized Mona Lisa from wikimedia commons:
Image

On the left is the original SVG artwork, as it was intended to be seen, and on the right, just the stroke with no fill. In the latter, there are a number of artifacts, such as the two lines across the neck. With a bit of care, it's possible to "flatten" this SVG into a set of shapes that can be cut out with a vinyl or paper cutter, or drawn with a pen plotter or Eggbot. But, for someone new to all of this-- for whom clip art is much more important than it is to a seasoned user --that can be extremely challenging.


I've thought about writing my own extension to remove hidden lines, but it looks harder that I would have hoped. An SVG viewer or browser should be able to tell you which object is *on top* at any given point in XY space. Considering that, as you trace along any given path, you could check to see if it's still the top object, and remove the part of the path where it is not the top object. Unfortunately, Inkscape does not expose any capability of this sort to extensions, so it would be necessary to include an independent SVG canvas library as part of the extension-- which seems patently absurd. Otherwise, you could consider generating a high-res bitmap of the SVG file to use as your reference for which object (or at least, color of object) is on top. That would allow you to lift the pen/knife when the screen pixel is white.
However, Inkscape does not provide any way to do this from within an extension, short of calling extra instances of Inkscape from the command line. While there are some extensions that do use this "call an extra Inkscape" method, I'd really prefer to avoid it if possible.


So, I'd like to ask the community: What possible Inkscape-based methods are there for "flattening" a vector image, to remove hidden lines and make it more suitable for use with a cutter or plotter?

Specifically,

1) Is there any known automatic or programmatic way to use the boolean operations to process (for example) the middle figure above for plotting, with a single, or just a few Inkscape operations?

2) One method that does work is to export the image as a bitmap, and then run the Trace Bitmap command to trace it back to a vector. But this stinks as a method, and can't really be done programmatically, even by an extension. Is there any better way to solve this issue along those lines?

3) Are there any (presumably plotter/cutter/CNC oriented) native Inkscape extensions that have already solved this issue, and are able to identify and skip hidden lines, or to otherwise "flatten" the drawing? Does InkCut, GCode, or any other similar extension provide this capability?

4) Is there any vector or toolpath (i.e., not bitmap) export method that can remove hidden lines? Perhaps some HPGL or EPS export or import option that I had not noticed?

5) I've mentioned some thoughts on building an extension to do this. Is there any other approach to writing an extension that might be a little bit less absurd?

6) Is there some entirely different method of removing hidden lines that anyone has discovered? I'd love to hear about it!


Anyway, I'd really like to hear whatever feedback all of you might have on this topic. As you can see, there's a lot to think about. Thanks!

User avatar
brynn
Posts: 10309
Joined: Wed Sep 26, 2007 4:34 pm
Location: western USA
Contact:

Re: Methods for flattening (managing hidden lines)

Postby brynn » Wed Mar 20, 2013 3:58 am

Image
Welcome to InkscapeForum!

Well I can certainly see where this would be an awesome tool for use with cutters/plotters! I don't really have the technical or coding knowledge needed to offer any concrete suggestions. But I wanted to direct you to the Extensions repository http://wiki.inkscape.org/wiki/index.php ... Repository. It's possible there's something there....oh, actually, I know there's at least one -- an extension to use with SignCut. But there's a set of caveats and special techniques that go with using Inkscape and SignCut. Here's more info: viewtopic.php?f=31&t=11849.

That's all I've got. But we have many members who can probably address your more technical questions :D

oskay
Posts: 6
Joined: Tue Jul 05, 2011 4:50 pm

Re: Methods for flattening (managing hidden lines)

Postby oskay » Wed Mar 20, 2013 8:09 am

Hi brynn,
Thanks for your reply. I've looked at the SignCut extension, and all that it does is send the raw Inkscape SVG to SignCut-- it doesn't even so much as look at the contents.

I'll hope to hear from anyone else who might have thoughts on the subject. :mrgreen:

MrGoon
Posts: 5
Joined: Fri Sep 02, 2011 11:25 pm

Re: Methods for flattening (managing hidden lines)

Postby MrGoon » Wed Jul 23, 2014 12:40 pm

The workaround I use is:

1. Export the image as a PNG at high resolution (say 600 dpi).
2. Open in GIMP.
3. Select by colour (Black), invert selection, and delete. (This gets rid of everything but the lines.)
4. Copy and paste back into Inkscape.
5. Trace bitmap (virtually any settings, because it's pure black and white).

That sounds like a hassle but it takes less than 10 seconds, apart from GIMP's start-up time, and if you know the keyboard shortcuts it's even faster. The other benefit of this process (for my purposes anyway) is that it simultaneously converts all strokes to paths.

One limitation is that you're not preserving "lines," you're preserving black areas.


Return to “Inkscape & Cutters/Plotters”