--- ray/src/util/rtpict.pl 2019/07/23 18:17:55 2.9 +++ ray/src/util/rtpict.pl 2020/04/08 16:20:00 2.18 @@ -1,5 +1,5 @@ #!/usr/bin/perl -w -# RCSid $Id: rtpict.pl,v 2.9 2019/07/23 18:17:55 greg Exp $ +# RCSid $Id: rtpict.pl,v 2.18 2020/04/08 16:20:00 greg Exp $ # # Run rtrace in parallel mode to simulate rpict -n option # May also be used to render layered images with -o* option @@ -11,27 +11,29 @@ use strict; my $nprocs = 1; # rtrace options and the associated number of arguments my %rtraceC = ('-dt',1, '-dc',1, '-dj',1, '-ds',1, '-dr',1, '-dp',1, - '-ss',1, '-st',1, '-e',1, '-am',1, + '-ss',1, '-st',1, '-e',1, '-am',1, '-P',1, '-PP',1, '-ab',1, '-af',1, '-ai',1, '-aI',1, '-ae',1, '-aE',1, '-av',3, '-aw',1, '-aa',1, '-ar',1, '-ad',1, '-as',1, - '-me',3, '-ma',3, '-mg',1, '-ms',1, '-lr',1, '-lw',1); + '-me',3, '-ma',3, '-mg',1, '-ms',1, '-lr',1, '-lw',1, + '-ap',2, '-am',1, '-ac',1, '-aC',1); # boolean rtrace options my @boolO = ('-w', '-bv', '-dv', '-i', '-u'); # view options and the associated number of arguments my %vwraysC = ('-vf',1, '-vtv',0, '-vtl',0, '-vth',0, '-vta',0, '-vts',0, '-vtc',0, '-x',1, '-y',1, '-vp',3, '-vd',3, '-vu',3, '-vh',1, '-vv',1, - '-vo',1, '-va',1, '-vs',1, '-vl',1, '-pa',1, '-pj',1, '-pd',1); + '-vo',1, '-va',1, '-vs',1, '-vl',1, '-pa',1, '-pj',1); # options we need to silently ignore -my %ignoreC = ('-t',1, '-ps',1, '-pt',1, '-pm',1); +my %ignoreC = ('-t',1, '-ps',1, '-pt',1, '-pm',1, '-pd',1); # Starting options for rtrace (rpict values) my @rtraceA = split(' ', 'rtrace -u- -dt .05 -dc .5 -ds .25 -dr 1 ' . '-aa .2 -ar 64 -ad 512 -as 128 -lr 7 -lw 1e-03'); my @vwraysA = ('vwrays', '-ff', '-pj', '.67'); my @vwrightA = ('vwright', '-vtv'); -my @rpictA = ('rpict'); +my @rpictA = ('rpict', '-ps', '1'); my $outpatt = '^-o[vrxlLRXnNsmM]+'; my $refDepth = ""; my $irrad = 0; +my $persist = 0; my $outlyr; my $outdir; my $outpic; @@ -40,7 +42,7 @@ OPTION: # sort through options while ($#ARGV >= 0 && "$ARGV[0]" =~ /^[-\@]/) { # Check for file inclusion if ("$ARGV[0]" =~ /^\@/) { - open my $handle, '<', substr($ARGV[0], 1); + open my $handle, '<', substr($ARGV[0], 1) or die "No file for $ARGV[0]\n"; shift @ARGV; chomp(my @args = <$handle>); close $handle; @@ -75,6 +77,7 @@ while ($#ARGV >= 0 && "$ARGV[0]" =~ /^[-\@]/) { } # Check rtrace options if (defined $rtraceC{$ARGV[0]}) { + $persist ||= ("$ARGV[0]" =~ /^-PP?$/); push @rtraceA, $ARGV[0]; push @rpictA, shift(@ARGV); for (my $i = $rtraceC{$rpictA[-1]}; $i-- > 0; ) { @@ -124,7 +127,7 @@ if (defined $outpic) { # redirect output? } ##################################################################### ##### May as well run rpict? -if ($nprocs == 1 && !defined($outdir)) { +if ($nprocs == 1 && $persist == 0 && !defined($outdir)) { push(@rpictA, $ARGV[0]) if ($#ARGV == 0); exec @rpictA ; } @@ -138,16 +141,14 @@ my @res = split(/\s/, `@vwraysA -d`); ##################################################################### ##### Generating picture with depth buffer? if (defined $outzbf) { - exec "@vwraysA | @rtraceA -fff -olv @res $oct | " . - "rsplit -ih -iH -f " . - "-of $outzbf " . - "-oh -oH -of3 '!pvalue -r -df' | " . - "getinfo -a 'VIEW=$view'"; + exec "@vwraysA | @rtraceA -fff -olv @res '$oct' | " . + "rsplit -ih -iH -f -of '$outzbf' -oh -oH -of3 - | " . + "pvalue -r -df | getinfo -a 'VIEW=$view'"; } ##################################################################### ##### Base case with output picture only? if (! defined $outdir) { - exec "@vwraysA | @rtraceA -ffc @res $oct | getinfo -a 'VIEW=$view'"; + exec "@vwraysA | @rtraceA -ffc @res '$oct' | getinfo -a 'VIEW=$view'"; } ##################################################################### ##### Layered image output case @@ -155,12 +156,12 @@ my @rsplitA = ("rsplit", "'-t '", "-ih", "-iH", "-oh", # Supported rtrace -o* options and output file name.typ my %rtoutC = ( v => 'radiance.hdr', - r => 'mirrored.hdr', - x => 'unmirrored.hdr', - l => 'effective.dpt', - L => 'firstsurface.dpt', - R => 'mirrored.dpt', - X => 'unmirrored.dpt', + r => 'r_refl.hdr', + x => 'r_unrefl.hdr', + l => 'd_effective.dpt', + L => 'd_firstsurf.dpt', + R => 'd_refl.dpt', + X => 'd_unrefl.dpt', n => 'perturbed.nrm', N => 'unperturbed.nrm', s => 'surface.idx', @@ -188,10 +189,12 @@ if (! -d $outdir) { foreach my $oval (split //, $outlyr) { die "Duplicate or unsupported type '$oval' in -o$outlyr\n" if (!defined $rtoutC{$oval}); + my $outfile = "$outdir/$rtoutC{$oval}"; + die "File '$outfile' already exists\n" if (-e $outfile); my ($otyp) = ($rtoutC{$oval} =~ /(\.[^.]+)$/); push @rsplitA, $rcodeC{$otyp}[0]; - push @rsplitA, qq{'$rcodeC{$otyp}[1] > "$outdir/$rtoutC{$oval}"'}; + push @rsplitA, qq{'$rcodeC{$otyp}[1] > "$outfile"'}; delete $rtoutC{$oval}; } # call rtrace + rsplit -exec "@vwraysA | @rtraceA -fff @res $oct | getinfo -a 'VIEW=$view' | @rsplitA"; +exec "@vwraysA | @rtraceA -fff @res '$oct' | getinfo -a 'VIEW=$view' | @rsplitA";