| 27 |
|
int output_orient = 0; |
| 28 |
|
|
| 29 |
|
/* BSDF histogram */ |
| 30 |
< |
int bsdf_hist[HISTLEN]; |
| 30 |
> |
unsigned long bsdf_hist[HISTLEN]; |
| 31 |
|
|
| 32 |
|
/* BSDF value for boundary regions */ |
| 33 |
|
double bsdf_min = 0; |
| 205 |
|
VCOPY(rbf->invec, invec); |
| 206 |
|
} |
| 207 |
|
|
| 208 |
– |
/* Compute volume associated with Gaussian lobe */ |
| 209 |
– |
double |
| 210 |
– |
rbf_volume(const RBFVAL *rbfp) |
| 211 |
– |
{ |
| 212 |
– |
double rad = R2ANG(rbfp->crad); |
| 213 |
– |
|
| 214 |
– |
return((2.*M_PI) * rbfp->peak * rad*rad); |
| 215 |
– |
} |
| 216 |
– |
|
| 208 |
|
/* Compute outgoing vector from grid position */ |
| 209 |
|
void |
| 210 |
|
ovec_from_pos(FVECT vec, int xpos, int ypos) |
| 234 |
|
pos[1] = (int)(sq[1]*grid_res); |
| 235 |
|
} |
| 236 |
|
|
| 237 |
+ |
/* Compute volume associated with Gaussian lobe */ |
| 238 |
+ |
double |
| 239 |
+ |
rbf_volume(const RBFVAL *rbfp) |
| 240 |
+ |
{ |
| 241 |
+ |
double rad = R2ANG(rbfp->crad); |
| 242 |
+ |
FVECT odir; |
| 243 |
+ |
double elev, integ; |
| 244 |
+ |
/* infinite integral approximation */ |
| 245 |
+ |
integ = (2.*M_PI) * rbfp->peak * rad*rad; |
| 246 |
+ |
/* check if we're near horizon */ |
| 247 |
+ |
ovec_from_pos(odir, rbfp->gx, rbfp->gy); |
| 248 |
+ |
elev = output_orient*odir[2]; |
| 249 |
+ |
/* apply cut-off correction if > 1% */ |
| 250 |
+ |
if (elev < 2.8*rad) { |
| 251 |
+ |
/* elev = asin(elev); /* this is so crude, anyway... */ |
| 252 |
+ |
integ *= 1. - .5*exp(-.5*elev*elev/(rad*rad)); |
| 253 |
+ |
} |
| 254 |
+ |
return(integ); |
| 255 |
+ |
} |
| 256 |
+ |
|
| 257 |
|
/* Evaluate RBF for DSF at the given normalized outgoing direction */ |
| 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) |
| 271 |
+ |
return(.0); |
| 272 |
|
/* use minimum if no information avail. */ |
| 273 |
< |
if (rp == NULL) { |
| 258 |
< |
if (outvec[2] > 0 ^ output_orient > 0) |
| 259 |
< |
return(.0); |
| 273 |
> |
if (rp == NULL) |
| 274 |
|
return(minval); |
| 275 |
< |
} |
| 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); |
| 266 |
< |
sig2 = (DOT(odir,outvec) - 1.) / (sig2*sig2); |
| 267 |
< |
if (sig2 > -19.) |
| 268 |
< |
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); |