--- ray/src/util/genBSDF.pl 2011/06/24 19:07:38 2.23 +++ ray/src/util/genBSDF.pl 2012/05/09 17:40:17 2.35 @@ -1,5 +1,5 @@ #!/usr/bin/perl -w -# RCSid $Id: genBSDF.pl,v 2.23 2011/06/24 19:07:38 greg Exp $ +# RCSid $Id: genBSDF.pl,v 2.35 2012/05/09 17:40:17 greg Exp $ # # Compute BSDF based on geometry and material description # @@ -8,7 +8,7 @@ use strict; 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] [input ..]\n"; + 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"); @@ -16,13 +16,14 @@ chomp $td; my @savedARGV = @ARGV; my $tensortree = 0; my $ttlog2 = 4; -my $nsamp = 1000; +my $nsamp = 2000; my $rtargs = "-w -ab 5 -ad 700 -lw 3e-6"; my $mgfin = 0; my $geout = 1; my $nproc = 1; my $doforw = 0; my $doback = 1; +my $pctcull = 90; my $gunit = "Meter"; my @dim; # Get options @@ -43,6 +44,10 @@ while ($#ARGV >= 0) { $doforw = ("$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]$/) { $tensortree = substr($ARGV[0], 2, 1); $ttlog2 = $ARGV[1]; @@ -149,18 +154,22 @@ print '; # Clean up temporary files and exit -if ( $persistfile && open(PFI, "< $persistfile") ) { - while () { - s/^[^ ]* //; - kill('ALRM', $_); - last; - } - close PFI; -} exec("rm -rf $td"); #-------------- 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 @@ -236,6 +245,7 @@ if ( $doback ) { die "rtcontrib process reported error" if ( $? ); $npleft++; } + persist_end(); ttree_out(0); } if ( $doforw ) { @@ -252,6 +262,7 @@ if ( $doforw ) { die "rtcontrib process reported error" if ( $? ); $npleft++; } + persist_end(); ttree_out(1); } } # end of sub do_tree_bsdf() @@ -311,6 +322,7 @@ sub bg_tree_rtcontrib { sub ttree_out { my $forw = shift; my $side = ("Back","Front")[$forw]; + my $cmd; # Only output one transmitted distribution, preferring backwards if ( !$forw || !$doback ) { print @@ -325,11 +337,21 @@ print 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 -h -ff -r $tensortree -g $ttlog2"; -die "Failure running rttree_reduce" if ( $? ); +$cmd = "rcalc -if3 -e 'Omega:PI/($ns*$ns)' " . + q{-e '$1=(0.265*$1+0.670*$2+0.065*$3)/Omega' }; +if ($pctcull >= 0) { + $cmd .= "-of $td/" . ($bmodnm,$fmodnm)[$forw] . "_???.flt " . + "| rttree_reduce -a -h -ff -t $pctcull -r $tensortree -g $ttlog2"; + system "$cmd" || die "Failure running rttree_reduce"; +} 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 ' @@ -351,11 +373,21 @@ print BRDF '; -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 -h -ff -r $tensortree -g $ttlog2"; -die "Failure running rttree_reduce" if ( $? ); +$cmd = "rcalc -if3 -e 'Omega:PI/($ns*$ns)' " . + q{-e '$1=(0.265*$1+0.670*$2+0.065*$3)/Omega' }; +if ($pctcull >= 0) { + $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 { + $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 ' @@ -372,7 +404,7 @@ sub do_matrix_bsdf { $tcal = ' DEGREE : PI/180; sq(x) : x*x; -Kpola(r) : select(r+1, -5, 5, 15, 25, 35, 45, 55, 65, 75, 90); +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)); @@ -393,9 +425,9 @@ KprojOmega = PI * if(Kbin-.5, $kcal = ' DEGREE : PI/180; abs(x) : if(x, x, -x); -Acos(x) : 1/DEGREE * if(x-1, 0, if(-1-x, 0, acos(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) : 1/DEGREE * posangle(atan2(y,x)); +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); @@ -427,8 +459,7 @@ my $rtcmd = "rtcontrib $rtargs -h -ff -fo -n $nproc -c "-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 'oval=(0.265*$1+0.670*$2+0.065*$3)/KprojOmega' } . - q[-o '${ oval },']; + 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]' " . @@ -454,8 +485,10 @@ $cmd = "cnt $ndiv $ny $nx | rcalc -of -e '$tcal' " . system "$cmd" || die "Failure running: $cmd\n"; @tbarr = `$rccmd $td/$bmodnm.flt`; die "Failure running: $rccmd $td/$bmodnm.flt\n" if ( $? ); +chomp(@tbarr); @rbarr = `$rccmd $td/$fmodnm.flt`; die "Failure running: $rccmd $td/$fmodnm.flt\n" if ( $? ); +chomp(@rbarr); } # Output angle basis print @@ -464,77 +497,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 + + '; @@ -555,7 +588,7 @@ 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]; + print $tfarr[$ndiv*$id + $od], ",\n"; } print "\n"; } @@ -578,7 +611,7 @@ print # Output front reflection (transposed order) for (my $od = 0; $od < $ndiv; $od++) { for (my $id = 0; $id < $ndiv; $id++) { - print $rfarr[$ndiv*$id + $od]; + print $rfarr[$ndiv*$id + $od], ",\n"; } print "\n"; } @@ -605,7 +638,7 @@ 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]; + print $tbarr[$ndiv*$id + $od], ",\n"; } print "\n"; } @@ -628,7 +661,7 @@ print # Output back reflection (transposed order) for (my $od = 0; $od < $ndiv; $od++) { for (my $id = 0; $id < $ndiv; $id++) { - print $rbarr[$ndiv*$id + $od]; + print $rbarr[$ndiv*$id + $od], ",\n"; } print "\n"; }