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.28 by greg, Mon Jan 20 21:29:04 2014 UTC vs.
Revision 2.36 by greg, Tue Jul 14 16:08:28 2015 UTC

# Line 33 | Line 33 | sum_images(const char *fspec, const CMATRIX *cv, FILE
33                  FILE            *fp;
34                  int             dt, xr, yr;
35                  COLORV          *psp;
36 +                char            *err;
37                                                          /* check for zero */
38                  if ((scv[RED] == 0) & (scv[GRN] == 0) & (scv[BLU] == 0) &&
39                                  (myDT != DTfromHeader) | (i < cv->nrows-1))
40                          continue;
41                                                          /* open next picture */
42                  sprintf(fname, fspec, i);
43 <                if ((fp = fopen(fname, "r")) == NULL) {
43 >                if ((fp = fopen(fname, "rb")) == NULL) {
44                          sprintf(errmsg, "cannot open picture '%s'", fname);
45                          error(SYSTEM, errmsg);
46                  }
47 <                SET_FILE_BINARY(fp);
48 <                dt = getDTfromHeader(fp);
47 >                dt = DTfromHeader;
48 >                if ((err = cm_getheader(&dt, NULL, NULL, fp)) != NULL)
49 >                        error(USER, err);
50                  if ((dt != DTrgbe) & (dt != DTxyze) ||
51                                  !fscnresolu(&xr, &yr, fp)) {
52                          sprintf(errmsg, "file '%s' not a picture", fname);
# Line 59 | Line 61 | sum_images(const char *fspec, const CMATRIX *cv, FILE
61                          pmat = cm_alloc(myYR, myXR);
62                          memset(pmat->cmem, 0, sizeof(COLOR)*myXR*myYR);
63                                                          /* finish header */
64 <                        fputformat(myDT==DTrgbe ? COLRFMT : CIEFMT, fout);
64 >                        fputformat((char *)cm_fmt_id[myDT], fout);
65                          fputc('\n', fout);
64                        fprtresolu(myXR, myYR, fout);
66                          fflush(fout);
67                  } else if ((dt != myDT) | (xr != myXR) | (yr != myYR)) {
68                          sprintf(errmsg, "picture '%s' format/size mismatch",
# Line 85 | Line 86 | sum_images(const char *fspec, const CMATRIX *cv, FILE
86                  fclose(fp);                             /* done this picture */
87          }
88          free(scanline);
89 <                                                        /* write scanlines */
90 <        for (y = 0; y < myYR; y++)
91 <                if (fwritescan((COLOR *)cm_lval(pmat, y, 0), myXR, fout) < 0)
91 <                        return(0);
92 <        cm_free(pmat);                                  /* all done */
93 <        return(fflush(fout) == 0);
89 >        i = cm_write(pmat, myDT, fout);                 /* write picture */
90 >        cm_free(pmat);                                  /* free data */
91 >        return(i);
92   }
93  
94   /* check to see if a string contains a %d or %o specification */
# Line 121 | Line 119 | hasNumberFormat(const char *s)
119   int
120   main(int argc, char *argv[])
121   {
122 <        int             skyfmt = DTascii;
123 <        int             nsteps = 1;
122 >        int             skyfmt = DTfromHeader;
123 >        int             outfmt = DTascii;
124 >        int             headout = 1;
125 >        int             nsteps = 0;
126          char            *ofspec = NULL;
127          FILE            *ofp = stdout;
128          CMATRIX         *cmtx;          /* component vector/matrix result */
# Line 135 | Line 135 | main(int argc, char *argv[])
135                  switch (argv[a][1]) {
136                  case 'n':
137                          nsteps = atoi(argv[++a]);
138 <                        if (nsteps <= 0)
138 >                        if (nsteps < 0)
139                                  goto userr;
140 +                        skyfmt = nsteps ? DTascii : DTfromHeader;
141                          break;
142 <                case 'o':
143 <                        ofspec = argv[++a];
142 >                case 'h':
143 >                        headout = !headout;
144                          break;
145                  case 'i':
146                          switch (argv[a][2]) {
# Line 156 | Line 157 | main(int argc, char *argv[])
157                                  goto userr;
158                          }
159                          break;
160 +                case 'o':
161 +                        switch (argv[a][2]) {
162 +                        case '\0':      /* output specification (not format) */
163 +                                ofspec = argv[++a];
164 +                                break;
165 +                        case 'f':
166 +                                outfmt = DTfloat;
167 +                                break;
168 +                        case 'd':
169 +                                outfmt = DTdouble;
170 +                                break;
171 +                        case 'a':
172 +                                outfmt = DTascii;
173 +                                break;
174 +                        default:
175 +                                goto userr;
176 +                        }
177 +                        break;
178                  default:
179                          goto userr;
180                  }
# Line 163 | Line 182 | main(int argc, char *argv[])
182                  goto userr;
183  
184          if (argc-a > 2) {                       /* VTDs expression */
185 <                CMATRIX *smtx, *Dmat, *Tmat, *imtx;
186 <                COLOR   tLamb;
185 >                CMATRIX         *smtx, *Dmat, *Tmat, *imtx;
186 >                const char      *ccp;
187                                                  /* get sky vector/matrix */
188                  smtx = cm_load(argv[a+3], 0, nsteps, skyfmt);
189 +                nsteps = smtx->ncols;
190                                                  /* load BSDF */
191 <                Tmat = cm_loadBSDF(argv[a+1], tLamb);
191 >                if (argv[a+1][0] != '!' &&
192 >                                (ccp = strrchr(argv[a+1], '.')) != NULL &&
193 >                                !strcasecmp(ccp+1, "XML"))
194 >                        Tmat = cm_loadBTDF(argv[a+1]);
195 >                else
196 >                        Tmat = cm_load(argv[a+1], 0, 0, DTfromHeader);
197                                                  /* load Daylight matrix */
198 <                Dmat = cm_load(argv[a+2], Tmat==NULL ? 0 : Tmat->ncols,
198 >                Dmat = cm_load(argv[a+2], Tmat->ncols,
199                                          smtx->nrows, DTfromHeader);
200                                                  /* multiply vector through */
201                  imtx = cm_multiply(Dmat, smtx);
202                  cm_free(Dmat); cm_free(smtx);
203 <                if (Tmat == NULL) {             /* diffuse only */
204 <                        cmtx = cm_scale(imtx, tLamb);
180 <                } else {                        /* else apply BTDF matrix */
181 <                        cmtx = cm_multiply(Tmat, imtx);
182 <                        cm_free(Tmat);
183 <                }
203 >                cmtx = cm_multiply(Tmat, imtx);
204 >                cm_free(Tmat);
205                  cm_free(imtx);
206          } else {                                /* sky vector/matrix only */
207                  cmtx = cm_load(argv[a+1], 0, nsteps, skyfmt);
208 +                nsteps = cmtx->ncols;
209          }
210                                                  /* prepare output stream */
211          if ((ofspec != NULL) & (nsteps == 1) && hasNumberFormat(ofspec)) {
# Line 240 | Line 262 | main(int argc, char *argv[])
262                  CMATRIX *Vmat = cm_load(argv[a], 0, cmtx->nrows, DTfromHeader);
263                  CMATRIX *rmtx = cm_multiply(Vmat, cmtx);
264                  cm_free(Vmat);
265 <                if (ofspec != NULL)             /* multiple vector files? */
265 >                if (ofspec != NULL) {           /* multiple vector files? */
266 >                        const char      *wtype = (outfmt==DTascii) ? "w" : "wb";
267                          for (i = 0; i < nsteps; i++) {
268                                  CMATRIX *rvec = cm_column(rmtx, i);
269                                  sprintf(fnbuf, ofspec, i+1);
270 <                                if ((ofp = fopen(fnbuf, "w")) == NULL) {
270 >                                if ((ofp = fopen(fnbuf, wtype)) == NULL) {
271                                          fprintf(stderr,
272                                          "%s: cannot open '%s' for output\n",
273                                                          progname, fnbuf);
274                                          return(1);
275                                  }
276 <                                cm_print(rvec, ofp);
276 > #ifdef getc_unlocked
277 >                                flockfile(ofp);
278 > #endif
279 >                                if (headout) {  /* header output */
280 >                                        newheader("RADIANCE", ofp);
281 >                                        printargs(argc, argv, ofp);
282 >                                        fputnow(ofp);
283 >                                        fprintf(ofp, "FRAME=%d\n", i+1);
284 >                                        fprintf(ofp, "NROWS=%d\n", rvec->nrows);
285 >                                        fputs("NCOLS=1\nNCOMP=3\n", ofp);
286 >                                        fputformat((char *)cm_fmt_id[outfmt], ofp);
287 >                                        fputc('\n', ofp);
288 >                                }
289 >                                cm_write(rvec, outfmt, ofp);
290                                  if (fclose(ofp) == EOF) {
291                                          fprintf(stderr,
292                                                  "%s: error writing to '%s'\n",
# Line 260 | Line 296 | main(int argc, char *argv[])
296                                  ofp = stdout;
297                                  cm_free(rvec);
298                          }
299 <                else
300 <                        cm_print(rmtx, ofp);
299 >                } else {
300 > #ifdef getc_unlocked
301 >                        flockfile(ofp);
302 > #endif
303 >                        if (outfmt != DTascii)
304 >                                SET_FILE_BINARY(ofp);
305 >                        if (headout) {          /* header output */
306 >                                newheader("RADIANCE", ofp);
307 >                                printargs(argc, argv, ofp);
308 >                                fputnow(ofp);
309 >                                fprintf(ofp, "NROWS=%d\n", rmtx->nrows);
310 >                                fprintf(ofp, "NCOLS=%d\n", rmtx->ncols);
311 >                                fputs("NCOMP=3\n", ofp);
312 >                                fputformat((char *)cm_fmt_id[outfmt], ofp);
313 >                                fputc('\n', ofp);
314 >                        }
315 >                        cm_write(rmtx, outfmt, ofp);
316 >                }
317                  cm_free(rmtx);
318          }
319          if (fflush(ofp) == EOF) {               /* final clean-up */
# Line 271 | Line 323 | main(int argc, char *argv[])
323          cm_free(cmtx);
324          return(0);
325   userr:
326 <        fprintf(stderr, "Usage: %s [-n nsteps][-o ospec][-i{f|d}] DCspec [skyf]\n",
326 >        fprintf(stderr, "Usage: %s [-n nsteps][-o ospec][-i{f|d|h}][-o{f|d}] DCspec [skyf]\n",
327                                  progname);
328 <        fprintf(stderr, "   or: %s [-n nsteps][-o ospec][-i{f|d}] Vspec Tbsdf.xml Dmat.dat [skyf]\n",
328 >        fprintf(stderr, "   or: %s [-n nsteps][-o ospec][-i{f|d|h}][-o{f|d}] Vspec Tbsdf Dmat.dat [skyf]\n",
329                                  progname);
330          return(1);
331   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines