7 |
|
# |
8 |
|
use strict; |
9 |
|
sub userror { |
10 |
< |
print STDERR "Usage: genBSDF [-n Nproc][-c Nsamp][-dim xmin xmax ymin ymax zmin zmax][{+|-}mgf][{+|-}geom] [input ..]"; |
10 |
> |
print STDERR "Usage: genBSDF [-n Nproc][-c Nsamp][-dim xmin xmax ymin ymax zmin zmax][{+|-}mgf][{+|-}geom] [input ..]\n"; |
11 |
|
exit 1; |
12 |
|
} |
13 |
|
my $td = `mktemp -d /tmp/genBSDF.XXXXXX`; |
75 |
|
# Kbin to produce incident direction in full Klems basis with (x1,x2) randoms |
76 |
|
my $tcal = ' |
77 |
|
DEGREE : PI/180; |
78 |
+ |
sq(x) : x*x; |
79 |
|
Kpola(r) : select(r+1, -5, 5, 15, 25, 35, 45, 55, 65, 75, 90); |
80 |
|
Knaz(r) : select(r, 1, 8, 16, 20, 24, 24, 24, 16, 12); |
81 |
|
Kaccum(r) : if(r-.5, Knaz(r) + Kaccum(r-1), 0); |
83 |
|
Kfindrow(r, rem) : if(rem-Knaz(r)+.5, Kfindrow(r+1, rem-Knaz(r)), r); |
84 |
|
Krow = if(Kbin-(Kmax-.5), 0, Kfindrow(1, Kbin)); |
85 |
|
Kcol = Kbin - Kaccum(Krow-1); |
86 |
< |
Kazi = 360*DEGREE * (Kcol + .5 - x2) / Knaz(Krow); |
86 |
> |
Kazi = 360*DEGREE * (Kcol + (.5 - x2)) / Knaz(Krow); |
87 |
|
Kpol = DEGREE * (x1*Kpola(Krow) + (1-x1)*Kpola(Krow-1)); |
88 |
|
sin_kpol = sin(Kpol); |
89 |
|
Dx = -cos(Kazi)*sin_kpol; |
90 |
|
Dy = sin(Kazi)*sin_kpol; |
91 |
|
Dz = sqrt(1 - sin_kpol*sin_kpol); |
92 |
+ |
KprojOmega = PI * if(Kbin-.5, |
93 |
+ |
(sq(cos(Kpola(Krow-1)*DEGREE)) - sq(cos(Kpola(Krow)*DEGREE)))/Knaz(Krow), |
94 |
+ |
1 - sq(cos(Kpola(1)*DEGREE))); |
95 |
|
'; |
96 |
|
# Compute Klems bin from exiting ray direction |
97 |
|
my $kcal = ' |
122 |
|
my $nx = int(sqrt($nsamp*($dim[1]-$dim[0])/($dim[3]-$dim[2])) + .5); |
123 |
|
my $ny = int($nsamp/$nx + .5); |
124 |
|
$nsamp = $nx * $ny; |
125 |
+ |
# Compute scattering data using rtcontrib |
126 |
+ |
my $cmd = "cnt $ndiv $ny $nx | rcalc -of -e '$tcal' " . |
127 |
+ |
"-e 'xp=(\$3+rand(.35*recno-15))*(($dim[1]-$dim[0])/$nx)+$dim[0]' " . |
128 |
+ |
"-e 'yp=(\$2+rand(.86*recno+11))*(($dim[3]-$dim[2])/$ny)+$dim[2]' " . |
129 |
+ |
"-e 'zp:$dim[4]-1e-5' " . |
130 |
+ |
q{-e 'Kbin=$1;x1=rand(1.21*recno+2.75);x2=rand(-3.55*recno-7.57)' } . |
131 |
+ |
q{-e '$1=xp;$2=yp;$3=zp;$4=Dx;$5=Dy;$6=Dz' } . |
132 |
+ |
"| rtcontrib -h -ff -n $nproc -c $nsamp -e '$kcal' -b kbin -bn $ndiv " . |
133 |
+ |
"-m $modnm -w -ab 5 -ad 700 -lw 3e-6 $octree " . |
134 |
+ |
"| rcalc -e '$tcal' " . |
135 |
+ |
"-e 'mod(n,d):n-floor(n/d)*d' -e 'Kbin=mod(recno-1,$ndiv)' " . |
136 |
+ |
q{-if3 -e '$1=(0.265*$1+0.670*$2+0.065*$3)/KprojOmega'}; |
137 |
+ |
my @darr = `$cmd`; |
138 |
+ |
die "Failure running: $cmd\n" if ( $? ); |
139 |
|
# Output XML prologue |
140 |
|
print |
141 |
|
'<?xml version="1.0" encoding="UTF-8"?> |
250 |
|
<ScatteringDataType>BTDF</ScatteringDataType> |
251 |
|
<ScatteringData> |
252 |
|
'; |
253 |
< |
# Compute actual scattering data using rtcontrib |
254 |
< |
system "cnt $ndiv $ny $nx | rcalc -of -e '$tcal' " . |
255 |
< |
"-e 'xp=(\$3+rand(.35*recno-15))*(($dim[1]-$dim[0])/$nx)+$dim[0]' " . |
256 |
< |
"-e 'yp=(\$2+rand(.86*recno+11))*(($dim[3]-$dim[2])/$ny)+$dim[2]' " . |
257 |
< |
"-e 'zp:$dim[4]-1e-5' " . |
258 |
< |
q{-e 'Kbin=$1;x1=rand(1.21*recno+2.75);x2=rand(-3.55*recno-7.57)' } . |
259 |
< |
q{-e '$1=xp;$2=yp;$3=zp;$4=Dx;$5=Dy;$6=Dz' } . |
242 |
< |
"| rtcontrib -h -ff -n $nproc -c $nsamp -e '$kcal' -b kbin -bn $ndiv " . |
243 |
< |
"-m $modnm -w -ab 4 -lw 1e-5 $octree " . |
244 |
< |
q{| rcalc -if3 -e '$1=0.265*$1+0.670*$2+0.065*$3'}; |
253 |
> |
# Output computed data (transposed order) |
254 |
> |
for (my $od = 0; $od < $ndiv; $od++) { |
255 |
> |
for (my $id = 0; $id < $ndiv; $id++) { |
256 |
> |
print $darr[$ndiv*$id + $od]; |
257 |
> |
} |
258 |
> |
print "\n"; |
259 |
> |
} |
260 |
|
# Output XML epilogue |
261 |
|
print |
262 |
|
' </ScatteringData> |