--- ray/src/common/bsdf.c 2011/06/03 18:12:58 2.29 +++ ray/src/common/bsdf.c 2011/09/17 22:09:33 2.36 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: bsdf.c,v 2.29 2011/06/03 18:12:58 greg Exp $"; +static const char RCSid[] = "$Id: bsdf.c,v 2.36 2011/09/17 22:09:33 greg Exp $"; #endif /* * bsdf.c @@ -10,9 +10,12 @@ static const char RCSid[] = "$Id: bsdf.c,v 2.29 2011/0 * */ +#define _USE_MATH_DEFINES #include #include +#include #include +#include #include "ezxml.h" #include "hilbert.h" #include "bsdf.h" @@ -106,6 +109,10 @@ SDloadGeometry(SDData *sd, ezxml_t wdb) if ((geom = ezxml_child(wdb, "Geometry")) == NULL || (mgfstr = ezxml_txt(geom)) == NULL) return SDEnone; + while (isspace(*mgfstr)) + ++mgfstr; + if (!*mgfstr) + return SDEnone; if ((fmt = ezxml_attr(geom, "format")) != NULL && strcasecmp(fmt, "MGF")) { sprintf(SDerrorDetail, @@ -164,8 +171,10 @@ SDloadFile(SDData *sd, const char *fname) } /* load geometry if present */ lastErr = SDloadGeometry(sd, ezxml_child(wtl, "Material")); - if (lastErr) + if (lastErr) { + ezxml_free(fl); return lastErr; + } /* try loading variable resolution data */ lastErr = SDloadTre(sd, wtl); /* check our result */ @@ -243,7 +252,8 @@ SDfreeSpectralDF(SDSpectralDF *df) return; SDfreeCumulativeCache(df); for (n = df->ncomp; n-- > 0; ) - (*df->comp[n].func->freeSC)(df->comp[n].dist); + if (df->comp[n].dist != NULL) + (*df->comp[n].func->freeSC)(df->comp[n].dist); free(df); } @@ -415,7 +425,7 @@ SDsampComponent(SDValue *sv, FVECT ioVec, double randX cd = (*sdc->func->getCDist)(inVec, sdc); if (cd == NULL) return SDEmemory; - if (cd->cTotal <= 1e-7) { /* anything to sample? */ + if (cd->cTotal <= 1e-6) { /* anything to sample? */ sv->spec = c_dfcolor; sv->cieY = .0; memset(ioVec, 0, 3*sizeof(double)); @@ -677,7 +687,7 @@ SDsampBSDF(SDValue *sv, FVECT ioVec, double randX, int } sv->cieY += cdarr[i]->cTotal; } - if (sv->cieY <= 1e-7) { /* anything to sample? */ + if (sv->cieY <= 1e-6) { /* anything to sample? */ sv->cieY = .0; memset(ioVec, 0, 3*sizeof(double)); return SDEnone; @@ -807,7 +817,6 @@ SDmapDir(FVECT resVec, RREAL vMtx[3][3], const FVECT i #include "standard.h" #include "paths.h" -#include #define MAXLATS 46 /* maximum number of latitudes */ @@ -927,7 +936,7 @@ ab_getndx( /* get index corresponding to the given ve { ANGLE_BASIS *ab = (ANGLE_BASIS *)p; int li, ndx; - double pol, azi, d; + double pol, azi; if ((v[2] < -1.0) | (v[2] > 1.0)) return(-1); @@ -1167,7 +1176,7 @@ check_bsdf_data( /* check that BSDF data is sane */ ) { double *omega_iarr, *omega_oarr; - double dom, contrib, hemi_total, full_total; + double dom, hemi_total, full_total; int nneg; FVECT v; int i, o; @@ -1317,9 +1326,11 @@ load_BSDF( /* load BSDF data from file */ error(WARNING, errmsg); ezxml_free(fl); return(NULL); - } - load_angle_basis(ezxml_child(ezxml_child(wtl, - "DataDefinition"), "AngleBasis")); + } + for (wld = ezxml_child(ezxml_child(wtl, + "DataDefinition"), "AngleBasis"); + wld != NULL; wld = wld->next) + load_angle_basis(wld); dp = (struct BSDF_data *)calloc(1, sizeof(struct BSDF_data)); load_geometry(dp, ezxml_child(wtl, "Material")); for (wld = ezxml_child(wtl, "WavelengthData");