| 92 |
|
|
| 93 |
|
if (wdb == NULL) /* no geometry section? */ |
| 94 |
|
return SDEnone; |
| 95 |
+ |
if ((geom = ezxml_child(wdb, "Name")) != NULL) { |
| 96 |
+ |
strncpy(sd->matn, ezxml_txt(geom), SDnameLn); |
| 97 |
+ |
sd->matn[SDnameLn-1] = '\0'; |
| 98 |
+ |
} |
| 99 |
+ |
if ((geom = ezxml_child(wdb, "Manufacturer")) != NULL) { |
| 100 |
+ |
strncpy(sd->makr, ezxml_txt(geom), SDnameLn); |
| 101 |
+ |
sd->makr[SDnameLn-1] = '\0'; |
| 102 |
+ |
} |
| 103 |
|
sd->dim[0] = sd->dim[1] = sd->dim[2] = .0; |
| 104 |
+ |
SDerrorDetail[0] = '\0'; |
| 105 |
|
if ((geom = ezxml_child(wdb, "Width")) != NULL) |
| 106 |
|
sd->dim[0] = atof(ezxml_txt(geom)) * |
| 107 |
|
to_meters(ezxml_attr(geom, "unit")); |
| 112 |
|
sd->dim[2] = atof(ezxml_txt(geom)) * |
| 113 |
|
to_meters(ezxml_attr(geom, "unit")); |
| 114 |
|
if ((sd->dim[0] < 0) | (sd->dim[1] < 0) | (sd->dim[2] < 0)) { |
| 115 |
< |
sprintf(SDerrorDetail, "Negative size in \"%s\"", sd->name); |
| 115 |
> |
if (!SDerrorDetail[0]) |
| 116 |
> |
sprintf(SDerrorDetail, "Negative dimension in \"%s\"", |
| 117 |
> |
sd->name); |
| 118 |
|
return SDEdata; |
| 119 |
|
} |
| 120 |
|
if ((geom = ezxml_child(wdb, "Geometry")) == NULL || |
| 132 |
|
return SDEsupport; |
| 133 |
|
} |
| 134 |
|
cfact = to_meters(ezxml_attr(geom, "unit")); |
| 135 |
+ |
if (cfact <= 0) |
| 136 |
+ |
return SDEformat; |
| 137 |
|
sd->mgf = (char *)malloc(strlen(mgfstr)+32); |
| 138 |
|
if (sd->mgf == NULL) { |
| 139 |
|
strcpy(SDerrorDetail, "Out of memory in SDloadGeometry"); |
| 177 |
|
} |
| 178 |
|
wtl = ezxml_child(ezxml_child(fl, "Optical"), "Layer"); |
| 179 |
|
if (wtl == NULL) { |
| 180 |
< |
sprintf(SDerrorDetail, "BSDF \"%s\": no optical layer'", |
| 180 |
> |
sprintf(SDerrorDetail, "BSDF \"%s\": no optical layers'", |
| 181 |
|
sd->name); |
| 182 |
|
ezxml_free(fl); |
| 183 |
|
return SDEformat; |
| 184 |
|
} |
| 185 |
|
/* load geometry if present */ |
| 186 |
|
lastErr = SDloadGeometry(sd, ezxml_child(wtl, "Material")); |
| 187 |
< |
if (lastErr) |
| 187 |
> |
if (lastErr) { |
| 188 |
> |
ezxml_free(fl); |
| 189 |
|
return lastErr; |
| 190 |
+ |
} |
| 191 |
|
/* try loading variable resolution data */ |
| 192 |
|
lastErr = SDloadTre(sd, wtl); |
| 193 |
|
/* check our result */ |
| 239 |
|
return df; |
| 240 |
|
} |
| 241 |
|
|
| 242 |
+ |
/* Add component(s) to spectral distribution function */ |
| 243 |
+ |
SDSpectralDF * |
| 244 |
+ |
SDaddComponent(SDSpectralDF *odf, int nadd) |
| 245 |
+ |
{ |
| 246 |
+ |
SDSpectralDF *df; |
| 247 |
+ |
|
| 248 |
+ |
if (odf == NULL) |
| 249 |
+ |
return SDnewSpectralDF(nadd); |
| 250 |
+ |
if (nadd <= 0) |
| 251 |
+ |
return odf; |
| 252 |
+ |
df = (SDSpectralDF *)realloc(odf, sizeof(SDSpectralDF) + |
| 253 |
+ |
(odf->ncomp+nadd-1)*sizeof(SDComponent)); |
| 254 |
+ |
if (df == NULL) { |
| 255 |
+ |
sprintf(SDerrorDetail, |
| 256 |
+ |
"Cannot add %d component(s) to spectral DF", nadd); |
| 257 |
+ |
SDfreeSpectralDF(odf); |
| 258 |
+ |
return NULL; |
| 259 |
+ |
} |
| 260 |
+ |
memset(df->comp+df->ncomp, 0, nadd*sizeof(SDComponent)); |
| 261 |
+ |
df->ncomp += nadd; |
| 262 |
+ |
return df; |
| 263 |
+ |
} |
| 264 |
+ |
|
| 265 |
|
/* Free cached cumulative distributions for BSDF component */ |
| 266 |
|
void |
| 267 |
|
SDfreeCumulativeCache(SDSpectralDF *df) |
| 288 |
|
return; |
| 289 |
|
SDfreeCumulativeCache(df); |
| 290 |
|
for (n = df->ncomp; n-- > 0; ) |
| 291 |
< |
(*df->comp[n].func->freeSC)(df->comp[n].dist); |
| 291 |
> |
if (df->comp[n].dist != NULL) |
| 292 |
> |
(*df->comp[n].func->freeSC)(df->comp[n].dist); |
| 293 |
|
free(df); |
| 294 |
|
} |
| 295 |
|
|
| 461 |
|
cd = (*sdc->func->getCDist)(inVec, sdc); |
| 462 |
|
if (cd == NULL) |
| 463 |
|
return SDEmemory; |
| 464 |
< |
if (cd->cTotal <= 1e-7) { /* anything to sample? */ |
| 464 |
> |
if (cd->cTotal <= 1e-6) { /* anything to sample? */ |
| 465 |
|
sv->spec = c_dfcolor; |
| 466 |
|
sv->cieY = .0; |
| 467 |
|
memset(ioVec, 0, 3*sizeof(double)); |
| 723 |
|
} |
| 724 |
|
sv->cieY += cdarr[i]->cTotal; |
| 725 |
|
} |
| 726 |
< |
if (sv->cieY <= 1e-7) { /* anything to sample? */ |
| 726 |
> |
if (sv->cieY <= 1e-6) { /* anything to sample? */ |
| 727 |
|
sv->cieY = .0; |
| 728 |
|
memset(ioVec, 0, 3*sizeof(double)); |
| 729 |
|
return SDEnone; |
| 1362 |
|
error(WARNING, errmsg); |
| 1363 |
|
ezxml_free(fl); |
| 1364 |
|
return(NULL); |
| 1365 |
< |
} |
| 1366 |
< |
load_angle_basis(ezxml_child(ezxml_child(wtl, |
| 1367 |
< |
"DataDefinition"), "AngleBasis")); |
| 1365 |
> |
} |
| 1366 |
> |
for (wld = ezxml_child(ezxml_child(wtl, |
| 1367 |
> |
"DataDefinition"), "AngleBasis"); |
| 1368 |
> |
wld != NULL; wld = wld->next) |
| 1369 |
> |
load_angle_basis(wld); |
| 1370 |
|
dp = (struct BSDF_data *)calloc(1, sizeof(struct BSDF_data)); |
| 1371 |
|
load_geometry(dp, ezxml_child(wtl, "Material")); |
| 1372 |
|
for (wld = ezxml_child(wtl, "WavelengthData"); |