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.13 by greg, Thu Jul 1 22:44:25 2010 UTC vs.
Revision 2.16 by greg, Mon Apr 11 03:47:46 2011 UTC

# Line 10 | Line 10 | static const char RCSid[] = "$Id$";
10   #include <ctype.h>
11   #include "standard.h"
12   #include "platform.h"
13 + #include "paths.h"
14   #include "color.h"
15   #include "resolu.h"
16   #include "bsdf.h"
17 + #include "bsdf_m.h"
18  
19   char    *progname;                      /* global argv[0] */
20  
# Line 291 | Line 293 | cm_print(const CMATRIX *cm, FILE *fp)
293          }
294   }
295  
296 < /* convert a BSDF to our matrix representation */
296 > /* Convert a BSDF to our matrix representation */
297   static CMATRIX *
298 < cm_bsdf(const struct BSDF_data *bsdf)
298 > cm_bsdf(const COLOR bsdfLamb, const COLOR specCol, const SDMat *bsdf)
299   {
300          CMATRIX *cm = cm_alloc(bsdf->nout, bsdf->ninc);
301          int     nbadohm = 0;
302          int     nneg = 0;
303 +        float   dom;
304 +        int     doforward;
305          int     r, c;
306 <        
306 >                                        /* reciprocity is "transparent" */
307          for (c = 0; c < cm->ncols; c++) {
308 <                float   dom = getBSDF_incohm(bsdf,c);
309 <                FVECT   v;
310 <                
307 <                if (dom <= .0) {
308 <                        nbadohm++;
309 <                        continue;
310 <                }
311 <                if (!getBSDF_incvec(v,bsdf,c) || v[2] > FTINY)
312 <                        error(USER, "illegal incoming BTDF direction");
313 <                dom *= -v[2];
308 >                                        /* get projected solid angle */
309 >                dom = mBSDF_incohm(bsdf,c);
310 >                nbadohm += (dom <= 0);
311  
312                  for (r = 0; r < cm->nrows; r++) {
313 <                        float   f = BSDF_value(bsdf,c,r);
313 >                        float   f = mBSDF_value(bsdf,c,r);
314                          COLORV  *mp = cm_lval(cm,r,c);
315 <
316 <                        if (f <= .0) {
315 >                                        /* check BSDF value */
316 >                        if ((f <= 0) | (dom <= 0)) {
317                                  nneg += (f < -FTINY);
318                                  f = .0f;
319                          }
320 <                        mp[0] = mp[1] = mp[2] = f * dom;
320 >                        copycolor(mp, specCol);
321 >                        scalecolor(mp, f);
322 >                        addcolor(mp, bsdfLamb);
323 >                        scalecolor(mp, dom);
324                  }
325          }
326 <        if (nneg || nbadohm) {
326 >        if (nneg | nbadohm) {
327                  sprintf(errmsg,
328                      "BTDF has %d negatives and %d bad incoming solid angles",
329                                  nneg, nbadohm);
# Line 332 | Line 332 | cm_bsdf(const struct BSDF_data *bsdf)
332          return(cm);
333   }
334  
335 + /* Load and convert a matrix BSDF from the given XML file */
336 + static CMATRIX *
337 + cm_loadBSDF(char *fname)
338 + {
339 +        CMATRIX *Tmat;
340 +        char    *fpath;
341 +        SDError ec;
342 +        SDData  myBSDF;
343 +        COLOR   bsdfLamb, specCol;
344 +                                        /* find path to BSDF file */
345 +        fpath = getpath(fname, getrlibpath(), R_OK);
346 +        if (fpath == NULL) {
347 +                sprintf(errmsg, "cannot find BSDF file '%s'", fname);
348 +                error(USER, errmsg);
349 +        }
350 +        SDclearBSDF(&myBSDF, fname);    /* load XML and check type */
351 +        ec = SDloadFile(&myBSDF, fpath);
352 +        if (ec)
353 +                error(USER, transSDError(ec));
354 +        if (myBSDF.tf == NULL || myBSDF.tf->ncomp != 1 ||
355 +                        myBSDF.tf->comp[0].func != &SDhandleMtx) {
356 +                sprintf(errmsg, "unsupported BSDF '%s'", fpath);
357 +                error(USER, errmsg);
358 +        }
359 +                                        /* convert BTDF to matrix */
360 +        ccy2rgb(&myBSDF.tLamb.spec, myBSDF.tLamb.cieY/PI, bsdfLamb);
361 +        ccy2rgb(&myBSDF.tf->comp[0].cspec[0], 1., specCol);
362 +        Tmat = cm_bsdf(bsdfLamb, specCol, (SDMat *)myBSDF.tf->comp[0].dist);
363 +                                        /* free BSDF and return */
364 +        SDfreeBSDF(&myBSDF);
365 +        return(Tmat);
366 + }
367 +
368   /* Sum together a set of images and write result to stdout */
369   static int
370   sum_images(const char *fspec, const CMATRIX *cv, FILE *fout)
# Line 350 | Line 383 | sum_images(const char *fspec, const CMATRIX *cv, FILE
383                  FILE            *fp;
384                  int             dt, xr, yr;
385                  COLORV          *psp;
386 +                                                        /* check for zero */
387 +                if ((scv[RED] == 0) & (scv[GRN] == 0) & (scv[BLU] == 0))
388 +                        continue;
389                                                          /* open next picture */
390                  sprintf(fname, fspec, i);
391                  if ((fp = fopen(fname, "r")) == NULL) {
# Line 418 | Line 454 | hasNumberFormat(const char *s)
454                  ++s;
455          while (isdigit(*s));
456  
457 <        return(*s == 'd' | *s == 'i' | *s == 'o' | *s == 'x' | *s == 'X');
457 >        return((*s == 'd') | (*s == 'i') | (*s == 'o') |
458 >                        (*s == 'x') | (*s == 'X'));
459   }
460  
461   int
# Line 437 | Line 474 | main(int argc, char *argv[])
474  
475          if (argc > 3) {                         /* VTDs expression */
476                  CMATRIX *svec, *Dmat, *Tmat, *ivec;
440                struct BSDF_data        *btdf;
477                                                  /* get sky vector */
478                  svec = cm_load(argv[4], 0, 1, DTascii);
479                                                  /* load BSDF */
480 <                btdf = load_BSDF(argv[2]);
445 <                if (btdf == NULL)
446 <                        return(1);
480 >                Tmat = cm_loadBSDF(argv[2]);
481                                                  /* load Daylight matrix */
482 <                Dmat = cm_load(argv[3], btdf->ninc, svec->nrows, DTfromHeader);
482 >                Dmat = cm_load(argv[3], Tmat->ncols, svec->nrows, DTfromHeader);
483                                                  /* multiply vector through */
484                  ivec = cm_multiply(Dmat, svec);
485                  cm_free(Dmat); cm_free(svec);
452                Tmat = cm_bsdf(btdf);           /* convert BTDF to matrix */
453                free_BSDF(btdf);
486                  cvec = cm_multiply(Tmat, ivec); /* cvec = component vector */
487                  cm_free(Tmat); cm_free(ivec);
488          } else {                                /* else just use sky vector */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines