64 |
|
int ii, jj; |
65 |
|
/* min. spacing = 1/4th division */ |
66 |
|
cos_thresh = (PI/4.)/(double)hp->ns; |
67 |
+ |
if (cos_thresh > 7.*PI/180.) /* 7 degrees is enough in any case */ |
68 |
+ |
cos_thresh = 7.*PI/180.; |
69 |
|
cos_thresh = 1. - .5*cos_thresh*cos_thresh; |
70 |
|
/* check existing neighbors */ |
71 |
|
for (ii = i-1; ii <= i+1; ii++) { |
129 |
|
spt[1]*hp->uy[ii] + |
130 |
|
zd*hp->onrm[ii]; |
131 |
|
checknorm(ar.rdir); |
132 |
< |
/* avoid coincident samples */ |
133 |
< |
if (!n && hp->ns >= 4 && ambcollision(hp, i, j, ar.rdir)) { |
132 |
> |
/* avoid coincident samples? */ |
133 |
> |
if (!n & (ambacc > FTINY) & (hp->ns >= 4) && |
134 |
> |
ambcollision(hp, i, j, ar.rdir)) { |
135 |
|
ss[0] = frandom(); ss[1] = frandom(); |
136 |
|
goto resample; /* reject this sample */ |
137 |
|
} |
176 |
|
if (earr == NULL) /* out of memory? */ |
177 |
|
return(NULL); |
178 |
|
/* sum squared neighbor diffs */ |
179 |
< |
for (ap = hp->sa, ep = earr, i = 0; i < hp->ns; i++) |
179 |
> |
ap = hp->sa; |
180 |
> |
ep = earr + hp->ns*hp->ns; /* original estimates to scratch */ |
181 |
> |
for (i = 0; i < hp->ns; i++) |
182 |
|
for (j = 0; j < hp->ns; j++, ap++, ep++) { |
183 |
|
b = pbright(ap[0].v); |
184 |
|
if (i) { /* from above */ |
204 |
|
ep[-hp->ns-1] += d2; |
205 |
|
} |
206 |
|
/* correct for number of neighbors */ |
207 |
< |
earr[0] *= 6./3.; |
208 |
< |
earr[hp->ns-1] *= 6./3.; |
209 |
< |
earr[(hp->ns-1)*hp->ns] *= 6./3.; |
210 |
< |
earr[(hp->ns-1)*hp->ns + hp->ns-1] *= 6./3.; |
207 |
> |
ep = earr + hp->ns*hp->ns; |
208 |
> |
ep[0] *= 6./3.; |
209 |
> |
ep[hp->ns-1] *= 6./3.; |
210 |
> |
ep[(hp->ns-1)*hp->ns] *= 6./3.; |
211 |
> |
ep[(hp->ns-1)*hp->ns + hp->ns-1] *= 6./3.; |
212 |
|
for (i = 1; i < hp->ns-1; i++) { |
213 |
< |
earr[i*hp->ns] *= 6./5.; |
214 |
< |
earr[i*hp->ns + hp->ns-1] *= 6./5.; |
213 |
> |
ep[i*hp->ns] *= 6./5.; |
214 |
> |
ep[i*hp->ns + hp->ns-1] *= 6./5.; |
215 |
|
} |
216 |
|
for (j = 1; j < hp->ns-1; j++) { |
217 |
< |
earr[j] *= 6./5.; |
218 |
< |
earr[(hp->ns-1)*hp->ns + j] *= 6./5.; |
217 |
> |
ep[j] *= 6./5.; |
218 |
> |
ep[(hp->ns-1)*hp->ns + j] *= 6./5.; |
219 |
|
} |
220 |
< |
/* blur map to reduce bias */ |
215 |
< |
memcpy(earr+hp->ns*hp->ns, earr, hp->ns*hp->ns*sizeof(float)); |
220 |
> |
/* blur final map to reduce bias */ |
221 |
|
for (i = 0; i < hp->ns-1; i++) { |
222 |
|
float *ep2; |
223 |
|
ep = earr + i*hp->ns; |
224 |
|
ep2 = ep + hp->ns*hp->ns; |
225 |
|
for (j = 0; j < hp->ns-1; j++, ep++, ep2++) { |
226 |
< |
ep[0] += .125*(ep2[1] + ep2[hp->ns]) - .5*ep2[0]; |
226 |
> |
ep[0] += .5*ep2[0] + .125*(ep2[1] + ep2[hp->ns]); |
227 |
|
ep[1] += .125*ep2[0]; |
228 |
|
ep[hp->ns] += .125*ep2[0]; |
229 |
|
} |