--- ray/src/util/dctimestep.c 2009/06/20 04:37:43 2.6 +++ ray/src/util/dctimestep.c 2009/12/09 20:33:48 2.11 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: dctimestep.c,v 2.6 2009/06/20 04:37:43 greg Exp $"; +static const char RCSid[] = "$Id: dctimestep.c,v 2.11 2009/12/09 20:33:48 greg Exp $"; #endif /* * Compute time-step result using Daylight Coefficient method. @@ -38,7 +38,7 @@ cm_alloc(int nrows, int ncols) CMATRIX *cm; if ((nrows <= 0) | (ncols <= 0)) - return(NULL); + error(USER, "attempt to create empty matrix"); cm = (CMATRIX *)malloc(sizeof(CMATRIX) + 3*sizeof(COLORV)*(nrows*ncols - 1)); if (cm == NULL) @@ -294,30 +294,33 @@ static CMATRIX * cm_bsdf(const struct BSDF_data *bsdf) { CMATRIX *cm = cm_alloc(bsdf->nout, bsdf->ninc); - COLORV *mp = cm->cmem; int nbadohm = 0; int nneg = 0; int r, c; - for (r = 0; r < cm->nrows; r++) - for (c = 0; c < cm->ncols; c++, mp += 3) { + for (c = 0; c < cm->ncols; c++) { + float dom = getBSDF_incohm(bsdf,c); + FVECT v; + + if (dom <= .0) { + nbadohm++; + continue; + } + if (!getBSDF_incvec(v,bsdf,c) || v[2] > FTINY) + error(USER, "illegal incoming BTDF direction"); + dom *= -v[2]; + + for (r = 0; r < cm->nrows; r++) { float f = BSDF_value(bsdf,c,r); - float dom = getBSDF_incohm(bsdf,c); - FVECT v; - + COLORV *mp = cm_lval(cm,r,c); + if (f <= .0) { nneg += (f < -FTINY); - continue; + f = .0f; } - if (dom <= .0) { - nbadohm++; - continue; - } - if (!getBSDF_incvec(v,bsdf,c) || v[2] > FTINY) - error(USER, "illegal incoming BTDF direction"); - - mp[0] = mp[1] = mp[2] = f * dom * -v[2]; + mp[0] = mp[1] = mp[2] = f * dom; } + } if (nneg || nbadohm) { sprintf(errmsg, "BTDF has %d negatives and %d bad incoming solid angles", @@ -401,9 +404,9 @@ sum_images(const char *fspec, const CMATRIX *cv) return(fflush(stdout) == 0); } -/* check to see if a string contains a %d specification */ -int -hasDecimalSpec(const char *s) +/* check to see if a string contains a %d or %o specification */ +static int +hasNumberFormat(const char *s) { while (*s && *s != '%') s++; @@ -413,7 +416,7 @@ hasDecimalSpec(const char *s) ++s; while (isdigit(*s)); - return(*s == 'd'); + return(*s == 'd' | *s == 'i' | *s == 'o' | *s == 'x' | *s == 'X'); } int @@ -444,7 +447,7 @@ main(int argc, char *argv[]) free_BSDF(btdf); cvec = cm_multiply(Tmat, ivec); /* cvec = component vector */ cm_free(Tmat); cm_free(ivec); - if (hasDecimalSpec(argv[1])) { /* generating image */ + if (hasNumberFormat(argv[1])) { /* generating image */ SET_FILE_BINARY(stdout); newheader("RADIANCE", stdout); printargs(argc, argv, stdout);