10 |
|
|
11 |
|
#include "holo.h" |
12 |
|
#include "view.h" |
13 |
+ |
#include "random.h" |
14 |
|
|
15 |
|
#ifndef DEPS |
16 |
|
#define DEPS 0.02 /* depth epsilon */ |
121 |
|
int d; |
122 |
|
register int4 i, p; |
123 |
|
|
124 |
< |
if (n <= 0) |
124 |
> |
if (n <= 0) { |
125 |
> |
#ifdef DEBUG |
126 |
> |
error(WARNING, "neighborless sample in kill_occl"); |
127 |
> |
#endif |
128 |
|
return(1); |
129 |
+ |
} |
130 |
|
p = v*hres + h; |
131 |
|
forequad[0][0] = forequad[0][1] = forequad[1][0] = forequad[1][1] = 0; |
132 |
|
for (i = n; i--; ) { |
144 |
|
|
145 |
|
|
146 |
|
int |
147 |
< |
grow_samp(h, v, nl, n) /* grow sample point appropriately */ |
147 |
> |
smooth_samp(h, v, nl, n) /* grow sample point smoothly */ |
148 |
|
int h, v; |
149 |
|
register short nl[NNEIGH][2]; |
150 |
|
int n; |
152 |
|
int dis[NNEIGH], ndis; |
153 |
|
COLOR mykern[MAXRAD2]; |
154 |
|
int4 maxr2; |
155 |
< |
double w, d; |
155 |
> |
double d; |
156 |
|
register int4 p, r2; |
157 |
|
int i, r, maxr, h2, v2; |
158 |
|
|
197 |
|
} |
198 |
|
if (i >= 0) continue; /* outside edge */ |
199 |
|
addcolor(mypixel[v2*hres+h2], mykern[r2]); |
200 |
< |
myweight[v2*hres+h2] += pixWeight[r2] * |
196 |
< |
myweight[v*hres+h]; |
200 |
> |
myweight[v2*hres+h2] += pixWeight[r2] * myweight[p]; |
201 |
|
} |
202 |
|
} |
203 |
|
return(1); |
204 |
|
} |
205 |
|
|
206 |
|
|
207 |
< |
pixFlush() /* done with beams -- flush pixel values */ |
207 |
> |
int |
208 |
> |
random_samp(h, v, nl, n, rf) /* grow sample point noisily */ |
209 |
> |
int h, v; |
210 |
> |
register short nl[NNEIGH][2]; |
211 |
> |
int n; |
212 |
> |
double *rf; |
213 |
|
{ |
214 |
< |
reset_flags(); /* set occupancy flags */ |
215 |
< |
meet_neighbors(kill_occl); /* eliminate occlusion errors */ |
216 |
< |
reset_flags(); /* reset occupancy flags */ |
217 |
< |
if (pixWeight[0] <= FTINY) { /* initialize weighting function */ |
218 |
< |
register int i, j, r2; |
219 |
< |
double d; |
220 |
< |
for (i = 1; i <= MAXRAD; i++) |
221 |
< |
for (j = 0; j <= i; j++) { |
222 |
< |
r2 = i*i + j*j; |
223 |
< |
if (r2 >= MAXRAD2) break; |
224 |
< |
d = sqrt((double)r2); |
225 |
< |
pixWeight[r2] = G0NORM/d; |
226 |
< |
isqrttab[r2] = d + 0.99; |
214 |
> |
float nwt[NNEIGH]; |
215 |
> |
int4 maxr2; |
216 |
> |
register int4 p, r2; |
217 |
> |
register int i; |
218 |
> |
int maxr, h2, v2; |
219 |
> |
COLOR ctmp; |
220 |
> |
|
221 |
> |
if (n <= 0) |
222 |
> |
return(1); |
223 |
> |
p = v*hres + h; /* compute kernel radius */ |
224 |
> |
maxr2 = (h-nl[n-1][0])*(h-nl[n-1][0]) + (v-nl[n-1][1])*(v-nl[n-1][1]); |
225 |
> |
DCHECK(maxr2>=MAXRAD2, CONSISTENCY, "out of range neighbor"); |
226 |
> |
maxr = isqrt(maxr2); |
227 |
> |
/* compute neighbor weights */ |
228 |
> |
for (i = n; i--; ) { |
229 |
> |
r2 = (nl[i][0]-h)*(nl[i][0]-h) + (nl[i][1]-v)*(nl[i][1]-v); |
230 |
> |
nwt[i] = pixWeight[r2]; |
231 |
> |
} |
232 |
> |
/* sample kernel */ |
233 |
> |
for (v2 = v-maxr; v2 <= v+maxr; v2++) { |
234 |
> |
if (v2 < 0) v2 = 0; |
235 |
> |
else if (v2 >= vres) break; |
236 |
> |
for (h2 = h-maxr; h2 <= h+maxr; h2++) { |
237 |
> |
if (h2 < 0) h2 = 0; |
238 |
> |
else if (h2 >= hres) break; |
239 |
> |
r2 = (h2-h)*(h2-h) + (v2-v)*(v2-v); |
240 |
> |
if (r2 > maxr2) continue; |
241 |
> |
if (CHK4(pixFlags, v2*hres+h2)) |
242 |
> |
continue; /* occupied */ |
243 |
> |
if (frandom() < *rf) { /* pick neighbor instead */ |
244 |
> |
i = random() % n; |
245 |
> |
r2 = nl[i][1]*hres + nl[i][0]; |
246 |
> |
copycolor(ctmp, mypixel[r2]); |
247 |
> |
scalecolor(ctmp, nwt[i]); |
248 |
> |
addcolor(mypixel[v2*hres+h2], ctmp); |
249 |
> |
myweight[v2*hres+h2] += nwt[i] * myweight[r2]; |
250 |
> |
continue; |
251 |
|
} |
252 |
< |
pixWeight[0] = 1.; |
253 |
< |
isqrttab[0] = 0; |
252 |
> |
copycolor(ctmp, mypixel[p]); |
253 |
> |
scalecolor(ctmp, pixWeight[r2]); |
254 |
> |
addcolor(mypixel[v2*hres+h2], ctmp); |
255 |
> |
myweight[v2*hres+h2] += pixWeight[r2] * myweight[p]; |
256 |
> |
} |
257 |
|
} |
258 |
< |
meet_neighbors(grow_samp); /* grow valid samples over image */ |
258 |
> |
return(1); |
259 |
> |
} |
260 |
> |
|
261 |
> |
|
262 |
> |
pixFinish(ransamp) /* done with beams -- compute pixel values */ |
263 |
> |
double ransamp; |
264 |
> |
{ |
265 |
> |
if (pixWeight[0] <= FTINY) |
266 |
> |
init_wfunc(); /* initialize weighting function */ |
267 |
> |
reset_flags(); /* set occupancy flags */ |
268 |
> |
meet_neighbors(kill_occl,NULL); /* eliminate occlusion errors */ |
269 |
> |
reset_flags(); /* reset occupancy flags */ |
270 |
> |
if (ransamp >= 0.) /* spread samples over image */ |
271 |
> |
meet_neighbors(random_samp,&ransamp); |
272 |
> |
else |
273 |
> |
meet_neighbors(smooth_samp,NULL); |
274 |
|
free((char *)pixFlags); /* free pixel flags */ |
275 |
|
pixFlags = NULL; |
276 |
|
} |
278 |
|
|
279 |
|
reset_flags() /* allocate/set/reset occupancy flags */ |
280 |
|
{ |
281 |
< |
register int p; |
281 |
> |
register int4 p; |
282 |
|
|
283 |
|
if (pixFlags == NULL) { |
284 |
|
pixFlags = (int4 *)calloc(FL4NELS(hres*vres), sizeof(int4)); |
291 |
|
} |
292 |
|
|
293 |
|
|
294 |
+ |
init_wfunc() /* initialize weighting function */ |
295 |
+ |
{ |
296 |
+ |
register int4 r2; |
297 |
+ |
register double d; |
298 |
+ |
|
299 |
+ |
for (r2 = MAXRAD2; --r2; ) { |
300 |
+ |
d = sqrt((double)r2); |
301 |
+ |
pixWeight[r2] = G0NORM/d; |
302 |
+ |
isqrttab[r2] = d + 0.99; |
303 |
+ |
} |
304 |
+ |
pixWeight[0] = 1.; |
305 |
+ |
isqrttab[0] = 0; |
306 |
+ |
} |
307 |
+ |
|
308 |
+ |
|
309 |
|
int |
310 |
|
findneigh(nl, h, v, rnl) /* find NNEIGH neighbors for pixel */ |
311 |
|
short nl[NNEIGH][2]; |
347 |
|
} |
348 |
|
|
349 |
|
|
350 |
< |
meet_neighbors(nf) /* run through samples and their neighbors */ |
350 |
> |
meet_neighbors(nf, dp) /* run through samples and their neighbors */ |
351 |
|
int (*nf)(); |
352 |
+ |
char *dp; |
353 |
|
{ |
354 |
|
short ln[NNEIGH][2]; |
355 |
|
int h, v, n, v2; |
373 |
|
if (!CHK4(pixFlags, v*hres+h)) |
374 |
|
continue; /* no one home */ |
375 |
|
n = findneigh(ln, h, v, rnl); |
376 |
< |
(*nf)(h, v, ln, n); /* call on neighbors */ |
376 |
> |
(*nf)(h, v, ln, n, dp); /* call on neighbors */ |
377 |
|
} |
378 |
|
if (++v >= vres) /* reinitialize row list */ |
379 |
|
break; |