--- ray/src/util/dctimestep.c 2009/06/20 04:27:18 2.5 +++ 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.5 2009/06/20 04:27:18 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) @@ -160,12 +160,12 @@ cm_load(const char *fname, int nrows, int ncols, int d int maxrow = (nrows > 0 ? nrows : 32000); int r, c; for (r = 0; r < maxrow; r++) { - if (r >= cm->nrows) /* need more space? */ + if (r >= cm->nrows) /* need more space? */ cm = cm_resize(cm, 2*cm->nrows); for (c = 0; c < ncols; c++) { COLORV *cv = cm_lval(cm,r,c); if (fscanf(fp, COLSPEC, cv, cv+1, cv+2) != 3) - if ((nrows <= 0) & (r > 0) & (c == 0)) { + if ((nrows <= 0) & (r > 0) & !c) { cm = cm_resize(cm, maxrow=r); break; } else @@ -193,7 +193,7 @@ cm_load(const char *fname, int nrows, int ncols, int d if (nread == cm->nrows*cm->ncols) /* need more space? */ cm = cm_resize(cm, 2*cm->nrows); - else if (nread % cm->ncols == 0) + else if (nread && !(nread % cm->ncols)) /* seem to be done */ cm = cm_resize(cm, nread/cm->ncols); else /* ended mid-row */ @@ -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);