| 10 |
|
* |
| 11 |
|
*/ |
| 12 |
|
|
| 13 |
+ |
#define _USE_MATH_DEFINES |
| 14 |
|
#include <stdio.h> |
| 15 |
|
#include <stdlib.h> |
| 16 |
+ |
#include <string.h> |
| 17 |
|
#include <math.h> |
| 18 |
+ |
#include <ctype.h> |
| 19 |
|
#include "ezxml.h" |
| 20 |
|
#include "hilbert.h" |
| 21 |
|
#include "bsdf.h" |
| 109 |
|
if ((geom = ezxml_child(wdb, "Geometry")) == NULL || |
| 110 |
|
(mgfstr = ezxml_txt(geom)) == NULL) |
| 111 |
|
return SDEnone; |
| 112 |
+ |
while (isspace(*mgfstr)) |
| 113 |
+ |
++mgfstr; |
| 114 |
+ |
if (!*mgfstr) |
| 115 |
+ |
return SDEnone; |
| 116 |
|
if ((fmt = ezxml_attr(geom, "format")) != NULL && |
| 117 |
|
strcasecmp(fmt, "MGF")) { |
| 118 |
|
sprintf(SDerrorDetail, |
| 171 |
|
} |
| 172 |
|
/* load geometry if present */ |
| 173 |
|
lastErr = SDloadGeometry(sd, ezxml_child(wtl, "Material")); |
| 174 |
< |
if (lastErr) |
| 174 |
> |
if (lastErr) { |
| 175 |
> |
ezxml_free(fl); |
| 176 |
|
return lastErr; |
| 177 |
+ |
} |
| 178 |
|
/* try loading variable resolution data */ |
| 179 |
|
lastErr = SDloadTre(sd, wtl); |
| 180 |
|
/* check our result */ |
| 181 |
< |
switch (lastErr) { |
| 173 |
< |
case SDEformat: |
| 174 |
< |
case SDEdata: |
| 175 |
< |
case SDEsupport: /* possibly we just tried the wrong format */ |
| 181 |
> |
if (lastErr == SDEsupport) /* try matrix BSDF if not tree data */ |
| 182 |
|
lastErr = SDloadMtx(sd, wtl); |
| 183 |
< |
break; |
| 178 |
< |
default: /* variable res. OK else serious error */ |
| 179 |
< |
break; |
| 180 |
< |
} |
| 183 |
> |
|
| 184 |
|
/* done with XML file */ |
| 185 |
|
ezxml_free(fl); |
| 186 |
|
|
| 226 |
|
return df; |
| 227 |
|
} |
| 228 |
|
|
| 229 |
+ |
/* Add component(s) to spectral distribution function */ |
| 230 |
+ |
SDSpectralDF * |
| 231 |
+ |
SDaddComponent(SDSpectralDF *odf, int nadd) |
| 232 |
+ |
{ |
| 233 |
+ |
SDSpectralDF *df; |
| 234 |
+ |
|
| 235 |
+ |
if (odf == NULL) |
| 236 |
+ |
return SDnewSpectralDF(nadd); |
| 237 |
+ |
if (nadd <= 0) |
| 238 |
+ |
return odf; |
| 239 |
+ |
df = (SDSpectralDF *)realloc(odf, sizeof(SDSpectralDF) + |
| 240 |
+ |
(odf->ncomp+nadd-1)*sizeof(SDComponent)); |
| 241 |
+ |
if (df == NULL) { |
| 242 |
+ |
sprintf(SDerrorDetail, |
| 243 |
+ |
"Cannot add %d component(s) to spectral DF", nadd); |
| 244 |
+ |
SDfreeSpectralDF(odf); |
| 245 |
+ |
return NULL; |
| 246 |
+ |
} |
| 247 |
+ |
memset(df->comp+df->ncomp, 0, nadd*sizeof(SDComponent)); |
| 248 |
+ |
df->ncomp += nadd; |
| 249 |
+ |
return df; |
| 250 |
+ |
} |
| 251 |
+ |
|
| 252 |
|
/* Free cached cumulative distributions for BSDF component */ |
| 253 |
|
void |
| 254 |
|
SDfreeCumulativeCache(SDSpectralDF *df) |
| 275 |
|
return; |
| 276 |
|
SDfreeCumulativeCache(df); |
| 277 |
|
for (n = df->ncomp; n-- > 0; ) |
| 278 |
< |
(*df->comp[n].func->freeSC)(df->comp[n].dist); |
| 278 |
> |
if (df->comp[n].dist != NULL) |
| 279 |
> |
(*df->comp[n].func->freeSC)(df->comp[n].dist); |
| 280 |
|
free(df); |
| 281 |
|
} |
| 282 |
|
|
| 448 |
|
cd = (*sdc->func->getCDist)(inVec, sdc); |
| 449 |
|
if (cd == NULL) |
| 450 |
|
return SDEmemory; |
| 451 |
< |
if (cd->cTotal <= 1e-7) { /* anything to sample? */ |
| 451 |
> |
if (cd->cTotal <= 1e-6) { /* anything to sample? */ |
| 452 |
|
sv->spec = c_dfcolor; |
| 453 |
|
sv->cieY = .0; |
| 454 |
|
memset(ioVec, 0, 3*sizeof(double)); |
| 710 |
|
} |
| 711 |
|
sv->cieY += cdarr[i]->cTotal; |
| 712 |
|
} |
| 713 |
< |
if (sv->cieY <= 1e-7) { /* anything to sample? */ |
| 713 |
> |
if (sv->cieY <= 1e-6) { /* anything to sample? */ |
| 714 |
|
sv->cieY = .0; |
| 715 |
|
memset(ioVec, 0, 3*sizeof(double)); |
| 716 |
|
return SDEnone; |
| 840 |
|
|
| 841 |
|
#include "standard.h" |
| 842 |
|
#include "paths.h" |
| 816 |
– |
#include <ctype.h> |
| 843 |
|
|
| 844 |
|
#define MAXLATS 46 /* maximum number of latitudes */ |
| 845 |
|
|
| 959 |
|
{ |
| 960 |
|
ANGLE_BASIS *ab = (ANGLE_BASIS *)p; |
| 961 |
|
int li, ndx; |
| 962 |
< |
double pol, azi, d; |
| 962 |
> |
double pol, azi; |
| 963 |
|
|
| 964 |
|
if ((v[2] < -1.0) | (v[2] > 1.0)) |
| 965 |
|
return(-1); |
| 1199 |
|
) |
| 1200 |
|
{ |
| 1201 |
|
double *omega_iarr, *omega_oarr; |
| 1202 |
< |
double dom, contrib, hemi_total, full_total; |
| 1202 |
> |
double dom, hemi_total, full_total; |
| 1203 |
|
int nneg; |
| 1204 |
|
FVECT v; |
| 1205 |
|
int i, o; |
| 1349 |
|
error(WARNING, errmsg); |
| 1350 |
|
ezxml_free(fl); |
| 1351 |
|
return(NULL); |
| 1352 |
< |
} |
| 1353 |
< |
load_angle_basis(ezxml_child(ezxml_child(wtl, |
| 1354 |
< |
"DataDefinition"), "AngleBasis")); |
| 1352 |
> |
} |
| 1353 |
> |
for (wld = ezxml_child(ezxml_child(wtl, |
| 1354 |
> |
"DataDefinition"), "AngleBasis"); |
| 1355 |
> |
wld != NULL; wld = wld->next) |
| 1356 |
> |
load_angle_basis(wld); |
| 1357 |
|
dp = (struct BSDF_data *)calloc(1, sizeof(struct BSDF_data)); |
| 1358 |
|
load_geometry(dp, ezxml_child(wtl, "Material")); |
| 1359 |
|
for (wld = ezxml_child(wtl, "WavelengthData"); |