| 1 |
greg |
2.1 |
#!/usr/bin/perl -w
|
| 2 |
greg |
2.5 |
# RCSid $Id: rtpict.pl,v 2.4 2018/03/20 23:05:48 greg Exp $
|
| 3 |
greg |
2.1 |
#
|
| 4 |
|
|
# Run rtrace in parallel mode to simulate rpict -n option
|
| 5 |
|
|
#
|
| 6 |
|
|
# G. Ward
|
| 7 |
|
|
#
|
| 8 |
|
|
use strict;
|
| 9 |
|
|
# we'll call rpict if this is not overridden
|
| 10 |
|
|
my $nprocs = 1;
|
| 11 |
|
|
# rtrace options and the associated number of arguments
|
| 12 |
|
|
my %rtraceC = ("-dt",1, "-dc",1, "-dj",1, "-ds",1, "-dr",1, "-dp",1,
|
| 13 |
|
|
"-ss",1, "-st",1, "-e",1, "-am",1,
|
| 14 |
|
|
"-ab",1, "-af",1, "-ai",1, "-aI",1, "-ae",1, "-aE",1,
|
| 15 |
|
|
"-av",3, "-aw",1, "-aa",1, "-ar",1, "-ad",1, "-as",1,
|
| 16 |
|
|
"-me",3, "-ma",3, "-mg",1, "-ms",1, "-lr",1, "-lw",1);
|
| 17 |
|
|
# boolean rtrace options
|
| 18 |
|
|
my @boolO = ("-w", "-bv", "-dv", "-i", "-u");
|
| 19 |
|
|
# view options and the associated number of arguments
|
| 20 |
greg |
2.2 |
my %vwraysC = ("-vf",1, "-vtv",0, "-vtl",0, "-vth",0, "-vta",0, "-vts",0, "-vtc",0,
|
| 21 |
greg |
2.1 |
"-x",1, "-y",1, "-vp",3, "-vd",3, "-vu",3, "-vh",1, "-vv",1,
|
| 22 |
greg |
2.2 |
"-vo",1, "-va",1, "-vs",1, "-vl",1, "-pa",1, "-pj",1, "-pd",1);
|
| 23 |
|
|
# options we need to silently ignore
|
| 24 |
|
|
my %ignoreC = ("-t",1, "-ps",1, "-pt",1, "-pm",1);
|
| 25 |
greg |
2.1 |
# Starting options for rtrace (rpict values)
|
| 26 |
greg |
2.5 |
my @rtraceA = split(' ', "rtrace -u- -dt .05 -dc .5 -ds .25 -dr 1 " .
|
| 27 |
|
|
"-aa .2 -ar 64 -ad 512 -as 128 -lr 7 -lw 1e-03");
|
| 28 |
greg |
2.1 |
my @vwraysA = ("vwrays", "-ff", "-pj", ".67");
|
| 29 |
|
|
my @vwrightA = ("vwright", "-vtv");
|
| 30 |
|
|
my @rpictA = ("rpict");
|
| 31 |
|
|
my $outpic;
|
| 32 |
greg |
2.5 |
my $outzbf;
|
| 33 |
greg |
2.1 |
OPTION: # sort through options
|
| 34 |
|
|
while ($#ARGV >= 0 && "$ARGV[0]" =~ /^[-\@]/) {
|
| 35 |
|
|
# Check for file inclusion
|
| 36 |
|
|
if ("$ARGV[0]" =~ /^\@/) {
|
| 37 |
greg |
2.2 |
open my $handle, '<', substr($ARGV[0], 1);
|
| 38 |
greg |
2.1 |
shift @ARGV;
|
| 39 |
|
|
chomp(my @args = <$handle>);
|
| 40 |
|
|
close $handle;
|
| 41 |
|
|
unshift @ARGV, split(/\s+/, "@args");
|
| 42 |
|
|
next OPTION;
|
| 43 |
|
|
}
|
| 44 |
|
|
# Check booleans
|
| 45 |
|
|
for my $boopt (@boolO) {
|
| 46 |
greg |
2.2 |
if ("$ARGV[0]" =~ ('^' . $boopt . '[-+01tfynTFYN]$')) {
|
| 47 |
|
|
push @rtraceA, $ARGV[0];
|
| 48 |
greg |
2.1 |
push @rpictA, shift(@ARGV);
|
| 49 |
|
|
next OPTION;
|
| 50 |
|
|
}
|
| 51 |
|
|
}
|
| 52 |
|
|
# Check view options
|
| 53 |
|
|
if (defined $vwraysC{$ARGV[0]}) {
|
| 54 |
greg |
2.2 |
push @vwraysA, $ARGV[0];
|
| 55 |
greg |
2.1 |
my $isvopt = ("$ARGV[0]" =~ /^-v/);
|
| 56 |
greg |
2.2 |
push(@vwrightA, $ARGV[0]) if ($isvopt);
|
| 57 |
greg |
2.1 |
push @rpictA, shift(@ARGV);
|
| 58 |
greg |
2.2 |
for (my $i = $vwraysC{$rpictA[-1]}; $i-- > 0; ) {
|
| 59 |
|
|
push @vwraysA, $ARGV[0];
|
| 60 |
|
|
push(@vwrightA, $ARGV[0]) if ($isvopt);
|
| 61 |
greg |
2.1 |
push @rpictA, shift(@ARGV);
|
| 62 |
|
|
}
|
| 63 |
|
|
next OPTION;
|
| 64 |
|
|
}
|
| 65 |
|
|
# Check rtrace options
|
| 66 |
|
|
if (defined $rtraceC{$ARGV[0]}) {
|
| 67 |
greg |
2.2 |
push @rtraceA, $ARGV[0];
|
| 68 |
greg |
2.1 |
push @rpictA, shift(@ARGV);
|
| 69 |
greg |
2.2 |
for (my $i = $rtraceC{$rpictA[-1]}; $i-- > 0; ) {
|
| 70 |
|
|
push @rtraceA, $ARGV[0];
|
| 71 |
greg |
2.1 |
push @rpictA, shift(@ARGV);
|
| 72 |
|
|
}
|
| 73 |
|
|
next OPTION;
|
| 74 |
|
|
}
|
| 75 |
greg |
2.2 |
# Check options to ignore
|
| 76 |
|
|
if (defined $ignoreC{$ARGV[0]}) {
|
| 77 |
|
|
push @rpictA, shift(@ARGV);
|
| 78 |
|
|
for (my $i = $ignoreC{$rpictA[-1]}; $i-- > 0; ) {
|
| 79 |
|
|
push @rpictA, shift(@ARGV);
|
| 80 |
|
|
}
|
| 81 |
greg |
2.1 |
next OPTION;
|
| 82 |
|
|
}
|
| 83 |
|
|
# Check for output file or number of processes
|
| 84 |
|
|
if ("$ARGV[0]" eq "-o") {
|
| 85 |
|
|
shift @ARGV;
|
| 86 |
|
|
$outpic = shift(@ARGV);
|
| 87 |
greg |
2.5 |
} elsif ("$ARGV[0]" eq "-z") {
|
| 88 |
|
|
push @rpictA, shift(@ARGV);
|
| 89 |
|
|
$outzbf = $ARGV[0];
|
| 90 |
|
|
push @rpictA, shift(@ARGV);
|
| 91 |
greg |
2.1 |
} elsif ("$ARGV[0]" eq "-n") {
|
| 92 |
|
|
shift @ARGV;
|
| 93 |
|
|
$nprocs = shift(@ARGV);
|
| 94 |
|
|
} else {
|
| 95 |
greg |
2.2 |
die "Unsupported option: " . $ARGV[0] . "\n";
|
| 96 |
greg |
2.1 |
}
|
| 97 |
|
|
}
|
| 98 |
|
|
die "Number of processes must be positive" if ($nprocs <= 0);
|
| 99 |
greg |
2.4 |
if (defined $outpic) { # redirect output?
|
| 100 |
|
|
die "File '$outpic' already exists\n" if (-e $outpic);
|
| 101 |
greg |
2.1 |
open STDOUT, '>', "$outpic";
|
| 102 |
|
|
}
|
| 103 |
|
|
if ($nprocs == 1) { # may as well run rpict?
|
| 104 |
greg |
2.2 |
push(@rpictA, $ARGV[0]) if ($#ARGV == 0);
|
| 105 |
greg |
2.1 |
exec @rpictA ;
|
| 106 |
|
|
}
|
| 107 |
greg |
2.5 |
push @rtraceA, ("-n", "$nprocs");
|
| 108 |
greg |
2.1 |
die "Need single octree argument\n" if ($#ARGV != 0);
|
| 109 |
greg |
2.5 |
my $oct = $ARGV[0];
|
| 110 |
|
|
my $view = `@vwrightA 0`;
|
| 111 |
|
|
my @res = split(/\s/, `@vwraysA -d`);
|
| 112 |
|
|
if (defined $outzbf) { # generating depth buffer?
|
| 113 |
|
|
my $tres = "/tmp/rtp$$";
|
| 114 |
|
|
system "@vwraysA | @rtraceA -fff -ovl $res[4] $oct > $tres" || exit 1;
|
| 115 |
|
|
system( q{getinfo -c rcalc -if4 -of -e '$1=$1;$2=$2;$3=$3' < } .
|
| 116 |
|
|
"$tres | pvalue -r -df -Y $res[3] +X $res[1] | " .
|
| 117 |
|
|
"getinfo -a 'VIEW=$view'" );
|
| 118 |
|
|
system( "getinfo - < $tres | rcalc -if4 -of > $outzbf" . q{ -e '$1=$4'} );
|
| 119 |
|
|
unlink $tres;
|
| 120 |
|
|
exit;
|
| 121 |
|
|
}
|
| 122 |
|
|
# no depth buffer, so simpler
|
| 123 |
|
|
exec "@vwraysA | @rtraceA -ffc @res $oct | getinfo -a 'VIEW=$view'";
|