51 |
|
|
52 |
|
|
53 |
|
static int |
54 |
+ |
ambcollision( /* proposed direciton collides? */ |
55 |
+ |
AMBHEMI *hp, |
56 |
+ |
int i, |
57 |
+ |
int j, |
58 |
+ |
FVECT dv |
59 |
+ |
) |
60 |
+ |
{ |
61 |
+ |
const double cos_thresh = 0.9999995; /* about 3.44 arcminutes */ |
62 |
+ |
int ii, jj; |
63 |
+ |
|
64 |
+ |
for (ii = i-1; ii <= i+1; ii++) { |
65 |
+ |
if (ii < 0) continue; |
66 |
+ |
if (ii >= hp->ns) break; |
67 |
+ |
for (jj = j-1; jj <= j+1; jj++) { |
68 |
+ |
AMBSAMP *ap; |
69 |
+ |
FVECT avec; |
70 |
+ |
double dprod; |
71 |
+ |
if (jj < 0) continue; |
72 |
+ |
if (jj >= hp->ns) break; |
73 |
+ |
if ((ii==i) & (jj==j)) continue; |
74 |
+ |
ap = &ambsam(hp,ii,jj); |
75 |
+ |
if (ap->d <= .5/FHUGE) continue; |
76 |
+ |
VSUB(avec, ap->p, hp->rp->rop); |
77 |
+ |
dprod = DOT(avec, dv); |
78 |
+ |
if (dprod >= cos_thresh*VLEN(avec)) |
79 |
+ |
return(1); /* collision */ |
80 |
+ |
} |
81 |
+ |
} |
82 |
+ |
return(0); |
83 |
+ |
} |
84 |
+ |
|
85 |
+ |
|
86 |
+ |
static int |
87 |
|
ambsample( /* initial ambient division sample */ |
88 |
|
AMBHEMI *hp, |
89 |
|
int i, |
111 |
|
hlist[1] = j; |
112 |
|
hlist[2] = i; |
113 |
|
multisamp(spt, 2, urand(ilhash(hlist,3)+n)); |
114 |
< |
/* avoid coincident samples */ |
82 |
< |
if (!n && (0 < i) & (i < hp->ns-1) && |
83 |
< |
(0 < j) & (j < hp->ns-1)) { |
84 |
< |
if ((spt[0] < 0.1) | (spt[0] >= 0.9)) |
85 |
< |
spt[0] = 0.1 + 0.8*frandom(); |
86 |
< |
if ((spt[1] < 0.1) | (spt[1] >= 0.9)) |
87 |
< |
spt[1] = 0.1 + 0.8*frandom(); |
88 |
< |
} |
114 |
> |
resample: |
115 |
|
SDsquare2disk(spt, (j+spt[1])/hp->ns, (i+spt[0])/hp->ns); |
116 |
|
zd = sqrt(1. - spt[0]*spt[0] - spt[1]*spt[1]); |
117 |
|
for (ii = 3; ii--; ) |
119 |
|
spt[1]*hp->uy[ii] + |
120 |
|
zd*hp->rp->ron[ii]; |
121 |
|
checknorm(ar.rdir); |
122 |
+ |
/* avoid coincident samples */ |
123 |
+ |
if (!n && ambcollision(hp, i, j, ar.rdir)) { |
124 |
+ |
spt[0] = frandom(); spt[1] = frandom(); |
125 |
+ |
goto resample; |
126 |
+ |
} |
127 |
|
dimlist[ndims++] = AI(hp,i,j) + 90171; |
128 |
|
rayvalue(&ar); /* evaluate ray */ |
129 |
|
ndims--; |
640 |
|
double ang, a1; |
641 |
|
int i, j; |
642 |
|
/* don't bother for a few samples */ |
643 |
< |
if (hp->ns < 12) |
643 |
> |
if (hp->ns < 8) |
644 |
|
return(0); |
645 |
|
/* check distances overhead */ |
646 |
|
for (i = hp->ns*3/4; i-- > hp->ns>>2; ) |