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.15 by greg, Wed May 25 19:24:11 2011 UTC vs.
Revision 2.22 by greg, Fri Jun 24 00:41:51 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;
# Line 22 | Line 23 | 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 139 | Line 149 | print
149   </WindowElement>
150   ';
151   # Clean up temporary files and exit
152 < if ( $persistfile ) {
143 <        open(PFI, "< $persistfile");
152 > if ( $persistfile && open(PFI, "< $persistfile") ) {
153          while (<PFI>) {
154                  s/^[^ ]* //;
155                  kill('ALRM', $_);
# Line 148 | Line 157 | if ( $persistfile ) {
157          }
158          close PFI;
159   }
160 < system "rm -rf $td";
161 < exit 0;
160 > exec("rm -rf $td");
161 >
162   #-------------- End of main program segment --------------#
163  
164   #++++++++++++++ Tensor tree BSDF generation ++++++++++++++#
# Line 204 | Line 213 | out_square_x = (out_square_a + 1)/2;
213   out_square_y = (out_square_b + 1)/2;
214   ';
215   # Announce ourselves in XML output
216 < print "         <DataDefinition>\n";
217 < print "                 <IncidentDataStructure>TensorTree$tensortree</IncidentDataStructure>\n";
218 < print "         </DataDefinition>\n";
216 > print "\t<DataDefinition>\n";
217 > print "\t\t<IncidentDataStructure>TensorTree$tensortree</IncidentDataStructure>\n";
218 > print "\t</DataDefinition>\n";
219   # Fork parallel rtcontrib processes to compute each side
220   if ( $doback ) {
221          for (my $proc = 0; $proc < $nproc; $proc++) {
# Line 249 | Line 258 | sub bg_tree_rtcontrib {
258                          "| rcalc -e 'r1=rand(($pn+.8681)*recno-.673892)' " .
259                          "-e 'r2=rand(($pn-5.37138)*recno+67.1737811)' " .
260                          "-e 'r3=rand(($pn+3.17603772)*recno+83.766771)' " .
261 <                        "-e 'Dx=1-($pbeg+\$1+r1)/$ns;Dy:0;Dz=sqrt(1-Dx*Dx)' " .
261 >                        "-e 'Dx=1-2*($pbeg+\$1+r1)/$ns;Dy:0;Dz=sqrt(1-Dx*Dx)' " .
262                          "-e 'xp=(\$3+r2)*(($dim[1]-$dim[0])/$nx)+$dim[0]' " .
263                          "-e 'yp=(\$2+r3)*(($dim[3]-$dim[2])/$ny)+$dim[2]' " .
264                          "-e 'zp=$dim[5-$forw]' -e 'myDz=Dz*($forw*2-1)' " .
# Line 316 | Line 325 | print
325                  <SourceSpectrum>CIE Illuminant D65 1nm.ssp</SourceSpectrum>
326                  <DetectorSpectrum>ASTM E308 1931 Y.dsp</DetectorSpectrum>
327                  <WavelengthDataBlock>
328 <                        <WavelengthDataDirection>Reflection $side</WavelengthDataDirection>
329 <                        <AngleBasis>LBNL/Shirley-Chiu</AngleBasis>
328 > ';
329 > print "\t\t\t<WavelengthDataDirection>Reflection $side</WavelengthDataDirection>\n";
330 > print
331 > '                       <AngleBasis>LBNL/Shirley-Chiu</AngleBasis>
332                          <ScatteringDataType>BRDF</ScatteringDataType>
333                          <ScatteringData>
334   ';
# Line 397 | Line 408 | my $rtcmd = "rtcontrib $rtargs -h -ff -fo -n $nproc -c
408          "-o '$td/%s.flt' -m $fmodnm -m $bmodnm $octree";
409   my $rccmd = "rcalc -e '$tcal' " .
410          "-e 'mod(n,d):n-floor(n/d)*d' -e 'Kbin=mod(recno-.999,$ndiv)' " .
411 <        q{-if3 -e '$1=(0.265*$1+0.670*$2+0.065*$3)/KprojOmega'};
411 >        q{-if3 -e 'oval=(0.265*$1+0.670*$2+0.065*$3)/KprojOmega' } .
412 >        q[-o '${  oval  },'];
413   if ( $doforw ) {
414   $cmd = "cnt $ndiv $ny $nx | rcalc -of -e '$tcal' " .
415          "-e 'xp=(\$3+rand(.12*recno+288))*(($dim[1]-$dim[0])/$nx)+$dim[0]' " .

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines