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.19 by greg, Thu Oct 3 17:01:02 2013 UTC vs.
Revision 2.27 by greg, Wed Mar 12 22:24:59 2014 UTC

# Line 11 | Line 11 | static const char RCSid[] = "$Id$";
11   #include <stdio.h>
12   #include <stdlib.h>
13   #include <math.h>
14 + #include "random.h"
15   #include "platform.h"
16 + #include "rtprocess.h"
17   #include "calcomp.h"
18   #include "bsdfrep.h"
19                                  /* global argv[0] */
# Line 26 | Line 28 | const double           ssamp_thresh = 0.35;
28   const int               nssamp = 100;
29                                  /* limit on number of RBF lobes */
30   static int              lobe_lim = 15000;
31 +                                /* progress bar length */
32 + static int              do_prog = 79;
33  
34 +
35 + /* Start new progress bar */
36 + #define prog_start(s)   if (do_prog) fprintf(stderr, "%s: %s...\n", progname, s); else
37 +
38 + /* Draw progress bar of the appropriate length */
39 + static void
40 + prog_show(double frac)
41 + {
42 +        char    pbar[256];
43 +        int     nchars;
44 +
45 +        if (do_prog <= 0) return;
46 +        if (do_prog > sizeof(pbar)-2)
47 +                do_prog = sizeof(pbar)-2;
48 +        if (frac < 0) frac = 0;
49 +        else if (frac > 1) frac = 1;
50 +        nchars = do_prog*frac + .5;
51 +        pbar[0] = '\r';
52 +        memset(pbar+1, '*', nchars);
53 +        memset(pbar+1+nchars, '-', do_prog-nchars);
54 +        pbar[do_prog+1] = '\0';
55 +        fputs(pbar, stderr);
56 + }
57 +
58 + /* Finish progress bar */
59 + static void
60 + prog_done(void)
61 + {
62 +        int     n = do_prog;
63 +
64 +        if (n <= 1) return;
65 +        fputc('\r', stderr);
66 +        while (n--)
67 +                fputc(' ', stderr);
68 +        fputc('\r', stderr);
69 + }
70 +
71   /* Output XML prologue to stdout */
72   static void
73   xml_prologue(int ac, char *av[])
# Line 44 | Line 85 | xml_prologue(int ac, char *av[])
85          puts("<Optical>");
86          puts("<Layer>");
87          puts("\t<Material>");
88 <        puts("\t\t<Name>Name</Name>");
89 <        puts("\t\t<Manufacturer>Manufacturer</Manufacturer>");
88 >        printf("\t\t<Name>%s</Name>\n", bsdf_name[0] ? bsdf_name : "Unknown");
89 >        printf("\t\t<Manufacturer>%s</Manufacturer>\n",
90 >                        bsdf_manuf[0] ? bsdf_manuf : "Unknown");
91          puts("\t\t<DeviceType>Other</DeviceType>");
92          puts("\t</Material>");
93          puts("\t<DataDefinition>");
# Line 122 | Line 164 | eval_isotropic(char *funame)
164  
165          data_prologue();                        /* begin output */
166          if (pctcull >= 0) {
167 <                sprintf(cmd, "rttree_reduce%s -h -ff -r 3 -t %f -g %d",
126 <                                (input_orient>0 ^ output_orient>0) ? "" : " -a",
167 >                sprintf(cmd, "rttree_reduce -a -h -ff -r 3 -t %f -g %d",
168                                  pctcull, samp_order);
169                  fflush(stdout);
170                  ofp = popen(cmd, "w");
# Line 133 | Line 174 | eval_isotropic(char *funame)
174                          exit(1);
175                  }
176                  SET_FILE_BINARY(ofp);
177 + #ifdef getc_unlocked                            /* avoid lock/unlock overhead */
178 +                flockfile(ofp);
179 + #endif
180          } else
181                  fputs("{\n", stdout);
182                                                  /* need to assign Dx, Dy, Dz? */
# Line 168 | Line 212 | eval_isotropic(char *funame)
212                              if (abs_diff(bsdf, last_bsdf) > ssamp_thresh) {
213                                  sum = 0;        /* super-sample voxel */
214                                  for (ssi = nssamp; ssi--; ) {
215 <                                    SDmultiSamp(ssa, 3, (ssi+drand48())/nssamp);
215 >                                    SDmultiSamp(ssa, 3, (ssi+frandom())/nssamp);
216                                      ssvec[0] = 2.*(ix+ssa[0])/sqres - 1.;
217                                      ssvec[1] = .0;
218                                      ssvec[2] = input_orient *
# Line 198 | Line 242 | eval_isotropic(char *funame)
242                  }
243                  if (rbf != NULL)
244                          free(rbf);
245 +                prog_show((ix+1.)*(2./sqres));
246          }
247          if (pctcull >= 0) {                     /* finish output */
248                  if (pclose(ofp)) {
# Line 211 | Line 256 | eval_isotropic(char *funame)
256                  fputs("}\n", stdout);
257          }
258          data_epilogue();
259 +        prog_done();
260   }
261  
262   /* Interpolate and output anisotropic BSDF data */
# Line 237 | Line 283 | eval_anisotropic(char *funame)
283                                          progname);
284                          exit(1);
285                  }
286 +                SET_FILE_BINARY(ofp);
287 + #ifdef getc_unlocked                            /* avoid lock/unlock overhead */
288 +                flockfile(ofp);
289 + #endif
290          } else
291                  fputs("{\n", stdout);
292                                                  /* need to assign Dx, Dy, Dz? */
# Line 273 | Line 323 | eval_anisotropic(char *funame)
323                              if (abs_diff(bsdf, last_bsdf) > ssamp_thresh) {
324                                  sum = 0;        /* super-sample voxel */
325                                  for (ssi = nssamp; ssi--; ) {
326 <                                    SDmultiSamp(ssa, 4, (ssi+drand48())/nssamp);
326 >                                    SDmultiSamp(ssa, 4, (ssi+frandom())/nssamp);
327                                      SDsquare2disk(ssvec, 1.-(ix+ssa[0])/sqres,
328                                                  1.-(iy+ssa[1])/sqres);
329                                      ssvec[2] = output_orient *
# Line 304 | Line 354 | eval_anisotropic(char *funame)
354                  }
355                  if (rbf != NULL)
356                          free(rbf);
357 +                prog_show((ix*sqres+iy+1.)/(sqres*sqres));
358              }
359          if (pctcull >= 0) {                     /* finish output */
360                  if (pclose(ofp)) {
# Line 314 | Line 365 | eval_anisotropic(char *funame)
365          } else
366                  fputs("}\n", stdout);
367          data_epilogue();
368 +        prog_done();
369   }
370  
371   /* Read in BSDF and interpolate as tensor tree representation */
# Line 363 | Line 415 | main(int argc, char *argv[])
415                  case 'l':
416                          lobe_lim = atoi(argv[++i]);
417                          break;
418 +                case 'p':
419 +                        do_prog = atoi(argv[i]+2);
420 +                        break;
421                  default:
422                          goto userr;
423                  }
# Line 373 | Line 428 | main(int argc, char *argv[])
428                          fprintf(stderr,
429          "%s: need single function with 6 arguments: bsdf(ix,iy,iz,ox,oy,oz)\n",
430                                          progname);
431 <                        fprintf(stderr, "\tor 3 arguments using Dx,Dy,Dz: bsdf(ix,iy,iz)\n",
377 <                                        progname);
431 >                        fprintf(stderr, "\tor 3 arguments using Dx,Dy,Dz: bsdf(ix,iy,iz)\n");
432                          goto userr;
433                  }
434                  ++eclock;
# Line 382 | Line 436 | main(int argc, char *argv[])
436                  if (dofwd) {
437                          input_orient = -1;
438                          output_orient = -1;
439 <                        (*evf)(argv[i]);        /* outside reflectance */
439 >                        prog_start("Evaluating outside reflectance");
440 >                        (*evf)(argv[i]);
441                          output_orient = 1;
442 <                        (*evf)(argv[i]);        /* outside -> inside */
442 >                        prog_start("Evaluating outside->inside transmission");
443 >                        (*evf)(argv[i]);
444                  }
445                  if (dobwd) {
446                          input_orient = 1;
447                          output_orient = 1;
448 <                        (*evf)(argv[i]);        /* inside reflectance */
448 >                        prog_start("Evaluating inside reflectance");
449 >                        (*evf)(argv[i]);
450                          output_orient = -1;
451 <                        (*evf)(argv[i]);        /* inside -> outside */
451 >                        prog_start("Evaluating inside->outside transmission");
452 >                        (*evf)(argv[i]);
453                  }
454                  xml_epilogue();                 /* finish XML output & exit */
455                  return(0);
# Line 399 | Line 457 | main(int argc, char *argv[])
457          if (i < argc) {                         /* open input files if given */
458                  int     nbsdf = 0;
459                  for ( ; i < argc; i++) {        /* interpolate each component */
460 +                        char    pbuf[256];
461                          FILE    *fpin = fopen(argv[i], "rb");
462                          if (fpin == NULL) {
463                                  fprintf(stderr, "%s: cannot open BSDF interpolant '%s'\n",
# Line 410 | Line 469 | main(int argc, char *argv[])
469                          fclose(fpin);
470                          if (!nbsdf++)           /* start XML on first dist. */
471                                  xml_prologue(argc, argv);
472 +                        sprintf(pbuf, "Interpolating component '%s'", argv[i]);
473 +                        prog_start(pbuf);
474                          if (single_plane_incident)
475                                  eval_isotropic(NULL);
476                          else
# Line 422 | Line 483 | main(int argc, char *argv[])
483          if (!load_bsdf_rep(stdin))
484                  return(1);
485          xml_prologue(argc, argv);               /* start XML output */
486 +        prog_start("Interpolating from standard input");
487          if (single_plane_incident)              /* resample dist. */
488                  eval_isotropic(NULL);
489          else

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines