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.1 by greg, Wed Jun 17 20:41:47 2009 UTC vs.
Revision 2.3 by greg, Fri Jun 19 14:21:42 2009 UTC

# Line 16 | Line 16 | static const char RCSid[] = "$Id$";
16  
17   char    *progname;                      /* global argv[0] */
18  
19 < /* Data types for matrix loading */
19 > /* Data types for file loading */
20   enum {DTfromHeader, DTascii, DTfloat, DTdouble, DTrgbe, DTxyze};
21  
22   /* A color coefficient matrix -- vectors have ncols==1 */
# Line 125 | Line 125 | cm_load(const char *fname, int nrows, int ncols, int d
125                  break;
126          default:
127                  error(USER, "unexpected data type in cm_load()");
128                return(NULL);
128          }
129          if (nrows <= 0) {                       /* don't know length? */
130                  int     guessrows = 147;        /* usually big enough */
# Line 135 | Line 134 | cm_load(const char *fname, int nrows, int ncols, int d
134                                  long    endpos = ftell(fp);
135                                  long    elemsiz = 3*(dtype==DTfloat ?
136                                              sizeof(float) : sizeof(double));
137 <                                guessrows = (endpos - startpos)/elemsiz;
137 >
138 >                                if ((endpos - startpos) % (ncols*elemsiz)) {
139 >                                        sprintf(errmsg,
140 >                                        "improper length for binary file '%s'",
141 >                                                        fname);
142 >                                        error(USER, errmsg);
143 >                                }
144 >                                guessrows = (endpos - startpos)/(ncols*elemsiz);
145                                  if (fseek(fp, startpos, SEEK_SET) < 0) {
146                                          sprintf(errmsg,
147                                                  "fseek() error on file '%s'",
148                                                          fname);
149                                          error(SYSTEM, errmsg);
150                                  }
151 <                                if ((endpos - startpos) % elemsiz == 0)
146 <                                        nrows = guessrows;      /* confident */
151 >                                nrows = guessrows;      /* we're confident */
152                          }
153                  }
154                  cm = cm_alloc(guessrows, ncols);
# Line 210 | Line 215 | cm_load(const char *fname, int nrows, int ncols, int d
215                                  copycolor(cvp, dc);
216                                  cvp += 3;
217                          }
213
218                  } else /* dtype == DTfloat */ {
219                          float   fc[3];                  /* load from float */
220                          COLORV  *cvp = cm->cmem;
# Line 291 | Line 295 | cm_bsdf(const struct BSDF_data *bsdf)
295   {
296          CMATRIX *cm = cm_alloc(bsdf->nout, bsdf->ninc);
297          COLORV  *mp = cm->cmem;
298 +        int     nbadohm = 0;
299 +        int     nneg = 0;
300          int     r, c;
301          
302          for (r = 0; r < cm->nrows; r++)
303 <                for (c = 0; c < cm->ncols; c++, mp += 3)
304 <                        mp[0] = mp[1] = mp[2] = BSDF_value(bsdf,c,r);
303 >                for (c = 0; c < cm->ncols; c++, mp += 3) {
304 >                        float   f = BSDF_value(bsdf,c,r);
305 >                        float   dom = getBSDF_incohm(bsdf,c);
306 >                        FVECT   v;
307 >                        
308 >                        if (f <= .0) {
309 >                                nneg += (f < -FTINY);
310 >                                continue;
311 >                        }
312 >                        if (dom <= .0) {
313 >                                nbadohm++;
314 >                                continue;
315 >                        }
316 >                        if (!getBSDF_incvec(v,bsdf,c) || v[2] > FTINY)
317 >                                error(USER, "illegal incoming BTDF direction");
318 >                                
319 >                        mp[0] = mp[1] = mp[2] = f * dom * -v[2];
320 >                }
321 >        if (nbadohm | nneg) {
322 >                sprintf(errmsg,
323 >                    "BTDF has %d negatives and %d bad incoming solid angles");
324 >                error(WARNING, errmsg);
325 >        }
326          return(cm);
327   }
328  
# Line 338 | Line 365 | sum_images(const char *fspec, const CMATRIX *cv)
365                                  error(SYSTEM, "out of memory in sum_images()");
366                          pmat = cm_alloc(myYR, myXR);
367                          memset(pmat->cmem, 0, sizeof(COLOR)*myXR*myYR);
368 +                                                        /* finish header */
369 +                        fputformat(myDT==DTrgbe ? COLRFMT : CIEFMT, stdout);
370 +                        fputc('\n', stdout);
371 +                        fprtresolu(myXR, myYR, stdout);
372 +                        fflush(stdout);
373                  } else if ((dt != myDT) | (xr != myXR) | (yr != myYR)) {
374                          sprintf(errmsg, "picture '%s' format/size mismatch",
375                                          fname);
# Line 360 | Line 392 | sum_images(const char *fspec, const CMATRIX *cv)
392                  fclose(fp);                             /* done this picture */
393          }
394          free(scanline);
363                                                        /* finish header */
364        fputformat(myDT==DTrgbe ? COLRFMT : CIEFMT, stdout);
365        fputc('\n', stdout);
366        fprtresolu(myXR, myYR, stdout);
395                                                          /* write scanlines */
396          for (y = 0; y < myYR; y++)
397                  if (fwritescan((COLOR *)cm_lval(pmat, y, 0), myXR, stdout) < 0)
# Line 390 | Line 418 | hasDecimalSpec(const char *s)
418   int
419   main(int argc, char *argv[])
420   {
421 <        CMATRIX                 *tvec, *Dmat, *Tmat, *vtmp, *cvec;
421 >        CMATRIX                 *tvec, *Dmat, *Tmat, *ivec, *cvec;
422          struct BSDF_data        *btdf;
423  
424          progname = argv[0];
# Line 411 | Line 439 | main(int argc, char *argv[])
439                  error(USER, errmsg);
440          }
441                                                  /* multiply vector through */
442 <        vtmp = cm_multiply(Dmat, tvec);
442 >        ivec = cm_multiply(Dmat, tvec);
443          cm_free(Dmat); cm_free(tvec);
444          Tmat = cm_bsdf(btdf);                   /* convert BTDF to matrix */
445          free_BSDF(btdf);
446 <        cvec = cm_multiply(Tmat, vtmp);         /* cvec = component vector */
447 <        cm_free(Tmat); cm_free(vtmp);
446 >        cvec = cm_multiply(Tmat, ivec);         /* cvec = component vector */
447 >        cm_free(Tmat); cm_free(ivec);
448          if (hasDecimalSpec(argv[1])) {          /* generating image */
449                  SET_FILE_BINARY(stdout);
450                  newheader("RADIANCE", stdout);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines