--- ray/src/util/genBSDF.pl 2010/09/02 02:29:24 2.1
+++ ray/src/util/genBSDF.pl 2010/12/15 17:23:58 2.6
@@ -1,5 +1,5 @@
#!/usr/bin/perl -w
-# RCSid $Id: genBSDF.pl,v 2.1 2010/09/02 02:29:24 greg Exp $
+# RCSid $Id: genBSDF.pl,v 2.6 2010/12/15 17:23:58 greg Exp $
#
# Compute BSDF based on geometry and material description
#
@@ -7,7 +7,7 @@
#
use strict;
sub userror {
- print STDERR "Usage: genBSDF [-n Nproc][-c Nsamp][-dim xmin xmax ymin ymax zmin zmax][{+|-}mgf][{+|-}geom] [input ..]";
+ print STDERR "Usage: genBSDF [-n Nproc][-c Nsamp][-dim xmin xmax ymin ymax zmin zmax][{+|-}mgf][{+|-}geom] [input ..]\n";
exit 1;
}
my $td = `mktemp -d /tmp/genBSDF.XXXXXX`;
@@ -75,6 +75,7 @@ die "Could not compile scene\n" if ( $? );
# Kbin to produce incident direction in full Klems basis with (x1,x2) randoms
my $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);
@@ -82,12 +83,15 @@ 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);
+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
my $kcal = '
@@ -118,6 +122,20 @@ my $ndiv = 145;
my $nx = int(sqrt($nsamp*($dim[1]-$dim[0])/($dim[3]-$dim[2])) + .5);
my $ny = int($nsamp/$nx + .5);
$nsamp = $nx * $ny;
+# Compute scattering data using rtcontrib
+my $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[4]-1e-5' " .
+ q{-e 'Kbin=$1;x1=rand(1.21*recno+2.75);x2=rand(-3.55*recno-7.57)' } .
+ q{-e '$1=xp;$2=yp;$3=zp;$4=Dx;$5=Dy;$6=Dz' } .
+ "| rtcontrib -h -ff -n $nproc -c $nsamp -e '$kcal' -b kbin -bn $ndiv " .
+ "-m $modnm -w -ab 5 -ad 700 -lw 3e-6 $octree " .
+ "| 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 @darr = `$cmd`;
+die "Failure running: $cmd\n" if ( $? );
# Output XML prologue
print
'
@@ -232,16 +250,13 @@ print '
BTDF
';
-# Compute actual scattering data using rtcontrib
-system "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[4]-1e-5' " .
- q{-e 'Kbin=$1;x1=rand(1.21*recno+2.75);x2=rand(-3.55*recno-7.57)' } .
- q{-e '$1=xp;$2=yp;$3=zp;$4=Dx;$5=Dy;$6=Dz' } .
- "| rtcontrib -h -ff -n $nproc -c $nsamp -e '$kcal' -b kbin -bn $ndiv " .
- "-m $modnm -w -ab 4 -lw 1e-5 $octree " .
- q{| rcalc -if3 -e '$1=0.265*$1+0.670*$2+0.065*$3'};
+# Output computed data (transposed order)
+for (my $od = 0; $od < $ndiv; $od++) {
+ for (my $id = 0; $id < $ndiv; $id++) {
+ print $darr[$ndiv*$id + $od];
+ }
+ print "\n";
+}
# Output XML epilogue
print
'