| 6 |
|
# G. Ward |
| 7 |
|
# |
| 8 |
|
use strict; |
| 9 |
+ |
my $windoz = ($^O eq "MSWin32" or $^O eq "MSWin64"); |
| 10 |
|
my @skycolor = (0.960, 1.004, 1.118); |
| 11 |
|
my $mf = 4; |
| 12 |
|
while ($#ARGV >= 0) { |
| 50 |
|
splice(@skydesc, $sunline, 5); |
| 51 |
|
} |
| 52 |
|
# Reinhart sky sample generator |
| 53 |
< |
my $rhcal = ' |
| 54 |
< |
DEGREE : PI/180; |
| 55 |
< |
x1 = .5; x2 = .5; |
| 56 |
< |
alpha : 90/(MF*7 + .5); |
| 57 |
< |
tnaz(r) : select(r, 30, 30, 24, 24, 18, 12, 6); |
| 58 |
< |
rnaz(r) : if(r-(7*MF-.5), 1, MF*tnaz(floor((r+.5)/MF) + 1)); |
| 59 |
< |
raccum(r) : if(r-.5, rnaz(r-1) + raccum(r-1), 0); |
| 60 |
< |
RowMax : 7*MF + 1; |
| 61 |
< |
Rmax : raccum(RowMax); |
| 62 |
< |
Rfindrow(r, rem) : if(rem-rnaz(r)-.5, Rfindrow(r+1, rem-rnaz(r)), r); |
| 63 |
< |
Rrow = if(Rbin-(Rmax-.5), RowMax-1, Rfindrow(0, Rbin)); |
| 64 |
< |
Rcol = Rbin - raccum(Rrow) - 1; |
| 65 |
< |
Razi_width = 2*PI / rnaz(Rrow); |
| 66 |
< |
RAH : alpha*DEGREE; |
| 67 |
< |
Razi = if(Rbin-.5, (Rcol + x2 - .5)*Razi_width, 2*PI*x2); |
| 68 |
< |
Ralt = if(Rbin-.5, (Rrow + x1)*RAH, asin(-x1)); |
| 69 |
< |
Romega = if(.5-Rbin, 2*PI, if(Rmax-.5-Rbin, |
| 70 |
< |
Razi_width*(sin(RAH*(Rrow+1)) - sin(RAH*Rrow)), |
| 71 |
< |
2*PI*(1 - cos(RAH/2)) ) ); |
| 72 |
< |
cos_ralt = cos(Ralt); |
| 73 |
< |
Dx = sin(Razi)*cos_ralt; |
| 74 |
< |
Dy = cos(Razi)*cos_ralt; |
| 75 |
< |
Dz = sin(Ralt); |
| 76 |
< |
'; |
| 77 |
< |
my $nbins = `rcalc -n -e MF:$mf -e \'$rhcal\' -e \'\$1=Rmax+1\'`; |
| 78 |
< |
chomp $nbins; |
| 53 |
> |
my $rhcal = 'DEGREE : PI/180;' . |
| 54 |
> |
'x1 = .5; x2 = .5;' . |
| 55 |
> |
'alpha : 90/(MF*7 + .5);' . |
| 56 |
> |
'tnaz(r) : select(r, 30, 30, 24, 24, 18, 12, 6);' . |
| 57 |
> |
'rnaz(r) : if(r-(7*MF-.5), 1, MF*tnaz(floor((r+.5)/MF) + 1));' . |
| 58 |
> |
'raccum(r) : if(r-.5, rnaz(r-1) + raccum(r-1), 0);' . |
| 59 |
> |
'RowMax : 7*MF + 1;' . |
| 60 |
> |
'Rmax : raccum(RowMax);' . |
| 61 |
> |
'Rfindrow(r, rem) : if(rem-rnaz(r)-.5, Rfindrow(r+1, rem-rnaz(r)), r);' . |
| 62 |
> |
'Rrow = if(Rbin-(Rmax-.5), RowMax-1, Rfindrow(0, Rbin));' . |
| 63 |
> |
'Rcol = Rbin - raccum(Rrow) - 1;' . |
| 64 |
> |
'Razi_width = 2*PI / rnaz(Rrow);' . |
| 65 |
> |
'RAH : alpha*DEGREE;' . |
| 66 |
> |
'Razi = if(Rbin-.5, (Rcol + x2 - .5)*Razi_width, 2*PI*x2);' . |
| 67 |
> |
'Ralt = if(Rbin-.5, (Rrow + x1)*RAH, asin(-x1));' . |
| 68 |
> |
'Romega = if(.5-Rbin, 2*PI, if(Rmax-.5-Rbin, ' . |
| 69 |
> |
' Razi_width*(sin(RAH*(Rrow+1)) - sin(RAH*Rrow)),' . |
| 70 |
> |
' 2*PI*(1 - cos(RAH/2)) ) );' . |
| 71 |
> |
'cos_ralt = cos(Ralt);' . |
| 72 |
> |
'Dx = sin(Razi)*cos_ralt;' . |
| 73 |
> |
'Dy = cos(Razi)*cos_ralt;' . |
| 74 |
> |
'Dz = sin(Ralt);' ; |
| 75 |
> |
my ($nbins, $octree, $tregcommand, $suncmd); |
| 76 |
> |
if ($windoz) { |
| 77 |
> |
$nbins = `rcalc -n -e MF:$mf -e \"$rhcal\" -e \"\$1=Rmax+1\"`; |
| 78 |
> |
chomp $nbins; |
| 79 |
> |
$octree = "gtv$$.oct"; |
| 80 |
> |
$tregcommand = "cnt $nbins 16 | rcalc -e MF:$mf -e \"$rhcal\" " . |
| 81 |
> |
q{-e "Rbin=$1;x1=rand(recno*.37-5.3);x2=rand(recno*-1.47+.86)" } . |
| 82 |
> |
q{-e "$1=0;$2=0;$3=0;$4=Dx;$5=Dy;$6=Dz" } . |
| 83 |
> |
"| rtrace -h -ab 0 -w $octree | total -16 -m"; |
| 84 |
> |
if (@sundir) { |
| 85 |
> |
$suncmd = "cnt " . ($nbins-1) . |
| 86 |
> |
" | rcalc -e MF:$mf -e \"$rhcal\" -e Rbin=recno " . |
| 87 |
> |
"-e \"dot=Dx*$sundir[0] + Dy*$sundir[1] + Dz*$sundir[2]\" " . |
| 88 |
> |
"-e \"cond=dot-.866\" " . |
| 89 |
> |
q{-e "$1=if(1-dot,acos(dot),0);$2=Romega;$3=recno" }; |
| 90 |
> |
} |
| 91 |
> |
} else { |
| 92 |
> |
$nbins = `rcalc -n -e MF:$mf -e \'$rhcal\' -e \'\$1=Rmax+1\'`; |
| 93 |
> |
chomp $nbins; |
| 94 |
> |
$octree = "/tmp/gtv$$.oct"; |
| 95 |
> |
$tregcommand = "cnt $nbins 16 | rcalc -of -e MF:$mf -e '$rhcal' " . |
| 96 |
> |
q{-e 'Rbin=$1;x1=rand(recno*.37-5.3);x2=rand(recno*-1.47+.86)' } . |
| 97 |
> |
q{-e '$1=0;$2=0;$3=0;$4=Dx;$5=Dy;$6=Dz' } . |
| 98 |
> |
"| rtrace -h -ff -ab 0 -w $octree | total -if3 -16 -m"; |
| 99 |
> |
if (@sundir) { |
| 100 |
> |
$suncmd = "cnt " . ($nbins-1) . |
| 101 |
> |
" | rcalc -e MF:$mf -e '$rhcal' -e Rbin=recno " . |
| 102 |
> |
"-e 'dot=Dx*$sundir[0] + Dy*$sundir[1] + Dz*$sundir[2]' " . |
| 103 |
> |
"-e 'cond=dot-.866' " . |
| 104 |
> |
q{-e '$1=if(1-dot,acos(dot),0);$2=Romega;$3=recno' }; |
| 105 |
> |
} |
| 106 |
> |
} |
| 107 |
|
# Create octree for rtrace |
| 79 |
– |
my $octree = "/tmp/gtv$$.oct"; |
| 108 |
|
open OCONV, "| oconv - > $octree"; |
| 109 |
|
print OCONV @skydesc; |
| 110 |
|
print OCONV "skyfunc glow skyglow 0 0 4 @skycolor 0\n"; |
| 111 |
|
print OCONV "skyglow source sky 0 0 4 0 0 1 360\n"; |
| 112 |
|
close OCONV; |
| 113 |
|
# Run rtrace and average output for every 16 samples |
| 86 |
– |
my $tregcommand = "cnt $nbins 16 | rcalc -of -e MF:$mf -e '$rhcal' " . |
| 87 |
– |
q{-e 'Rbin=$1;x1=rand(recno*.37-5.3);x2=rand(recno*-1.47+.86)' } . |
| 88 |
– |
q{-e '$1=0;$2=0;$3=0;$4=Dx;$5=Dy;$6=Dz' } . |
| 89 |
– |
"| rtrace -h -ff -ab 0 -w $octree | total -if3 -16 -m"; |
| 114 |
|
my @tregval = `$tregcommand`; |
| 115 |
|
unlink $octree; |
| 116 |
|
# Find closest 3 patches to sun and divvy up direct solar contribution |
| 117 |
< |
my @bestdir; |
| 117 |
> |
sub numSort1 { |
| 118 |
> |
my @a1 = split("\t", $a); |
| 119 |
> |
my @b1 = split("\t", $b); |
| 120 |
> |
return ($a1[0] <=> $b1[0]); |
| 121 |
> |
} |
| 122 |
|
if (@sundir) { |
| 123 |
|
my $somega = ($sundir[3]/360)**2 * 3.141592654**3; |
| 124 |
< |
my $cmd = "cnt " . ($nbins-1) . |
| 125 |
< |
" | rcalc -e MF:$mf -e '$rhcal' -e Rbin=recno " . |
| 98 |
< |
"-e 'dot=Dx*$sundir[0] + Dy*$sundir[1] + Dz*$sundir[2]' " . |
| 99 |
< |
"-e 'cond=dot-.866' " . |
| 100 |
< |
q{-e '$1=if(1-dot,acos(dot),0);$2=Romega;$3=recno' }; |
| 101 |
< |
@bestdir = `$cmd | sort -n | head -3`; |
| 124 |
> |
my @bestdir = `$suncmd`; |
| 125 |
> |
@bestdir = sort numSort1 @bestdir; |
| 126 |
|
my (@ang, @dom, @ndx); |
| 127 |
|
my $wtot = 0; |
| 128 |
|
for my $i (0..2) { |