--- ray/src/util/genBSDF.pl 2015/03/25 22:50:48 2.54 +++ ray/src/util/genBSDF.pl 2016/07/13 00:51:17 2.64 @@ -1,5 +1,5 @@ #!/usr/bin/perl -w -# RCSid $Id: genBSDF.pl,v 2.54 2015/03/25 22:50:48 greg Exp $ +# RCSid $Id: genBSDF.pl,v 2.64 2016/07/13 00:51:17 greg Exp $ # # Compute BSDF based on geometry and material description # @@ -9,7 +9,7 @@ use strict; my $windoz = ($^O eq "MSWin32" or $^O eq "MSWin64"); use File::Temp qw/ :mktemp /; sub userror { - print STDERR "Usage: genBSDF [-n Nproc][-c Nsamp][-W][-t{3|4} Nlog2][-r \"ropts\"][-f \"x=string;y=string\"][-dim xmin xmax ymin ymax zmin zmax][{+|-}C][{+|-}f][{+|-}b][{+|-}mgf][{+|-}geom units] [input ..]\n"; + print STDERR "Usage: genBSDF [-n Nproc][-c Nsamp][-W][-t{3|4} Nlog2][-r \"ropts\"][-s \"x=string;y=string\"][-dim xmin xmax ymin ymax zmin zmax][{+|-}C][{+|-}f][{+|-}b][{+|-}mgf][{+|-}geom units] [input ..]\n"; exit 1; } my ($td,$radscn,$mgfscn,$octree,$fsender,$bsender,$receivers,$facedat,$behinddat,$rmtmp); @@ -39,7 +39,7 @@ if ($windoz) { $tbz = "$td\\tbz.dat"; $rbz = "$td\\rbz.dat"; chomp $td; - $rmtmp = "rmdir /S /Q $td"; + $rmtmp = "rd /S /Q $td"; } else { $td = mkdtemp("/tmp/genBSDF.XXXXXX"); chomp $td; @@ -104,12 +104,15 @@ while ($#ARGV >= 0) { } elsif ("$ARGV[0]" eq "-t") { # Use value < 0 for rttree_reduce bypass $pctcull = $ARGV[1]; + if ($pctcull >= 100) { + die "Illegal -t culling percentage, must be < 100\n"; + } shift @ARGV; } elsif ("$ARGV[0]" =~ /^-t[34]$/) { $tensortree = substr($ARGV[0], 2, 1); $ttlog2 = $ARGV[1]; shift @ARGV; - } elsif ("$ARGV[0]" eq "-f") { + } elsif ("$ARGV[0]" eq "-s") { $wrapper .= " -f \"$ARGV[1]\""; shift @ARGV; } elsif ("$ARGV[0]" eq "-W") { @@ -149,8 +152,14 @@ if ( $mgfin ) { if ($#dim != 5) { @dim = split ' ', `getbbox -h $radscn`; } -print STDERR "Warning: Device extends into room\n" if ($dim[5] > 1e-5); -$wrapper .= ' -f "t=' . ($dim[5] - $dim[4]) . ';w=' . ($dim[1] - $dim[0]) . +die "Device entirely inside room!\n" if ($dim[4] >= 0); +if ($dim[5] > 1e-5) { + print STDERR "Warning: Device extends into room\n"; +} elsif ($dim[5]*$dim[5] < .01*($dim[1]-$dim[0])*($dim[3]-$dim[2])) { + print STDERR "Warning: Device far behind Z==0 plane\n"; +} +# Assume Zmax==0 to derive thickness so pkgBSDF will work +$wrapper .= ' -f "t=' . (-$dim[4]) . ';w=' . ($dim[1] - $dim[0]) . ';h=' . ($dim[3] - $dim[2]) . '"'; # Generate octree system "oconv -w $radscn > $octree"; @@ -171,16 +180,18 @@ if ( $geout ) { $wrapper .= " -g $mgfscn"; } # Create receiver & sender surfaces (rectangular) +my $FEPS = 1e-5; my $nx = int(sqrt($nsamp*($dim[1]-$dim[0])/($dim[3]-$dim[2])) + 1); my $ny = int($nsamp/$nx + 1); $nsamp = $nx * $ny; my $ns = 2**$ttlog2; open(RADSCN, "> $receivers"); -print RADSCN '#@rfluxmtx ' . ($tensortree ? "h=sc$ns\n" : "h=kf\n"); -print RADSCN '#@rfluxmtx ' . "u=Y o=$facedat\n\n"; +print RADSCN '#@rfluxmtx ' . ($tensortree ? "h=-sc$ns\n" : "h=-kf\n"); +print RADSCN '#@rfluxmtx ' . "u=-Y o=$facedat\n\n"; print RADSCN "void glow receiver_face\n0\n0\n4 1 1 1 0\n\n"; print RADSCN "receiver_face source f_receiver\n0\n0\n4 0 0 1 180\n\n"; -print RADSCN '#@rfluxmtx ' . "u=Y o=$behinddat\n\n"; +print RADSCN '#@rfluxmtx ' . ($tensortree ? "h=+sc$ns\n" : "h=+kf\n"); +print RADSCN '#@rfluxmtx ' . "u=-Y o=$behinddat\n\n"; print RADSCN "void glow receiver_behind\n0\n0\n4 1 1 1 0\n\n"; print RADSCN "receiver_behind source b_receiver\n0\n0\n4 0 0 -1 180\n"; close RADSCN; @@ -188,20 +199,20 @@ close RADSCN; $rfluxmtx .= " -n $nproc -c $nsamp"; if ( $tensortree != 3 ) { # Isotropic tensor tree is exception open (RADSCN, "> $fsender"); - print RADSCN '#@rfluxmtx u=Y ' . ($tensortree ? "h=sc$ns\n\n" : "h=kf\n\n"); + print RADSCN '#@rfluxmtx u=-Y ' . ($tensortree ? "h=-sc$ns\n\n" : "h=-kf\n\n"); print RADSCN "void polygon fwd_sender\n0\n0\n12\n"; - printf RADSCN "\t%f\t%f\t%f\n", $dim[0], $dim[2], $dim[4]; - printf RADSCN "\t%f\t%f\t%f\n", $dim[0], $dim[3], $dim[4]; - printf RADSCN "\t%f\t%f\t%f\n", $dim[1], $dim[3], $dim[4]; - printf RADSCN "\t%f\t%f\t%f\n", $dim[1], $dim[2], $dim[4]; + printf RADSCN "\t%e\t%e\t%e\n", $dim[0], $dim[2], $dim[4]-$FEPS; + printf RADSCN "\t%e\t%e\t%e\n", $dim[0], $dim[3], $dim[4]-$FEPS; + printf RADSCN "\t%e\t%e\t%e\n", $dim[1], $dim[3], $dim[4]-$FEPS; + printf RADSCN "\t%e\t%e\t%e\n", $dim[1], $dim[2], $dim[4]-$FEPS; close RADSCN; open (RADSCN, "> $bsender"); - print RADSCN '#@rfluxmtx u=Y ' . ($tensortree ? "h=sc$ns\n\n" : "h=kf\n\n"); - print RADSCN "void polygon fwd_sender\n0\n0\n12\n"; - printf RADSCN "\t%f\t%f\t%f\n", $dim[0], $dim[2], $dim[5]; - printf RADSCN "\t%f\t%f\t%f\n", $dim[1], $dim[2], $dim[5]; - printf RADSCN "\t%f\t%f\t%f\n", $dim[1], $dim[3], $dim[5]; - printf RADSCN "\t%f\t%f\t%f\n", $dim[0], $dim[3], $dim[5]; + print RADSCN '#@rfluxmtx u=-Y ' . ($tensortree ? "h=+sc$ns\n\n" : "h=+kf\n\n"); + print RADSCN "void polygon bwd_sender\n0\n0\n12\n"; + printf RADSCN "\t%e\t%e\t%e\n", $dim[0], $dim[2], $dim[5]+$FEPS; + printf RADSCN "\t%e\t%e\t%e\n", $dim[1], $dim[2], $dim[5]+$FEPS; + printf RADSCN "\t%e\t%e\t%e\n", $dim[1], $dim[3], $dim[5]+$FEPS; + printf RADSCN "\t%e\t%e\t%e\n", $dim[0], $dim[3], $dim[5]+$FEPS; close RADSCN; } # Calculate CIE (u',v') from Radiance RGB: @@ -217,12 +228,8 @@ if ( $tensortree ) { do_matrix_bsdf(); } # Output XML -my $old_fh = select(STDOUT); -$| = 1; -select($old_fh); -print "\n"; # print STDERR "Running: $wrapper\n"; -system $wrapper; +system "$wrapper -C \"Created by: genBSDF @savedARGV\""; die "Could not wrap BSDF data\n" if ( $? ); # Clean up temporary files and exit exec $rmtmp; @@ -355,7 +362,7 @@ sub ttree_comp { if ($pctcull >= 0) { my $avg = ( "$typ" =~ /^r[fb]/ ) ? " -a" : ""; my $pcull = ("$spec" eq "Visible") ? $pctcull : - (100 - (100-$pctcull)/3) ; + (100 - (100-$pctcull)*.25) ; if ($windoz) { $cmd = "rcollate -ho -oc 1 $src | " . $cmd . @@ -450,16 +457,16 @@ sub matrix_comp { my $dest = shift; my $cmd = "rmtxop -fa -t"; if ("$spec" eq "Visible") { - $cmd .= " -c 0.265 0.670 0.065"; + $cmd .= " -c 0.2651 0.6701 0.0648"; } elsif ("$spec" eq "CIE-X") { - $cmd .= " -c 0.514 0.324 0.162"; + $cmd .= " -c 0.5141 0.3239 0.1620"; } elsif ("$spec" eq "CIE-Z") { - $cmd .= " -c 0.024 0.123 0.853"; + $cmd .= " -c 0.0241 0.1229 0.8530"; } $cmd .= " $src | rcollate -ho -oc 145"; # print STDERR "Running: $cmd\n"; system "$cmd > $dest"; - die "Failure running rttree_reduce" if ( $? ); + die "Failure running rmtxop" if ( $? ); if ( "$spec" ne "$curspec" ) { $wrapper .= " -s $spec"; $curspec = $spec;