Friday, October 15, 2010

Commercial Pocketing Software

I have been asked to help someone make a commercial Windows dll to do pocketing like in HeeksCNC. Unfortunately the polygon offsetting used in HeeksCNC is derived from the "kbool" software, with its' GPL license, so it has to stay free. I have done quite a lot of work recently to adapt the "Clipper" polygon clipping library to do offsetting too.

Here are my results.
The first picture was made using kbool.

The second picture was made using my modified version of clipper.

5 comments:

angusj said...

As someone who knows nothing about CNC, would you mind saying whether your results with Clipper are comparable with PolyBool?
Angus, author of Clipper :)

Dan Heeks said...

Angus, Thank you for writing clipper. The software I am comparing it with is called "Boolean" by Klaas Holwerda. I was calling it "kbool" because that's the name of the folder the files are in. ( this software http://boolean.klaasholwerda.nl/bool.html ).

Other software I considered was:
PolyBoolean by Michael Leonov. (Not free to use in commercial software)
Clippoly by Klamer Schutte. (doesn't support holes)
Polypack by David Kennison. (can't see where to download it, and it's in FORTRAN!)

I have just done a test offsetting a 100mm x 100mm square inwards by 0.1mm each time until there is nothing left. The test also includes the time it takes to write out the toolpath to NC code using python.
The measurement was only done with the stopwatch on my mobile phone!

with "Boolean" it took 1.8 seconds
with modified "Clipper" it took 0.6 seconds.
Clipper wins!

I had to make a few changes to Clipper to get it work how I wanted. This was all related to the ValidateOrientation function.
For example in Clipper::AddLocalMinPoly, I had to add a test "if (!IsHorizontal( *e )", because it was wrongly marking holes as outsides, when there were horizontal edges. Also I had to add a new function to check if a polygon is clockwise, which works for any polygon not just simple polygons.

I didn't really understand your software well enough, so I am probably doing some strange unecessary things; for example I could only get offsetting outwards to work, so to offset inwards I reverse all the directions of the polygons and add a very large outer polygon, which I remove later.

Angus, feel free to contact me, danheeks@gmail.com for more information.

angusj said...

Dan, thank you for your very informative reply. I'll contact you by email shortly (ie in a few hours since it's 3:20am here) to further discuss the issues you've raised.

andyw said...

could you describe how you do polygon offsetting using boolean operations? thanks.

Dan Heeks said...

How I do polygon offsetting using Clipper?
Look at my source code in the libarea project, in AreaClipper.cpp
CArea::Offset calls OffsetWithLoops.
OffsetWithLoops simply offsets each line to the right and adds an arc joining it to the next line. With some corners this is perfect, but with others it makes a loop ( more than 180 degrees arc ). Also there are now sometimes overlapping parts of the polygon.
Then, at line 183, I use Clipper to do a "Union" of this polygon and, somehow, it removes all the overlapping bits and leaves me with the curve that I want.
This works fine for offsetting outwards, but for some reason not for offsetting inwards. So I have to cheat for inwards offsetting. line 138