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

Comparing ray/src/util/genBSDF.pl (file contents):
Revision 2.17 by greg, Wed Jun 1 00:29:40 2011 UTC vs.
Revision 2.24 by greg, Tue Aug 23 14:02:41 2011 UTC

# Line 13 | Line 13 | sub userror {
13   }
14   my $td = mkdtemp("/tmp/genBSDF.XXXXXX");
15   chomp $td;
16 + my @savedARGV = @ARGV;
17   my $tensortree = 0;
18   my $ttlog2 = 4;
19 < my $nsamp = 1000;
19 > my $nsamp = 10000;
20   my $rtargs = "-w -ab 5 -ad 700 -lw 3e-6";
21   my $mgfin = 0;
22   my $geout = 1;
23   my $nproc = 1;
24   my $doforw = 0;
25   my $doback = 1;
26 + my $gunit = "Meter";
27   my @dim;
28   # Get options
29   while ($#ARGV >= 0) {
# Line 32 | Line 34 | while ($#ARGV >= 0) {
34                  shift @ARGV;
35          } elsif ("$ARGV[0]" =~ /^[-+]g/) {
36                  $geout = ("$ARGV[0]" =~ /^\+/);
37 +                $gunit = $ARGV[1];
38 +                if ($gunit !~ /^(?i)(meter|foot|inch|centimeter|millimeter)$/) {
39 +                        die "Illegal geometry unit '$gunit': must be meter, foot, inch, centimeter, or millimeter\n";
40 +                }
41 +                shift @ARGV;
42          } elsif ("$ARGV[0]" =~ /^[-+]f/) {
43                  $doforw = ("$ARGV[0]" =~ /^\+/);
44          } elsif ("$ARGV[0]" =~ /^[-+]b/) {
# Line 98 | Line 105 | die "Could not compile scene\n" if ( $? );
105   print
106   '<?xml version="1.0" encoding="UTF-8"?>
107   <WindowElement xmlns="http://windows.lbl.gov" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://windows.lbl.gov/BSDF-v1.4.xsd">
108 < <WindowElementType>System</WindowElementType>
108 > ';
109 > print "<!-- File produced by: genBSDF @savedARGV -->\n";
110 > print
111 > '<WindowElementType>System</WindowElementType>
112   <Optical>
113   <Layer>
114          <Material>
115                  <Name>Name</Name>
116                  <Manufacturer>Manufacturer</Manufacturer>
117   ';
118 < printf "\t\t<Thickness unit=\"Meter\">%.3f</Thickness>\n", $dim[5] - $dim[4];
119 < printf "\t\t<Width unit=\"Meter\">%.3f</Width>\n", $dim[1] - $dim[0];
120 < printf "\t\t<Height unit=\"Meter\">%.3f</Height>\n", $dim[3] - $dim[2];
118 > printf "\t\t<Thickness unit=\"$gunit\">%.3f</Thickness>\n", $dim[5] - $dim[4];
119 > printf "\t\t<Width unit=\"$gunit\">%.3f</Width>\n", $dim[1] - $dim[0];
120 > printf "\t\t<Height unit=\"$gunit\">%.3f</Height>\n", $dim[3] - $dim[2];
121   print "\t\t<DeviceType>Integral</DeviceType>\n";
122   # Output MGF description if requested
123   if ( $geout ) {
124 <        print "\t\t<Geometry format=\"MGF\" unit=\"Meter\">\n";
124 >        print "\t\t<Geometry format=\"MGF\" unit=\"$gunit\">\n";
125          printf "xf -t %.6f %.6f 0\n", -($dim[0]+$dim[1])/2, -($dim[2]+$dim[3])/2;
126          open(MGFSCN, "< $mgfscn");
127          while (<MGFSCN>) { print $_; }
# Line 156 | Line 166 | sub do_tree_bsdf {
166   # Get sampling rate and subdivide task
167   my $ns2 = $ns;
168   $ns2 /= 2 if ( $tensortree == 3 );
169 < @pdiv = (0, int($ns2/$nproc));
170 < my $nrem = $ns2 % $nproc;
171 < for (my $i = 1; $i < $nproc; $i++) {
169 > my $nsplice = $nproc;
170 > $nsplice *= 10 if ($nproc > 1);
171 > $nsplice = $ns2 if ($nsplice > $ns2);
172 > $nsplice = 999 if ($nsplice > 999);
173 > @pdiv = (0, int($ns2/$nsplice));
174 > my $nrem = $ns2 % $nsplice;
175 > for (my $i = 1; $i < $nsplice; $i++) {
176          my $nv = $pdiv[$i] + $pdiv[1];
177          ++$nv if ( $nrem-- > 0 );
178          push @pdiv, $nv;
# Line 207 | Line 221 | print "\t<DataDefinition>\n";
221   print "\t\t<IncidentDataStructure>TensorTree$tensortree</IncidentDataStructure>\n";
222   print "\t</DataDefinition>\n";
223   # Fork parallel rtcontrib processes to compute each side
224 + my $npleft = $nproc;
225   if ( $doback ) {
226 <        for (my $proc = 0; $proc < $nproc; $proc++) {
227 <                bg_tree_rtcontrib(0, $proc);
226 >        for (my $splice = 0; $splice < $nsplice; $splice++) {
227 >                if (! $npleft ) {
228 >                        wait();
229 >                        die "rtcontrib process reported error" if ( $? );
230 >                        $npleft++;
231 >                }
232 >                bg_tree_rtcontrib(0, $splice);
233 >                $npleft--;
234          }
235          while (wait() >= 0) {
236                  die "rtcontrib process reported error" if ( $? );
237 +                $npleft++;
238          }
239          ttree_out(0);
240   }
241   if ( $doforw ) {
242 <        for (my $proc = 0; $proc < $nproc; $proc++) {
243 <                bg_tree_rtcontrib(1, $proc);
242 >        for (my $splice = 0; $splice < $nsplice; $splice++) {
243 >                if (! $npleft ) {
244 >                        wait();
245 >                        die "rtcontrib process reported error" if ( $? );
246 >                        $npleft++;
247 >                }
248 >                bg_tree_rtcontrib(1, $splice);
249 >                $npleft--;
250          }
251          while (wait() >= 0) {
252                  die "rtcontrib process reported error" if ( $? );
253 +                $npleft++;
254          }
255          ttree_out(1);
256   }
257   }       # end of sub do_tree_bsdf()
258  
259 < # Run i'th rtcontrib process for generating tensor tree samples
259 > # Run rtcontrib process in background to generate tensor tree samples
260   sub bg_tree_rtcontrib {
261          my $pid = fork();
262          die "Cannot fork new process" unless defined $pid;
# Line 248 | Line 277 | sub bg_tree_rtcontrib {
277                          "| rcalc -e 'r1=rand(($pn+.8681)*recno-.673892)' " .
278                          "-e 'r2=rand(($pn-5.37138)*recno+67.1737811)' " .
279                          "-e 'r3=rand(($pn+3.17603772)*recno+83.766771)' " .
280 <                        "-e 'Dx=1-($pbeg+\$1+r1)/$ns;Dy:0;Dz=sqrt(1-Dx*Dx)' " .
280 >                        "-e 'Dx=1-2*($pbeg+\$1+r1)/$ns;Dy:0;Dz=sqrt(1-Dx*Dx)' " .
281                          "-e 'xp=(\$3+r2)*(($dim[1]-$dim[0])/$nx)+$dim[0]' " .
282                          "-e 'yp=(\$2+r3)*(($dim[3]-$dim[2])/$ny)+$dim[2]' " .
283                          "-e 'zp=$dim[5-$forw]' -e 'myDz=Dz*($forw*2-1)' " .
# Line 317 | Line 346 | print
346                  <WavelengthDataBlock>
347   ';
348   print "\t\t\t<WavelengthDataDirection>Reflection $side</WavelengthDataDirection>\n";
349 < print '
350 <                        <AngleBasis>LBNL/Shirley-Chiu</AngleBasis>
349 > print
350 > '                       <AngleBasis>LBNL/Shirley-Chiu</AngleBasis>
351                          <ScatteringDataType>BRDF</ScatteringDataType>
352                          <ScatteringData>
353   ';
# Line 398 | Line 427 | my $rtcmd = "rtcontrib $rtargs -h -ff -fo -n $nproc -c
427          "-o '$td/%s.flt' -m $fmodnm -m $bmodnm $octree";
428   my $rccmd = "rcalc -e '$tcal' " .
429          "-e 'mod(n,d):n-floor(n/d)*d' -e 'Kbin=mod(recno-.999,$ndiv)' " .
430 <        q{-if3 -e '$1=(0.265*$1+0.670*$2+0.065*$3)/KprojOmega'};
430 >        q{-if3 -e 'oval=(0.265*$1+0.670*$2+0.065*$3)/KprojOmega' } .
431 >        q[-o '${  oval  },'];
432   if ( $doforw ) {
433   $cmd = "cnt $ndiv $ny $nx | rcalc -of -e '$tcal' " .
434          "-e 'xp=(\$3+rand(.12*recno+288))*(($dim[1]-$dim[0])/$nx)+$dim[0]' " .

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines