515 |
|
c_toSharpRGB(&cxy, yval, rgb); |
516 |
|
} |
517 |
|
|
518 |
+ |
static double |
519 |
+ |
pfrac(double x) |
520 |
+ |
{ |
521 |
+ |
return( x - (int)x ); |
522 |
+ |
} |
523 |
+ |
|
524 |
|
/* Query BSDF value and sample hypercube for the given vectors */ |
525 |
|
static int |
526 |
|
SDqueryTre(const SDTre *sdt, float *coef, |
527 |
|
const FVECT inVec, const FVECT outVec, double *hc) |
528 |
|
{ |
529 |
|
const RREAL *vtmp; |
530 |
+ |
double hcube[SD_MAXDIM+1]; |
531 |
|
float yval; |
532 |
|
FVECT rOutVec; |
533 |
|
RREAL gridPos[4]; |
534 |
+ |
double d; |
535 |
+ |
int i; |
536 |
|
|
537 |
|
if (sdt->stc[tt_Y] == NULL) /* paranoia, I hope */ |
538 |
|
return 0; |
576 |
|
disk2square(gridPos+2, outVec[0], outVec[1]); |
577 |
|
} else |
578 |
|
return 0; /* should be internal error */ |
579 |
< |
/* get BSDF value */ |
579 |
> |
|
580 |
> |
if (hc == NULL) hc = hcube; /* get BSDF value */ |
581 |
|
yval = SDlookupTre(sdt->stc[tt_Y], gridPos, hc); |
582 |
|
if (coef == NULL) /* just getting hypercube? */ |
583 |
|
return 1; |
584 |
+ |
d = 0; /* position-specific perturbation */ |
585 |
+ |
for (i = sdt->stc[tt_Y]->ndim; i--; ) |
586 |
+ |
d += pfrac((2<<i)/(hc[i]+.01687)) - .5; |
587 |
+ |
yval *= 1. + 1e-4*d; /* assumes tolerance is > 0.04% */ |
588 |
|
if (sdt->stc[tt_u] == NULL || sdt->stc[tt_v] == NULL) { |
589 |
|
*coef = yval; |
590 |
|
return 1; /* no color */ |