--- ray/src/util/genklemsamp.pl 2009/06/14 00:33:16 2.1 +++ ray/src/util/genklemsamp.pl 2009/06/19 06:49:42 2.4 @@ -1,10 +1,13 @@ #!/usr/bin/perl -w -# RCSid $Id: genklemsamp.pl,v 2.1 2009/06/14 00:33:16 greg Exp $ +# RCSid $Id: genklemsamp.pl,v 2.4 2009/06/19 06:49:42 greg Exp $ # # Sample Klems (full) directions impinging on surface(s) # +# G. Ward +# +use strict; if ($#ARGV < 0) { - print "Usage: genklemsamp [-c N ][-f{a|f|d}] [view opts] [geom.rad ..]\n"; + print STDERR "Usage: genklemsamp [-c N ][-f{a|f|d}] [view opts] [geom.rad ..]\n"; exit 1; } my $td = `mktemp -d /tmp/genklemsamp.XXXXXX`; @@ -25,10 +28,10 @@ while ($#ARGV >= 0) { push @vopts, "@ARGV[0..1]"; shift @ARGV; } elsif ("$ARGV[0]" =~ /^-v./) { - print "Unsupported view option: $ARGV[0]\n"; + print STDERR "Unsupported view option: $ARGV[0]\n"; exit 1; } elsif ("$ARGV[0]" =~ /^-./) { - print "Unknown option: $ARGV[0]\n"; + print STDERR "Unknown option: $ARGV[0]\n"; exit 1; } else { last; @@ -83,9 +86,9 @@ if ($#ARGV >= 0) { $vwset = `vwright @vopts V`; my $xres; my $yres; - my $ntot; + my $ntot = 0; # This generally passes through the loop twice to get density right - do { + while ($ntot < $nsamp) { $xres = int($width*$sca) + 1; $yres = int($height*$sca) + 1; system "vwrays -ff -x $xres -y $yres -pa 0 -pj .7 @vopts " . @@ -97,13 +100,17 @@ if ($#ARGV >= 0) { $ntot = -s "$td/origins.flt"; $ntot /= 3*4; if ($ntot == 0) { - print "View direction does not correspond to any surfaces\n"; + if ($sca < sqrt(199/($width*$height))) { + $sca = sqrt(200/($width*$height)); + redo; + } + print STDERR "View direction does not correspond to any surfaces\n"; exit 1; } $sca *= 1.05 * sqrt($nsamp/$ntot); - } while ($ntot < $nsamp); + } # All set to produce our samples - for ($k = 1; $k <= $ndiv; $k++) { + for (my $k = 1; $k <= $ndiv; $k++) { my $rn = rand(10); my $r1 = rand; my $r2 = rand; # Chance of using = (number_still_needed)/(number_left_avail) @@ -121,7 +128,7 @@ if ($#ARGV >= 0) { my $xres = int($width*$sca) + 1; my $yres = int($height*$sca) + 1; my $ntot = $xres * $yres; - for ($k = 1; $k <= $ndiv; $k++) { + for (my $k = 1; $k <= $ndiv; $k++) { my $rn = rand(10); my $r1 = rand; my $r2 = rand; my $r3 = rand; my $r4 = rand;