258 |
|
double |
259 |
|
eval_rbfrep(const RBFNODE *rp, const FVECT outvec) |
260 |
|
{ |
261 |
+ |
const double rfact2 = (38./M_PI/M_PI)*(grid_res*grid_res); |
262 |
|
double minval = bsdf_min*output_orient*outvec[2]; |
263 |
+ |
int pos[2]; |
264 |
|
double res = 0; |
265 |
|
const RBFVAL *rbfp; |
266 |
|
FVECT odir; |
267 |
< |
double sig2; |
267 |
> |
double rad2; |
268 |
|
int n; |
269 |
|
/* check for wrong side */ |
270 |
|
if (outvec[2] > 0 ^ output_orient > 0) |
272 |
|
/* use minimum if no information avail. */ |
273 |
|
if (rp == NULL) |
274 |
|
return(minval); |
275 |
+ |
/* optimization for fast lobe culling */ |
276 |
+ |
pos_from_vec(pos, outvec); |
277 |
|
/* sum radial basis function */ |
278 |
|
rbfp = rp->rbfa; |
279 |
|
for (n = rp->nrbf; n--; rbfp++) { |
280 |
+ |
int d2 = (pos[0]-rbfp->gx)*(pos[0]-rbfp->gx) + |
281 |
+ |
(pos[1]-rbfp->gy)*(pos[1]-rbfp->gy); |
282 |
+ |
rad2 = R2ANG(rbfp->crad); |
283 |
+ |
rad2 *= rad2; |
284 |
+ |
if (d2 > rad2*rfact2) |
285 |
+ |
continue; |
286 |
|
ovec_from_pos(odir, rbfp->gx, rbfp->gy); |
287 |
< |
sig2 = R2ANG(rbfp->crad); |
278 |
< |
sig2 = (DOT(odir,outvec) - 1.) / (sig2*sig2); |
279 |
< |
if (sig2 > -19.) |
280 |
< |
res += rbfp->peak * exp(sig2); |
287 |
> |
res += rbfp->peak * exp((DOT(odir,outvec) - 1.) / rad2); |
288 |
|
} |
289 |
|
if (res < minval) /* never return less than minval */ |
290 |
|
return(minval); |
513 |
|
progname); |
514 |
|
return(0); |
515 |
|
} |
516 |
< |
rbfh.next = NULL; /* read each DSF */ |
510 |
< |
rbfh.ejl = NULL; |
516 |
> |
memset(&rbfh, 0, sizeof(rbfh)); /* read each DSF */ |
517 |
|
while ((rbfh.ord = getint(4, ifp)) >= 0) { |
518 |
|
RBFNODE *newrbf; |
519 |
|
|
530 |
|
sizeof(RBFVAL)*(rbfh.nrbf-1)); |
531 |
|
if (newrbf == NULL) |
532 |
|
goto memerr; |
533 |
< |
memcpy(newrbf, &rbfh, sizeof(RBFNODE)-sizeof(RBFVAL)); |
533 |
> |
*newrbf = rbfh; |
534 |
|
for (i = 0; i < rbfh.nrbf; i++) { |
535 |
|
newrbf->rbfa[i].peak = getflt(ifp); |
536 |
|
newrbf->rbfa[i].crad = getint(2, ifp) & 0xffff; |