--- ray/src/util/genBSDF.pl 2011/08/24 04:14:58 2.25 +++ ray/src/util/genBSDF.pl 2011/11/21 20:07:50 2.28 @@ -1,5 +1,5 @@ #!/usr/bin/perl -w -# RCSid $Id: genBSDF.pl,v 2.25 2011/08/24 04:14:58 greg Exp $ +# RCSid $Id: genBSDF.pl,v 2.28 2011/11/21 20:07:50 greg Exp $ # # Compute BSDF based on geometry and material description # @@ -23,6 +23,7 @@ my $geout = 1; my $nproc = 1; my $doforw = 0; my $doback = 1; +my $pctcull = 95; my $gunit = "Meter"; my @dim; # Get options @@ -43,6 +44,9 @@ while ($#ARGV >= 0) { $doforw = ("$ARGV[0]" =~ /^\+/); } elsif ("$ARGV[0]" =~ /^[-+]b/) { $doback = ("$ARGV[0]" =~ /^\+/); + } elsif ("$ARGV[0]" eq "-t") { + $pctcull = $ARGV[1]; + shift @ARGV; } elsif ("$ARGV[0]" =~ /^-t[34]$/) { $tensortree = substr($ARGV[0], 2, 1); $ttlog2 = $ARGV[1]; @@ -149,18 +153,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 +244,7 @@ if ( $doback ) { die "rtcontrib process reported error" if ( $? ); $npleft++; } + persist_end(); ttree_out(0); } if ( $doforw ) { @@ -252,6 +261,7 @@ if ( $doforw ) { die "rtcontrib process reported error" if ( $? ); $npleft++; } + persist_end(); ttree_out(1); } } # end of sub do_tree_bsdf() @@ -328,7 +338,7 @@ print 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"; + "| rttree_reduce -a -h -ff -t $pctcull -r $tensortree -g $ttlog2"; die "Failure running rttree_reduce" if ( $? ); print ' @@ -354,7 +364,7 @@ print 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"; + "| rttree_reduce -a -h -ff -t $pctcull -r $tensortree -g $ttlog2"; die "Failure running rttree_reduce" if ( $? ); print ' @@ -575,10 +585,10 @@ print BRDF '; -# Output front reflection (transposed order) +# Output front reflection (reciprocity averaging) for (my $od = 0; $od < $ndiv; $od++) { for (my $id = 0; $id < $ndiv; $id++) { - print $rfarr[$ndiv*$id + $od]; + print .5*($rfarr[$ndiv*$id + $od] + $rfarr[$ndiv*$od + $id]); } print "\n"; } @@ -625,10 +635,10 @@ print BRDF '; -# Output back reflection (transposed order) +# Output back reflection (reciprocity averaging) for (my $od = 0; $od < $ndiv; $od++) { for (my $id = 0; $id < $ndiv; $id++) { - print $rbarr[$ndiv*$id + $od]; + print .5*($rbarr[$ndiv*$id + $od] + $rbarr[$ndiv*$od + $id]); } print "\n"; }