9 |
|
my $windoz = ($^O eq "MSWin32" or $^O eq "MSWin64"); |
10 |
|
my @skycolor = (0.960, 1.004, 1.118); |
11 |
|
my $mf = 4; |
12 |
+ |
my $dosky = 1; |
13 |
+ |
my $dofive = 0; |
14 |
+ |
my $headout = 1; |
15 |
+ |
my @origARGV = @ARGV; |
16 |
|
while ($#ARGV >= 0) { |
17 |
|
if ("$ARGV[0]" eq "-c") { |
18 |
|
@skycolor = @ARGV[1..3]; |
19 |
< |
shift @ARGV; shift @ARGV; shift @ARGV; |
19 |
> |
shift @ARGV for (1..3); |
20 |
|
} elsif ("$ARGV[0]" eq "-m") { |
21 |
|
$mf = $ARGV[1]; |
22 |
|
shift @ARGV; |
23 |
+ |
} elsif ("$ARGV[0]" eq "-d") { |
24 |
+ |
$dosky = 0; |
25 |
+ |
} elsif ("$ARGV[0]" eq "-5") { |
26 |
+ |
$dofive = 1; |
27 |
+ |
} elsif ("$ARGV[0]" eq "-h") { |
28 |
+ |
$headout = 0; |
29 |
+ |
} else { |
30 |
+ |
die "Unexpected command-line argument: $ARGV[0]\n"; |
31 |
|
} |
32 |
|
shift @ARGV; |
33 |
|
} |
93 |
|
q{-e "Rbin=$1;x1=rand(recno*.37-5.3);x2=rand(recno*-1.47+.86)" } . |
94 |
|
q{-e "$1=0;$2=0;$3=0;$4=Dx;$5=Dy;$6=Dz" } . |
95 |
|
"| rtrace -h -ab 0 -w $octree | total -16 -m"; |
96 |
< |
$suncmd = "cnt " . ($nbins-1) . |
97 |
< |
" | 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" }; |
96 |
> |
if (@sundir) { |
97 |
> |
$suncmd = "cnt " . ($nbins-1) . |
98 |
> |
" | rcalc -e MF:$mf -e \"$rhcal\" -e Rbin=recno " . |
99 |
> |
"-e \"dot=Dx*$sundir[0] + Dy*$sundir[1] + Dz*$sundir[2]\" " . |
100 |
> |
"-e \"cond=dot-.866\" " . |
101 |
> |
q{-e "$1=if(1-dot,acos(dot),0);$2=Romega;$3=recno" }; |
102 |
> |
} |
103 |
|
} else { |
104 |
|
$nbins = `rcalc -n -e MF:$mf -e \'$rhcal\' -e \'\$1=Rmax+1\'`; |
105 |
|
chomp $nbins; |
108 |
|
q{-e 'Rbin=$1;x1=rand(recno*.37-5.3);x2=rand(recno*-1.47+.86)' } . |
109 |
|
q{-e '$1=0;$2=0;$3=0;$4=Dx;$5=Dy;$6=Dz' } . |
110 |
|
"| rtrace -h -ff -ab 0 -w $octree | total -if3 -16 -m"; |
111 |
< |
$suncmd = "cnt " . ($nbins-1) . |
112 |
< |
" | rcalc -e MF:$mf -e '$rhcal' -e Rbin=recno " . |
113 |
< |
"-e 'dot=Dx*$sundir[0] + Dy*$sundir[1] + Dz*$sundir[2]' " . |
114 |
< |
"-e 'cond=dot-.866' " . |
115 |
< |
q{-e '$1=if(1-dot,acos(dot),0);$2=Romega;$3=recno' }; |
111 |
> |
if (@sundir) { |
112 |
> |
$suncmd = "cnt " . ($nbins-1) . |
113 |
> |
" | rcalc -e MF:$mf -e '$rhcal' -e Rbin=recno " . |
114 |
> |
"-e 'dot=Dx*$sundir[0] + Dy*$sundir[1] + Dz*$sundir[2]' " . |
115 |
> |
"-e 'cond=dot-.866' " . |
116 |
> |
q{-e '$1=if(1-dot,acos(dot),0);$2=Romega;$3=recno' }; |
117 |
> |
} |
118 |
|
} |
119 |
< |
# Create octree for rtrace |
120 |
< |
open OCONV, "| oconv - > $octree"; |
121 |
< |
print OCONV @skydesc; |
122 |
< |
print OCONV "skyfunc glow skyglow 0 0 4 @skycolor 0\n"; |
123 |
< |
print OCONV "skyglow source sky 0 0 4 0 0 1 360\n"; |
124 |
< |
close OCONV; |
125 |
< |
# Run rtrace and average output for every 16 samples |
126 |
< |
my @tregval = `$tregcommand`; |
127 |
< |
unlink $octree; |
128 |
< |
# Find closest 3 patches to sun and divvy up direct solar contribution |
119 |
> |
my @tregval; |
120 |
> |
if ($dosky) { |
121 |
> |
# Create octree for rtrace |
122 |
> |
open OCONV, "| oconv - > $octree"; |
123 |
> |
print OCONV @skydesc; |
124 |
> |
print OCONV "skyfunc glow skyglow 0 0 4 @skycolor 0\n"; |
125 |
> |
print OCONV "skyglow source sky 0 0 4 0 0 1 360\n"; |
126 |
> |
close OCONV; |
127 |
> |
# Run rtrace and average output for every 16 samples |
128 |
> |
@tregval = `$tregcommand`; |
129 |
> |
unlink $octree; |
130 |
> |
} else { |
131 |
> |
push @tregval, "0\t0\t0\n" for (1..$nbins); |
132 |
> |
} |
133 |
> |
# Find closest patch(es) to sun and divvy up direct solar contribution |
134 |
|
sub numSort1 { |
135 |
|
my @a1 = split("\t", $a); |
136 |
|
my @b1 = split("\t", $b); |
137 |
|
return ($a1[0] <=> $b1[0]); |
138 |
|
} |
139 |
|
if (@sundir) { |
119 |
– |
my $somega = ($sundir[3]/360)**2 * 3.141592654**3; |
140 |
|
my @bestdir = `$suncmd`; |
141 |
|
@bestdir = sort numSort1 @bestdir; |
142 |
< |
my (@ang, @dom, @ndx); |
143 |
< |
my $wtot = 0; |
144 |
< |
for my $i (0..2) { |
145 |
< |
($ang[$i], $dom[$i], $ndx[$i]) = split(' ', $bestdir[$i]); |
146 |
< |
$wtot += 1./($ang[$i]+.02); |
142 |
> |
if ($dofive) { |
143 |
> |
my ($ang, $dom, $ndx); |
144 |
> |
($ang, $dom, $ndx) = split(' ', $bestdir[0]); |
145 |
> |
$tregval[$ndx] = "$sunval[0]\t$sunval[1]\t$sunval[2]\n"; |
146 |
> |
} else { |
147 |
> |
my (@ang, @dom, @ndx); |
148 |
> |
my $somega = ($sundir[3]/360)**2 * 3.141592654**3; |
149 |
> |
my $wtot = 0; |
150 |
> |
for my $i (0..2) { |
151 |
> |
($ang[$i], $dom[$i], $ndx[$i]) = split(' ', $bestdir[$i]); |
152 |
> |
$wtot += 1./($ang[$i]+.02); |
153 |
> |
} |
154 |
> |
for my $i (0..2) { |
155 |
> |
my $wt = 1./($ang[$i]+.02)/$wtot * $somega / $dom[$i]; |
156 |
> |
my @scolor = split(' ', $tregval[$ndx[$i]]); |
157 |
> |
for my $j (0..2) { $scolor[$j] += $wt * $sunval[$j]; } |
158 |
> |
$tregval[$ndx[$i]] = "$scolor[0]\t$scolor[1]\t$scolor[2]\n"; |
159 |
> |
} |
160 |
|
} |
161 |
< |
for my $i (0..2) { |
162 |
< |
my $wt = 1./($ang[$i]+.02)/$wtot * $somega / $dom[$i]; |
163 |
< |
my @scolor = split(' ', $tregval[$ndx[$i]]); |
164 |
< |
for my $j (0..2) { $scolor[$j] += $wt * $sunval[$j]; } |
165 |
< |
$tregval[$ndx[$i]] = "$scolor[0]\t$scolor[1]\t$scolor[2]\n"; |
166 |
< |
} |
161 |
> |
} |
162 |
> |
# Output header if requested |
163 |
> |
if ($headout) { |
164 |
> |
print "#?RADIANCE\n"; |
165 |
> |
print "genskyvec @origARGV\n"; |
166 |
> |
print "NROWS=", $#tregval+1, "\n"; |
167 |
> |
print "NCOLS=1\nNCOMP=3\n"; |
168 |
> |
print "FORMAT=ascii\n"; |
169 |
> |
print "\n"; |
170 |
|
} |
171 |
|
# Output our final vector |
172 |
|
print @tregval; |