--- ray/src/util/genBSDF.pl 2012/02/17 00:14:46 2.29
+++ ray/src/util/genBSDF.pl 2014/07/09 15:03:11 2.48
@@ -1,18 +1,35 @@
#!/usr/bin/perl -w
-# RCSid $Id: genBSDF.pl,v 2.29 2012/02/17 00:14:46 greg Exp $
+# RCSid $Id: genBSDF.pl,v 2.48 2014/07/09 15:03:11 greg Exp $
#
# Compute BSDF based on geometry and material description
#
# G. Ward
#
use strict;
+my $windoz = ($^O eq "MSWin32" or $^O eq "MSWin64");
use File::Temp qw/ :mktemp /;
sub userror {
print STDERR "Usage: genBSDF [-n Nproc][-c Nsamp][-t{3|4} Nlog2][-r \"ropts\"][-dim xmin xmax ymin ymax zmin zmax][{+|-}f][{+|-}b][{+|-}mgf][{+|-}geom units] [input ..]\n";
exit 1;
}
-my $td = mkdtemp("/tmp/genBSDF.XXXXXX");
-chomp $td;
+my ($td,$radscn,$mgfscn,$octree,$cnttmp,$rmtmp);
+if ($windoz) {
+ my $tmploc = `echo \%TMP\%`;
+ chomp($tmploc);
+ $td = mkdtemp("$tmploc\\genBSDF.XXXXXX");
+ $radscn = "$td\\device.rad";
+ $mgfscn = "$td\\device.mgf";
+ $octree = "$td\\device.oct";
+ chomp $td;
+ $rmtmp = "rmdir /S /Q $td";
+} else{
+ $td = mkdtemp("/tmp/genBSDF.XXXXXX");
+ chomp $td;
+ $radscn = "$td/device.rad";
+ $mgfscn = "$td/device.mgf";
+ $octree = "$td/device.oct";
+ $rmtmp = "rm -rf $td";
+}
my @savedARGV = @ARGV;
my $tensortree = 0;
my $ttlog2 = 4;
@@ -23,8 +40,8 @@ my $geout = 1;
my $nproc = 1;
my $doforw = 0;
my $doback = 1;
-my $pctcull = 95;
-my $gunit = "Meter";
+my $pctcull = 90;
+my $gunit = "meter";
my @dim;
# Get options
while ($#ARGV >= 0) {
@@ -45,6 +62,7 @@ while ($#ARGV >= 0) {
} elsif ("$ARGV[0]" =~ /^[-+]b/) {
$doback = ("$ARGV[0]" =~ /^\+/);
} elsif ("$ARGV[0]" eq "-t") {
+ # Use value < 0 for rttree_reduce bypass
$pctcull = $ARGV[1];
shift @ARGV;
} elsif ("$ARGV[0]" =~ /^-t[34]$/) {
@@ -70,18 +88,13 @@ while ($#ARGV >= 0) {
}
# Check that we're actually being asked to do something
die "Must have at least one of +forward or +backward\n" if (!$doforw && !$doback);
-# Name our own persist file?
-my $persistfile;
-if ( $tensortree && $nproc > 1 && "$rtargs" !~ /-PP /) {
- $persistfile = "$td/pfile.txt";
- $rtargs = "-PP $persistfile $rtargs";
-}
+# Issue warning for unhandled reciprocity case
+print STDERR "Warning: recommend both +forward and +backward with -t3" if
+ ($tensortree==3 && !($doforw && $doback));
# Get scene description and dimensions
-my $radscn = "$td/device.rad";
-my $mgfscn = "$td/device.mgf";
-my $octree = "$td/device.oct";
+
if ( $mgfin ) {
- system "mgfilt '#,o,xf,c,cxy,cspec,cmix,m,sides,rd,td,rs,ts,ir,v,p,n,f,fh,sph,cyl,cone,prism,ring,torus' @ARGV > $mgfscn";
+ system qq{mgfilt "#,o,xf,c,cxy,cspec,cmix,m,sides,rd,td,rs,ts,ir,v,p,n,f,fh,sph,cyl,cone,prism,ring,torus" @ARGV > $mgfscn};
die "Could not load MGF input\n" if ( $? );
system "mgf2rad $mgfscn > $radscn";
} else {
@@ -113,30 +126,33 @@ print
print "\n";
print
'System
+BSDF
Name
Manufacturer
';
-printf "\t\t%.3f\n", $dim[5] - $dim[4];
-printf "\t\t%.3f\n", $dim[1] - $dim[0];
-printf "\t\t%.3f\n", $dim[3] - $dim[2];
-print "\t\tIntegral\n";
+printf qq{\t\t%.6f\n}, $dim[5] - $dim[4];
+printf qq{\t\t%.6f\n}, $dim[1] - $dim[0];
+printf qq{\t\t%.6f\n}, $dim[3] - $dim[2];
+print "\t\tOther\n";
+print "\t\n";
# Output MGF description if requested
if ( $geout ) {
- print "\t\t\n";
+ print qq{\t\t\n};
+ print qq{\t\t\n};
printf "xf -t %.6f %.6f 0\n", -($dim[0]+$dim[1])/2, -($dim[2]+$dim[3])/2;
open(MGFSCN, "< $mgfscn");
while () { print $_; }
close MGFSCN;
print "xf\n";
- print "\t\t\n";
+ print "\n";
+ print "\t\n";
}
-print " \n";
# Set up surface sampling
-my $nx = int(sqrt($nsamp*($dim[1]-$dim[0])/($dim[3]-$dim[2])) + .5);
-my $ny = int($nsamp/$nx + .5);
+my $nx = int(sqrt($nsamp*($dim[1]-$dim[0])/($dim[3]-$dim[2])) + 1);
+my $ny = int($nsamp/$nx + 1);
$nsamp = $nx * $ny;
my $ns = 2**$ttlog2;
my (@pdiv, $disk2sq, $sq2disk, $tcal, $kcal);
@@ -153,193 +169,192 @@ print
';
# Clean up temporary files and exit
-exec("rm -rf $td");
+system $rmtmp;
#-------------- End of main program segment --------------#
-#++++++++++++++ Kill persistent rtrace +++++++++++++++++++#
-sub persist_end {
- if ( $persistfile && open(PFI, "< $persistfile") ) {
- while () {
- s/^[^ ]* //;
- kill('ALRM', $_);
- last;
- }
- close PFI;
- }
-}
-
#++++++++++++++ Tensor tree BSDF generation ++++++++++++++#
sub do_tree_bsdf {
-# Get sampling rate and subdivide task
-my $ns2 = $ns;
-$ns2 /= 2 if ( $tensortree == 3 );
-my $nsplice = $nproc;
-$nsplice *= 10 if ($nproc > 1);
-$nsplice = $ns2 if ($nsplice > $ns2);
-$nsplice = 999 if ($nsplice > 999);
-@pdiv = (0, int($ns2/$nsplice));
-my $nrem = $ns2 % $nsplice;
-for (my $i = 1; $i < $nsplice; $i++) {
- my $nv = $pdiv[$i] + $pdiv[1];
- ++$nv if ( $nrem-- > 0 );
- push @pdiv, $nv;
-}
-die "Script error 1" if ($pdiv[-1] != $ns2);
# Shirley-Chiu mapping from unit square to disk
-$sq2disk = '
-in_square_a = 2*in_square_x - 1;
-in_square_b = 2*in_square_y - 1;
-in_square_rgn = if(in_square_a + in_square_b,
- if(in_square_a - in_square_b, 1, 2),
- if(in_square_b - in_square_a, 3, 4));
-out_disk_r = .999995*select(in_square_rgn, in_square_a, in_square_b,
- -in_square_a, -in_square_b);
-out_disk_phi = PI/4 * select(in_square_rgn,
- in_square_b/in_square_a,
- 2 - in_square_a/in_square_b,
- 4 + in_square_b/in_square_a,
- if(in_square_b*in_square_b,
- 6 - in_square_a/in_square_b, 0));
-Dx = out_disk_r*cos(out_disk_phi);
-Dy = out_disk_r*sin(out_disk_phi);
-Dz = sqrt(1 - out_disk_r*out_disk_r);
-';
+$sq2disk = 'in_square_a = 2*in_square_x - 1; ' .
+ 'in_square_b = 2*in_square_y - 1; ' .
+ 'in_square_rgn = if(in_square_a + in_square_b, ' .
+ 'if(in_square_a - in_square_b, 1, 2), ' .
+ 'if(in_square_b - in_square_a, 3, 4)); ' .
+ 'out_disk_r = .999995*select(in_square_rgn, in_square_a, in_square_b, ' .
+ '-in_square_a, -in_square_b); ' .
+ 'out_disk_phi = PI/4 * select(in_square_rgn, ' .
+ 'in_square_b/in_square_a, ' .
+ '2 - in_square_a/in_square_b, ' .
+ '4 + in_square_b/in_square_a, ' .
+ 'if(in_square_b*in_square_b, ' .
+ '6 - in_square_a/in_square_b, 0)); ' .
+ 'Dx = out_disk_r*cos(out_disk_phi); ' .
+ 'Dy = out_disk_r*sin(out_disk_phi); ' .
+ 'Dz = sqrt(1 - out_disk_r*out_disk_r);' ;
# Shirley-Chiu mapping from unit disk to square
-$disk2sq = '
-norm_radians(p) : if(-p - PI/4, p + 2*PI, p);
-in_disk_r = .999995*sqrt(Dx*Dx + Dy*Dy);
-in_disk_phi = norm_radians(atan2(Dy, Dx));
-in_disk_rgn = floor((in_disk_phi + PI/4)/(PI/2)) + 1;
-out_square_a = select(in_disk_rgn,
- in_disk_r,
- (PI/2 - in_disk_phi)*in_disk_r/(PI/4),
- -in_disk_r,
- (in_disk_phi - 3*PI/2)*in_disk_r/(PI/4));
-out_square_b = select(in_disk_rgn,
- in_disk_phi*in_disk_r/(PI/4),
- in_disk_r,
- (PI - in_disk_phi)*in_disk_r/(PI/4),
- -in_disk_r);
-out_square_x = (out_square_a + 1)/2;
-out_square_y = (out_square_b + 1)/2;
-';
+$disk2sq = 'norm_radians(p) : if(-p - PI/4, p + 2*PI, p); ' .
+ 'in_disk_r = .999995*sqrt(Dx*Dx + Dy*Dy); ' .
+ 'in_disk_phi = norm_radians(atan2(Dy, Dx)); ' .
+ 'in_disk_rgn = floor((.999995*in_disk_phi + PI/4)/(PI/2)) + 1; ' .
+ 'out_square_a = select(in_disk_rgn, ' .
+ 'in_disk_r, ' .
+ '(PI/2 - in_disk_phi)*in_disk_r/(PI/4), ' .
+ '-in_disk_r, ' .
+ '(in_disk_phi - 3*PI/2)*in_disk_r/(PI/4)); ' .
+ 'out_square_b = select(in_disk_rgn, ' .
+ 'in_disk_phi*in_disk_r/(PI/4), ' .
+ 'in_disk_r, ' .
+ '(PI - in_disk_phi)*in_disk_r/(PI/4), ' .
+ '-in_disk_r); ' .
+ 'out_square_x = (out_square_a + 1)/2; ' .
+ 'out_square_y = (out_square_b + 1)/2;';
# Announce ourselves in XML output
print "\t\n";
print "\t\tTensorTree$tensortree\n";
print "\t\n";
-# Fork parallel rtcontrib processes to compute each side
-my $npleft = $nproc;
-if ( $doback ) {
- for (my $splice = 0; $splice < $nsplice; $splice++) {
- if (! $npleft ) {
- wait();
- die "rtcontrib process reported error" if ( $? );
- $npleft++;
- }
- bg_tree_rtcontrib(0, $splice);
- $npleft--;
- }
- while (wait() >= 0) {
- die "rtcontrib process reported error" if ( $? );
- $npleft++;
- }
- persist_end();
- ttree_out(0);
-}
-if ( $doforw ) {
- for (my $splice = 0; $splice < $nsplice; $splice++) {
- if (! $npleft ) {
- wait();
- die "rtcontrib process reported error" if ( $? );
- $npleft++;
- }
- bg_tree_rtcontrib(1, $splice);
- $npleft--;
- }
- while (wait() >= 0) {
- die "rtcontrib process reported error" if ( $? );
- $npleft++;
- }
- persist_end();
- ttree_out(1);
-}
+
+# Start rcontrib processes for compute each side
+do_tree_rtcontrib(0) if ( $doback );
+do_tree_rtcontrib(1) if ( $doforw );
+
} # end of sub do_tree_bsdf()
-# Run rtcontrib process in background to generate tensor tree samples
-sub bg_tree_rtcontrib {
- my $pid = fork();
- die "Cannot fork new process" unless defined $pid;
- if ($pid > 0) { return $pid; }
+# Run rcontrib process to generate tensor tree samples
+sub do_tree_rtcontrib {
my $forw = shift;
- my $pn = shift;
- my $pbeg = $pdiv[$pn];
- my $plen = $pdiv[$pn+1] - $pbeg;
+ my $cmd;
my $matargs = "-m $bmodnm";
- if ( !$forw || !$doback ) { $matargs .= " -m $fmodnm"; }
- my $cmd = "rtcontrib $rtargs -h -ff -fo -c $nsamp " .
- "-e '$disk2sq' -bn '$ns*$ns' " .
- "-b '$ns*floor(out_square_x*$ns)+floor(out_square_y*$ns)' " .
- "-o $td/%s_" . sprintf("%03d", $pn) . ".flt $matargs $octree";
+ if ( !$forw || !$doback || $tensortree==3 ) { $matargs .= " -m $fmodnm"; }
+ if ($windoz) {
+ $cmd = "rcontrib $rtargs -h -faa -fo -n $nproc -c $nsamp " .
+ qq{-e "$disk2sq" -bn "$ns*$ns" } .
+ qq{-b "$ns*floor(out_square_x*$ns)+floor(out_square_y*$ns)" } .
+ "-o $td/%s.flt $matargs $octree";
+ } else {
+ $cmd = "rcontrib $rtargs -h -fff -fo -n $nproc -c $nsamp " .
+ qq{-e "$disk2sq" -bn "$ns*$ns" } .
+ qq{-b "$ns*floor(out_square_x*$ns)+floor(out_square_y*$ns)" } .
+ "-o $td/%s.flt $matargs $octree";
+ }
if ( $tensortree == 3 ) {
# Isotropic BSDF
- $cmd = "cnt $plen $ny $nx " .
- "| rcalc -e 'r1=rand(($pn+.8681)*recno-.673892)' " .
- "-e 'r2=rand(($pn-5.37138)*recno+67.1737811)' " .
- "-e 'r3=rand(($pn+3.17603772)*recno+83.766771)' " .
- "-e 'Dx=1-2*($pbeg+\$1+r1)/$ns;Dy:0;Dz=sqrt(1-Dx*Dx)' " .
- "-e 'xp=(\$3+r2)*(($dim[1]-$dim[0])/$nx)+$dim[0]' " .
- "-e 'yp=(\$2+r3)*(($dim[3]-$dim[2])/$ny)+$dim[2]' " .
- "-e 'zp=$dim[5-$forw]' -e 'myDz=Dz*($forw*2-1)' " .
- "-e '\$1=xp-Dx;\$2=yp-Dy;\$3=zp-myDz' " .
- "-e '\$4=Dx;\$5=Dy;\$6=myDz' -of " .
- "| $cmd";
+ my $ns2 = $ns / 2;
+ if ($windoz) {
+ $cmd = "cnt $ns2 $ny $nx " .
+ qq{| rcalc -e "r1=rand(.8681*recno-.673892)" } .
+ qq{-e "r2=rand(-5.37138*recno+67.1737811)" } .
+ qq{-e "r3=rand(+3.17603772*recno+83.766771)" } .
+ qq{-e "Dx=1-2*(\$1+r1)/$ns;Dy:0;Dz=sqrt(1-Dx*Dx)" } .
+ qq{-e "xp=(\$3+r2)*(($dim[1]-$dim[0])/$nx)+$dim[0]" } .
+ qq{-e "yp=(\$2+r3)*(($dim[3]-$dim[2])/$ny)+$dim[2]" } .
+ qq{-e "zp=$dim[5-$forw]" -e "myDz=Dz*($forw*2-1)" } .
+ qq{-e "\$1=xp-Dx;\$2=yp-Dy;\$3=zp-myDz" } .
+ qq{-e "\$4=Dx;\$5=Dy;\$6=myDz" } .
+ "| $cmd";
+ } else {
+ $cmd = "cnt $ns2 $ny $nx " .
+ qq{| rcalc -e "r1=rand(.8681*recno-.673892)" } .
+ qq{-e "r2=rand(-5.37138*recno+67.1737811)" } .
+ qq{-e "r3=rand(+3.17603772*recno+83.766771)" } .
+ qq{-e "Dx=1-2*(\$1+r1)/$ns;Dy:0;Dz=sqrt(1-Dx*Dx)" } .
+ qq{-e "xp=(\$3+r2)*(($dim[1]-$dim[0])/$nx)+$dim[0]" } .
+ qq{-e "yp=(\$2+r3)*(($dim[3]-$dim[2])/$ny)+$dim[2]" } .
+ qq{-e "zp=$dim[5-$forw]" -e "myDz=Dz*($forw*2-1)" } .
+ qq{-e '\$1=xp-Dx;\$2=yp-Dy;\$3=zp-myDz' } .
+ qq{-e '\$4=Dx;\$5=Dy;\$6=myDz' -of } .
+ "| $cmd";
+ }
} else {
# Anisotropic BSDF
# Sample area vertically to improve load balance, since
# shading systems usually have bilateral symmetry (L-R)
- $cmd = "cnt $plen $ns $ny $nx " .
- "| rcalc -e 'r1=rand(($pn+.8681)*recno-.673892)' " .
- "-e 'r2=rand(($pn-5.37138)*recno+67.1737811)' " .
- "-e 'r3=rand(($pn+3.17603772)*recno+83.766771)' " .
- "-e 'r4=rand(($pn-2.3857833)*recno-964.72738)' " .
- "-e 'in_square_x=($pbeg+\$1+r1)/$ns' " .
- "-e 'in_square_y=(\$2+r2)/$ns' -e '$sq2disk' " .
- "-e 'xp=(\$4+r3)*(($dim[1]-$dim[0])/$nx)+$dim[0]' " .
- "-e 'yp=(\$3+r4)*(($dim[3]-$dim[2])/$ny)+$dim[2]' " .
- "-e 'zp=$dim[5-$forw]' -e 'myDz=Dz*($forw*2-1)' " .
- "-e '\$1=xp-Dx;\$2=yp-Dy;\$3=zp-myDz' " .
- "-e '\$4=Dx;\$5=Dy;\$6=myDz' -of " .
- "| $cmd";
+ if ($windoz) {
+ $cmd = "cnt $ns $ns $ny $nx " .
+ qq{| rcalc -e "r1=rand(.8681*recno-.673892)" } .
+ qq{-e "r2=rand(-5.37138*recno+67.1737811)" } .
+ qq{-e "r3=rand(3.17603772*recno+83.766771)" } .
+ qq{-e "r4=rand(-2.3857833*recno-964.72738)" } .
+ qq{-e "in_square_x=(\$1+r1)/$ns" } .
+ qq{-e "in_square_y=(\$2+r2)/$ns" -e "$sq2disk" } .
+ qq{-e "xp=(\$4+r3)*(($dim[1]-$dim[0])/$nx)+$dim[0]" } .
+ qq{-e "yp=(\$3+r4)*(($dim[3]-$dim[2])/$ny)+$dim[2]" } .
+ qq{-e "zp=$dim[5-$forw]" -e "myDz=Dz*($forw*2-1)" } .
+ qq{-e "\$1=xp-Dx;\$2=yp-Dy;\$3=zp-myDz" } .
+ qq{-e "\$4=Dx;\$5=Dy;\$6=myDz" } .
+ "| $cmd";
+ } else {
+ $cmd = "cnt $ns $ns $ny $nx " .
+ qq{| rcalc -e "r1=rand(.8681*recno-.673892)" } .
+ qq{-e "r2=rand(-5.37138*recno+67.1737811)" } .
+ qq{-e "r3=rand(3.17603772*recno+83.766771)" } .
+ qq{-e "r4=rand(-2.3857833*recno-964.72738)" } .
+ qq{-e "in_square_x=(\$1+r1)/$ns" } .
+ qq{-e "in_square_y=(\$2+r2)/$ns" -e "$sq2disk" } .
+ qq{-e "xp=(\$4+r3)*(($dim[1]-$dim[0])/$nx)+$dim[0]" } .
+ qq{-e "yp=(\$3+r4)*(($dim[3]-$dim[2])/$ny)+$dim[2]" } .
+ qq{-e "zp=$dim[5-$forw]" -e "myDz=Dz*($forw*2-1)" } .
+ qq{-e '\$1=xp-Dx;\$2=yp-Dy;\$3=zp-myDz' } .
+ qq{-e '\$4=Dx;\$5=Dy;\$6=myDz' -of } .
+ "| $cmd";
+ }
}
# print STDERR "Starting: $cmd\n";
- exec($cmd); # no return; status report to parent via wait
- die "Cannot exec: $cmd\n";
-} # end of bg_tree_rtcontrib()
+ system "$cmd" || die "Failure running rcontrib";
+ ttree_out($forw);
+} # end of do_tree_rtcontrib()
# Simplify and output tensor tree results
sub ttree_out {
my $forw = shift;
my $side = ("Back","Front")[$forw];
-# Only output one transmitted distribution, preferring backwards
-if ( !$forw || !$doback ) {
+ my $cmd;
+# Only output one transmitted anisotropic distribution, preferring backwards
+if ( !$forw || !$doback || $tensortree==3 ) {
print
'
System
Visible
CIE Illuminant D65 1nm.ssp
ASTM E308 1931 Y.dsp
-
- Transmission
- LBNL/Shirley-Chiu
+ ' ;
+print "\t\t\tTransmission $side\n";
+print
+' LBNL/Shirley-Chiu
BTDF
';
-system "rcalc -if3 -e 'Omega:PI/($ns*$ns)' " .
- q{-e '$1=(0.265*$1+0.670*$2+0.065*$3)/Omega' -of } .
- "$td/" . ($bmodnm,$fmodnm)[$forw] . "_???.flt " .
- "| rttree_reduce -a -h -ff -t $pctcull -r $tensortree -g $ttlog2";
-die "Failure running rttree_reduce" if ( $? );
+if ($windoz) {
+ $cmd = qq{rcalc -e "Omega:PI/($ns*$ns)" } .
+ q{-e "$1=(0.265*$1+0.670*$2+0.065*$3)/Omega" };
+} else {
+ $cmd = "rcalc -if3 -e 'Omega:PI/($ns*$ns)' " .
+ q{-e '$1=(0.265*$1+0.670*$2+0.065*$3)/Omega' };
+}
+if ($pctcull >= 0) {
+ if ($windoz) {
+ $cmd = "rcollate -h -oc 1 $td/" . ($bmodnm,$fmodnm)[$forw] . ".flt | " .
+ $cmd .
+ "| rttree_reduce -h -fa -t $pctcull -r $tensortree -g $ttlog2";
+ } else {
+ $cmd .= "-of $td/" . ($bmodnm,$fmodnm)[$forw] . ".flt " .
+ " | rttree_reduce -h -ff -t $pctcull -r $tensortree -g $ttlog2";
+ }
+ system "$cmd" || die "Failure running rttree_reduce";
+} else {
+ if ($windoz) {
+ $cmd = "rcollate -h -oc 1 $td/" . ($bmodnm,$fmodnm)[$forw] . ".flt | " .
+ $cmd ;
+ } else {
+ $cmd .= "$td/" . ($bmodnm,$fmodnm)[$forw] . ".flt";
+ }
+ print "{\n";
+ system "$cmd" || die "Failure running rcalc";
+ for (my $i = ($tensortree==3)*$ns*$ns*$ns/2; $i-- > 0; ) {
+ print "0\n";
+ }
+ print "}\n";
+}
print
'
@@ -358,14 +373,41 @@ print
print "\t\t\tReflection $side\n";
print
' LBNL/Shirley-Chiu
- BRDF
+ BTDF
';
-system "rcalc -if3 -e 'Omega:PI/($ns*$ns)' " .
- q{-e '$1=(0.265*$1+0.670*$2+0.065*$3)/Omega' -of } .
- "$td/" . ($fmodnm,$bmodnm)[$forw] . "_???.flt " .
- "| rttree_reduce -a -h -ff -t $pctcull -r $tensortree -g $ttlog2";
-die "Failure running rttree_reduce" if ( $? );
+if ($windoz) {
+ $cmd = qq{rcalc -e "Omega:PI/($ns*$ns)" } .
+ q{-e "$1=(0.265*$1+0.670*$2+0.065*$3)/Omega" };
+}else {
+ $cmd = "rcalc -if3 -e 'Omega:PI/($ns*$ns)' " .
+ q{-e '$1=(0.265*$1+0.670*$2+0.065*$3)/Omega' };
+}
+if ($pctcull >= 0) {
+ if ($windoz) {
+ $cmd = "rcollate -h -oc 1 $td/" . ($fmodnm,$bmodnm)[$forw] . ".flt |" .
+ $cmd .
+ " | rttree_reduce -a -h -fa -t $pctcull -r $tensortree -g $ttlog2";
+
+ } else {
+ $cmd .= "-of $td/" . ($fmodnm,$bmodnm)[$forw] . ".flt " .
+ "| rttree_reduce -a -h -ff -t $pctcull -r $tensortree -g $ttlog2";
+ }
+ system "$cmd" || die "Failure running rttree_reduce";
+} else {
+ if ($windoz) {
+ $cmd = "rcollate -h -oc 1 $td/" . ($fmodnm,$bmodnm)[$forw] . ".flt |" .
+ $cmd ;
+ } else {
+ $cmd .= "$td/" . ($fmodnm,$bmodnm)[$forw] . ".flt";
+ }
+ print "{\n";
+ system "$cmd" || die "Failure running rcalc";
+ for (my $i = ($tensortree==3)*$ns*$ns*$ns/2; $i-- > 0; ) {
+ print "0\n";
+ }
+ print "}\n";
+}
print
'
@@ -379,93 +421,140 @@ print
sub do_matrix_bsdf {
# Set up sampling of portal
# Kbin to produce incident direction in full Klems basis with (x1,x2) randoms
-$tcal = '
-DEGREE : PI/180;
-sq(x) : x*x;
-Kpola(r) : select(r+1, -5, 5, 15, 25, 35, 45, 55, 65, 75, 90);
-Knaz(r) : select(r, 1, 8, 16, 20, 24, 24, 24, 16, 12);
-Kaccum(r) : if(r-.5, Knaz(r) + Kaccum(r-1), 0);
-Kmax : Kaccum(Knaz(0));
-Kfindrow(r, rem) : if(rem-Knaz(r)+.5, Kfindrow(r+1, rem-Knaz(r)), r);
-Krow = if(Kbin-(Kmax-.5), 0, Kfindrow(1, Kbin));
-Kcol = Kbin - Kaccum(Krow-1);
-Kazi = 360*DEGREE * (Kcol + (.5 - x2)) / Knaz(Krow);
-Kpol = DEGREE * (x1*Kpola(Krow) + (1-x1)*Kpola(Krow-1));
-sin_kpol = sin(Kpol);
-Dx = cos(Kazi)*sin_kpol;
-Dy = sin(Kazi)*sin_kpol;
-Dz = sqrt(1 - sin_kpol*sin_kpol);
-KprojOmega = PI * if(Kbin-.5,
- (sq(cos(Kpola(Krow-1)*DEGREE)) - sq(cos(Kpola(Krow)*DEGREE)))/Knaz(Krow),
- 1 - sq(cos(Kpola(1)*DEGREE)));
-';
+$tcal = 'DEGREE : PI/180; ' .
+ 'sq(x) : x*x; ' .
+ 'Kpola(r) : select(r+1, 0, 5, 15, 25, 35, 45, 55, 65, 75, 90); ' .
+ 'Knaz(r) : select(r, 1, 8, 16, 20, 24, 24, 24, 16, 12); ' .
+ 'Kaccum(r) : if(r-.5, Knaz(r) + Kaccum(r-1), 0); ' .
+ 'Kmax : Kaccum(Knaz(0)); ' .
+ 'Kfindrow(r, rem) : if(rem-Knaz(r)+.5, Kfindrow(r+1, rem-Knaz(r)), r); ' .
+ 'Krow = if(Kbin-(Kmax-.5), 0, Kfindrow(1, Kbin)); ' .
+ 'Kcol = Kbin - Kaccum(Krow-1); ' .
+ 'Kazi = 360*DEGREE * (Kcol + (.5 - x2)) / Knaz(Krow); ' .
+ 'Kpol = DEGREE * (x1*Kpola(Krow) + (1-x1)*Kpola(Krow-1)); ' .
+ 'sin_kpol = sin(Kpol); ' .
+ 'Dx = cos(Kazi)*sin_kpol; ' .
+ 'Dy = sin(Kazi)*sin_kpol; ' .
+ 'Dz = sqrt(1 - sin_kpol*sin_kpol); ' .
+ 'KprojOmega = PI * if(Kbin-.5, ' .
+ '(sq(cos(Kpola(Krow-1)*DEGREE)) - sq(cos(Kpola(Krow)*DEGREE)))/Knaz(Krow), ' .
+ '1 - sq(cos(Kpola(1)*DEGREE))); ';
# Compute Klems bin from exiting ray direction (forward or backward)
-$kcal = '
-DEGREE : PI/180;
-abs(x) : if(x, x, -x);
-Acos(x) : 1/DEGREE * if(x-1, 0, if(-1-x, 0, acos(x)));
-posangle(a) : if(-a, a + 2*PI, a);
-Atan2(y,x) : 1/DEGREE * posangle(atan2(y,x));
-kpola(r) : select(r, 5, 15, 25, 35, 45, 55, 65, 75, 90);
-knaz(r) : select(r, 1, 8, 16, 20, 24, 24, 24, 16, 12);
-kaccum(r) : if(r-.5, knaz(r) + kaccum(r-1), 0);
-kfindrow(r, pol) : if(r-kpola(0)+.5, r,
- if(pol-kpola(r), kfindrow(r+1, pol), r) );
-kazn(azi,inc) : if((360-.5*inc)-azi, floor((azi+.5*inc)/inc), 0);
-kbin2(pol,azi) = select(kfindrow(1, pol),
- kazn(azi,360/knaz(1)),
- kaccum(1) + kazn(azi,360/knaz(2)),
- kaccum(2) + kazn(azi,360/knaz(3)),
- kaccum(3) + kazn(azi,360/knaz(4)),
- kaccum(4) + kazn(azi,360/knaz(5)),
- kaccum(5) + kazn(azi,360/knaz(6)),
- kaccum(6) + kazn(azi,360/knaz(7)),
- kaccum(7) + kazn(azi,360/knaz(8)),
- kaccum(8) + kazn(azi,360/knaz(9))
- );
-kbin = kbin2(Acos(abs(Dz)),Atan2(Dy,Dx));
-';
+$kcal = 'DEGREE : PI/180; ' .
+ 'abs(x) : if(x, x, -x); ' .
+ 'Acos(x) : if(x-1, 0, if(-1-x, PI, acos(x)))/DEGREE; ' .
+ 'posangle(a) : if(-a, a + 2*PI, a); ' .
+ 'Atan2(y,x) : posangle(atan2(y,x))/DEGREE; ' .
+ 'kpola(r) : select(r, 5, 15, 25, 35, 45, 55, 65, 75, 90); ' .
+ 'knaz(r) : select(r, 1, 8, 16, 20, 24, 24, 24, 16, 12); ' .
+ 'kaccum(r) : if(r-.5, knaz(r) + kaccum(r-1), 0); ' .
+ 'kfindrow(r, pol) : if(r-kpola(0)+.5, r, ' .
+ 'if(pol-kpola(r), kfindrow(r+1, pol), r) ); ' .
+ 'kazn(azi,inc) : if((360-.5*inc)-azi, floor((azi+.5*inc)/inc), 0); ' .
+ 'kbin2(pol,azi) = select(kfindrow(1, pol), ' .
+ 'kazn(azi,360/knaz(1)), ' .
+ 'kaccum(1) + kazn(azi,360/knaz(2)), ' .
+ 'kaccum(2) + kazn(azi,360/knaz(3)), ' .
+ 'kaccum(3) + kazn(azi,360/knaz(4)), ' .
+ 'kaccum(4) + kazn(azi,360/knaz(5)), ' .
+ 'kaccum(5) + kazn(azi,360/knaz(6)), ' .
+ 'kaccum(6) + kazn(azi,360/knaz(7)), ' .
+ 'kaccum(7) + kazn(azi,360/knaz(8)), ' .
+ 'kaccum(8) + kazn(azi,360/knaz(9)) ' .
+ '); ' .
+ 'kbin = kbin2(Acos(abs(Dz)),Atan2(Dy,Dx));';
my $ndiv = 145;
-# Compute scattering data using rtcontrib
+# Compute scattering data using rcontrib
my @tfarr;
my @rfarr;
my @tbarr;
my @rbarr;
+my (@data,@line); # for windows
my $cmd;
-my $rtcmd = "rtcontrib $rtargs -h -ff -fo -n $nproc -c $nsamp " .
- "-e '$kcal' -b kbin -bn $ndiv " .
- "-o '$td/%s.flt' -m $fmodnm -m $bmodnm $octree";
-my $rccmd = "rcalc -e '$tcal' " .
- "-e 'mod(n,d):n-floor(n/d)*d' -e 'Kbin=mod(recno-.999,$ndiv)' " .
- q{-if3 -e '$1=(0.265*$1+0.670*$2+0.065*$3)/KprojOmega' };
+my $rtcmd;
+my $rccmd;
+if ($windoz) {
+ $rtcmd = "rcontrib $rtargs -h -fo -n $nproc -c $nsamp " .
+ qq{-e "$kcal" -b kbin -bn $ndiv } .
+ qq{-o "$td\\%s.flt" -m $fmodnm -m $bmodnm $octree };
+ $rccmd = qq{rcalc -e "$tcal" } .
+ qq{-e "mod(n,d):n-floor(n/d)*d" -e "Kbin=mod(recno-.999,$ndiv)" } .
+ q{ -e "$1=(0.265*$1+0.670*$2+0.065*$3)/KprojOmega" };
+} else {
+ $rtcmd = "rcontrib $rtargs -h -ff -fo -n $nproc -c $nsamp " .
+ "-e '$kcal' -b kbin -bn $ndiv " .
+ "-o '$td/%s.flt' -m $fmodnm -m $bmodnm $octree";
+ $rccmd = "rcalc -e '$tcal' " .
+ "-e 'mod(n,d):n-floor(n/d)*d' -e 'Kbin=mod(recno-.999,$ndiv)' " .
+ q{-if3 -e '$1=(0.265*$1+0.670*$2+0.065*$3)/KprojOmega' };
+}
if ( $doforw ) {
-$cmd = "cnt $ndiv $ny $nx | rcalc -of -e '$tcal' " .
- "-e 'xp=(\$3+rand(.12*recno+288))*(($dim[1]-$dim[0])/$nx)+$dim[0]' " .
- "-e 'yp=(\$2+rand(.37*recno-44))*(($dim[3]-$dim[2])/$ny)+$dim[2]' " .
- "-e 'zp:$dim[4]' " .
- q{-e 'Kbin=$1;x1=rand(2.75*recno+3.1);x2=rand(-2.01*recno-3.37)' } .
- q{-e '$1=xp-Dx;$2=yp-Dy;$3=zp-Dz;$4=Dx;$5=Dy;$6=Dz' } .
- "| $rtcmd";
+ if ($windoz) {
+ $cmd = qq{cnt $ndiv $ny $nx | rcalc -e "$tcal" } .
+ qq{-e "xp=(\$3+rand(.12*recno+288))*(($dim[1]-$dim[0])/$nx)+$dim[0]" } .
+ qq{-e "yp=(\$2+rand(.37*recno-44))*(($dim[3]-$dim[2])/$ny)+$dim[2]" } .
+ qq{-e "zp:$dim[4]" } .
+ q{-e "Kbin=$1;x1=rand(2.75*recno+3.1);x2=rand(-2.01*recno-3.37)" } .
+ q{-e "$1=xp-Dx;$2=yp-Dy;$3=zp-Dz;$4=Dx;$5=Dy;$6=Dz" } .
+ "| $rtcmd ";
+ } else {
+ $cmd = "cnt $ndiv $ny $nx | rcalc -of -e '$tcal' " .
+ "-e 'xp=(\$3+rand(.12*recno+288))*(($dim[1]-$dim[0])/$nx)+$dim[0]' " .
+ "-e 'yp=(\$2+rand(.37*recno-44))*(($dim[3]-$dim[2])/$ny)+$dim[2]' " .
+ "-e 'zp:$dim[4]' " .
+ q{-e 'Kbin=$1;x1=rand(2.75*recno+3.1);x2=rand(-2.01*recno-3.37)' } .
+ q{-e '$1=xp-Dx;$2=yp-Dy;$3=zp-Dz;$4=Dx;$5=Dy;$6=Dz' } .
+ "| $rtcmd";
+ }
system "$cmd" || die "Failure running: $cmd\n";
-@tfarr = `$rccmd $td/$fmodnm.flt`;
+if ($windoz) {
+ @tfarr = `rcollate -h -oc 1 $td\\$fmodnm.flt | $rccmd`;
+} else {
+ @tfarr = `$rccmd $td/$fmodnm.flt`;
+}
die "Failure running: $rccmd $td/$fmodnm.flt\n" if ( $? );
-@rfarr = `$rccmd $td/$bmodnm.flt`;
+if ($windoz) {
+ @rfarr = `rcollate -h -oc 1 $td\\$bmodnm.flt | $rccmd`;
+} else {
+ @rfarr = `$rccmd $td/$bmodnm.flt`;
+}
die "Failure running: $rccmd $td/$bmodnm.flt\n" if ( $? );
}
if ( $doback ) {
-$cmd = "cnt $ndiv $ny $nx | rcalc -of -e '$tcal' " .
- "-e 'xp=(\$3+rand(.35*recno-15))*(($dim[1]-$dim[0])/$nx)+$dim[0]' " .
- "-e 'yp=(\$2+rand(.86*recno+11))*(($dim[3]-$dim[2])/$ny)+$dim[2]' " .
- "-e 'zp:$dim[5]' " .
- q{-e 'Kbin=$1;x1=rand(1.21*recno+2.75);x2=rand(-3.55*recno-7.57)' } .
- q{-e '$1=xp-Dx;$2=yp-Dy;$3=zp+Dz;$4=Dx;$5=Dy;$6=-Dz' } .
- "| $rtcmd";
+ if ($windoz) {
+ $cmd = qq{cnt $ndiv $ny $nx | rcalc -e "$tcal" } .
+ qq{-e "xp=(\$3+rand(.35*recno-15))*(($dim[1]-$dim[0])/$nx)+$dim[0]" } .
+ qq{-e "yp=(\$2+rand(.86*recno+11))*(($dim[3]-$dim[2])/$ny)+$dim[2]" } .
+ qq{-e "zp:$dim[5]" } .
+ q{-e "Kbin=$1;x1=rand(1.21*recno+2.75);x2=rand(-3.55*recno-7.57)" } .
+ q{-e "$1=xp-Dx;$2=yp-Dy;$3=zp+Dz;$4=Dx;$5=Dy;$6=-Dz" } .
+ "| $rtcmd";
+ } else {
+ $cmd = "cnt $ndiv $ny $nx | rcalc -of -e '$tcal' " .
+ "-e 'xp=(\$3+rand(.35*recno-15))*(($dim[1]-$dim[0])/$nx)+$dim[0]' " .
+ "-e 'yp=(\$2+rand(.86*recno+11))*(($dim[3]-$dim[2])/$ny)+$dim[2]' " .
+ "-e 'zp:$dim[5]' " .
+ q{-e 'Kbin=$1;x1=rand(1.21*recno+2.75);x2=rand(-3.55*recno-7.57)' } .
+ q{-e '$1=xp-Dx;$2=yp-Dy;$3=zp+Dz;$4=Dx;$5=Dy;$6=-Dz' } .
+ "| $rtcmd";
+ }
system "$cmd" || die "Failure running: $cmd\n";
-@tbarr = `$rccmd $td/$bmodnm.flt`;
+if ($windoz) {
+ @tbarr = `rcollate -h -oc 1 $td\\$bmodnm.flt | $rccmd`;
+} else {
+ @tbarr = `$rccmd $td/$bmodnm.flt`;
+}
die "Failure running: $rccmd $td/$bmodnm.flt\n" if ( $? );
-@rbarr = `$rccmd $td/$fmodnm.flt`;
+chomp(@tbarr);
+if ($windoz) {
+ @rbarr = `rcollate -h -oc 1 $td\\$fmodnm.flt | $rccmd`;
+} else {
+ @rbarr = `$rccmd $td/$fmodnm.flt`;
+}
die "Failure running: $rccmd $td/$fmodnm.flt\n" if ( $? );
+chomp(@rbarr);
}
+
# Output angle basis
print
'
@@ -473,77 +562,77 @@ print
LBNL/Klems Full
- 0
- 1
-
- 0
- 5
-
-
-
- 10
- 8
-
- 5
- 15
-
-
-
- 20
- 16
-
- 15
- 25
-
-
-
- 30
- 20
-
- 25
- 35
-
-
-
- 40
- 24
-
- 35
- 45
-
-
-
- 50
- 24
-
- 45
- 55
-
-
-
- 60
- 24
-
- 55
- 65
-
-
-
- 70
- 16
-
- 65
- 75
-
-
-
- 82.5
- 12
-
- 75
- 90
-
+ 0
+ 1
+
+ 0
+ 5
+
+
+ 10
+ 8
+
+ 5
+ 15
+
+
+
+ 20
+ 16
+
+ 15
+ 25
+
+
+
+ 30
+ 20
+
+ 25
+ 35
+
+
+
+ 40
+ 24
+
+ 35
+ 45
+
+
+
+ 50
+ 24
+
+ 45
+ 55
+
+
+
+ 60
+ 24
+
+ 55
+ 65
+
+
+
+ 70
+ 16
+
+ 65
+ 75
+
+
+
+ 82.5
+ 12
+
+ 75
+ 90
+
+
';
@@ -564,7 +653,8 @@ print
# Output front transmission (transposed order)
for (my $od = 0; $od < $ndiv; $od++) {
for (my $id = 0; $id < $ndiv; $id++) {
- print $tfarr[$ndiv*$id + $od], ",\n";
+ chomp $tfarr[$ndiv*$id + $od];
+ print $tfarr[$ndiv*$id + $od], ",\t";
}
print "\n";
}
@@ -581,13 +671,14 @@ print
Reflection Front
LBNL/Klems Full
LBNL/Klems Full
- BRDF
+ BTDF
';
-# Output front reflection (reciprocity averaging)
+# Output front reflection (transposed order)
for (my $od = 0; $od < $ndiv; $od++) {
for (my $id = 0; $id < $ndiv; $id++) {
- print .5*($rfarr[$ndiv*$id + $od] + $rfarr[$ndiv*$od + $id]), ",\n";
+ chomp $rfarr[$ndiv*$id + $od];
+ print $rfarr[$ndiv*$id + $od], ",\t";
}
print "\n";
}
@@ -614,7 +705,8 @@ print
# Output back transmission (transposed order)
for (my $od = 0; $od < $ndiv; $od++) {
for (my $id = 0; $id < $ndiv; $id++) {
- print $tbarr[$ndiv*$id + $od], ",\n";
+ chomp $tbarr[$ndiv*$id + $od];
+ print $tbarr[$ndiv*$id + $od], ",\t";
}
print "\n";
}
@@ -631,13 +723,14 @@ print
Reflection Back
LBNL/Klems Full
LBNL/Klems Full
- BRDF
+ BTDF
';
-# Output back reflection (reciprocity averaging)
+# Output back reflection (transposed order)
for (my $od = 0; $od < $ndiv; $od++) {
for (my $id = 0; $id < $ndiv; $id++) {
- print .5*($rbarr[$ndiv*$id + $od] + $rbarr[$ndiv*$od + $id]), ",\n";
+ chomp $rbarr[$ndiv*$id + $od];
+ print $rbarr[$ndiv*$id + $od], ",\t";
}
print "\n";
}