G Code (gCode) Filter
I wrote this code as part of a laser engraver project to speed up the Grbl controller and Grbl interpreter (to stop them burning the work).
Most of the problem was with the original CAD design - far too many points.
The gCode file has 46,000 lines of code, even with a tolerance of 0.01 mm (the resolution of my laser engraver) the output is only 2000 lines of code (see the first image).
With a tolerance of 0.1 mm (very noticeable point reduction) the output is 1100 lines of code (see the second image).
-i Input file
-o Output file
Tolerance is the maximum distance the point (that if deleted) would be from the new line:
The code if written in plain C (using CodeBlocks) but uses Daniil Guitelson's BGI library.
You will need to add "graphics.h" and "libBGI.a" to your working directory, and the following linker options:
You will also need to add the working directory to your "compiler and linker search directories".
You can always delete the graphics code if you don't want it.
Now a word of warning the code has limitations. It only passes the following codes:
G, X, Y, Z, F, S, T and M
I have only considered G0 and G1 in my code so you can try G2 or G3 but you will be disappointed. The code in not complicated so you can modify it if you like.