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`; |
31 |
|
shift @ARGV; |
32 |
|
} elsif ("$ARGV[0]" =~ /^-d/) { |
33 |
|
userror() if ($#ARGV < 6); |
34 |
< |
@dim = "@ARGV[1..6]"; |
34 |
> |
@dim = @ARGV[1..6]; |
35 |
|
shift @ARGV for (1..6); |
36 |
|
} elsif ("$ARGV[0]" =~ /^[-+]./) { |
37 |
|
userror(); |
54 |
|
system "rad2mgf $radscn > $mgfscn" if ( $geout ); |
55 |
|
} |
56 |
|
if ($#dim != 5) { |
57 |
< |
@dim = split /\s+/, `getbbox -h $radscn`; |
58 |
< |
shift @dim; |
57 |
> |
@dim = split ' ', `getbbox -h $radscn`; |
58 |
|
} |
59 |
|
print STDERR "Warning: Device extends into room\n" if ($dim[5] > 1e-5); |
60 |
|
# Add receiver surface (rectangle) |
74 |
|
# Kbin to produce incident direction in full Klems basis with (x1,x2) randoms |
75 |
|
my $tcal = ' |
76 |
|
DEGREE : PI/180; |
77 |
+ |
sq(x) : x*x; |
78 |
|
Kpola(r) : select(r+1, -5, 5, 15, 25, 35, 45, 55, 65, 75, 90); |
79 |
|
Knaz(r) : select(r, 1, 8, 16, 20, 24, 24, 24, 16, 12); |
80 |
|
Kaccum(r) : if(r-.5, Knaz(r) + Kaccum(r-1), 0); |
82 |
|
Kfindrow(r, rem) : if(rem-Knaz(r)+.5, Kfindrow(r+1, rem-Knaz(r)), r); |
83 |
|
Krow = if(Kbin-(Kmax-.5), 0, Kfindrow(1, Kbin)); |
84 |
|
Kcol = Kbin - Kaccum(Krow-1); |
85 |
< |
Kazi = 360*DEGREE * (Kcol + .5 - x2) / Knaz(Krow); |
85 |
> |
Kazi = 360*DEGREE * (Kcol + (.5 - x2)) / Knaz(Krow); |
86 |
|
Kpol = DEGREE * (x1*Kpola(Krow) + (1-x1)*Kpola(Krow-1)); |
87 |
|
sin_kpol = sin(Kpol); |
88 |
|
Dx = -cos(Kazi)*sin_kpol; |
89 |
|
Dy = sin(Kazi)*sin_kpol; |
90 |
|
Dz = sqrt(1 - sin_kpol*sin_kpol); |
91 |
+ |
KprojOmega = PI * if(Kbin-.5, |
92 |
+ |
(sq(cos(Kpola(Krow-1)*DEGREE)) - sq(cos(Kpola(Krow)*DEGREE)))/Knaz(Krow), |
93 |
+ |
1 - sq(cos(Kpola(1)*DEGREE))); |
94 |
|
'; |
95 |
|
# Compute Klems bin from exiting ray direction |
96 |
|
my $kcal = ' |
121 |
|
my $nx = int(sqrt($nsamp*($dim[1]-$dim[0])/($dim[3]-$dim[2])) + .5); |
122 |
|
my $ny = int($nsamp/$nx + .5); |
123 |
|
$nsamp = $nx * $ny; |
124 |
+ |
# Compute scattering data using rtcontrib |
125 |
+ |
my $cmd = "cnt $ndiv $ny $nx | rcalc -of -e '$tcal' " . |
126 |
+ |
"-e 'xp=(\$3+rand(.35*recno-15))*(($dim[1]-$dim[0])/$nx)+$dim[0]' " . |
127 |
+ |
"-e 'yp=(\$2+rand(.86*recno+11))*(($dim[3]-$dim[2])/$ny)+$dim[2]' " . |
128 |
+ |
"-e 'zp:$dim[4]-1e-5' " . |
129 |
+ |
q{-e 'Kbin=$1;x1=rand(1.21*recno+2.75);x2=rand(-3.55*recno-7.57)' } . |
130 |
+ |
q{-e '$1=xp;$2=yp;$3=zp;$4=Dx;$5=Dy;$6=Dz' } . |
131 |
+ |
"| rtcontrib -h -ff -n $nproc -c $nsamp -e '$kcal' -b kbin -bn $ndiv " . |
132 |
+ |
"-m $modnm -w -ab 5 -ad 700 -lw 3e-6 $octree " . |
133 |
+ |
"| rcalc -e '$tcal' " . |
134 |
+ |
"-e 'mod(n,d):n-floor(n/d)*d' -e 'Kbin=mod(recno-.999,$ndiv)' " . |
135 |
+ |
q{-if3 -e '$1=(0.265*$1+0.670*$2+0.065*$3)/KprojOmega'}; |
136 |
+ |
my @darr = `$cmd`; |
137 |
+ |
die "Failure running: $cmd\n" if ( $? ); |
138 |
|
# Output XML prologue |
139 |
|
print |
140 |
|
'<?xml version="1.0" encoding="UTF-8"?> |
249 |
|
<ScatteringDataType>BTDF</ScatteringDataType> |
250 |
|
<ScatteringData> |
251 |
|
'; |
252 |
< |
# Compute actual scattering data using rtcontrib |
253 |
< |
system "cnt $ndiv $ny $nx | rcalc -of -e '$tcal' " . |
254 |
< |
"-e 'xp=(\$3+rand(.35*recno-15))*(($dim[1]-$dim[0])/$nx)+$dim[0]' " . |
255 |
< |
"-e 'yp=(\$2+rand(.86*recno+11))*(($dim[3]-$dim[2])/$ny)+$dim[2]' " . |
256 |
< |
"-e 'zp:$dim[4]-1e-5' " . |
257 |
< |
q{-e 'Kbin=$1;x1=rand(1.21*recno+2.75);x2=rand(-3.55*recno-7.57)' } . |
258 |
< |
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'}; |
252 |
> |
# Output computed data (transposed order) |
253 |
> |
for (my $od = 0; $od < $ndiv; $od++) { |
254 |
> |
for (my $id = 0; $id < $ndiv; $id++) { |
255 |
> |
print $darr[$ndiv*$id + $od]; |
256 |
> |
} |
257 |
> |
print "\n"; |
258 |
> |
} |
259 |
|
# Output XML epilogue |
260 |
|
print |
261 |
|
' </ScatteringData> |