ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/cv/bsdf2ttree.c
(Generate patch)

Comparing ray/src/cv/bsdf2ttree.c (file contents):
Revision 2.30 by greg, Tue May 5 22:16:49 2015 UTC vs.
Revision 2.40 by greg, Fri Feb 17 22:31:49 2017 UTC

# Line 13 | Line 13 | static const char RCSid[] = "$Id$";
13   #include <math.h>
14   #include "random.h"
15   #include "platform.h"
16 < #include "rtprocess.h"
16 > #include "paths.h"
17 > #include "rtio.h"
18   #include "calcomp.h"
19   #include "bsdfrep.h"
20                                  /* global argv[0] */
21   char                    *progname;
22                                  /* percentage to cull (<0 to turn off) */
23 < double                  pctcull = 90.;
23 > static double           pctcull = 90.;
24                                  /* sampling order */
25 < int                     samp_order = 6;
25 > static int              samp_order = 6;
26                                  /* super-sampling threshold */
27   const double            ssamp_thresh = 0.35;
28                                  /* number of super-samples */
29   #ifndef NSSAMP
30 < #define NSSAMP          100
30 > #define NSSAMP          64
31   #endif
32                                  /* limit on number of RBF lobes */
33   static int              lobe_lim = 15000;
34                                  /* progress bar length */
35   static int              do_prog = 79;
36  
37 + #define MAXCARG         512     /* wrapBSDF command */
38 + static char             *wrapBSDF[MAXCARG] = {"wrapBSDF", "-U"};
39 + static int              wbsdfac = 2;
40  
41 + /* Add argument to wrapBSDF, allocating space if !isstatic */
42 + static void
43 + add_wbsdf(const char *arg, int isstatic)
44 + {
45 +        if (arg == NULL)
46 +                return;
47 +        if (wbsdfac >= MAXCARG-1) {
48 +                fputs(progname, stderr);
49 +                fputs(": too many command arguments to wrapBSDF\n", stderr);
50 +                exit(1);
51 +        }
52 +        if (!*arg)
53 +                arg = "";
54 +        else if (!isstatic)
55 +                arg = savqstr((char *)arg);
56 +
57 +        wrapBSDF[wbsdfac++] = (char *)arg;
58 + }
59 +
60 + /* Create Yuv component file and add appropriate arguments */
61 + static char *
62 + create_component_file(int c)
63 + {
64 +        static const char       sname[3][6] = {"CIE-Y", "CIE-u", "CIE-v"};
65 +        static const char       cname[4][4] = {"-rf", "-tf", "-tb", "-rb"};
66 +        char                    *tfname = mktemp(savqstr(TEMPLATE));
67 +
68 +        add_wbsdf("-s", 1); add_wbsdf(sname[c], 1);
69 +        add_wbsdf(cname[(input_orient>0)<<1 | (output_orient>0)], 1);
70 +        add_wbsdf(tfname, 1);
71 +        return(tfname);
72 + }
73 +
74   /* Start new progress bar */
75   #define prog_start(s)   if (do_prog) fprintf(stderr, "%s: %s...\n", progname, s); else
76  
# Line 73 | Line 110 | prog_done(void)
110          fputc('\r', stderr);
111   }
112  
76 /* Output XML prologue to stdout */
77 static void
78 xml_prologue(int ac, char *av[])
79 {
80        puts("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
81        puts("<WindowElement xmlns=\"http://windows.lbl.gov\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://windows.lbl.gov/BSDF-v1.4.xsd\">");
82        fputs("<!-- File produced by:", stdout);
83        while (ac-- > 0) {
84                fputc(' ', stdout);
85                fputs(*av++, stdout);
86        }
87        puts(" -->");
88        puts("<WindowElementType>System</WindowElementType>");
89        puts("<FileType>BSDF</FileType>");
90        puts("<Optical>");
91        puts("<Layer>");
92        puts("\t<Material>");
93        printf("\t\t<Name>%s</Name>\n", bsdf_name[0] ? bsdf_name : "Unknown");
94        printf("\t\t<Manufacturer>%s</Manufacturer>\n",
95                        bsdf_manuf[0] ? bsdf_manuf : "Unknown");
96        puts("\t\t<DeviceType>Other</DeviceType>");
97        puts("\t</Material>");
98        puts("\t<DataDefinition>");
99        printf("\t\t<IncidentDataStructure>TensorTree%c</IncidentDataStructure>\n",
100                        single_plane_incident ? '3' : '4');
101        puts("\t</DataDefinition>");
102 }
103
104 /* Output XML data prologue to stdout */
105 static void
106 data_prologue()
107 {
108        static const char       *bsdf_type[4] = {
109                                        "Reflection Front",
110                                        "Transmission Front",
111                                        "Transmission Back",
112                                        "Reflection Back"
113                                };
114
115        puts("\t<WavelengthData>");
116        puts("\t\t<LayerNumber>System</LayerNumber>");
117        puts("\t\t<Wavelength unit=\"Integral\">Visible</Wavelength>");
118        puts("\t\t<SourceSpectrum>CIE Illuminant D65 1nm.ssp</SourceSpectrum>");
119        puts("\t\t<DetectorSpectrum>ASTM E308 1931 Y.dsp</DetectorSpectrum>");
120        puts("\t\t<WavelengthDataBlock>");
121        printf("\t\t\t<WavelengthDataDirection>%s</WavelengthDataDirection>\n",
122                        bsdf_type[(input_orient>0)<<1 | (output_orient>0)]);
123        puts("\t\t\t<AngleBasis>LBNL/Shirley-Chiu</AngleBasis>");
124        puts("\t\t\t<ScatteringDataType>BTDF</ScatteringDataType>");
125        puts("\t\t\t<ScatteringData>");
126 }
127
128 /* Output XML data epilogue to stdout */
129 static void
130 data_epilogue(void)
131 {
132        puts("\t\t\t</ScatteringData>");
133        puts("\t\t</WavelengthDataBlock>");
134        puts("\t</WavelengthData>");
135 }
136
137 /* Output XML epilogue to stdout */
138 static void
139 xml_epilogue(void)
140 {
141        puts("</Layer>");
142        puts("</Optical>");
143        puts("</WindowElement>");
144 }
145
113   /* Compute absolute relative difference */
114   static double
115   abs_diff(double v1, double v0)
# Line 160 | Line 127 | static void
127   eval_isotropic(char *funame)
128   {
129          const int       sqres = 1<<samp_order;
130 <        FILE            *ofp = NULL;
130 >        FILE            *ofp, *uvfp[2];
131          int             assignD = 0;
132          char            cmd[128];
133          int             ix, ox, oy;
134          double          iovec[6];
135 <        float           bsdf;
135 >        float           bsdf, uv[2];
136  
170        data_prologue();                        /* begin output */
137          if (pctcull >= 0) {
138 <                sprintf(cmd, "rttree_reduce -a -h -ff -r 3 -t %f -g %d",
139 <                                pctcull, samp_order);
174 <                fflush(stdout);
138 >                sprintf(cmd, "rttree_reduce -a -h -ff -r 3 -t %f -g %d > %s",
139 >                                pctcull, samp_order, create_component_file(0));
140                  ofp = popen(cmd, "w");
141                  if (ofp == NULL) {
142                          fprintf(stderr, "%s: cannot create pipe to rttree_reduce\n",
# Line 182 | Line 147 | eval_isotropic(char *funame)
147   #ifdef getc_unlocked                            /* avoid lock/unlock overhead */
148                  flockfile(ofp);
149   #endif
150 <        } else
151 <                fputs("{\n", stdout);
152 <                                                /* need to assign Dx, Dy, Dz? */
153 <        if (funame != NULL)
150 >                if (rbf_colorimetry == RBCtristimulus) {
151 >                        double  uvcull = 100. - (100.-pctcull)*.25;
152 >                        sprintf(cmd, "rttree_reduce -a -h -ff -r 3 -t %f -g %d > %s",
153 >                                        uvcull, samp_order, create_component_file(1));
154 >                        uvfp[0] = popen(cmd, "w");
155 >                        sprintf(cmd, "rttree_reduce -a -h -ff -r 3 -t %f -g %d > %s",
156 >                                        uvcull, samp_order, create_component_file(2));
157 >                        uvfp[1] = popen(cmd, "w");
158 >                        if ((uvfp[0] == NULL) | (uvfp[1] == NULL)) {
159 >                                fprintf(stderr, "%s: cannot open pipes to uv output\n",
160 >                                                progname);
161 >                                exit(1);
162 >                        }
163 >                        SET_FILE_BINARY(uvfp[0]); SET_FILE_BINARY(uvfp[1]);
164 > #ifdef getc_unlocked
165 >                        flockfile(uvfp[0]); flockfile(uvfp[1]);
166 > #endif
167 >                }
168 >        } else {
169 >                ofp = fopen(create_component_file(0), "w");
170 >                if (ofp == NULL) {
171 >                        fprintf(stderr, "%s: cannot create Y output file\n",
172 >                                        progname);
173 >                        exit(1);
174 >                }
175 >                fputs("{\n", ofp);
176 >                if (rbf_colorimetry == RBCtristimulus) {
177 >                        uvfp[0] = fopen(create_component_file(1), "w");
178 >                        uvfp[1] = fopen(create_component_file(2), "w");
179 >                        if ((uvfp[0] == NULL) | (uvfp[1] == NULL)) {
180 >                                fprintf(stderr, "%s: cannot create uv output file(s)\n",
181 >                                                progname);
182 >                                exit(1);
183 >                        }
184 >                        fputs("{\n", uvfp[0]);
185 >                        fputs("{\n", uvfp[1]);
186 >                }
187 >        }
188 >        if (funame != NULL)                     /* need to assign Dx, Dy, Dz? */
189                  assignD = (fundefined(funame) < 6);
190                                                  /* run through directions */
191          for (ix = 0; ix < sqres/2; ix++) {
# Line 201 | Line 201 | eval_isotropic(char *funame)
201                          SDsquare2disk(iovec+3, (ox+.5)/sqres, (oy+.5)/sqres);
202                          iovec[5] = output_orient *
203                                  sqrt(1. - iovec[3]*iovec[3] - iovec[4]*iovec[4]);
204 <                        if (funame == NULL)
205 <                            bsdf = eval_rbfrep(rbf, iovec+3);
206 <                        else {
204 >                        if (funame == NULL) {
205 >                            SDValue     sdv;
206 >                            eval_rbfcol(&sdv, rbf, iovec+3);
207 >                            bsdf = sdv.cieY;
208 >                            if (rbf_colorimetry == RBCtristimulus) {
209 >                                uv[0] = uv[1] = 1. /
210 >                                    (-2.*sdv.spec.cx + 12.*sdv.spec.cy + 3.);
211 >                                uv[0] *= 4.*sdv.spec.cx;
212 >                                uv[1] *= 9.*sdv.spec.cy;
213 >                            }
214 >                        } else {
215                              if (assignD) {
216                                  varset("Dx", '=', -iovec[3]);
217                                  varset("Dy", '=', -iovec[4]);
# Line 241 | Line 249 | eval_isotropic(char *funame)
249   #endif
250                          }
251                          if (pctcull >= 0)
252 <                                fwrite(&bsdf, sizeof(bsdf), 1, ofp);
252 >                                putbinary(&bsdf, sizeof(bsdf), 1, ofp);
253                          else
254 <                                printf("\t%.3e\n", bsdf);
254 >                                fprintf(ofp, "\t%.3e\n", bsdf);
255 >
256 >                        if (rbf_colorimetry == RBCtristimulus) {
257 >                                if (pctcull >= 0) {
258 >                                        putbinary(&uv[0], sizeof(*uv), 1, uvfp[0]);
259 >                                        putbinary(&uv[1], sizeof(*uv), 1, uvfp[1]);
260 >                                } else {
261 >                                        fprintf(uvfp[0], "\t%.3e\n", uv[0]);
262 >                                        fprintf(uvfp[1], "\t%.3e\n", uv[1]);
263 >                                }
264 >                        }
265                          last_bsdf = bsdf;
266                      }
267                  }
# Line 251 | Line 269 | eval_isotropic(char *funame)
269                          free(rbf);
270                  prog_show((ix+1.)*(2./sqres));
271          }
272 +        prog_done();
273          if (pctcull >= 0) {                     /* finish output */
274                  if (pclose(ofp)) {
275 <                        fprintf(stderr, "%s: error running '%s'\n",
276 <                                        progname, cmd);
275 >                        fprintf(stderr, "%s: error running rttree_reduce on Y\n",
276 >                                        progname);
277                          exit(1);
278                  }
279 +                if (rbf_colorimetry == RBCtristimulus &&
280 +                                (pclose(uvfp[0]) || pclose(uvfp[1]))) {
281 +                        fprintf(stderr, "%s: error running rttree_reduce on uv\n",
282 +                                        progname);
283 +                        exit(1);
284 +                }
285          } else {
286                  for (ix = sqres*sqres*sqres/2; ix--; )
287 <                        fputs("\t0\n", stdout);
288 <                fputs("}\n", stdout);
287 >                        fputs("\t0\n", ofp);
288 >                fputs("}\n", ofp);
289 >                if (fclose(ofp)) {
290 >                        fprintf(stderr, "%s: error writing Y file\n",
291 >                                        progname);
292 >                        exit(1);
293 >                }
294 >                if (rbf_colorimetry == RBCtristimulus) {
295 >                        for (ix = sqres*sqres*sqres/2; ix--; ) {
296 >                                fputs("\t0\n", uvfp[0]);
297 >                                fputs("\t0\n", uvfp[1]);
298 >                        }
299 >                        fputs("}\n", uvfp[0]);
300 >                        fputs("}\n", uvfp[1]);
301 >                        if (fclose(uvfp[0]) || fclose(uvfp[1])) {
302 >                                fprintf(stderr, "%s: error writing uv file(s)\n",
303 >                                                progname);
304 >                                exit(1);
305 >                        }
306 >                }
307          }
265        data_epilogue();
266        prog_done();
308   }
309  
310   /* Interpolate and output anisotropic BSDF data */
# Line 271 | Line 312 | static void
312   eval_anisotropic(char *funame)
313   {
314          const int       sqres = 1<<samp_order;
315 <        FILE            *ofp = NULL;
315 >        FILE            *ofp, *uvfp[2];
316          int             assignD = 0;
317          char            cmd[128];
318          int             ix, iy, ox, oy;
319          double          iovec[6];
320 <        float           bsdf;
320 >        float           bsdf, uv[2];
321  
281        data_prologue();                        /* begin output */
322          if (pctcull >= 0) {
323 <                sprintf(cmd, "rttree_reduce%s -h -ff -r 4 -t %f -g %d",
324 <                                (input_orient>0 ^ output_orient>0) ? "" : " -a",
325 <                                pctcull, samp_order);
326 <                fflush(stdout);
323 >                const char      *avgopt = (input_orient>0 ^ output_orient>0)
324 >                                                ? "" : " -a";
325 >                sprintf(cmd, "rttree_reduce%s -h -ff -r 4 -t %f -g %d > %s",
326 >                                avgopt, pctcull, samp_order,
327 >                                create_component_file(0));
328                  ofp = popen(cmd, "w");
329                  if (ofp == NULL) {
330                          fprintf(stderr, "%s: cannot create pipe to rttree_reduce\n",
# Line 294 | Line 335 | eval_anisotropic(char *funame)
335   #ifdef getc_unlocked                            /* avoid lock/unlock overhead */
336                  flockfile(ofp);
337   #endif
338 <        } else
339 <                fputs("{\n", stdout);
340 <                                                /* need to assign Dx, Dy, Dz? */
341 <        if (funame != NULL)
338 >                if (rbf_colorimetry == RBCtristimulus) {
339 >                        double  uvcull = 100. - (100.-pctcull)*.25;
340 >                        sprintf(cmd, "rttree_reduce%s -h -ff -r 4 -t %f -g %d > %s",
341 >                                        avgopt, uvcull, samp_order,
342 >                                        create_component_file(1));
343 >                        uvfp[0] = popen(cmd, "w");
344 >                        sprintf(cmd, "rttree_reduce%s -h -ff -r 4 -t %f -g %d > %s",
345 >                                        avgopt, uvcull, samp_order,
346 >                                        create_component_file(2));
347 >                        uvfp[1] = popen(cmd, "w");
348 >                        if ((uvfp[0] == NULL) | (uvfp[1] == NULL)) {
349 >                                fprintf(stderr, "%s: cannot open pipes to uv output\n",
350 >                                                progname);
351 >                                exit(1);
352 >                        }
353 >                        SET_FILE_BINARY(uvfp[0]); SET_FILE_BINARY(uvfp[1]);
354 > #ifdef getc_unlocked
355 >                        flockfile(uvfp[0]); flockfile(uvfp[1]);
356 > #endif
357 >                }
358 >        } else {
359 >                ofp = fopen(create_component_file(0), "w");
360 >                if (ofp == NULL) {
361 >                        fprintf(stderr, "%s: cannot create Y output file\n",
362 >                                        progname);
363 >                        exit(1);
364 >                }
365 >                fputs("{\n", ofp);
366 >                if (rbf_colorimetry == RBCtristimulus) {
367 >                        uvfp[0] = fopen(create_component_file(1), "w");
368 >                        uvfp[1] = fopen(create_component_file(2), "w");
369 >                        if ((uvfp[0] == NULL) | (uvfp[1] == NULL)) {
370 >                                fprintf(stderr, "%s: cannot create uv output file(s)\n",
371 >                                                progname);
372 >                                exit(1);
373 >                        }
374 >                        fputs("{\n", uvfp[0]);
375 >                        fputs("{\n", uvfp[1]);
376 >                }
377 >        }
378 >        if (funame != NULL)                     /* need to assign Dx, Dy, Dz? */
379                  assignD = (fundefined(funame) < 6);
380                                                  /* run through directions */
381          for (ix = 0; ix < sqres; ix++)
# Line 314 | Line 392 | eval_anisotropic(char *funame)
392                          SDsquare2disk(iovec+3, (ox+.5)/sqres, (oy+.5)/sqres);
393                          iovec[5] = output_orient *
394                                  sqrt(1. - iovec[3]*iovec[3] - iovec[4]*iovec[4]);
395 <                        if (funame == NULL)
396 <                            bsdf = eval_rbfrep(rbf, iovec+3);
397 <                        else {
395 >                        if (funame == NULL) {
396 >                            SDValue     sdv;
397 >                            eval_rbfcol(&sdv, rbf, iovec+3);
398 >                            bsdf = sdv.cieY;
399 >                            if (rbf_colorimetry == RBCtristimulus) {
400 >                                uv[0] = uv[1] = 1. /
401 >                                    (-2.*sdv.spec.cx + 12.*sdv.spec.cy + 3.);
402 >                                uv[0] *= 4.*sdv.spec.cx;
403 >                                uv[1] *= 9.*sdv.spec.cy;
404 >                            }
405 >                        } else {
406                              if (assignD) {
407                                  varset("Dx", '=', -iovec[3]);
408                                  varset("Dy", '=', -iovec[4]);
# Line 355 | Line 441 | eval_anisotropic(char *funame)
441   #endif
442                          }
443                          if (pctcull >= 0)
444 <                                fwrite(&bsdf, sizeof(bsdf), 1, ofp);
444 >                                putbinary(&bsdf, sizeof(bsdf), 1, ofp);
445                          else
446 <                                printf("\t%.3e\n", bsdf);
446 >                                fprintf(ofp, "\t%.3e\n", bsdf);
447 >
448 >                        if (rbf_colorimetry == RBCtristimulus) {
449 >                                if (pctcull >= 0) {
450 >                                        putbinary(&uv[0], sizeof(*uv), 1, uvfp[0]);
451 >                                        putbinary(&uv[1], sizeof(*uv), 1, uvfp[1]);
452 >                                } else {
453 >                                        fprintf(uvfp[0], "\t%.3e\n", uv[0]);
454 >                                        fprintf(uvfp[1], "\t%.3e\n", uv[1]);
455 >                                }
456 >                        }
457                          last_bsdf = bsdf;
458                      }
459                  }
# Line 365 | Line 461 | eval_anisotropic(char *funame)
461                          free(rbf);
462                  prog_show((ix*sqres+iy+1.)/(sqres*sqres));
463              }
464 +        prog_done();
465          if (pctcull >= 0) {                     /* finish output */
466                  if (pclose(ofp)) {
467 <                        fprintf(stderr, "%s: error running '%s'\n",
468 <                                        progname, cmd);
467 >                        fprintf(stderr, "%s: error running rttree_reduce on Y\n",
468 >                                        progname);
469                          exit(1);
470                  }
471 <        } else
472 <                fputs("}\n", stdout);
473 <        data_epilogue();
474 <        prog_done();
471 >                if (rbf_colorimetry == RBCtristimulus &&
472 >                                (pclose(uvfp[0]) || pclose(uvfp[1]))) {
473 >                        fprintf(stderr, "%s: error running rttree_reduce on uv\n",
474 >                                        progname);
475 >                        exit(1);
476 >                }
477 >        } else {
478 >                fputs("}\n", ofp);
479 >                if (fclose(ofp)) {
480 >                        fprintf(stderr, "%s: error writing Y file\n",
481 >                                        progname);
482 >                        exit(1);
483 >                }
484 >                if (rbf_colorimetry == RBCtristimulus) {
485 >                        fputs("}\n", uvfp[0]);
486 >                        fputs("}\n", uvfp[1]);
487 >                        if (fclose(uvfp[0]) || fclose(uvfp[1])) {
488 >                                fprintf(stderr, "%s: error writing uv file(s)\n",
489 >                                                progname);
490 >                                exit(1);
491 >                        }
492 >                }
493 >        }
494   }
495  
496 + #if defined(_WIN32) || defined(_WIN64)
497 + /* Execute wrapBSDF command (may never return) */
498 + static int
499 + wrap_up(void)
500 + {
501 +        char    cmd[8192];
502 +
503 +        if (bsdf_manuf[0]) {
504 +                add_wbsdf("-f", 1);
505 +                strcpy(cmd, "m=");
506 +                strcpy(cmd+2, bsdf_manuf);
507 +                add_wbsdf(cmd, 0);
508 +        }
509 +        if (bsdf_name[0]) {
510 +                add_wbsdf("-f", 1);
511 +                strcpy(cmd, "n=");
512 +                strcpy(cmd+2, bsdf_name);
513 +                add_wbsdf(cmd, 0);
514 +        }
515 +        if (!convert_commandline(cmd, sizeof(cmd), wrapBSDF)) {
516 +                fputs(progname, stderr);
517 +                fputs(": command line too long in wrap_up()\n", stderr);
518 +                return(1);
519 +        }
520 +        return(system(cmd));
521 + }
522 + #else
523 + /* Execute wrapBSDF command (may never return) */
524 + static int
525 + wrap_up(void)
526 + {
527 +        char    buf[256];
528 +        char    *compath = getpath((char *)wrapBSDF[0], getenv("PATH"), X_OK);
529 +
530 +        if (compath == NULL) {
531 +                fprintf(stderr, "%s: cannot locate %s\n", progname, wrapBSDF[0]);
532 +                return(1);
533 +        }
534 +        if (bsdf_manuf[0]) {
535 +                add_wbsdf("-f", 1);
536 +                strcpy(buf, "m=");
537 +                strcpy(buf+2, bsdf_manuf);
538 +                add_wbsdf(buf, 0);
539 +        }
540 +        if (bsdf_name[0]) {
541 +                add_wbsdf("-f", 1);
542 +                strcpy(buf, "n=");
543 +                strcpy(buf+2, bsdf_name);
544 +                add_wbsdf(buf, 0);
545 +        }
546 +        execv(compath, wrapBSDF);       /* successful call never returns */
547 +        perror(compath);
548 +        return(1);
549 + }
550 + #endif
551 +
552   /* Read in BSDF and interpolate as tensor tree representation */
553   int
554   main(int argc, char *argv[])
555   {
556 +        static char     tfmt[2][4] = {"t4", "t3"};
557          int     dofwd = 0, dobwd = 1;
558 +        char    buf[2048];
559          int     i, na;
560  
561          progname = argv[0];
# Line 395 | Line 569 | main(int argc, char *argv[])
569                          scompile(argv[++i], NULL, 0);
570                          break;
571                  case 'f':
572 <                        if (!argv[i][2])
573 <                                fcompile(argv[++i]);
574 <                        else
572 >                        if (!argv[i][2]) {
573 >                                if (strchr(argv[++i], '=') != NULL) {
574 >                                        add_wbsdf("-f", 1);
575 >                                        add_wbsdf(argv[i], 1);
576 >                                } else
577 >                                        fcompile(argv[i]);
578 >                        } else
579                                  dofwd = (argv[i][0] == '+');
580                          break;
581                  case 'b':
# Line 427 | Line 605 | main(int argc, char *argv[])
605                  case 'p':
606                          do_prog = atoi(argv[i]+2);
607                          break;
608 +                case 'W':
609 +                        add_wbsdf(argv[i], 1);
610 +                        break;
611 +                case 'u':
612 +                case 'C':
613 +                        add_wbsdf(argv[i], 1);
614 +                        add_wbsdf(argv[++i], 1);
615 +                        break;
616                  default:
617                          goto userr;
618                  }
619 +        strcpy(buf, "File produced by: ");
620 +        if (convert_commandline(buf+18, sizeof(buf)-18, argv) != NULL) {
621 +                add_wbsdf("-C", 1); add_wbsdf(buf, 0);
622 +        }
623          if (single_plane_incident >= 0) {       /* function-based BSDF? */
624                  void    (*evf)(char *s) = single_plane_incident ?
625 <                                &eval_isotropic : &eval_anisotropic;
625 >                                eval_isotropic : eval_anisotropic;
626                  if (i != argc-1 || fundefined(argv[i]) < 3) {
627                          fprintf(stderr,
628          "%s: need single function with 6 arguments: bsdf(ix,iy,iz,ox,oy,oz)\n",
# Line 441 | Line 631 | main(int argc, char *argv[])
631                          goto userr;
632                  }
633                  ++eclock;
634 <                xml_prologue(argc, argv);       /* start XML output */
634 >                add_wbsdf("-a", 1);
635 >                add_wbsdf(tfmt[single_plane_incident], 1);
636                  if (dofwd) {
637                          input_orient = -1;
638                          output_orient = -1;
# Line 460 | Line 651 | main(int argc, char *argv[])
651                          prog_start("Evaluating inside->outside transmission");
652                          (*evf)(argv[i]);
653                  }
654 <                xml_epilogue();                 /* finish XML output & exit */
464 <                return(0);
654 >                return(wrap_up());
655          }
656          if (i < argc) {                         /* open input files if given */
657                  int     nbsdf = 0;
# Line 476 | Line 666 | main(int argc, char *argv[])
666                          if (!load_bsdf_rep(fpin))
667                                  return(1);
668                          fclose(fpin);
479                        if (!nbsdf++)           /* start XML on first dist. */
480                                xml_prologue(argc, argv);
669                          sprintf(pbuf, "Interpolating component '%s'", argv[i]);
670                          prog_start(pbuf);
671 +                        if (!nbsdf++) {
672 +                                add_wbsdf("-a", 1);
673 +                                add_wbsdf(tfmt[single_plane_incident], 1);
674 +                        }
675                          if (single_plane_incident)
676                                  eval_isotropic(NULL);
677                          else
678                                  eval_anisotropic(NULL);
679                  }
680 <                xml_epilogue();                 /* finish XML output & exit */
489 <                return(0);
680 >                return(wrap_up());
681          }
682          SET_FILE_BINARY(stdin);                 /* load from stdin */
683          if (!load_bsdf_rep(stdin))
684                  return(1);
494        xml_prologue(argc, argv);               /* start XML output */
685          prog_start("Interpolating from standard input");
686 +        add_wbsdf("-a", 1);
687 +        add_wbsdf(tfmt[single_plane_incident], 1);
688          if (single_plane_incident)              /* resample dist. */
689                  eval_isotropic(NULL);
690          else
691                  eval_anisotropic(NULL);
692 <        xml_epilogue();                         /* finish XML output & exit */
693 <        return(0);
692 >
693 >        return(wrap_up());
694   userr:
695          fprintf(stderr,
696          "Usage: %s [-g Nlog2][-t pctcull][-l maxlobes] [bsdf.sir ..] > bsdf.xml\n",

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines