Do you fill like I do ?
By Anar on 14/11/2011, 09:53 - Software - Permalink
Now that you understand what drawing with Gcode really means, you know that only vectors can be turned into stroke paths.
In a vector graphic editor such as Inkscape you can fill a closed path, but that filling will only exist on your screen.
Even if you tell Inkscape to fill in some path, you will only get the path's outline plotted when converted into Gcode instructions. That's because only the outline is a path but the filled area isn't.
So if we want our filled areas to be pen-plotted, we must first find a way to convert them into stroke paths.
Usually when you fill an area by hand using a pen, you do it by drawing successive "S" shape strokes.
So the first idea that comes in mind is to hand draw a stroke path that will cover the filled area in the same way you would do it by hand.
That can be easy for a very simple closed shape like a circle but will become mostly impossible with a more complex design. So we have to find something that will just do it for us.
Pattern fill method :
My first idea was to try to replace the filling with some pattern (lines) that would then be converted into paths. That method works but is not straight forward and involves much too many steps. And as the result is not satisfying I won't describe it further than that :
- fill your paths with a "Stripe" pattern
- rotate and scale the pattern as desired
- do an image copy
- recreate a path from that image copy
At that point I was a bit stuck with no more ideas than...
...having a look at what others might have done which means doing some web search.
Web searching brought me to the Makerbot project one more time. As a derivative work, some guys created the Eggbot project which focuses on drawing (pen-plotting) on egg shaped objects. Sounds weird to me but... why not ? And some Inkscape tools where especially developped for their needs including some filling plugins.
Interesting ! Let's try 'em out !
Hatch fill method :
The first one I tried was an automatic filling plugin called "Hatch fill" which comes with a "Eggbot contributed" Inkscape extensions package.
Once this package is installed, using the "Hatch fill" script is very simple :
- select the paths you want to fill
- Extensions / Eggbot contributed / Hatch fill
- choose orientation and frequency
As a result, all the selected closed paths will now be filled with parallel lines. As these lines are now vectors they will be converted to Gcode instructions, resulting in a parallel strokes filling aspect drawing. While this is a good and fast method, it also has some drawback :
- it doesn't imitate a human hand drawn filling
- it requires a lot of pen-up-and-down instructions
The more pen-up-and-down instructions you will generate, the more time it will take to draw, and the faster you will "damage" your pen tip (not so important) but also your Rapman's threaded rods at the top (worse). So trying to achieve a more human like "S" shape filling path is not just a question of aesthetic : it will also result in much less pen-up-and-down instructions.
But how can we do that ?
Once again the answer comes from the Eggbot community...
Path effect / Hatches method
Another great Inkscape extensions package provided by the Eggbot community is the "Eggbot" package and especially the "Preset hatch for fills" plugin. While this method can be done without the plugin, it will save you actions and time if you use it. The process is less straight forward than with the previous method but the result is worth doing the extra job. All you have to do is :
- select the paths you want to fill
- Path effect editor / Hatches (rough)

- Extensions / Eggbot / Preset hatch for fills

- rotate and scale the result


- Path / Object to path
As a result you will have an "S" shape style filling which means fewer pen-up-and-down instructions.

But what if I want even less pen-up-and-down instructions ?
How much can I reduce those and what is the minimum number of stroke paths needed to produce a drawing ?
Theorically the answer is 1...
Travel Salesman Problem (TSP) method
After some new web search it came out that my problem was related to this mathematical problem known as the TSP (Travel Salesman Problem) : giving a number of cities on a map (area), what is the shortest path in order to visit all cities and to visit them only once ?
What does it have to do with our need ?
Imagine the list of cities to be a list of points with XY coordinates instead : a TSP algorithm should be able to find a single path that will connect all these points in one single stroke ! Have to try that !
The best and easiest way for me was to use a python script called tspart.py that can be found here.
Now the process is not difficult. First we have to create a stippled image from our artwork :
- turn your image into grayscale

- wash it out into some low contrasted light gray

- dither it to a black & white image

- save it as a .pbm (portable bitmap)
A a result, you should have a nice point cloud with some higher density where the original image was darker.
For a nice result you might need to adjust your lightness/contrast and try again. You can also decide to delete some points from the resulting point cloud at this stage.
Now we need to ask the TSP solver to compute the best travel for us. This is just a simple command line (more details can be found here).
The solver might take some time to find the result but when it's done you will have a nice .svg file containing one single path that you can then convert into Gcode for you Rapman. It is sometime good to break that single path into a few ones before plotting it. Of course, each time you will break the path you will introduce a new pen-up-and-down instruction.
This TSP method produces something that no human could do, so its "beauty" has something strange and attractive.

Looking at the Rapman drawing very complex stuff without ever lifting the pen is something fascinating, and I bet you will look at it all the way from the beginning until the end when you will do your first print !
That's it with the different filling methods I have used so far.
What about you ?
How do you fill ?



Comments
Very good research, useful technique and wonderful result !
Also some parts of it (TSP over image point-cloud for example) can be used for various other things.
Further I would try to tweak the path, for example to make a spline out of its nodes, which will render more "hand-made" look... what else ?
Thanks Elephant for your comment.
I completely agree with you that interesting results can be obtained by tweaking the path after the TSP solver.
For example that's a TSP art on which I have done successive "Simplify path" operations.
Note that I have also deleted some of the original TSP path's nodes. If you follow the path you will see there are a few pen-ups.
I also forgot to mention that you can, of course, mix all (or part) of these methods to produce different interesting results.