ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/Development/ray/src/util/rtpict.pl
(Generate patch)

Comparing ray/src/util/rtpict.pl (file contents):
Revision 2.8 by greg, Tue Jul 23 01:03:30 2019 UTC vs.
Revision 2.32 by greg, Sat Sep 13 16:52:28 2025 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines