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).
Usage:
FilterGCode.exe -i Fish6.nc -o NewFish6.nc -t 0.01
Parameters:
-i Input file
-o Output file
-t Tolerance
Tolerance is the maximum distance the point (that if deleted) would be from the new line:
Code:
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:
-lBGI -lgdi32
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.
LIMITATIONS
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.
Regards AlanX