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.8 by greg, Sun Jun 21 21:49:13 2009 UTC vs.
Revision 2.14 by greg, Sun Apr 3 03:06:19 2011 UTC

# Line 38 | Line 38 | cm_alloc(int nrows, int ncols)
38          CMATRIX *cm;
39  
40          if ((nrows <= 0) | (ncols <= 0))
41 <                return(NULL);
41 >                error(USER, "attempt to create empty matrix");
42          cm = (CMATRIX *)malloc(sizeof(CMATRIX) +
43                                  3*sizeof(COLORV)*(nrows*ncols - 1));
44          if (cm == NULL)
# 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 294 | Line 296 | static CMATRIX *
296   cm_bsdf(const struct BSDF_data *bsdf)
297   {
298          CMATRIX *cm = cm_alloc(bsdf->nout, bsdf->ninc);
297        COLORV  *mp = cm->cmem;
299          int     nbadohm = 0;
300          int     nneg = 0;
301          int     r, c;
# Line 313 | Line 314 | cm_bsdf(const struct BSDF_data *bsdf)
314  
315                  for (r = 0; r < cm->nrows; r++) {
316                          float   f = BSDF_value(bsdf,c,r);
317 +                        COLORV  *mp = cm_lval(cm,r,c);
318  
319                          if (f <= .0) {
320                                  nneg += (f < -FTINY);
321                                  f = .0f;
322                          }
321                        mp = cm_lval(cm,r,c);
323                          mp[0] = mp[1] = mp[2] = f * dom;
324                  }
325          }
# Line 333 | 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 *fout)
338   {
339          int     myDT = DTfromHeader;
340          CMATRIX *pmat;
# Line 349 | Line 350 | sum_images(const char *fspec, const CMATRIX *cv)
350                  FILE            *fp;
351                  int             dt, xr, yr;
352                  COLORV          *psp;
353 +                                                        /* check for zero */
354 +                if ((scv[RED] == .0) & (scv[GRN] == .0) & (scv[BLU] == .0))
355 +                        continue;
356                                                          /* open next picture */
357                  sprintf(fname, fspec, i);
358                  if ((fp = fopen(fname, "r")) == NULL) {
# Line 371 | Line 375 | sum_images(const char *fspec, const CMATRIX *cv)
375                          pmat = cm_alloc(myYR, myXR);
376                          memset(pmat->cmem, 0, sizeof(COLOR)*myXR*myYR);
377                                                          /* finish header */
378 <                        fputformat(myDT==DTrgbe ? COLRFMT : CIEFMT, stdout);
379 <                        fputc('\n', stdout);
380 <                        fprtresolu(myXR, myYR, stdout);
381 <                        fflush(stdout);
378 >                        fputformat(myDT==DTrgbe ? COLRFMT : CIEFMT, fout);
379 >                        fputc('\n', fout);
380 >                        fprtresolu(myXR, myYR, fout);
381 >                        fflush(fout);
382                  } else if ((dt != myDT) | (xr != myXR) | (yr != myYR)) {
383                          sprintf(errmsg, "picture '%s' format/size mismatch",
384                                          fname);
# Line 399 | Line 403 | sum_images(const char *fspec, const CMATRIX *cv)
403          free(scanline);
404                                                          /* write scanlines */
405          for (y = 0; y < myYR; y++)
406 <                if (fwritescan((COLOR *)cm_lval(pmat, y, 0), myXR, stdout) < 0)
406 >                if (fwritescan((COLOR *)cm_lval(pmat, y, 0), myXR, fout) < 0)
407                          return(0);
408          cm_free(pmat);                                  /* all done */
409 <        return(fflush(stdout) == 0);
409 >        return(fflush(fout) == 0);
410   }
411  
412 < /* check to see if a string contains a %d specification */
413 < int
414 < hasDecimalSpec(const char *s)
412 > /* check to see if a string contains a %d or %o specification */
413 > static int
414 > hasNumberFormat(const char *s)
415   {
416          while (*s && *s != '%')
417                  s++;
# Line 417 | Line 421 | hasDecimalSpec(const char *s)
421                  ++s;
422          while (isdigit(*s));
423  
424 <        return(*s == 'd');
424 >        return(*s == 'd' | *s == 'i' | *s == 'o' | *s == 'x' | *s == 'X');
425   }
426  
427   int
428   main(int argc, char *argv[])
429   {
430 <        CMATRIX                 *tvec, *Dmat, *Tmat, *ivec, *cvec;
427 <        struct BSDF_data        *btdf;
430 >        CMATRIX                 *cvec;
431  
432          progname = argv[0];
433  
434 <        if ((argc < 4) | (argc > 5)) {
435 <                fprintf(stderr, "Usage: %s Vspec Tbsdf.xml Dmat.dat [tregvec]\n",
436 <                                progname);
434 >        if ((argc < 2) | (argc > 5)) {
435 >                fprintf(stderr, "Usage: %s DCspec [tregvec]\n", progname);
436 >                fprintf(stderr, "   or: %s Vspec Tbsdf.xml Dmat.dat [tregvec]\n",
437 >                                        progname);
438                  return(1);
439          }
440 <                                                /* load Tregenza vector */
441 <        tvec = cm_load(argv[4], 0, 1, DTascii); /* argv[4]==NULL iff argc==4 */
442 <                                                /* load BTDF */
443 <        btdf = load_BSDF(argv[2]);
444 <        if (btdf == NULL)
445 <                return(1);
440 >
441 >        if (argc > 3) {                         /* VTDs expression */
442 >                CMATRIX *svec, *Dmat, *Tmat, *ivec;
443 >                struct BSDF_data        *btdf;
444 >                                                /* get sky vector */
445 >                svec = cm_load(argv[4], 0, 1, DTascii);
446 >                                                /* load BSDF */
447 >                btdf = load_BSDF(argv[2]);
448 >                if (btdf == NULL)
449 >                        return(1);
450                                                  /* load Daylight matrix */
451 <        Dmat = cm_load(argv[3], btdf->ninc, tvec->nrows, DTfromHeader);
451 >                Dmat = cm_load(argv[3], btdf->ninc, svec->nrows, DTfromHeader);
452                                                  /* multiply vector through */
453 <        ivec = cm_multiply(Dmat, tvec);
454 <        cm_free(Dmat); cm_free(tvec);
455 <        Tmat = cm_bsdf(btdf);                   /* convert BTDF to matrix */
456 <        free_BSDF(btdf);
457 <        cvec = cm_multiply(Tmat, ivec);         /* cvec = component vector */
458 <        cm_free(Tmat); cm_free(ivec);
459 <        if (hasDecimalSpec(argv[1])) {          /* generating image */
453 >                ivec = cm_multiply(Dmat, svec);
454 >                cm_free(Dmat); cm_free(svec);
455 >                Tmat = cm_bsdf(btdf);           /* convert BTDF to matrix */
456 >                free_BSDF(btdf);
457 >                cvec = cm_multiply(Tmat, ivec); /* cvec = component vector */
458 >                cm_free(Tmat); cm_free(ivec);
459 >        } else {                                /* else just use sky vector */
460 >                cvec = cm_load(argv[2], 0, 1, DTascii);
461 >        }
462 >
463 >        if (hasNumberFormat(argv[1])) {         /* generating image */
464                  SET_FILE_BINARY(stdout);
465                  newheader("RADIANCE", stdout);
466                  printargs(argc, argv, stdout);
467                  fputnow(stdout);
468 <                if (!sum_images(argv[1], cvec))
468 >                if (!sum_images(argv[1], cvec, stdout))
469                          return(1);
470          } else {                                /* generating vector */
471                  CMATRIX *Vmat = cm_load(argv[1], 0, cvec->nrows, DTfromHeader);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines