| 8 |
|
use strict; |
| 9 |
|
use File::Temp qw/ :mktemp /; |
| 10 |
|
sub userror { |
| 11 |
< |
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] [input ..]\n"; |
| 11 |
> |
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"; |
| 12 |
|
exit 1; |
| 13 |
|
} |
| 14 |
|
my $td = mkdtemp("/tmp/genBSDF.XXXXXX"); |
| 16 |
|
my @savedARGV = @ARGV; |
| 17 |
|
my $tensortree = 0; |
| 18 |
|
my $ttlog2 = 4; |
| 19 |
< |
my $nsamp = 1000; |
| 19 |
> |
my $nsamp = 2000; |
| 20 |
|
my $rtargs = "-w -ab 5 -ad 700 -lw 3e-6"; |
| 21 |
|
my $mgfin = 0; |
| 22 |
|
my $geout = 1; |
| 23 |
|
my $nproc = 1; |
| 24 |
|
my $doforw = 0; |
| 25 |
|
my $doback = 1; |
| 26 |
+ |
my $pctcull = 95; |
| 27 |
|
my $gunit = "Meter"; |
| 28 |
|
my @dim; |
| 29 |
|
# Get options |
| 44 |
|
$doforw = ("$ARGV[0]" =~ /^\+/); |
| 45 |
|
} elsif ("$ARGV[0]" =~ /^[-+]b/) { |
| 46 |
|
$doback = ("$ARGV[0]" =~ /^\+/); |
| 47 |
+ |
} elsif ("$ARGV[0]" eq "-t") { |
| 48 |
+ |
$pctcull = $ARGV[1]; |
| 49 |
+ |
shift @ARGV; |
| 50 |
|
} elsif ("$ARGV[0]" =~ /^-t[34]$/) { |
| 51 |
|
$tensortree = substr($ARGV[0], 2, 1); |
| 52 |
|
$ttlog2 = $ARGV[1]; |
| 153 |
|
</WindowElement> |
| 154 |
|
'; |
| 155 |
|
# Clean up temporary files and exit |
| 152 |
– |
if ( $persistfile && open(PFI, "< $persistfile") ) { |
| 153 |
– |
while (<PFI>) { |
| 154 |
– |
s/^[^ ]* //; |
| 155 |
– |
kill('ALRM', $_); |
| 156 |
– |
last; |
| 157 |
– |
} |
| 158 |
– |
close PFI; |
| 159 |
– |
} |
| 156 |
|
exec("rm -rf $td"); |
| 157 |
|
|
| 158 |
|
#-------------- End of main program segment --------------# |
| 159 |
|
|
| 160 |
+ |
#++++++++++++++ Kill persistent rtrace +++++++++++++++++++# |
| 161 |
+ |
sub persist_end { |
| 162 |
+ |
if ( $persistfile && open(PFI, "< $persistfile") ) { |
| 163 |
+ |
while (<PFI>) { |
| 164 |
+ |
s/^[^ ]* //; |
| 165 |
+ |
kill('ALRM', $_); |
| 166 |
+ |
last; |
| 167 |
+ |
} |
| 168 |
+ |
close PFI; |
| 169 |
+ |
} |
| 170 |
+ |
} |
| 171 |
+ |
|
| 172 |
|
#++++++++++++++ Tensor tree BSDF generation ++++++++++++++# |
| 173 |
|
sub do_tree_bsdf { |
| 174 |
|
# Get sampling rate and subdivide task |
| 244 |
|
die "rtcontrib process reported error" if ( $? ); |
| 245 |
|
$npleft++; |
| 246 |
|
} |
| 247 |
+ |
persist_end(); |
| 248 |
|
ttree_out(0); |
| 249 |
|
} |
| 250 |
|
if ( $doforw ) { |
| 261 |
|
die "rtcontrib process reported error" if ( $? ); |
| 262 |
|
$npleft++; |
| 263 |
|
} |
| 264 |
+ |
persist_end(); |
| 265 |
|
ttree_out(1); |
| 266 |
|
} |
| 267 |
|
} # end of sub do_tree_bsdf() |
| 338 |
|
system "rcalc -if3 -e 'Omega:PI/($ns*$ns)' " . |
| 339 |
|
q{-e '$1=(0.265*$1+0.670*$2+0.065*$3)/Omega' -of } . |
| 340 |
|
"$td/" . ($bmodnm,$fmodnm)[$forw] . "_???.flt " . |
| 341 |
< |
"| rttree_reduce -h -ff -r $tensortree -g $ttlog2"; |
| 341 |
> |
"| rttree_reduce -a -h -ff -t $pctcull -r $tensortree -g $ttlog2"; |
| 342 |
|
die "Failure running rttree_reduce" if ( $? ); |
| 343 |
|
print |
| 344 |
|
' </ScatteringData> |
| 364 |
|
system "rcalc -if3 -e 'Omega:PI/($ns*$ns)' " . |
| 365 |
|
q{-e '$1=(0.265*$1+0.670*$2+0.065*$3)/Omega' -of } . |
| 366 |
|
"$td/" . ($fmodnm,$bmodnm)[$forw] . "_???.flt " . |
| 367 |
< |
"| rttree_reduce -h -ff -r $tensortree -g $ttlog2"; |
| 367 |
> |
"| rttree_reduce -a -h -ff -t $pctcull -r $tensortree -g $ttlog2"; |
| 368 |
|
die "Failure running rttree_reduce" if ( $? ); |
| 369 |
|
print |
| 370 |
|
' </ScatteringData> |
| 403 |
|
$kcal = ' |
| 404 |
|
DEGREE : PI/180; |
| 405 |
|
abs(x) : if(x, x, -x); |
| 406 |
< |
Acos(x) : 1/DEGREE * if(x-1, 0, if(-1-x, 0, acos(x))); |
| 406 |
> |
Acos(x) : if(x-1, 0, if(-1-x, PI, acos(x))) / DEGREE; |
| 407 |
|
posangle(a) : if(-a, a + 2*PI, a); |
| 408 |
< |
Atan2(y,x) : 1/DEGREE * posangle(atan2(y,x)); |
| 408 |
> |
Atan2(y,x) : posangle(atan2(y,x)) / DEGREE; |
| 409 |
|
kpola(r) : select(r, 5, 15, 25, 35, 45, 55, 65, 75, 90); |
| 410 |
|
knaz(r) : select(r, 1, 8, 16, 20, 24, 24, 24, 16, 12); |
| 411 |
|
kaccum(r) : if(r-.5, knaz(r) + kaccum(r-1), 0); |
| 437 |
|
"-o '$td/%s.flt' -m $fmodnm -m $bmodnm $octree"; |
| 438 |
|
my $rccmd = "rcalc -e '$tcal' " . |
| 439 |
|
"-e 'mod(n,d):n-floor(n/d)*d' -e 'Kbin=mod(recno-.999,$ndiv)' " . |
| 440 |
< |
q{-if3 -e 'oval=(0.265*$1+0.670*$2+0.065*$3)/KprojOmega' } . |
| 431 |
< |
q[-o '${ oval },']; |
| 440 |
> |
q{-if3 -e '$1=(0.265*$1+0.670*$2+0.065*$3)/KprojOmega' }; |
| 441 |
|
if ( $doforw ) { |
| 442 |
|
$cmd = "cnt $ndiv $ny $nx | rcalc -of -e '$tcal' " . |
| 443 |
|
"-e 'xp=(\$3+rand(.12*recno+288))*(($dim[1]-$dim[0])/$nx)+$dim[0]' " . |
| 463 |
|
system "$cmd" || die "Failure running: $cmd\n"; |
| 464 |
|
@tbarr = `$rccmd $td/$bmodnm.flt`; |
| 465 |
|
die "Failure running: $rccmd $td/$bmodnm.flt\n" if ( $? ); |
| 466 |
+ |
chomp(@tbarr); |
| 467 |
|
@rbarr = `$rccmd $td/$fmodnm.flt`; |
| 468 |
|
die "Failure running: $rccmd $td/$fmodnm.flt\n" if ( $? ); |
| 469 |
+ |
chomp(@rbarr); |
| 470 |
|
} |
| 471 |
|
# Output angle basis |
| 472 |
|
print |
| 566 |
|
# Output front transmission (transposed order) |
| 567 |
|
for (my $od = 0; $od < $ndiv; $od++) { |
| 568 |
|
for (my $id = 0; $id < $ndiv; $id++) { |
| 569 |
< |
print $tfarr[$ndiv*$id + $od]; |
| 569 |
> |
print $tfarr[$ndiv*$id + $od], ",\n"; |
| 570 |
|
} |
| 571 |
|
print "\n"; |
| 572 |
|
} |
| 589 |
|
# Output front reflection (transposed order) |
| 590 |
|
for (my $od = 0; $od < $ndiv; $od++) { |
| 591 |
|
for (my $id = 0; $id < $ndiv; $id++) { |
| 592 |
< |
print $rfarr[$ndiv*$id + $od]; |
| 592 |
> |
print $rfarr[$ndiv*$id + $od], ",\n"; |
| 593 |
|
} |
| 594 |
|
print "\n"; |
| 595 |
|
} |
| 616 |
|
# Output back transmission (transposed order) |
| 617 |
|
for (my $od = 0; $od < $ndiv; $od++) { |
| 618 |
|
for (my $id = 0; $id < $ndiv; $id++) { |
| 619 |
< |
print $tbarr[$ndiv*$id + $od]; |
| 619 |
> |
print $tbarr[$ndiv*$id + $od], ",\n"; |
| 620 |
|
} |
| 621 |
|
print "\n"; |
| 622 |
|
} |
| 636 |
|
<ScatteringDataType>BRDF</ScatteringDataType> |
| 637 |
|
<ScatteringData> |
| 638 |
|
'; |
| 639 |
< |
# Output back reflection (transposed order) |
| 639 |
> |
# Output back reflection (reciprocity averaging) |
| 640 |
|
for (my $od = 0; $od < $ndiv; $od++) { |
| 641 |
|
for (my $id = 0; $id < $ndiv; $id++) { |
| 642 |
< |
print $rbarr[$ndiv*$id + $od]; |
| 642 |
> |
print $rbarr[$ndiv*$id + $od], ",\n"; |
| 643 |
|
} |
| 644 |
|
print "\n"; |
| 645 |
|
} |