--- ray/src/common/bsdf_m.c 2012/09/02 15:33:15 3.23 +++ ray/src/common/bsdf_m.c 2014/03/21 17:49:53 3.28 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: bsdf_m.c,v 3.23 2012/09/02 15:33:15 greg Exp $"; +static const char RCSid[] = "$Id: bsdf_m.c,v 3.28 2014/03/21 17:49:53 greg Exp $"; #endif /* * bsdf_m.c @@ -29,21 +29,7 @@ static const char RCSid[] = "$Id: bsdf_m.c,v 3.23 2012 #define RC_INTERR (-4) #define RC_MEMERR (-5) -#define MAXLATS 46 /* maximum number of latitudes */ - -/* BSDF angle specification */ -typedef struct { - char name[64]; /* basis name */ - int nangles; /* total number of directions */ - struct { - float tmin; /* starting theta */ - int nphis; /* number of phis (0 term) */ - } lat[MAXLATS+1]; /* latitudes */ -} ANGLE_BASIS; - -#define MAXABASES 7 /* limit on defined bases */ - -static ANGLE_BASIS abase_list[MAXABASES] = { +ANGLE_BASIS abase_list[MAXABASES] = { { "LBNL/Klems Full", 145, { {0., 1}, @@ -77,7 +63,7 @@ static ANGLE_BASIS abase_list[MAXABASES] = { } }; -static int nabases = 3; /* current number of defined bases */ +int nabases = 3; /* current number of defined bases */ static int fequal(double a, double b) @@ -146,8 +132,8 @@ SDnewMatrix(int ni, int no) /* Free a BSDF matrix */ #define SDfreeMatrix free -/* get vector for this angle basis index (front exiting) */ -static int +/* Get vector for this angle basis index (front exiting) */ +int fo_getvec(FVECT v, double ndxr, void *p) { ANGLE_BASIS *ab = (ANGLE_BASIS *)p; @@ -172,8 +158,8 @@ fo_getvec(FVECT v, double ndxr, void *p) return RC_GOOD; } -/* get index corresponding to the given vector (front exiting) */ -static int +/* Get index corresponding to the given vector (front exiting) */ +int fo_getndx(const FVECT v, void *p) { ANGLE_BASIS *ab = (ANGLE_BASIS *)p; @@ -184,7 +170,7 @@ fo_getndx(const FVECT v, void *p) return -1; if ((v[2] < 0) | (v[2] > 1.)) return -1; - pol = 180.0/M_PI*acos(v[2]); + pol = 180.0/M_PI*Acos(v[2]); azi = 180.0/M_PI*atan2(v[1], v[0]); if (azi < 0.0) azi += 360.0; for (li = 1; ab->lat[li].tmin <= pol; li++) @@ -201,8 +187,8 @@ fo_getndx(const FVECT v, void *p) /* compute square of real value */ static double sq(double x) { return x*x; } -/* get projected solid angle for this angle basis index (universal) */ -static double +/* Get projected solid angle for this angle basis index (universal) */ +double io_getohm(int ndx, void *p) { static int last_li = -1; @@ -224,8 +210,8 @@ io_getohm(int ndx, void *p) (double)ab->lat[li].nphis; } -/* get vector for this angle basis index (back incident) */ -static int +/* Get vector for this angle basis index (back incident) */ +int bi_getvec(FVECT v, double ndxr, void *p) { if (!fo_getvec(v, ndxr, p)) @@ -238,8 +224,8 @@ bi_getvec(FVECT v, double ndxr, void *p) return RC_GOOD; } -/* get index corresponding to the vector (back incident) */ -static int +/* Get index corresponding to the vector (back incident) */ +int bi_getndx(const FVECT v, void *p) { FVECT v2; @@ -251,8 +237,8 @@ bi_getndx(const FVECT v, void *p) return fo_getndx(v2, p); } -/* get vector for this angle basis index (back exiting) */ -static int +/* Get vector for this angle basis index (back exiting) */ +int bo_getvec(FVECT v, double ndxr, void *p) { if (!fo_getvec(v, ndxr, p)) @@ -263,8 +249,8 @@ bo_getvec(FVECT v, double ndxr, void *p) return RC_GOOD; } -/* get index corresponding to the vector (back exiting) */ -static int +/* Get index corresponding to the vector (back exiting) */ +int bo_getndx(const FVECT v, void *p) { FVECT v2; @@ -276,8 +262,8 @@ bo_getndx(const FVECT v, void *p) return fo_getndx(v2, p); } -/* get vector for this angle basis index (front incident) */ -static int +/* Get vector for this angle basis index (front incident) */ +int fi_getvec(FVECT v, double ndxr, void *p) { if (!fo_getvec(v, ndxr, p)) @@ -289,8 +275,8 @@ fi_getvec(FVECT v, double ndxr, void *p) return RC_GOOD; } -/* get index corresponding to the vector (front incident) */ -static int +/* Get index corresponding to the vector (front incident) */ +int fi_getndx(const FVECT v, void *p) { FVECT v2; @@ -409,25 +395,25 @@ load_bsdf_data(SDData *sd, ezxml_t wdb, int rowinc) * Remember that front and back are reversed from WINDOW 6 orientations */ if (!strcasecmp(sdata, "Transmission Front")) { - if (sd->tf != NULL) - SDfreeSpectralDF(sd->tf); - if ((sd->tf = SDnewSpectralDF(1)) == NULL) - return RC_MEMERR; - df = sd->tf; - } else if (!strcasecmp(sdata, "Transmission Back")) { if (sd->tb != NULL) SDfreeSpectralDF(sd->tb); if ((sd->tb = SDnewSpectralDF(1)) == NULL) return RC_MEMERR; df = sd->tb; + } else if (!strcasecmp(sdata, "Transmission Back")) { + if (sd->tf != NULL) + SDfreeSpectralDF(sd->tf); + if ((sd->tf = SDnewSpectralDF(1)) == NULL) + return RC_MEMERR; + df = sd->tf; } else if (!strcasecmp(sdata, "Reflection Front")) { - if (sd->rb != NULL) /* note back-front reversal */ + if (sd->rb != NULL) SDfreeSpectralDF(sd->rb); if ((sd->rb = SDnewSpectralDF(1)) == NULL) return RC_MEMERR; df = sd->rb; } else if (!strcasecmp(sdata, "Reflection Back")) { - if (sd->rf != NULL) /* note front-back reversal */ + if (sd->rf != NULL) SDfreeSpectralDF(sd->rf); if ((sd->rf = SDnewSpectralDF(1)) == NULL) return RC_MEMERR; @@ -502,7 +488,8 @@ load_bsdf_data(SDData *sd, ezxml_t wdb, int rowinc) return RC_FORMERR; } for (i = 0; i < dp->ninc*dp->nout; i++) { - char *sdnext = fskip(sdata); + char *sdnext = fskip(sdata); + double val; if (sdnext == NULL) { sprintf(SDerrorDetail, "Bad/missing BSDF ScatteringData in '%s'", @@ -512,12 +499,14 @@ load_bsdf_data(SDData *sd, ezxml_t wdb, int rowinc) while (isspace(*sdnext)) sdnext++; if (*sdnext == ',') sdnext++; + if ((val = atof(sdata)) < 0) + val = 0; /* don't allow negative values */ if (rowinc) { int r = i/dp->nout; int c = i - r*dp->nout; - mBSDF_value(dp,r,c) = atof(sdata); + mBSDF_value(dp,r,c) = val; } else - dp->bsdf[i] = atof(sdata); + dp->bsdf[i] = val; sdata = sdnext; } return get_extrema(df); @@ -616,7 +605,10 @@ SDloadMtx(SDData *sd, ezxml_t wtl) /* separate diffuse components */ extract_diffuse(&sd->rLambFront, sd->rf); extract_diffuse(&sd->rLambBack, sd->rb); - extract_diffuse(&sd->tLamb, (sd->tf != NULL) ? sd->tf : sd->tb); + if (sd->tf != NULL) + extract_diffuse(&sd->tLamb, sd->tf); + if (sd->tb != NULL) + extract_diffuse(&sd->tLamb, sd->tb); /* return success */ return SDEnone; }