--- ray/src/util/genBSDF.pl 2011/06/08 23:16:47 2.21
+++ ray/src/util/genBSDF.pl 2011/08/24 04:14:58 2.25
@@ -1,5 +1,5 @@
#!/usr/bin/perl -w
-# RCSid $Id: genBSDF.pl,v 2.21 2011/06/08 23:16:47 greg Exp $
+# RCSid $Id: genBSDF.pl,v 2.25 2011/08/24 04:14:58 greg Exp $
#
# Compute BSDF based on geometry and material description
#
@@ -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 $gunit = "Meter";
my @dim;
# Get options
while ($#ARGV >= 0) {
@@ -33,6 +34,11 @@ while ($#ARGV >= 0) {
shift @ARGV;
} elsif ("$ARGV[0]" =~ /^[-+]g/) {
$geout = ("$ARGV[0]" =~ /^\+/);
+ $gunit = $ARGV[1];
+ if ($gunit !~ /^(?i)(meter|foot|inch|centimeter|millimeter)$/) {
+ die "Illegal geometry unit '$gunit': must be meter, foot, inch, centimeter, or millimeter\n";
+ }
+ shift @ARGV;
} elsif ("$ARGV[0]" =~ /^[-+]f/) {
$doforw = ("$ARGV[0]" =~ /^\+/);
} elsif ("$ARGV[0]" =~ /^[-+]b/) {
@@ -109,13 +115,13 @@ print
Name
Manufacturer
';
-printf "\t\t%.3f\n", $dim[5] - $dim[4];
-printf "\t\t%.3f\n", $dim[1] - $dim[0];
-printf "\t\t%.3f\n", $dim[3] - $dim[2];
+printf "\t\t%.3f\n", $dim[5] - $dim[4];
+printf "\t\t%.3f\n", $dim[1] - $dim[0];
+printf "\t\t%.3f\n", $dim[3] - $dim[2];
print "\t\tIntegral\n";
# Output MGF description if requested
if ( $geout ) {
- print "\t\t\n";
+ print "\t\t\n";
printf "xf -t %.6f %.6f 0\n", -($dim[0]+$dim[1])/2, -($dim[2]+$dim[3])/2;
open(MGFSCN, "< $mgfscn");
while () { print $_; }
@@ -160,9 +166,13 @@ sub do_tree_bsdf {
# Get sampling rate and subdivide task
my $ns2 = $ns;
$ns2 /= 2 if ( $tensortree == 3 );
-@pdiv = (0, int($ns2/$nproc));
-my $nrem = $ns2 % $nproc;
-for (my $i = 1; $i < $nproc; $i++) {
+my $nsplice = $nproc;
+$nsplice *= 10 if ($nproc > 1);
+$nsplice = $ns2 if ($nsplice > $ns2);
+$nsplice = 999 if ($nsplice > 999);
+@pdiv = (0, int($ns2/$nsplice));
+my $nrem = $ns2 % $nsplice;
+for (my $i = 1; $i < $nsplice; $i++) {
my $nv = $pdiv[$i] + $pdiv[1];
++$nv if ( $nrem-- > 0 );
push @pdiv, $nv;
@@ -211,27 +221,42 @@ print "\t\n";
print "\t\tTensorTree$tensortree\n";
print "\t\n";
# Fork parallel rtcontrib processes to compute each side
+my $npleft = $nproc;
if ( $doback ) {
- for (my $proc = 0; $proc < $nproc; $proc++) {
- bg_tree_rtcontrib(0, $proc);
+ for (my $splice = 0; $splice < $nsplice; $splice++) {
+ if (! $npleft ) {
+ wait();
+ die "rtcontrib process reported error" if ( $? );
+ $npleft++;
+ }
+ bg_tree_rtcontrib(0, $splice);
+ $npleft--;
}
while (wait() >= 0) {
die "rtcontrib process reported error" if ( $? );
+ $npleft++;
}
ttree_out(0);
}
if ( $doforw ) {
- for (my $proc = 0; $proc < $nproc; $proc++) {
- bg_tree_rtcontrib(1, $proc);
+ for (my $splice = 0; $splice < $nsplice; $splice++) {
+ if (! $npleft ) {
+ wait();
+ die "rtcontrib process reported error" if ( $? );
+ $npleft++;
+ }
+ bg_tree_rtcontrib(1, $splice);
+ $npleft--;
}
while (wait() >= 0) {
die "rtcontrib process reported error" if ( $? );
+ $npleft++;
}
ttree_out(1);
}
} # end of sub do_tree_bsdf()
-# Run i'th rtcontrib process for generating tensor tree samples
+# Run rtcontrib process in background to generate tensor tree samples
sub bg_tree_rtcontrib {
my $pid = fork();
die "Cannot fork new process" unless defined $pid;