7 |
|
# |
8 |
|
use strict; |
9 |
|
if ($#ARGV < 0) { |
10 |
< |
print STDERR, "Usage: genklemsamp [-c N ][-f{a|f|d}] [view opts] [geom.rad ..]\n"; |
10 |
> |
print STDERR "Usage: genklemsamp [-c N ][-f{a|f|d}] [view opts] [geom.rad ..]\n"; |
11 |
|
exit 1; |
12 |
|
} |
13 |
|
my $td = `mktemp -d /tmp/genklemsamp.XXXXXX`; |
28 |
|
push @vopts, "@ARGV[0..1]"; |
29 |
|
shift @ARGV; |
30 |
|
} elsif ("$ARGV[0]" =~ /^-v./) { |
31 |
< |
print STDERR, "Unsupported view option: $ARGV[0]\n"; |
31 |
> |
print STDERR "Unsupported view option: $ARGV[0]\n"; |
32 |
|
exit 1; |
33 |
|
} elsif ("$ARGV[0]" =~ /^-./) { |
34 |
< |
print STDERR, "Unknown option: $ARGV[0]\n"; |
34 |
> |
print STDERR "Unknown option: $ARGV[0]\n"; |
35 |
|
exit 1; |
36 |
|
} else { |
37 |
|
last; |
63 |
|
sin_kpol = sin(Kpol); |
64 |
|
K0 = cos(Kazi)*sin_kpol; |
65 |
|
K1 = sin(Kazi)*sin_kpol; |
66 |
< |
K2 = cos(Kpol); |
66 |
> |
K2 = sqrt(1 - sin_kpol*sin_kpol); |
67 |
|
'; |
68 |
|
my $ndiv = 145; |
69 |
|
# Do we have any Radiance input files? |
86 |
|
$vwset = `vwright @vopts V`; |
87 |
|
my $xres; |
88 |
|
my $yres; |
89 |
< |
my $ntot; |
89 |
> |
my $ntot = 0; |
90 |
|
# This generally passes through the loop twice to get density right |
91 |
< |
do { |
91 |
> |
while ($ntot < $nsamp) { |
92 |
|
$xres = int($width*$sca) + 1; |
93 |
|
$yres = int($height*$sca) + 1; |
94 |
|
system "vwrays -ff -x $xres -y $yres -pa 0 -pj .7 @vopts " . |
100 |
|
$ntot = -s "$td/origins.flt"; |
101 |
|
$ntot /= 3*4; |
102 |
|
if ($ntot == 0) { |
103 |
< |
print STDERR, "View direction does not correspond to any surfaces\n"; |
103 |
> |
if ($sca < sqrt(199/($width*$height))) { |
104 |
> |
$sca = sqrt(200/($width*$height)); |
105 |
> |
redo; |
106 |
> |
} |
107 |
> |
print STDERR "View direction does not correspond to any surfaces\n"; |
108 |
|
exit 1; |
109 |
|
} |
110 |
|
$sca *= 1.05 * sqrt($nsamp/$ntot); |
111 |
< |
} while ($ntot < $nsamp); |
111 |
> |
} |
112 |
|
# All set to produce our samples |
113 |
< |
for ($k = 1; $k <= $ndiv; $k++) { |
113 |
> |
for (my $k = 1; $k <= $ndiv; $k++) { |
114 |
|
my $rn = rand(10); |
115 |
|
my $r1 = rand; my $r2 = rand; |
116 |
|
# Chance of using = (number_still_needed)/(number_left_avail) |
118 |
|
"-e 'cond=($nsamp-outno+1)/($ntot-recno+1)-rand($rn+recno)' " . |
119 |
|
"-e 'Kbin=$k;x1=rand($r1+recno);x2=rand($r2+recno)' " . |
120 |
|
q{-e '$1=$1+Vo*Vdx; $2=$2+Vo*Vdy; $3=$3+Vo*Vdz' } . |
121 |
< |
q{-e '$4=K0*Vhx+K1*Vvx+K2*Vdx' } . |
122 |
< |
q{-e '$5=K0*Vhy+K1*Vvy+K2*Vdy' } . |
123 |
< |
q{-e '$6=K0*Vhz+K1*Vvz+K2*Vdz' } . |
121 |
> |
q{-e '$4=K0*Vhx-K1*Vvx+K2*Vdx' } . |
122 |
> |
q{-e '$5=K0*Vhy-K1*Vvy+K2*Vdy' } . |
123 |
> |
q{-e '$6=K0*Vhz-K1*Vvz+K2*Vdz' } . |
124 |
|
"-if3 $td/origins.flt"; |
125 |
|
} |
126 |
|
} else { |
128 |
|
my $xres = int($width*$sca) + 1; |
129 |
|
my $yres = int($height*$sca) + 1; |
130 |
|
my $ntot = $xres * $yres; |
131 |
< |
for ($k = 1; $k <= $ndiv; $k++) { |
131 |
> |
for (my $k = 1; $k <= $ndiv; $k++) { |
132 |
|
my $rn = rand(10); |
133 |
|
my $r1 = rand; my $r2 = rand; |
134 |
|
my $r3 = rand; my $r4 = rand; |
142 |
|
q{-e '$1=Vpx+Vo*Vdx+hpos*Vhx+vpos*Vvx' } . |
143 |
|
q{-e '$2=Vpy+Vo*Vdy+hpos*Vhy+vpos*Vvy' } . |
144 |
|
q{-e '$3=Vpz+Vo*Vdz+hpos*Vhz+vpos*Vvz' } . |
145 |
< |
q{-e '$4=K0*Vhx+K1*Vvx+K2*Vdx' } . |
146 |
< |
q{-e '$5=K0*Vhy+K1*Vvy+K2*Vdy' } . |
147 |
< |
q{-e '$6=K0*Vhz+K1*Vvz+K2*Vdz' } ; |
145 |
> |
q{-e '$4=K0*Vhx-K1*Vvx+K2*Vdx' } . |
146 |
> |
q{-e '$5=K0*Vhy-K1*Vvy+K2*Vdy' } . |
147 |
> |
q{-e '$6=K0*Vhz-K1*Vvz+K2*Vdz' } ; |
148 |
|
} |
149 |
|
} |
150 |
|
system "rm -rf $td"; |