ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/rtpict.pl
Revision: 2.30
Committed: Fri Jan 5 18:33:26 2024 UTC (3 months, 2 weeks ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 2.29: +3 -3 lines
Log Message:
fix(rtpict): Renamed rmtxcomb to rcomb

File Contents

# User Rev Content
1 greg 2.1 #!/usr/bin/perl -w
2 greg 2.30 # RCSid $Id: rtpict.pl,v 2.29 2023/12/11 19:21:43 greg Exp $
3 greg 2.1 #
4     # Run rtrace in parallel mode to simulate rpict -n option
5 greg 2.8 # May also be used to render layered images with -o* option
6 greg 2.1 #
7     # G. Ward
8     #
9     use strict;
10 greg 2.8 # we'll run rpict if no -n or -o* option
11 greg 2.1 my $nprocs = 1;
12     # rtrace options and the associated number of arguments
13 greg 2.9 my %rtraceC = ('-dt',1, '-dc',1, '-dj',1, '-ds',1, '-dr',1, '-dp',1,
14 greg 2.16 '-ss',1, '-st',1, '-e',1, '-am',1, '-P',1, '-PP',1,
15 greg 2.9 '-ab',1, '-af',1, '-ai',1, '-aI',1, '-ae',1, '-aE',1,
16     '-av',3, '-aw',1, '-aa',1, '-ar',1, '-ad',1, '-as',1,
17 greg 2.18 '-me',3, '-ma',3, '-mg',1, '-ms',1, '-lr',1, '-lw',1,
18 greg 2.27 '-ap',2, '-am',1, '-ac',1, '-aC',1,
19 greg 2.28 '-cs',1, '-cw',2, '-pc',8, '-pXYZ',0);
20 greg 2.1 # boolean rtrace options
21 greg 2.29 my @boolO = ('-w', '-bv', '-dv', '-i', '-u', '-co');
22 greg 2.1 # view options and the associated number of arguments
23 greg 2.9 my %vwraysC = ('-vf',1, '-vtv',0, '-vtl',0, '-vth',0, '-vta',0, '-vts',0, '-vtc',0,
24     '-x',1, '-y',1, '-vp',3, '-vd',3, '-vu',3, '-vh',1, '-vv',1,
25 greg 2.19 '-vo',1, '-va',1, '-vs',1, '-vl',1, '-pa',1, '-pj',1, '-pd',1);
26 greg 2.2 # options we need to silently ignore
27 greg 2.19 my %ignoreC = ('-t',1, '-ps',1, '-pt',1, '-pm',1,);
28 greg 2.1 # Starting options for rtrace (rpict values)
29 greg 2.9 my @rtraceA = split(' ', 'rtrace -u- -dt .05 -dc .5 -ds .25 -dr 1 ' .
30 greg 2.26 '-aa .2 -ar 64 -ad 512 -as 128 -lr 7 -lw 1e-04');
31 greg 2.22 my @vwraysA = ('vwrays', '-pj', '.67');
32 greg 2.9 my @vwrightA = ('vwright', '-vtv');
33 greg 2.17 my @rpictA = ('rpict', '-ps', '1');
34 greg 2.28 my @pvalueA = ('pvalue', '-r');
35 greg 2.9 my $outpatt = '^-o[vrxlLRXnNsmM]+';
36     my $refDepth = "";
37     my $irrad = 0;
38 greg 2.29 my $specout = 0;
39     my $ncsamp = 3;
40 greg 2.17 my $persist = 0;
41 greg 2.20 my $ambounce = 0;
42     my $ambcache = 1;
43     my $ambfile;
44 greg 2.8 my $outlyr;
45     my $outdir;
46 greg 2.1 my $outpic;
47 greg 2.5 my $outzbf;
48 greg 2.1 OPTION: # sort through options
49     while ($#ARGV >= 0 && "$ARGV[0]" =~ /^[-\@]/) {
50     # Check for file inclusion
51     if ("$ARGV[0]" =~ /^\@/) {
52 greg 2.14 open my $handle, '<', substr($ARGV[0], 1) or die "No file for $ARGV[0]\n";
53 greg 2.1 shift @ARGV;
54     chomp(my @args = <$handle>);
55     close $handle;
56     unshift @ARGV, split(/\s+/, "@args");
57     next OPTION;
58     }
59     # Check booleans
60     for my $boopt (@boolO) {
61 greg 2.6 if ("$ARGV[0]" =~ ('^' . $boopt . '[-+01tfynTFYN]?$')) {
62 greg 2.9 if ("$ARGV[0]" eq '-i') {
63 greg 2.8 $irrad = ! $irrad;
64     } elsif ("$ARGV[0]" =~ /^-i[-+01tfynTFYN]/) {
65     $irrad = ("$ARGV[0]" =~ /^-i[+1tyTY]/);
66 greg 2.29 } elsif ("$ARGV[0]" eq '-co') {
67     $specout = ! $specout;
68     } elsif ("$ARGV[0]" =~ /^-co[-+01tfynTFYN]/) {
69     $specout = ("$ARGV[0]" =~ /^-co[+1tyTY]/);
70 greg 2.8 }
71 greg 2.29 push(@rpictA, $ARGV[0]) if ("$ARGV[0]" !~ /^-co/);
72     push @rtraceA, shift(@ARGV);
73 greg 2.1 next OPTION;
74     }
75     }
76     # Check view options
77     if (defined $vwraysC{$ARGV[0]}) {
78 greg 2.2 push @vwraysA, $ARGV[0];
79 greg 2.1 my $isvopt = ("$ARGV[0]" =~ /^-v/);
80 greg 2.2 push(@vwrightA, $ARGV[0]) if ($isvopt);
81 greg 2.1 push @rpictA, shift(@ARGV);
82 greg 2.2 for (my $i = $vwraysC{$rpictA[-1]}; $i-- > 0; ) {
83     push @vwraysA, $ARGV[0];
84     push(@vwrightA, $ARGV[0]) if ($isvopt);
85 greg 2.1 push @rpictA, shift(@ARGV);
86     }
87     next OPTION;
88     }
89     # Check rtrace options
90     if (defined $rtraceC{$ARGV[0]}) {
91 greg 2.20 if ("$ARGV[0]" =~ /^-PP?$/) {
92     $persist = 1;
93     } elsif ("$ARGV[0]" eq '-ab') {
94     $ambounce = $ARGV[1];
95     } elsif ("$ARGV[0]" eq '-aa') {
96     $ambcache = ($ARGV[1] > 0.0);
97     } elsif ("$ARGV[0]" eq '-af') {
98     $ambfile = "$ARGV[1]";
99 greg 2.28 } elsif ("$ARGV[0]" eq '-pXYZ') {
100     push @pvalueA, $ARGV[0];
101 greg 2.29 $specout = 0;
102 greg 2.28 } elsif ("$ARGV[0]" eq '-pc') {
103     push @pvalueA, '-p';
104     push @pvalueA, @ARGV[1..8];
105 greg 2.29 $specout = 0;
106     } elsif ("$ARGV[0]" eq '-cs') {
107     $ncsamp = $ARGV[1];
108 greg 2.20 }
109 greg 2.2 push @rtraceA, $ARGV[0];
110 greg 2.1 push @rpictA, shift(@ARGV);
111 greg 2.2 for (my $i = $rtraceC{$rpictA[-1]}; $i-- > 0; ) {
112     push @rtraceA, $ARGV[0];
113 greg 2.1 push @rpictA, shift(@ARGV);
114     }
115     next OPTION;
116     }
117 greg 2.2 # Check options to ignore
118     if (defined $ignoreC{$ARGV[0]}) {
119     push @rpictA, shift(@ARGV);
120     for (my $i = $ignoreC{$rpictA[-1]}; $i-- > 0; ) {
121     push @rpictA, shift(@ARGV);
122     }
123 greg 2.1 next OPTION;
124     }
125     # Check for output file or number of processes
126 greg 2.9 if ("$ARGV[0]" eq '-o') {
127 greg 2.1 shift @ARGV;
128     $outpic = shift(@ARGV);
129 greg 2.9 } elsif ("$ARGV[0]" eq '-z') {
130 greg 2.5 push @rpictA, shift(@ARGV);
131     $outzbf = $ARGV[0];
132     push @rpictA, shift(@ARGV);
133 greg 2.9 } elsif ("$ARGV[0]" eq '-n') {
134 greg 2.1 shift @ARGV;
135     $nprocs = shift(@ARGV);
136 greg 2.9 } elsif ("$ARGV[0]" eq '-d') {
137 greg 2.8 shift @ARGV;
138 greg 2.9 $refDepth = ' -d ' . shift(@ARGV);
139 greg 2.8 } elsif ("$ARGV[0]" =~ "$outpatt") {
140     push @rtraceA, $ARGV[0];
141     $outlyr = substr(shift(@ARGV), 2);
142     $outdir = shift(@ARGV);
143 greg 2.1 } else {
144 greg 2.2 die "Unsupported option: " . $ARGV[0] . "\n";
145 greg 2.1 }
146     }
147     die "Number of processes must be positive" if ($nprocs <= 0);
148 greg 2.29 if ($specout) {
149     $specout = ($ncsamp > 3);
150     }
151 greg 2.8 if (defined $outdir) { # check conflicting options
152     die "Options -o and -o* are mutually exclusive\n" if (defined $outpic);
153     die "Options -z and -o* are mutually exclusive\n" if (defined $outzbf);
154     }
155 greg 2.4 if (defined $outpic) { # redirect output?
156     die "File '$outpic' already exists\n" if (-e $outpic);
157 greg 2.1 open STDOUT, '>', "$outpic";
158     }
159 greg 2.9 #####################################################################
160     ##### May as well run rpict?
161 greg 2.29 if ($specout == 0 && $nprocs == 1 && $persist == 0 && !defined($outdir)) {
162 greg 2.2 push(@rpictA, $ARGV[0]) if ($#ARGV == 0);
163 greg 2.1 exec @rpictA ;
164     }
165 greg 2.9 # OK, we're running rtrace in some capacity...
166     push @rtraceA, ('-n', "$nprocs");
167 greg 2.1 die "Need single octree argument\n" if ($#ARGV != 0);
168 greg 2.5 my $oct = $ARGV[0];
169     my $view = `@vwrightA 0`;
170 greg 2.9 chomp $view;
171 greg 2.5 my @res = split(/\s/, `@vwraysA -d`);
172 greg 2.9 #####################################################################
173 greg 2.22 ##### Resort pixels to reduce ambient cache collisions?
174 greg 2.20 if ($nprocs > 1 && $ambounce > 0 && $ambcache && defined($ambfile)) {
175 greg 2.29 if ($specout == 0 && !defined($outzbf) && !defined($outdir)) {
176 greg 2.25 # Straight picture output, so just shuffle sample order
177 greg 2.24 system "cnt -s $res[1] $res[3] > /tmp/ord$$.txt";
178     die "cnt error\n" if ( $? );
179 greg 2.22 system "@vwraysA -ff -i < /tmp/ord$$.txt " .
180     "| @rtraceA -ffa -ov '$oct' > /tmp/pix$$.txt";
181     die "Error running rtrace\n" if ( $? );
182 greg 2.23 system "( getinfo < /tmp/pix$$.txt | getinfo -a 'VIEW=$view'; " .
183     "getinfo - < /tmp/pix$$.txt | rlam /tmp/ord$$.txt - " .
184 greg 2.28 "| sort -k2rn -k1n ) | @pvalueA -Y $res[3] +X $res[1]";
185 greg 2.22 die "rlam error\n" if ( $? );
186     unlink ("/tmp/ord$$.txt", "/tmp/pix$$.txt");
187     exit 0;
188     }
189     # Else randomize overture calculation to prime ambient cache
190 greg 2.25 my @ores = (int($res[1]/6), int($res[3]/6));
191     print STDERR "Running $ores[0] by $ores[1] overture calculation " .
192 greg 2.20 "to populate '$ambfile'...\n";
193 greg 2.25 system "cnt -s @ores | @vwraysA -i -ff -x $ores[0] -y $ores[1] -pj 0 " .
194 greg 2.29 "| @rtraceA -ff -ov -pY '$oct' > /dev/null";
195 greg 2.20 die "Failure running overture\n" if ( $? );
196     print STDERR "Finished overture.\n";
197     }
198     #####################################################################
199 greg 2.9 ##### Generating picture with depth buffer?
200     if (defined $outzbf) {
201 greg 2.30 my $picvt = $specout ? 'rcomb -fc -' : "@pvalueA -df";
202 greg 2.22 exec "@vwraysA -ff | @rtraceA -fff -olv @res '$oct' | " .
203 greg 2.29 "rsplit -ih -iH -f -of '$outzbf' -oh -oH -of$ncsamp - | " .
204     $picvt . " | getinfo -a 'VIEW=$view'";
205 greg 2.5 }
206 greg 2.9 #####################################################################
207     ##### Base case with output picture only?
208     if (! defined $outdir) {
209 greg 2.22 exec "@vwraysA -ff | @rtraceA -ffc @res '$oct' | getinfo -a 'VIEW=$view'";
210 greg 2.9 }
211     #####################################################################
212     ##### Layered image output case
213     my @rsplitA = ("rsplit", "'-t '", "-ih", "-iH", "-oh", "-oH");
214     # Supported rtrace -o* options and output file name.typ
215     my %rtoutC = (
216     v => 'radiance.hdr',
217 greg 2.10 r => 'r_refl.hdr',
218     x => 'r_unrefl.hdr',
219     l => 'd_effective.dpt',
220     L => 'd_firstsurf.dpt',
221     R => 'd_refl.dpt',
222     X => 'd_unrefl.dpt',
223 greg 2.9 n => 'perturbed.nrm',
224     N => 'unperturbed.nrm',
225     s => 'surface.idx',
226     m => 'modifier.idx',
227     M => 'material.idx'
228     );
229     # Arguments for rsplit based on output file type
230     my %rcodeC = (
231 greg 2.28 '.hdr', ['-of3', "!@pvalueA -df -u"],
232 greg 2.30 '.hsr', ["-of$ncsamp", '!rcomb -fc -'],
233 greg 2.9 '.dpt', ['-of', "!rcode_depth$refDepth -ff"],
234     '.nrm', ['-of3', '!rcode_norm -ff'],
235     '.idx', ['-oa', '!rcode_ident "-t "']
236     );
237 greg 2.29 if ($specout) { # adjust actions for -co+ option
238     $rtoutC{'v'} = 'radiance.hsr';
239     $rtoutC{'r'} = 'r_refl.hsr';
240     $rtoutC{'x'} = 'r_unrefl.hsr';
241     }
242 greg 2.9 if ($irrad) { # adjust actions for -i+ option
243 greg 2.29 $rtoutC{'v'} = $specout ? 'irradiance.hsr' : 'irradiance.hdr';
244 greg 2.9 delete $rtoutC{'r'};
245     delete $rtoutC{'x'};
246     delete $rtoutC{'R'};
247     delete $rtoutC{'X'};
248     }
249     if (! -d $outdir) {
250     mkdir $outdir or die("Cannot create output directory '$outdir'\n");
251     }
252     # construct rsplit command
253     foreach my $oval (split //, $outlyr) {
254     die "Duplicate or unsupported type '$oval' in -o$outlyr\n"
255     if (!defined $rtoutC{$oval});
256 greg 2.15 my $outfile = "$outdir/$rtoutC{$oval}";
257     die "File '$outfile' already exists\n" if (-e $outfile);
258 greg 2.9 my ($otyp) = ($rtoutC{$oval} =~ /(\.[^.]+)$/);
259     push @rsplitA, $rcodeC{$otyp}[0];
260 greg 2.15 push @rsplitA, qq{'$rcodeC{$otyp}[1] > "$outfile"'};
261 greg 2.9 delete $rtoutC{$oval};
262     }
263     # call rtrace + rsplit
264 greg 2.22 exec "@vwraysA -ff | @rtraceA -fff @res '$oct' | getinfo -a 'VIEW=$view' | @rsplitA";