--- ray/src/common/bsdf.c 2011/04/24 19:39:21 2.24 +++ ray/src/common/bsdf.c 2011/06/28 21:11:04 2.33 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: bsdf.c,v 2.24 2011/04/24 19:39:21 greg Exp $"; +static const char RCSid[] = "$Id: bsdf.c,v 2.33 2011/06/28 21:11:04 greg Exp $"; #endif /* * bsdf.c @@ -10,9 +10,12 @@ static const char RCSid[] = "$Id: bsdf.c,v 2.24 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, @@ -169,15 +176,9 @@ SDloadFile(SDData *sd, const char *fname) /* try loading variable resolution data */ lastErr = SDloadTre(sd, wtl); /* check our result */ - switch (lastErr) { - case SDEformat: - case SDEdata: - case SDEsupport: /* possibly we just tried the wrong format */ + if (lastErr == SDEsupport) /* try matrix BSDF if not tree data */ lastErr = SDloadMtx(sd, wtl); - break; - default: /* variable res. OK else serious error */ - break; - } + /* done with XML file */ ezxml_free(fl); @@ -433,7 +434,7 @@ SDsampComponent(SDValue *sv, FVECT ioVec, double randX if (ec) return ec; /* get BSDF color */ - n = (*sdc->func->getBSDFs)(coef, ioVec, inVec, sdc->dist); + n = (*sdc->func->getBSDFs)(coef, ioVec, inVec, sdc); if (n <= 0) { strcpy(SDerrorDetail, "BSDF sample value error"); return SDEinternal; @@ -496,7 +497,7 @@ SDsizeBSDF(double *projSA, const FVECT v1, const RREAL SDError ec; int i; /* check arguments */ - if ((projSA == NULL) | (v1 == NULL)) + if ((projSA == NULL) | (v1 == NULL) | (sd == NULL)) return SDEargument; /* initialize extrema */ switch (qflags) { @@ -516,21 +517,22 @@ SDsizeBSDF(double *projSA, const FVECT v1, const RREAL rdf = sd->rf; else rdf = sd->rb; - tdf = NULL; /* transmitted component? */ - if (v2 != NULL && v1[2] > 0 ^ v2[2] > 0) { - rdf = NULL; - tdf = sd->tf; - } + tdf = sd->tf; + if (v2 != NULL) /* bidirectional? */ + if (v1[2] > 0 ^ v2[2] > 0) + rdf = NULL; + else + tdf = NULL; ec = SDEdata; /* run through components */ for (i = (rdf==NULL) ? 0 : rdf->ncomp; i--; ) { ec = (*rdf->comp[i].func->queryProjSA)(projSA, v1, v2, - qflags, rdf->comp[i].dist); + qflags, &rdf->comp[i]); if (ec) return ec; } for (i = (tdf==NULL) ? 0 : tdf->ncomp; i--; ) { ec = (*tdf->comp[i].func->queryProjSA)(projSA, v1, v2, - qflags, tdf->comp[i].dist); + qflags, &tdf->comp[i]); if (ec) return ec; } @@ -572,7 +574,7 @@ SDevalBSDF(SDValue *sv, const FVECT outVec, const FVEC i = (sdf != NULL) ? sdf->ncomp : 0; while (i-- > 0) { nch = (*sdf->comp[i].func->getBSDFs)(coef, outVec, inVec, - sdf->comp[i].dist); + &sdf->comp[i]); while (nch-- > 0) { c_cmix(&sv->spec, sv->cieY, &sv->spec, coef[nch], &sdf->comp[i].cspec[nch]); @@ -715,7 +717,7 @@ SDsampBSDF(SDValue *sv, FVECT ioVec, double randX, int if (ec) return ec; /* compute color */ - j = (*sdc->func->getBSDFs)(coef, ioVec, inVec, sdc->dist); + j = (*sdc->func->getBSDFs)(coef, ioVec, inVec, sdc); if (j <= 0) { sprintf(SDerrorDetail, "BSDF \"%s\" sampling value error", sd->name); @@ -812,7 +814,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 */ @@ -932,7 +933,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); @@ -1172,7 +1173,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;