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.34 by greg, Tue Feb 2 22:34:00 2016 UTC vs.
Revision 2.41 by greg, Wed May 31 17:25:21 2017 UTC

# Line 19 | Line 19 | static const char RCSid[] = "$Id$";
19   #include "bsdfrep.h"
20                                  /* global argv[0] */
21   char                    *progname;
22 +                                /* reciprocity averaging option */
23 + static const char       *recip = " -a";
24                                  /* percentage to cull (<0 to turn off) */
25   static double           pctcull = 90.;
26                                  /* sampling order */
# Line 27 | Line 29 | static int             samp_order = 6;
29   const double            ssamp_thresh = 0.35;
30                                  /* number of super-samples */
31   #ifndef NSSAMP
32 < #define NSSAMP          100
32 > #define NSSAMP          64
33   #endif
34                                  /* limit on number of RBF lobes */
35   static int              lobe_lim = 15000;
# Line 38 | Line 40 | static int             do_prog = 79;
40   static char             *wrapBSDF[MAXCARG] = {"wrapBSDF", "-U"};
41   static int              wbsdfac = 2;
42  
43 < /* Add argument to wrapBSDF, allocating space if isstatic */
43 > /* Add argument to wrapBSDF, allocating space if !isstatic */
44   static void
45   add_wbsdf(const char *arg, int isstatic)
46   {
# Line 135 | Line 137 | eval_isotropic(char *funame)
137          float           bsdf, uv[2];
138  
139          if (pctcull >= 0) {
140 <                sprintf(cmd, "rttree_reduce -a -h -ff -r 3 -t %f -g %d > %s",
141 <                                pctcull, samp_order, create_component_file(0));
140 >                sprintf(cmd, "rttree_reduce%s -h -ff -r 3 -t %f -g %d > %s",
141 >                                recip, pctcull, samp_order, create_component_file(0));
142                  ofp = popen(cmd, "w");
143                  if (ofp == NULL) {
144                          fprintf(stderr, "%s: cannot create pipe to rttree_reduce\n",
# Line 149 | Line 151 | eval_isotropic(char *funame)
151   #endif
152                  if (rbf_colorimetry == RBCtristimulus) {
153                          double  uvcull = 100. - (100.-pctcull)*.25;
154 <                        sprintf(cmd, "rttree_reduce -a -h -ff -r 3 -t %f -g %d > %s",
155 <                                        uvcull, samp_order, create_component_file(1));
154 >                        sprintf(cmd, "rttree_reduce%s -h -ff -r 3 -t %f -g %d > %s",
155 >                                        recip, uvcull, samp_order, create_component_file(1));
156                          uvfp[0] = popen(cmd, "w");
157 <                        sprintf(cmd, "rttree_reduce -a -h -ff -r 3 -t %f -g %d > %s",
158 <                                        uvcull, samp_order, create_component_file(2));
157 >                        sprintf(cmd, "rttree_reduce%s -h -ff -r 3 -t %f -g %d > %s",
158 >                                        recip, uvcull, samp_order, create_component_file(2));
159                          uvfp[1] = popen(cmd, "w");
160                          if ((uvfp[0] == NULL) | (uvfp[1] == NULL)) {
161                                  fprintf(stderr, "%s: cannot open pipes to uv output\n",
# Line 185 | Line 187 | eval_isotropic(char *funame)
187                          fputs("{\n", uvfp[1]);
188                  }
189          }
190 <                                                /* need to assign Dx, Dy, Dz? */
189 <        if (funame != NULL)
190 >        if (funame != NULL)                     /* need to assign Dx, Dy, Dz? */
191                  assignD = (fundefined(funame) < 6);
192                                                  /* run through directions */
193          for (ix = 0; ix < sqres/2; ix++) {
# Line 207 | Line 208 | eval_isotropic(char *funame)
208                              eval_rbfcol(&sdv, rbf, iovec+3);
209                              bsdf = sdv.cieY;
210                              if (rbf_colorimetry == RBCtristimulus) {
210                                c_ccvt(&sdv.spec, C_CSXY);
211                                  uv[0] = uv[1] = 1. /
212                                      (-2.*sdv.spec.cx + 12.*sdv.spec.cy + 3.);
213                                  uv[0] *= 4.*sdv.spec.cx;
# Line 251 | Line 251 | eval_isotropic(char *funame)
251   #endif
252                          }
253                          if (pctcull >= 0)
254 <                                fwrite(&bsdf, sizeof(bsdf), 1, ofp);
254 >                                putbinary(&bsdf, sizeof(bsdf), 1, ofp);
255                          else
256                                  fprintf(ofp, "\t%.3e\n", bsdf);
257  
258                          if (rbf_colorimetry == RBCtristimulus) {
259                                  if (pctcull >= 0) {
260 <                                        fwrite(&uv[0], sizeof(*uv), 1, uvfp[0]);
261 <                                        fwrite(&uv[1], sizeof(*uv), 1, uvfp[1]);
260 >                                        putbinary(&uv[0], sizeof(*uv), 1, uvfp[0]);
261 >                                        putbinary(&uv[1], sizeof(*uv), 1, uvfp[1]);
262                                  } else {
263                                          fprintf(uvfp[0], "\t%.3e\n", uv[0]);
264                                          fprintf(uvfp[1], "\t%.3e\n", uv[1]);
# Line 271 | Line 271 | eval_isotropic(char *funame)
271                          free(rbf);
272                  prog_show((ix+1.)*(2./sqres));
273          }
274 +        prog_done();
275          if (pctcull >= 0) {                     /* finish output */
276                  if (pclose(ofp)) {
277                          fprintf(stderr, "%s: error running rttree_reduce on Y\n",
# Line 306 | Line 307 | eval_isotropic(char *funame)
307                          }
308                  }
309          }
309        prog_done();
310   }
311  
312   /* Interpolate and output anisotropic BSDF data */
# Line 322 | Line 322 | eval_anisotropic(char *funame)
322          float           bsdf, uv[2];
323  
324          if (pctcull >= 0) {
325 +                const char      *avgopt = (input_orient>0 ^ output_orient>0)
326 +                                                ? "" : recip;
327                  sprintf(cmd, "rttree_reduce%s -h -ff -r 4 -t %f -g %d > %s",
328 <                                (input_orient>0 ^ output_orient>0) ? "" : " -a",
329 <                                pctcull, samp_order, create_component_file(0));
328 >                                avgopt, pctcull, samp_order,
329 >                                create_component_file(0));
330                  ofp = popen(cmd, "w");
331                  if (ofp == NULL) {
332                          fprintf(stderr, "%s: cannot create pipe to rttree_reduce\n",
# Line 338 | Line 340 | eval_anisotropic(char *funame)
340                  if (rbf_colorimetry == RBCtristimulus) {
341                          double  uvcull = 100. - (100.-pctcull)*.25;
342                          sprintf(cmd, "rttree_reduce%s -h -ff -r 4 -t %f -g %d > %s",
343 <                                        (input_orient>0 ^ output_orient>0) ? "" : " -a",
344 <                                        uvcull, samp_order, create_component_file(1));
343 >                                        avgopt, uvcull, samp_order,
344 >                                        create_component_file(1));
345                          uvfp[0] = popen(cmd, "w");
346                          sprintf(cmd, "rttree_reduce%s -h -ff -r 4 -t %f -g %d > %s",
347 <                                        (input_orient>0 ^ output_orient>0) ? "" : " -a",
348 <                                        uvcull, samp_order, create_component_file(2));
347 >                                        avgopt, uvcull, samp_order,
348 >                                        create_component_file(2));
349                          uvfp[1] = popen(cmd, "w");
350                          if ((uvfp[0] == NULL) | (uvfp[1] == NULL)) {
351                                  fprintf(stderr, "%s: cannot open pipes to uv output\n",
# Line 375 | Line 377 | eval_anisotropic(char *funame)
377                          fputs("{\n", uvfp[1]);
378                  }
379          }
380 <                                                /* need to assign Dx, Dy, Dz? */
379 <        if (funame != NULL)
380 >        if (funame != NULL)                     /* need to assign Dx, Dy, Dz? */
381                  assignD = (fundefined(funame) < 6);
382                                                  /* run through directions */
383          for (ix = 0; ix < sqres; ix++)
# Line 398 | Line 399 | eval_anisotropic(char *funame)
399                              eval_rbfcol(&sdv, rbf, iovec+3);
400                              bsdf = sdv.cieY;
401                              if (rbf_colorimetry == RBCtristimulus) {
401                                c_ccvt(&sdv.spec, C_CSXY);
402                                  uv[0] = uv[1] = 1. /
403                                      (-2.*sdv.spec.cx + 12.*sdv.spec.cy + 3.);
404                                  uv[0] *= 4.*sdv.spec.cx;
# Line 443 | Line 443 | eval_anisotropic(char *funame)
443   #endif
444                          }
445                          if (pctcull >= 0)
446 <                                fwrite(&bsdf, sizeof(bsdf), 1, ofp);
446 >                                putbinary(&bsdf, sizeof(bsdf), 1, ofp);
447                          else
448                                  fprintf(ofp, "\t%.3e\n", bsdf);
449  
450                          if (rbf_colorimetry == RBCtristimulus) {
451                                  if (pctcull >= 0) {
452 <                                        fwrite(&uv[0], sizeof(*uv), 1, uvfp[0]);
453 <                                        fwrite(&uv[1], sizeof(*uv), 1, uvfp[1]);
452 >                                        putbinary(&uv[0], sizeof(*uv), 1, uvfp[0]);
453 >                                        putbinary(&uv[1], sizeof(*uv), 1, uvfp[1]);
454                                  } else {
455                                          fprintf(uvfp[0], "\t%.3e\n", uv[0]);
456                                          fprintf(uvfp[1], "\t%.3e\n", uv[1]);
# Line 463 | Line 463 | eval_anisotropic(char *funame)
463                          free(rbf);
464                  prog_show((ix*sqres+iy+1.)/(sqres*sqres));
465              }
466 +        prog_done();
467          if (pctcull >= 0) {                     /* finish output */
468                  if (pclose(ofp)) {
469                          fprintf(stderr, "%s: error running rttree_reduce on Y\n",
# Line 492 | Line 493 | eval_anisotropic(char *funame)
493                          }
494                  }
495          }
495        prog_done();
496   }
497  
498 < #ifdef _WIN32
498 > #if defined(_WIN32) || defined(_WIN64)
499   /* Execute wrapBSDF command (may never return) */
500   static int
501   wrap_up(void)
# Line 565 | Line 565 | main(int argc, char *argv[])
565          esupport &= ~(E_INCHAN|E_OUTCHAN);
566          scompile("PI:3.14159265358979323846", NULL, 0);
567          biggerlib();
568 <        for (i = 1; i < argc-1 && (argv[i][0] == '-') | (argv[i][0] == '+'); i++)
568 >        for (i = 1; i < argc && (argv[i][0] == '-') | (argv[i][0] == '+'); i++)
569                  switch (argv[i][1]) {           /* get options */
570                  case 'e':
571                          scompile(argv[++i], NULL, 0);
# Line 580 | Line 580 | main(int argc, char *argv[])
580                          } else
581                                  dofwd = (argv[i][0] == '+');
582                          break;
583 +                case 'a':
584 +                        recip = (argv[i][0] == '+') ? " -a" : "";
585 +                        break;
586                  case 'b':
587                          dobwd = (argv[i][0] == '+');
588                          break;
# Line 695 | Line 698 | main(int argc, char *argv[])
698          return(wrap_up());
699   userr:
700          fprintf(stderr,
701 <        "Usage: %s [-g Nlog2][-t pctcull][-l maxlobes] [bsdf.sir ..] > bsdf.xml\n",
701 >        "Usage: %s [{+|-}a][-g Nlog2][-t pctcull][-l maxlobes] [bsdf.sir ..] > bsdf.xml\n",
702                                  progname);
703          fprintf(stderr,
704 <        "   or: %s -t{3|4} [-g Nlog2][-t pctcull][{+|-}for[ward]][{+|-}b[ackward]][-e expr][-f file] bsdf_func > bsdf.xml\n",
704 >        "   or: %s -t{3|4} [{+|-}a][-g Nlog2][-t pctcull][{+|-}for[ward]][{+|-}b[ackward]][-e expr][-f file] bsdf_func > bsdf.xml\n",
705                                  progname);
706          return(1);
707   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines