ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/dctimestep.c
(Generate patch)

Comparing ray/src/util/dctimestep.c (file contents):
Revision 2.15 by greg, Fri Apr 8 18:13:48 2011 UTC vs.
Revision 2.20 by greg, Tue Aug 7 18:17:17 2012 UTC

# Line 252 | Line 252 | not_handled:
252          return(NULL);   /* gratis return */
253   }
254  
255 < /* Multiply two matrices (or a matrix and a vector) and allocate the result*/
255 > /* Scale a matrix by a single value */
256   static CMATRIX *
257 + cm_scale(const CMATRIX *cm1, const COLOR sca)
258 + {
259 +        CMATRIX *cmr;
260 +        int     dr, dc;
261 +
262 +        cmr = cm_alloc(cm1->nrows, cm1->ncols);
263 +        if (cmr == NULL)
264 +                return(NULL);
265 +        for (dr = 0; dr < cmr->nrows; dr++)
266 +            for (dc = 0; dc < cmr->ncols; dc++) {
267 +                const COLORV    *sp = cm_lval(cm1,dr,dc);
268 +                COLORV          *dp = cm_lval(cmr,dr,dc);
269 +                dp[0] = sp[0] * sca[0];
270 +                dp[1] = sp[1] * sca[1];
271 +                dp[2] = sp[2] * sca[2];
272 +            }
273 +        return(cmr);
274 + }
275 +
276 + /* Multiply two matrices (or a matrix and a vector) and allocate the result */
277 + static CMATRIX *
278   cm_multiply(const CMATRIX *cm1, const CMATRIX *cm2)
279   {
280          CMATRIX *cmr;
# Line 297 | Line 318 | cm_print(const CMATRIX *cm, FILE *fp)
318   static CMATRIX *
319   cm_bsdf(const COLOR bsdfLamb, const COLOR specCol, const SDMat *bsdf)
320   {
321 <        CMATRIX *cm;
321 >        CMATRIX *cm = cm_alloc(bsdf->nout, bsdf->ninc);
322          int     nbadohm = 0;
323          int     nneg = 0;
303        FVECT   v;
304        float   dom;
305        int     doforward;
324          int     r, c;
325 +                                        /* reciprocity is "transparent" */
326 +        for (c = 0; c < cm->ncols; c++) {
327 +                const double    dom = mBSDF_incohm(bsdf,c);
328 +                                        /* projected solid angle */
329 +                nbadohm += (dom <= 0);
330  
331 <        mBSDF_incvec(v, bsdf, .5);      /* check BTDF orientation */
332 <
333 <        if (v[2] < 0) {                 /* incident from outside */
334 <                cm = cm_alloc(bsdf->nout, bsdf->ninc);
335 <                for (c = 0; c < cm->ncols; c++) {
336 <                        dom = mBSDF_incohm(bsdf,c);
337 <                        
315 <                        nbadohm += (dom <= 0);
316 <
317 <                        if (!mBSDF_incvec(v,bsdf,c+.5) || v[2] > 0)
318 <                                error(USER, "illegal incoming BTDF direction");
319 <                        dom *= -v[2];
320 <
321 <                        for (r = 0; r < cm->nrows; r++) {
322 <                                float   f = mBSDF_value(bsdf,c,r);
323 <                                COLORV  *mp = cm_lval(cm,r,c);
324 <
325 <                                if ((f <= 0) | (dom <= 0)) {
326 <                                        nneg += (f < -FTINY);
327 <                                        f = .0f;
328 <                                }
329 <                                copycolor(mp, specCol);
330 <                                f *= dom;
331 <                                scalecolor(mp, f);
332 <                                addcolor(mp, bsdfLamb);
331 >                for (r = 0; r < cm->nrows; r++) {
332 >                        float   f = mBSDF_value(bsdf,c,r);
333 >                        COLORV  *mp = cm_lval(cm,r,c);
334 >                                        /* check BSDF value */
335 >                        if ((f <= 0) | (dom <= 0)) {
336 >                                nneg += (f < -FTINY);
337 >                                f = .0f;
338                          }
339 +                        copycolor(mp, specCol);
340 +                        scalecolor(mp, f);
341 +                        addcolor(mp, bsdfLamb);
342 +                        scalecolor(mp, dom);
343                  }
335        } else {                        /* rely on reciprocity */
336                cm = cm_alloc(bsdf->ninc, bsdf->nout);
337                for (c = 0; c < cm->ncols; c++) {
338                        dom = mBSDF_outohm(bsdf,c);
339                        
340                        nbadohm += (dom <= 0);
341
342                        if (!mBSDF_outvec(v,bsdf,c+.5) || v[2] > 0)
343                                error(USER, "illegal outgoing BTDF direction");
344                        dom *= -v[2];
345
346                        for (r = 0; r < cm->nrows; r++) {
347                                float   f = mBSDF_value(bsdf,r,c);
348                                COLORV  *mp = cm_lval(cm,r,c);
349
350                                if ((f <= 0) | (dom <= 0)) {
351                                        nneg += (f < -FTINY);
352                                        f = .0f;
353                                }
354                                copycolor(mp, specCol);
355                                f *= dom;
356                                scalecolor(mp, f);
357                                addcolor(mp, bsdfLamb);
358                        }
359                }
344          }
345          if (nneg | nbadohm) {
346                  sprintf(errmsg,
# Line 369 | Line 353 | cm_bsdf(const COLOR bsdfLamb, const COLOR specCol, con
353  
354   /* Load and convert a matrix BSDF from the given XML file */
355   static CMATRIX *
356 < cm_loadBSDF(char *fname)
356 > cm_loadBSDF(char *fname, COLOR cLamb)
357   {
358          CMATRIX *Tmat;
359          char    *fpath;
# Line 382 | Line 366 | cm_loadBSDF(char *fname)
366                  sprintf(errmsg, "cannot find BSDF file '%s'", fname);
367                  error(USER, errmsg);
368          }
369 <        SDclipName(myBSDF.name, fname);
386 <                                        /* load XML and check type */
369 >        SDclearBSDF(&myBSDF, fname);    /* load XML and check type */
370          ec = SDloadFile(&myBSDF, fpath);
371          if (ec)
372                  error(USER, transSDError(ec));
373 <        if (myBSDF.tf == NULL || myBSDF.tf->ncomp != 1 ||
374 <                        myBSDF.tf->comp[0].func != &SDhandleMtx) {
373 >        ccy2rgb(&myBSDF.tLamb.spec, myBSDF.tLamb.cieY/PI, bsdfLamb);
374 >        if (myBSDF.tf == NULL) {        /* no non-Lambertian transmission? */
375 >                if (cLamb != NULL)
376 >                        copycolor(cLamb, bsdfLamb);
377 >                SDfreeBSDF(&myBSDF);
378 >                return(NULL);
379 >        }
380 >        if (myBSDF.tf->ncomp != 1 || myBSDF.tf->comp[0].func != &SDhandleMtx) {
381                  sprintf(errmsg, "unsupported BSDF '%s'", fpath);
382                  error(USER, errmsg);
383          }
384                                          /* convert BTDF to matrix */
396        ccy2rgb(&myBSDF.tLamb.spec, myBSDF.tLamb.cieY/PI, bsdfLamb);
385          ccy2rgb(&myBSDF.tf->comp[0].cspec[0], 1., specCol);
386          Tmat = cm_bsdf(bsdfLamb, specCol, (SDMat *)myBSDF.tf->comp[0].dist);
387 +        if (cLamb != NULL)              /* Lambertian is included */
388 +                setcolor(cLamb, .0, .0, .0);
389                                          /* free BSDF and return */
390          SDfreeBSDF(&myBSDF);
391          return(Tmat);
# Line 420 | Line 410 | sum_images(const char *fspec, const CMATRIX *cv, FILE
410                  int             dt, xr, yr;
411                  COLORV          *psp;
412                                                          /* check for zero */
413 <                if ((scv[RED] == 0) & (scv[GRN] == 0) & (scv[BLU] == 0))
413 >                if ((scv[RED] == 0) & (scv[GRN] == 0) & (scv[BLU] == 0) &&
414 >                                (myDT != DTfromHeader) | (i < cv->nrows-1))
415                          continue;
416                                                          /* open next picture */
417                  sprintf(fname, fspec, i);
# Line 482 | Line 473 | sum_images(const char *fspec, const CMATRIX *cv, FILE
473   static int
474   hasNumberFormat(const char *s)
475   {
476 <        while (*s && *s != '%')
477 <                s++;
478 <        if (!*s)
479 <                return(0);
480 <        do
481 <                ++s;
482 <        while (isdigit(*s));
483 <
484 <        return((*s == 'd') | (*s == 'i') | (*s == 'o') |
485 <                        (*s == 'x') | (*s == 'X'));
476 >        while (*s) {
477 >                while (*s != '%')
478 >                        if (!*s++)
479 >                                return(0);
480 >                if (*++s == '%') {              /* ignore "%%" */
481 >                        ++s;
482 >                        continue;
483 >                }
484 >                while (isdigit(*s))             /* field length */
485 >                        ++s;
486 >                                                /* field we'll use? */
487 >                if ((*s == 'd') | (*s == 'i') | (*s == 'o') |
488 >                                        (*s == 'x') | (*s == 'X'))
489 >                        return(1);
490 >        }
491 >        return(0);                              /* didn't find one */
492   }
493  
494   int
495   main(int argc, char *argv[])
496   {
497 <        CMATRIX                 *cvec;
497 >        CMATRIX                 *cvec;          /* component vector result */
498  
499          progname = argv[0];
500  
# Line 510 | Line 507 | main(int argc, char *argv[])
507  
508          if (argc > 3) {                         /* VTDs expression */
509                  CMATRIX *svec, *Dmat, *Tmat, *ivec;
510 +                COLOR   tLamb;
511                                                  /* get sky vector */
512                  svec = cm_load(argv[4], 0, 1, DTascii);
513                                                  /* load BSDF */
514 <                Tmat = cm_loadBSDF(argv[2]);
514 >                Tmat = cm_loadBSDF(argv[2], tLamb);
515                                                  /* load Daylight matrix */
516 <                Dmat = cm_load(argv[3], Tmat->ncols, svec->nrows, DTfromHeader);
516 >                Dmat = cm_load(argv[3], Tmat==NULL ? 0 : Tmat->ncols,
517 >                                        svec->nrows, DTfromHeader);
518                                                  /* multiply vector through */
519                  ivec = cm_multiply(Dmat, svec);
520                  cm_free(Dmat); cm_free(svec);
521 <                cvec = cm_multiply(Tmat, ivec); /* cvec = component vector */
522 <                cm_free(Tmat); cm_free(ivec);
521 >                if (Tmat == NULL) {             /* diffuse only */
522 >                        cvec = cm_scale(ivec, tLamb);
523 >                } else {                        /* else apply BTDF matrix */
524 >                        cvec = cm_multiply(Tmat, ivec);
525 >                        cm_free(Tmat);
526 >                }
527 >                cm_free(ivec);
528          } else {                                /* else just use sky vector */
529                  cvec = cm_load(argv[2], 0, 1, DTascii);
530          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines