ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/rtpict.pl
Revision: 2.6
Committed: Tue May 22 15:16:53 2018 UTC (5 years, 10 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad5R2
Changes since 2.5: +2 -2 lines
Log Message:
Fixed issue with boolean option toggling (thanks to Axel Jacobs)

File Contents

# Content
1 #!/usr/bin/perl -w
2 # RCSid $Id: rtpict.pl,v 2.5 2018/03/21 17:56:08 greg Exp $
3 #
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 my %vwraysC = ("-vf",1, "-vtv",0, "-vtl",0, "-vth",0, "-vta",0, "-vts",0, "-vtc",0,
21 "-x",1, "-y",1, "-vp",3, "-vd",3, "-vu",3, "-vh",1, "-vv",1,
22 "-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 # Starting options for rtrace (rpict values)
26 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 my @vwraysA = ("vwrays", "-ff", "-pj", ".67");
29 my @vwrightA = ("vwright", "-vtv");
30 my @rpictA = ("rpict");
31 my $outpic;
32 my $outzbf;
33 OPTION: # sort through options
34 while ($#ARGV >= 0 && "$ARGV[0]" =~ /^[-\@]/) {
35 # Check for file inclusion
36 if ("$ARGV[0]" =~ /^\@/) {
37 open my $handle, '<', substr($ARGV[0], 1);
38 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 if ("$ARGV[0]" =~ ('^' . $boopt . '[-+01tfynTFYN]?$')) {
47 push @rtraceA, $ARGV[0];
48 push @rpictA, shift(@ARGV);
49 next OPTION;
50 }
51 }
52 # Check view options
53 if (defined $vwraysC{$ARGV[0]}) {
54 push @vwraysA, $ARGV[0];
55 my $isvopt = ("$ARGV[0]" =~ /^-v/);
56 push(@vwrightA, $ARGV[0]) if ($isvopt);
57 push @rpictA, shift(@ARGV);
58 for (my $i = $vwraysC{$rpictA[-1]}; $i-- > 0; ) {
59 push @vwraysA, $ARGV[0];
60 push(@vwrightA, $ARGV[0]) if ($isvopt);
61 push @rpictA, shift(@ARGV);
62 }
63 next OPTION;
64 }
65 # Check rtrace options
66 if (defined $rtraceC{$ARGV[0]}) {
67 push @rtraceA, $ARGV[0];
68 push @rpictA, shift(@ARGV);
69 for (my $i = $rtraceC{$rpictA[-1]}; $i-- > 0; ) {
70 push @rtraceA, $ARGV[0];
71 push @rpictA, shift(@ARGV);
72 }
73 next OPTION;
74 }
75 # 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 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 } elsif ("$ARGV[0]" eq "-z") {
88 push @rpictA, shift(@ARGV);
89 $outzbf = $ARGV[0];
90 push @rpictA, shift(@ARGV);
91 } elsif ("$ARGV[0]" eq "-n") {
92 shift @ARGV;
93 $nprocs = shift(@ARGV);
94 } else {
95 die "Unsupported option: " . $ARGV[0] . "\n";
96 }
97 }
98 die "Number of processes must be positive" if ($nprocs <= 0);
99 if (defined $outpic) { # redirect output?
100 die "File '$outpic' already exists\n" if (-e $outpic);
101 open STDOUT, '>', "$outpic";
102 }
103 if ($nprocs == 1) { # may as well run rpict?
104 push(@rpictA, $ARGV[0]) if ($#ARGV == 0);
105 exec @rpictA ;
106 }
107 push @rtraceA, ("-n", "$nprocs");
108 die "Need single octree argument\n" if ($#ARGV != 0);
109 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'";