Merge pull request #717 from triffid/post-processing-scripts
Post processing scripts
This commit is contained in:
commit
02b11fb49a
2 changed files with 59 additions and 6 deletions
53
utils/post-processing/decimate.pl
Executable file
53
utils/post-processing/decimate.pl
Executable file
|
@ -0,0 +1,53 @@
|
||||||
|
#!/usr/bin/perl -i~
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
|
||||||
|
my %lastpos = (X => 10000, Y => 10000, Z => 10000, E => 10000, F => 10000);
|
||||||
|
my %pos = (X => 0, Y => 0, Z => 0, E => 0, F => 0);
|
||||||
|
|
||||||
|
my $mindist = 0.33;
|
||||||
|
|
||||||
|
my $mindistz = 0.005;
|
||||||
|
|
||||||
|
my $mindistsq = $mindist * $mindist;
|
||||||
|
|
||||||
|
sub dist {
|
||||||
|
my $sq = 0;
|
||||||
|
for (qw/X Y Z E/) {
|
||||||
|
$sq += ($pos{$_} - $lastpos{$_}) ** 2;
|
||||||
|
}
|
||||||
|
return $sq;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (<>) {
|
||||||
|
if (m#\bG[01]\b#) {
|
||||||
|
while (m#([XYZEF])(\d+(\.\d+)?)#gi) {
|
||||||
|
$pos{uc $1} = $2;
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
(
|
||||||
|
/X/ &&
|
||||||
|
/Y/ &&
|
||||||
|
(dist() >= $mindistsq)
|
||||||
|
) ||
|
||||||
|
(abs($pos{Z} - $lastpos{Z}) > $mindistz) ||
|
||||||
|
(!/X/ || !/Y/)
|
||||||
|
) {
|
||||||
|
print;
|
||||||
|
%lastpos = %pos;
|
||||||
|
}
|
||||||
|
elsif (($pos{F} - $lastpos{F}) != 0) {
|
||||||
|
printf "G1 F%s\n", $pos{F};
|
||||||
|
$lastpos{F} = $pos{F};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (m#\bG92\b#) {
|
||||||
|
while (m#([XYZEF])(\d+(\.\d+)?)#gi) {
|
||||||
|
$lastpos{uc $1} = $2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
print;
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,17 +8,17 @@ my $z = 0;
|
||||||
# read stdin and any/all files passed as parameters one line at a time
|
# read stdin and any/all files passed as parameters one line at a time
|
||||||
while (<>) {
|
while (<>) {
|
||||||
# if we find a Z word, save it
|
# if we find a Z word, save it
|
||||||
$z = $1 if /Z(\d+(\.\d+)?)/;
|
$z = $1 if /Z\s*(\d+(\.\d+)?)/;
|
||||||
|
|
||||||
# if we don't have Z, but we do have X and Y
|
# if we don't have Z, but we do have X and Y
|
||||||
if (!/Z/ && /X/ && /Y/ && $z > 0) {
|
if (!/Z/ && /X/ && /Y/ && $z > 0) {
|
||||||
# chop off the end of the line (incl. comments), saving chopped section in $1
|
# chop off the end of the line (incl. comments), saving chopped section in $1
|
||||||
s/\s*([\r\n\;\(].*)//s;
|
s/\s*([\r\n\;\(].*)/" Z$z $1"/es;
|
||||||
# print start of line, insert our Z value then re-add the chopped end of line
|
# print start of line, insert our Z value then re-add the chopped end of line
|
||||||
print "$_ Z$z $1";
|
# print "$_ Z$z $1";
|
||||||
}
|
}
|
||||||
else {
|
#else {
|
||||||
# nothing interesting, print line as-is
|
# nothing interesting, print line as-is
|
||||||
print;
|
print or die $!;
|
||||||
}
|
#}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue