--- ray/src/common/bsdf_m.c 2012/05/07 23:17:59 3.22 +++ ray/src/common/bsdf_m.c 2013/04/23 17:25:23 3.26 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: bsdf_m.c,v 3.22 2012/05/07 23:17:59 greg Exp $"; +static const char RCSid[] = "$Id: bsdf_m.c,v 3.26 2013/04/23 17:25:23 greg Exp $"; #endif /* * bsdf_m.c @@ -29,21 +29,7 @@ static const char RCSid[] = "$Id: bsdf_m.c,v 3.22 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; @@ -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; @@ -399,7 +385,6 @@ load_bsdf_data(SDData *sd, ezxml_t wdb, int rowinc) SDSpectralDF *df; SDMat *dp; char *sdata; - int tfront; int inbi, outbi; int i; /* allocate BSDF component */ @@ -408,24 +393,27 @@ load_bsdf_data(SDData *sd, ezxml_t wdb, int rowinc) return RC_FAIL; /* * Remember that front and back are reversed from WINDOW 6 orientations - * Favor their "Front" (incoming light) since that's more often valid */ - tfront = !strcasecmp(sdata, "Transmission Back"); - if (!strcasecmp(sdata, "Transmission Front") || - tfront & (sd->tf == NULL)) { + if (!strcasecmp(sdata, "Transmission Front")) { + 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; @@ -467,17 +455,15 @@ load_bsdf_data(SDData *sd, ezxml_t wdb, int rowinc) dp->ib_priv = &abase_list[inbi]; dp->ob_priv = &abase_list[outbi]; if (df == sd->tf) { - if (tfront) { - dp->ib_vec = &fi_getvec; - dp->ib_ndx = &fi_getndx; - dp->ob_vec = &bo_getvec; - dp->ob_ndx = &bo_getndx; - } else { - dp->ib_vec = &bi_getvec; - dp->ib_ndx = &bi_getndx; - dp->ob_vec = &fo_getvec; - dp->ob_ndx = &fo_getndx; - } + dp->ib_vec = &fi_getvec; + dp->ib_ndx = &fi_getndx; + dp->ob_vec = &bo_getvec; + dp->ob_ndx = &bo_getndx; + } else if (df == sd->tb) { + dp->ib_vec = &bi_getvec; + dp->ib_ndx = &bi_getndx; + dp->ob_vec = &fo_getvec; + dp->ob_ndx = &fo_getndx; } else if (df == sd->rf) { dp->ib_vec = &fi_getvec; dp->ib_ndx = &fi_getndx; @@ -616,7 +602,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); + if (sd->tf != NULL) + extract_diffuse(&sd->tLamb, sd->tf); + if (sd->tb != NULL) + extract_diffuse(&sd->tLamb, sd->tb); /* return success */ return SDEnone; }