569 |
|
return 0; /* should be internal error */ |
570 |
|
/* get BSDF value */ |
571 |
|
yval = SDlookupTre(sdt->stc[tt_Y], gridPos, hc); |
572 |
+ |
if (coef == NULL) /* just getting hypercube? */ |
573 |
+ |
return 1; |
574 |
|
if (sdt->stc[tt_u] == NULL || sdt->stc[tt_v] == NULL) { |
575 |
< |
if (coef != NULL) *coef = yval; |
575 |
> |
*coef = yval; |
576 |
|
return 1; /* no color */ |
577 |
|
} |
576 |
– |
if (coef == NULL) /* just getting hypercube? */ |
577 |
– |
return 1; |
578 |
|
/* else decode color */ |
579 |
|
SDyuv2rgb(yval, SDlookupTre(sdt->stc[tt_u], gridPos, NULL), |
580 |
|
SDlookupTre(sdt->stc[tt_v], gridPos, NULL), coef); |
789 |
|
for (i = sdt->stc[tt_Y]->ndim - 2; i--; ) |
790 |
|
inCoord[i] = floor(inCoord[i]/quantum)*quantum + .5*quantum; |
791 |
|
cdlast = NULL; /* check for direction in cache list */ |
792 |
+ |
/* PLACE MUTEX LOCK HERE FOR THREAD-SAFE */ |
793 |
|
for (cd = (SDTreCDst *)sdc->cdList; cd != NULL; |
794 |
|
cdlast = cd, cd = cd->next) { |
795 |
|
if (cd->sidef != mode) |
808 |
|
cd->next = (SDTreCDst *)sdc->cdList; |
809 |
|
sdc->cdList = (SDCDst *)cd; |
810 |
|
} |
811 |
+ |
/* END MUTEX LOCK */ |
812 |
|
return (SDCDst *)cd; /* ready to go */ |
813 |
|
} |
814 |
|
|
926 |
|
} |
927 |
|
|
928 |
|
/* Advance pointer past matching token (or any token if c==0) */ |
929 |
< |
#define eat_token(spp,c) (next_token(spp)==(c) ^ !(c) ? *(*(spp))++ : 0) |
929 |
> |
#define eat_token(spp,c) ((next_token(spp)==(c)) ^ !(c) ? *(*(spp))++ : 0) |
930 |
|
|
931 |
|
/* Count words from this point in string to '}' */ |
932 |
|
static int |
1176 |
|
static double |
1177 |
|
subtract_min_Y(SDNode *st) |
1178 |
|
{ |
1179 |
< |
float vmin; |
1179 |
> |
const float vmaxmin = 1.5/M_PI; |
1180 |
> |
float vmin; |
1181 |
|
/* be sure to skip unused portion */ |
1182 |
|
if (st->ndim == 3) { |
1183 |
|
int n; |
1184 |
< |
vmin = 1./M_PI; |
1184 |
> |
vmin = vmaxmin; |
1185 |
|
if (st->log2GR < 0) { |
1186 |
|
for (n = 0; n < 8; n += 2) { |
1187 |
|
float v = SDgetTreMin(st->u.t[n]); |
1197 |
|
} else /* anisotropic covers entire tree */ |
1198 |
|
vmin = SDgetTreMin(st); |
1199 |
|
|
1200 |
< |
if (vmin <= FTINY) |
1201 |
< |
return .0; |
1200 |
> |
if ((vmin >= vmaxmin) | (vmin <= .01/M_PI)) |
1201 |
> |
return .0; /* not worth bothering about */ |
1202 |
|
|
1203 |
|
SDsubtractTreVal(st, vmin); |
1204 |
|
|
1244 |
|
{ |
1245 |
|
SDextRGBs *mp = (SDextRGBs *)cptr; |
1246 |
|
double cmax[SD_MAXDIM]; |
1247 |
+ |
double yval; |
1248 |
|
float rgb[3]; |
1249 |
< |
int ok; |
1249 |
> |
C_COLOR clr; |
1250 |
|
|
1251 |
|
if (mp->stc[tt_Y]->ndim == 3) { |
1252 |
|
if (cmin[0] + .5*csiz >= .5) |
1257 |
|
cmax[1] = cmin[1] + csiz; |
1258 |
|
cmax[2] = cmin[2] + csiz; |
1259 |
|
/* average RGB color over voxel */ |
1260 |
< |
SDyuv2rgb(SDavgTreBox(mp->stc[tt_Y], cmin, cmax), uprime, |
1260 |
> |
SDyuv2rgb(yval=SDavgTreBox(mp->stc[tt_Y], cmin, cmax), uprime, |
1261 |
|
SDavgTreBox(mp->stc[tt_v], cmin, cmax), rgb); |
1262 |
< |
/* subtract minimum */ |
1263 |
< |
ok = (rgb[0] -= mp->rgb[0]) > 1e-5; |
1264 |
< |
ok &= (rgb[1] -= mp->rgb[1]) > 1e-5; |
1265 |
< |
ok &= (rgb[2] -= mp->rgb[2]) > 1e-5; |
1266 |
< |
if (ok) { /* compute new u' for adj. RGB */ |
1267 |
< |
C_COLOR clr; |
1264 |
< |
c_fromSharpRGB(rgb, &clr); |
1265 |
< |
uprime = 4.*clr.cx/(-2.*clr.cx + 12.*clr.cy + 3.); |
1266 |
< |
} else |
1267 |
< |
uprime = 4./3./(-2./3. + 12./3. + 3.); |
1262 |
> |
/* subtract minimum (& clamp) */ |
1263 |
> |
if ((rgb[0] -= mp->rgb[0]) < 1e-5*yval) rgb[0] = 1e-5*yval; |
1264 |
> |
if ((rgb[1] -= mp->rgb[1]) < 1e-5*yval) rgb[1] = 1e-5*yval; |
1265 |
> |
if ((rgb[2] -= mp->rgb[2]) < 1e-5*yval) rgb[2] = 1e-5*yval; |
1266 |
> |
c_fromSharpRGB(rgb, &clr); /* compute new u' for adj. RGB */ |
1267 |
> |
uprime = 4.*clr.cx/(-2.*clr.cx + 12.*clr.cy + 3.); |
1268 |
|
/* assign in new u' tree */ |
1269 |
|
mp->new_stu = SDsetVoxel(mp->new_stu, mp->stc[tt_Y]->ndim, |
1270 |
|
cmin, csiz, uprime); |
1277 |
|
{ |
1278 |
|
SDextRGBs *mp = (SDextRGBs *)cptr; |
1279 |
|
double cmax[SD_MAXDIM]; |
1280 |
+ |
double yval; |
1281 |
|
float rgb[3]; |
1282 |
< |
int ok; |
1282 |
> |
C_COLOR clr; |
1283 |
|
|
1284 |
|
if (mp->stc[tt_Y]->ndim == 3) { |
1285 |
|
if (cmin[0] + .5*csiz >= .5) |
1290 |
|
cmax[1] = cmin[1] + csiz; |
1291 |
|
cmax[2] = cmin[2] + csiz; |
1292 |
|
/* average RGB color over voxel */ |
1293 |
< |
SDyuv2rgb(SDavgTreBox(mp->stc[tt_Y], cmin, cmax), |
1293 |
> |
SDyuv2rgb(yval=SDavgTreBox(mp->stc[tt_Y], cmin, cmax), |
1294 |
|
SDavgTreBox(mp->stc[tt_u], cmin, cmax), |
1295 |
|
vprime, rgb); |
1296 |
< |
/* subtract minimum */ |
1297 |
< |
ok = (rgb[0] -= mp->rgb[0]) > 1e-5; |
1298 |
< |
ok &= (rgb[1] -= mp->rgb[1]) > 1e-5; |
1299 |
< |
ok &= (rgb[2] -= mp->rgb[2]) > 1e-5; |
1300 |
< |
if (ok) { /* compute new v' for adj. RGB */ |
1301 |
< |
C_COLOR clr; |
1301 |
< |
c_fromSharpRGB(rgb, &clr); |
1302 |
< |
vprime = 9.*clr.cy/(-2.*clr.cx + 12.*clr.cy + 3.); |
1303 |
< |
} else |
1304 |
< |
vprime = 9./3./(-2./3. + 12./3. + 3.); |
1296 |
> |
/* subtract minimum (& clamp) */ |
1297 |
> |
if ((rgb[0] -= mp->rgb[0]) < 1e-5*yval) rgb[0] = 1e-5*yval; |
1298 |
> |
if ((rgb[1] -= mp->rgb[1]) < 1e-5*yval) rgb[1] = 1e-5*yval; |
1299 |
> |
if ((rgb[2] -= mp->rgb[2]) < 1e-5*yval) rgb[2] = 1e-5*yval; |
1300 |
> |
c_fromSharpRGB(rgb, &clr); /* compute new v' for adj. RGB */ |
1301 |
> |
vprime = 9.*clr.cy/(-2.*clr.cx + 12.*clr.cy + 3.); |
1302 |
|
/* assign in new v' tree */ |
1303 |
|
mp->new_stv = SDsetVoxel(mp->new_stv, mp->stc[tt_Y]->ndim, |
1304 |
|
cmin, csiz, vprime); |
1317 |
|
my_min.new_stu = my_min.new_stv = NULL; |
1318 |
|
/* get minimum RGB value */ |
1319 |
|
SDtraverseTre(stc[tt_Y], NULL, 0, get_min_RGB, &my_min); |
1320 |
< |
ymin = tt_RGB_coef[0]*my_min.rgb[0] + |
1321 |
< |
tt_RGB_coef[1]*my_min.rgb[1] + |
1322 |
< |
tt_RGB_coef[2]*my_min.rgb[2]; |
1323 |
< |
if (ymin <= 1e-5) { |
1324 |
< |
*cs = c_dfcolor; |
1328 |
< |
return .0; /* not worth bothering about */ |
1329 |
< |
} |
1330 |
< |
/* adjust u' & v' values */ |
1320 |
> |
/* convert to C_COLOR */ |
1321 |
> |
ymin = c_fromSharpRGB(my_min.rgb, cs); |
1322 |
> |
if ((ymin >= .5*FHUGE) | (ymin <= .01/M_PI)) |
1323 |
> |
return .0; /* close to zero or no tree */ |
1324 |
> |
/* adjust u' & v' trees */ |
1325 |
|
SDtraverseTre(stc[tt_u], NULL, 0, adjust_utree, &my_min); |
1326 |
|
SDtraverseTre(stc[tt_v], NULL, 0, adjust_vtree, &my_min); |
1327 |
|
SDfreeTre(stc[tt_u]); SDfreeTre(stc[tt_v]); |
1328 |
|
stc[tt_u] = SDsimplifyTre(my_min.new_stu); |
1329 |
|
stc[tt_v] = SDsimplifyTre(my_min.new_stv); |
1330 |
< |
/* finally, subtract Y value */ |
1330 |
> |
/* subtract Y & return hemispherical */ |
1331 |
|
SDsubtractTreVal(stc[tt_Y], ymin); |
1332 |
< |
/* return color and Y */ |
1333 |
< |
c_fromSharpRGB(my_min.rgb, cs); |
1340 |
< |
return M_PI*ymin; |
1332 |
> |
|
1333 |
> |
return M_PI * ymin; |
1334 |
|
} |
1335 |
|
|
1336 |
|
/* Extract and separate diffuse portion of BSDF */ |
1357 |
|
memcpy(df->comp[0].cspec, tt_RGB_prim, sizeof(tt_RGB_prim)); |
1358 |
|
dv->cieY = subtract_min_RGB(&dv->spec, sdt->stc); |
1359 |
|
} else { |
1360 |
< |
df->comp[0].cspec[0] = c_dfcolor; |
1360 |
> |
df->comp[0].cspec[0] = dv->spec = c_dfcolor; |
1361 |
|
dv->cieY = subtract_min_Y(sdt->stc[tt_Y]); |
1362 |
|
} |
1363 |
|
df->maxHemi -= dv->cieY; /* adjust maximum hemispherical */ |
1422 |
|
} |
1423 |
|
|
1424 |
|
/* Variable resolution BSDF methods */ |
1425 |
< |
SDFunc SDhandleTre = { |
1425 |
> |
const SDFunc SDhandleTre = { |
1426 |
|
&SDgetTreBSDF, |
1427 |
|
&SDqueryTreProjSA, |
1428 |
|
&SDgetTreCDist, |