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.11 by greg, Wed Dec 9 20:33:48 2009 UTC vs.
Revision 2.12 by greg, Thu Jul 1 21:54:56 2010 UTC

# Line 108 | Line 108 | cm_load(const char *fname, int nrows, int ncols, int d
108          CMATRIX *cm;
109          FILE    *fp = stdin;
110  
111 +        if (ncols <= 0)
112 +                error(USER, "Non-positive number of columns");
113          if (fname == NULL)
114                  fname = "<stdin>";
115          else if ((fp = fopen(fname, "r")) == NULL) {
# Line 332 | Line 334 | cm_bsdf(const struct BSDF_data *bsdf)
334  
335   /* Sum together a set of images and write result to stdout */
336   static int
337 < sum_images(const char *fspec, const CMATRIX *cv)
337 > sum_images(const char *fspec, const CMATRIX *cv, FILE *fp)
338   {
339          int     myDT = DTfromHeader;
340          CMATRIX *pmat;
# Line 370 | Line 372 | sum_images(const char *fspec, const CMATRIX *cv)
372                          pmat = cm_alloc(myYR, myXR);
373                          memset(pmat->cmem, 0, sizeof(COLOR)*myXR*myYR);
374                                                          /* finish header */
375 <                        fputformat(myDT==DTrgbe ? COLRFMT : CIEFMT, stdout);
376 <                        fputc('\n', stdout);
377 <                        fprtresolu(myXR, myYR, stdout);
378 <                        fflush(stdout);
375 >                        fputformat(myDT==DTrgbe ? COLRFMT : CIEFMT, fp);
376 >                        fputc('\n', fp);
377 >                        fprtresolu(myXR, myYR, fp);
378 >                        fflush(fp);
379                  } else if ((dt != myDT) | (xr != myXR) | (yr != myYR)) {
380                          sprintf(errmsg, "picture '%s' format/size mismatch",
381                                          fname);
# Line 398 | Line 400 | sum_images(const char *fspec, const CMATRIX *cv)
400          free(scanline);
401                                                          /* write scanlines */
402          for (y = 0; y < myYR; y++)
403 <                if (fwritescan((COLOR *)cm_lval(pmat, y, 0), myXR, stdout) < 0)
403 >                if (fwritescan((COLOR *)cm_lval(pmat, y, 0), myXR, fp) < 0)
404                          return(0);
405          cm_free(pmat);                                  /* all done */
406 <        return(fflush(stdout) == 0);
406 >        return(fflush(fp) == 0);
407   }
408  
409   /* check to see if a string contains a %d or %o specification */
# Line 422 | Line 424 | hasNumberFormat(const char *s)
424   int
425   main(int argc, char *argv[])
426   {
427 <        CMATRIX                 *tvec, *Dmat, *Tmat, *ivec, *cvec;
426 <        struct BSDF_data        *btdf;
427 >        CMATRIX                 *cvec;
428  
429          progname = argv[0];
430  
431 <        if ((argc < 4) | (argc > 5)) {
432 <                fprintf(stderr, "Usage: %s Vspec Tbsdf.xml Dmat.dat [tregvec]\n",
433 <                                progname);
431 >        if ((argc < 2) | (argc > 5)) {
432 >                fprintf(stderr, "Usage: %s DCspec [tregvec]\n", progname);
433 >                fprintf(stderr, "   or: %s Vspec Tbsdf.xml Dmat.dat [tregvec]\n",
434 >                                        progname);
435                  return(1);
436          }
437 <                                                /* load Tregenza vector */
438 <        tvec = cm_load(argv[4], 0, 1, DTascii); /* argv[4]==NULL iff argc==4 */
439 <                                                /* load BTDF */
440 <        btdf = load_BSDF(argv[2]);
441 <        if (btdf == NULL)
442 <                return(1);
437 >
438 >        if (argc > 3) {                         /* need to compute DC matrix? */
439 >                CMATRIX *svec, *Dmat, *Tmat, *ivec;
440 >                struct BSDF_data        *btdf;
441 >                                                /* get sky vector */
442 >                svec = cm_load(argv[4], 0, 1, DTascii);
443 >                                                /* load BSDF */
444 >                btdf = load_BSDF(argv[2]);
445 >                if (btdf == NULL)
446 >                        return(1);
447                                                  /* load Daylight matrix */
448 <        Dmat = cm_load(argv[3], btdf->ninc, tvec->nrows, DTfromHeader);
448 >                Dmat = cm_load(argv[3], btdf->ninc, svec->nrows, DTfromHeader);
449                                                  /* multiply vector through */
450 <        ivec = cm_multiply(Dmat, tvec);
451 <        cm_free(Dmat); cm_free(tvec);
452 <        Tmat = cm_bsdf(btdf);                   /* convert BTDF to matrix */
453 <        free_BSDF(btdf);
454 <        cvec = cm_multiply(Tmat, ivec);         /* cvec = component vector */
455 <        cm_free(Tmat); cm_free(ivec);
450 >                ivec = cm_multiply(Dmat, svec);
451 >                cm_free(Dmat); cm_free(svec);
452 >                Tmat = cm_bsdf(btdf);           /* convert BTDF to matrix */
453 >                free_BSDF(btdf);
454 >                cvec = cm_multiply(Tmat, ivec); /* cvec = component vector */
455 >                cm_free(Tmat); cm_free(ivec);
456 >        } else {                                /* else just use sky vector */
457 >                cvec = cm_load(argv[2], 0, 1, DTascii);
458 >        }
459 >
460          if (hasNumberFormat(argv[1])) {         /* generating image */
461                  SET_FILE_BINARY(stdout);
462                  newheader("RADIANCE", stdout);
463                  printargs(argc, argv, stdout);
464                  fputnow(stdout);
465 <                if (!sum_images(argv[1], cvec))
465 >                if (!sum_images(argv[1], cvec, stdout))
466                          return(1);
467          } else {                                /* generating vector */
468                  CMATRIX *Vmat = cm_load(argv[1], 0, cvec->nrows, DTfromHeader);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines