--- ray/src/util/dctimestep.c 2011/04/08 18:13:48 2.15 +++ ray/src/util/dctimestep.c 2012/02/21 20:09:25 2.19 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: dctimestep.c,v 2.15 2011/04/08 18:13:48 greg Exp $"; +static const char RCSid[] = "$Id: dctimestep.c,v 2.19 2012/02/21 20:09:25 greg Exp $"; #endif /* * Compute time-step result using Daylight Coefficient method. @@ -297,66 +297,29 @@ cm_print(const CMATRIX *cm, FILE *fp) static CMATRIX * cm_bsdf(const COLOR bsdfLamb, const COLOR specCol, const SDMat *bsdf) { - CMATRIX *cm; + CMATRIX *cm = cm_alloc(bsdf->nout, bsdf->ninc); int nbadohm = 0; int nneg = 0; - FVECT v; - float dom; - int doforward; int r, c; + /* reciprocity is "transparent" */ + for (c = 0; c < cm->ncols; c++) { + const double dom = mBSDF_incohm(bsdf,c); + /* projected solid angle */ + nbadohm += (dom <= 0); - mBSDF_incvec(v, bsdf, .5); /* check BTDF orientation */ - - if (v[2] < 0) { /* incident from outside */ - cm = cm_alloc(bsdf->nout, bsdf->ninc); - for (c = 0; c < cm->ncols; c++) { - dom = mBSDF_incohm(bsdf,c); - - nbadohm += (dom <= 0); - - if (!mBSDF_incvec(v,bsdf,c+.5) || v[2] > 0) - error(USER, "illegal incoming BTDF direction"); - dom *= -v[2]; - - for (r = 0; r < cm->nrows; r++) { - float f = mBSDF_value(bsdf,c,r); - COLORV *mp = cm_lval(cm,r,c); - - if ((f <= 0) | (dom <= 0)) { - nneg += (f < -FTINY); - f = .0f; - } - copycolor(mp, specCol); - f *= dom; - scalecolor(mp, f); - addcolor(mp, bsdfLamb); + for (r = 0; r < cm->nrows; r++) { + float f = mBSDF_value(bsdf,c,r); + COLORV *mp = cm_lval(cm,r,c); + /* check BSDF value */ + if ((f <= 0) | (dom <= 0)) { + nneg += (f < -FTINY); + f = .0f; } + copycolor(mp, specCol); + scalecolor(mp, f); + addcolor(mp, bsdfLamb); + scalecolor(mp, dom); } - } else { /* rely on reciprocity */ - cm = cm_alloc(bsdf->ninc, bsdf->nout); - for (c = 0; c < cm->ncols; c++) { - dom = mBSDF_outohm(bsdf,c); - - nbadohm += (dom <= 0); - - if (!mBSDF_outvec(v,bsdf,c+.5) || v[2] > 0) - error(USER, "illegal outgoing BTDF direction"); - dom *= -v[2]; - - for (r = 0; r < cm->nrows; r++) { - float f = mBSDF_value(bsdf,r,c); - COLORV *mp = cm_lval(cm,r,c); - - if ((f <= 0) | (dom <= 0)) { - nneg += (f < -FTINY); - f = .0f; - } - copycolor(mp, specCol); - f *= dom; - scalecolor(mp, f); - addcolor(mp, bsdfLamb); - } - } } if (nneg | nbadohm) { sprintf(errmsg, @@ -382,8 +345,7 @@ cm_loadBSDF(char *fname) sprintf(errmsg, "cannot find BSDF file '%s'", fname); error(USER, errmsg); } - SDclipName(myBSDF.name, fname); - /* load XML and check type */ + SDclearBSDF(&myBSDF, fname); /* load XML and check type */ ec = SDloadFile(&myBSDF, fpath); if (ec) error(USER, transSDError(ec)); @@ -420,7 +382,8 @@ sum_images(const char *fspec, const CMATRIX *cv, FILE int dt, xr, yr; COLORV *psp; /* check for zero */ - if ((scv[RED] == 0) & (scv[GRN] == 0) & (scv[BLU] == 0)) + if ((scv[RED] == 0) & (scv[GRN] == 0) & (scv[BLU] == 0) && + (myDT != DTfromHeader) | (i < cv->nrows-1)) continue; /* open next picture */ sprintf(fname, fspec, i); @@ -482,16 +445,22 @@ sum_images(const char *fspec, const CMATRIX *cv, FILE static int hasNumberFormat(const char *s) { - while (*s && *s != '%') - s++; - if (!*s) - return(0); - do - ++s; - while (isdigit(*s)); - - return((*s == 'd') | (*s == 'i') | (*s == 'o') | - (*s == 'x') | (*s == 'X')); + while (*s) { + while (*s != '%') + if (!*s++) + return(0); + if (*++s == '%') { /* ignore "%%" */ + ++s; + continue; + } + while (isdigit(*s)) /* field length */ + ++s; + /* field we'll use? */ + if ((*s == 'd') | (*s == 'i') | (*s == 'o') | + (*s == 'x') | (*s == 'X')) + return(1); + } + return(0); /* didn't find one */ } int