--- ray/src/util/genskyvec.pl 2011/05/16 23:56:32 2.6 +++ ray/src/util/genskyvec.pl 2014/09/17 22:40:49 2.9 @@ -1,5 +1,5 @@ #!/usr/bin/perl -w -# RCSid $Id: genskyvec.pl,v 2.6 2011/05/16 23:56:32 greg Exp $ +# RCSid $Id: genskyvec.pl,v 2.9 2014/09/17 22:40:49 greg Exp $ # # Generate Reinhart vector for a given sky description # @@ -9,13 +9,20 @@ use strict; my $windoz = ($^O eq "MSWin32" or $^O eq "MSWin64"); my @skycolor = (0.960, 1.004, 1.118); my $mf = 4; +my $dosky = 1; +my $headout = 1; +my @origARGV = @ARGV; while ($#ARGV >= 0) { if ("$ARGV[0]" eq "-c") { @skycolor = @ARGV[1..3]; - shift @ARGV; shift @ARGV; shift @ARGV; + shift @ARGV for (1..3); } elsif ("$ARGV[0]" eq "-m") { $mf = $ARGV[1]; shift @ARGV; + } elsif ("$ARGV[0]" eq "-d") { + $dosky = 0; + } elsif ("$ARGV[0]" eq "-h") { + $headout = 0; } shift @ARGV; } @@ -81,11 +88,13 @@ if ($windoz) { q{-e "Rbin=$1;x1=rand(recno*.37-5.3);x2=rand(recno*-1.47+.86)" } . q{-e "$1=0;$2=0;$3=0;$4=Dx;$5=Dy;$6=Dz" } . "| rtrace -h -ab 0 -w $octree | total -16 -m"; - $suncmd = "cnt " . ($nbins-1) . - " | rcalc -e MF:$mf -e \"$rhcal\" -e Rbin=recno " . - "-e \"dot=Dx*$sundir[0] + Dy*$sundir[1] + Dz*$sundir[2]\" " . - "-e \"cond=dot-.866\" " . - q{-e "$1=if(1-dot,acos(dot),0);$2=Romega;$3=recno" }; + if (@sundir) { + $suncmd = "cnt " . ($nbins-1) . + " | rcalc -e MF:$mf -e \"$rhcal\" -e Rbin=recno " . + "-e \"dot=Dx*$sundir[0] + Dy*$sundir[1] + Dz*$sundir[2]\" " . + "-e \"cond=dot-.866\" " . + q{-e "$1=if(1-dot,acos(dot),0);$2=Romega;$3=recno" }; + } } else { $nbins = `rcalc -n -e MF:$mf -e \'$rhcal\' -e \'\$1=Rmax+1\'`; chomp $nbins; @@ -94,21 +103,28 @@ if ($windoz) { q{-e 'Rbin=$1;x1=rand(recno*.37-5.3);x2=rand(recno*-1.47+.86)' } . q{-e '$1=0;$2=0;$3=0;$4=Dx;$5=Dy;$6=Dz' } . "| rtrace -h -ff -ab 0 -w $octree | total -if3 -16 -m"; - $suncmd = "cnt " . ($nbins-1) . - " | rcalc -e MF:$mf -e '$rhcal' -e Rbin=recno " . - "-e 'dot=Dx*$sundir[0] + Dy*$sundir[1] + Dz*$sundir[2]' " . - "-e 'cond=dot-.866' " . - q{-e '$1=if(1-dot,acos(dot),0);$2=Romega;$3=recno' }; + if (@sundir) { + $suncmd = "cnt " . ($nbins-1) . + " | rcalc -e MF:$mf -e '$rhcal' -e Rbin=recno " . + "-e 'dot=Dx*$sundir[0] + Dy*$sundir[1] + Dz*$sundir[2]' " . + "-e 'cond=dot-.866' " . + q{-e '$1=if(1-dot,acos(dot),0);$2=Romega;$3=recno' }; + } } -# Create octree for rtrace -open OCONV, "| oconv - > $octree"; -print OCONV @skydesc; -print OCONV "skyfunc glow skyglow 0 0 4 @skycolor 0\n"; -print OCONV "skyglow source sky 0 0 4 0 0 1 360\n"; -close OCONV; -# Run rtrace and average output for every 16 samples -my @tregval = `$tregcommand`; -unlink $octree; +my @tregval; +if ($dosky) { + # Create octree for rtrace + open OCONV, "| oconv - > $octree"; + print OCONV @skydesc; + print OCONV "skyfunc glow skyglow 0 0 4 @skycolor 0\n"; + print OCONV "skyglow source sky 0 0 4 0 0 1 360\n"; + close OCONV; + # Run rtrace and average output for every 16 samples + @tregval = `$tregcommand`; + unlink $octree; +} else { + push @tregval, "0\t0\t0\n" for (1..$nbins); +} # Find closest 3 patches to sun and divvy up direct solar contribution sub numSort1 { my @a1 = split("\t", $a); @@ -131,6 +147,15 @@ if (@sundir) { for my $j (0..2) { $scolor[$j] += $wt * $sunval[$j]; } $tregval[$ndx[$i]] = "$scolor[0]\t$scolor[1]\t$scolor[2]\n"; } +} +# Output header if requested +if ($headout) { + print "#?RADIANCE\n"; + print "genskyvec @origARGV\n"; + print "NROWS=", $#tregval+1, "\n"; + print "NCOLS=1\nNCOMP=3\n"; + print "FORMAT=ascii\n"; + print "\n"; } # Output our final vector print @tregval;