211 |
|
memset(bsdf_hist, 0, sizeof(bsdf_hist)); |
212 |
|
} |
213 |
|
|
214 |
+ |
/* Find n nearest sub-sampled neighbors to the given grid position */ |
215 |
+ |
static int |
216 |
+ |
get_neighbors(int neigh[][2], int n, const int i, const int j) |
217 |
+ |
{ |
218 |
+ |
int k = 0; |
219 |
+ |
int r; |
220 |
+ |
/* search concentric squares */ |
221 |
+ |
for (r = 1; r < GRIDRES; r++) { |
222 |
+ |
int ii, jj; |
223 |
+ |
for (ii = i-r; ii <= i+r; ii++) { |
224 |
+ |
int jstep = 1; |
225 |
+ |
if (ii < 0) continue; |
226 |
+ |
if (ii >= GRIDRES) break; |
227 |
+ |
if ((i-r < ii) & (ii < i+r)) |
228 |
+ |
jstep = r<<1; |
229 |
+ |
for (jj = j-r; jj <= j+r; jj += jstep) { |
230 |
+ |
if (jj < 0) continue; |
231 |
+ |
if (jj >= GRIDRES) break; |
232 |
+ |
if (dsf_grid[ii][jj].nval) { |
233 |
+ |
neigh[k][0] = ii; |
234 |
+ |
neigh[k][1] = jj; |
235 |
+ |
if (++k >= n) |
236 |
+ |
return(n); |
237 |
+ |
} |
238 |
+ |
} |
239 |
+ |
} |
240 |
+ |
} |
241 |
+ |
return(k); |
242 |
+ |
} |
243 |
+ |
|
244 |
+ |
/* Adjust coded radius for the given grid position based on neighborhood */ |
245 |
+ |
static int |
246 |
+ |
adj_coded_radius(const int i, const int j) |
247 |
+ |
{ |
248 |
+ |
const double max_frac = 0.33; |
249 |
+ |
const double rad0 = R2ANG(dsf_grid[i][j].crad); |
250 |
+ |
double currad = RSCA * rad0; |
251 |
+ |
int neigh[5][2]; |
252 |
+ |
int n; |
253 |
+ |
FVECT our_dir; |
254 |
+ |
|
255 |
+ |
ovec_from_pos(our_dir, i, j); |
256 |
+ |
n = get_neighbors(neigh, 5, i, j); |
257 |
+ |
while (n--) { |
258 |
+ |
FVECT their_dir; |
259 |
+ |
double max_ratio, rad_ok2; |
260 |
+ |
/* check our value at neighbor */ |
261 |
+ |
ovec_from_pos(their_dir, neigh[n][0], neigh[n][1]); |
262 |
+ |
max_ratio = max_frac * dsf_grid[neigh[n][0]][neigh[n][1]].vsum |
263 |
+ |
/ dsf_grid[i][j].vsum; |
264 |
+ |
if (max_ratio >= 1) |
265 |
+ |
continue; |
266 |
+ |
rad_ok2 = (DOT(their_dir,our_dir) - 1.)/log(max_ratio); |
267 |
+ |
if (rad_ok2 >= currad*currad) |
268 |
+ |
continue; /* value fraction OK */ |
269 |
+ |
currad = sqrt(rad_ok2); /* else reduce lobe radius */ |
270 |
+ |
if (currad <= rad0) /* limit how small we'll go */ |
271 |
+ |
return(dsf_grid[i][j].crad); |
272 |
+ |
} |
273 |
+ |
return(ANG2R(currad)); /* encode selected radius */ |
274 |
+ |
} |
275 |
+ |
|
276 |
|
/* Count up filled nodes and build RBF representation from current grid */ |
277 |
|
RBFNODE * |
278 |
|
make_rbfrep(void) |
311 |
|
for (j = 0; j < GRIDRES; j++) |
312 |
|
if (dsf_grid[i][j].nval) { |
313 |
|
newnode->rbfa[nn].peak = dsf_grid[i][j].vsum; |
314 |
< |
newnode->rbfa[nn].crad = RSCA*dsf_grid[i][j].crad + .5; |
314 |
> |
newnode->rbfa[nn].crad = adj_coded_radius(i, j); |
315 |
|
newnode->rbfa[nn].gx = i; |
316 |
|
newnode->rbfa[nn].gy = j; |
317 |
|
++nn; |