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

Comparing ray/src/cv/bsdf2klems.c (file contents):
Revision 2.2 by greg, Tue Apr 23 04:40:23 2013 UTC vs.
Revision 2.11 by greg, Sat Nov 9 05:47:49 2013 UTC

# Line 17 | Line 17 | static const char RCSid[] = "$Id$";
17   #include "calcomp.h"
18   #include "bsdfrep.h"
19   #include "bsdf_m.h"
20 +                                /* assumed maximum # Klems patches */
21 + #define MAXPATCHES      145
22                                  /* global argv[0] */
23   char                    *progname;
24                                  /* selected basis function name */
25   static const char       *kbasis = "LBNL/Klems Full";
26                                  /* number of BSDF samples per patch */
27   static int              npsamps = 256;
28 +                                /* limit on number of RBF lobes */
29 + static int              lobe_lim = 15000;
30  
31   /* Return angle basis corresponding to the given name */
32   ANGLE_BASIS *
# Line 36 | Line 40 | get_basis(const char *bn)
40          return NULL;
41   }
42  
43 < /* Output XML prologue to stdout */
43 > /* Output XML header to stdout */
44   static void
45 < xml_prologue(int ac, char *av[])
45 > xml_header(int ac, char *av[])
46   {
43        ANGLE_BASIS     *abp = get_basis(kbasis);
44        int             i;
45
46        if (abp == NULL) {
47                fprintf(stderr, "%s: unknown angle basis '%s'\n", progname, kbasis);
48                exit(1);
49        }
47          puts("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
48          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\">");
49          fputs("<!-- File produced by:", stdout);
# Line 55 | Line 52 | xml_prologue(int ac, char *av[])
52                  fputs(*av++, stdout);
53          }
54          puts(" -->");
55 + }
56 +
57 + /* Output XML prologue to stdout */
58 + static void
59 + xml_prologue(const SDData *sd)
60 + {
61 +        const char      *matn = (sd && sd->matn[0]) ? sd->matn :
62 +                                bsdf_name[0] ? bsdf_name : "Unknown";
63 +        const char      *makr = (sd && sd->makr[0]) ? sd->makr :
64 +                                bsdf_manuf[0] ? bsdf_manuf : "Unknown";
65 +        ANGLE_BASIS     *abp = get_basis(kbasis);
66 +        int             i;
67 +
68 +        if (abp == NULL) {
69 +                fprintf(stderr, "%s: unknown angle basis '%s'\n", progname, kbasis);
70 +                exit(1);
71 +        }
72          puts("<WindowElementType>System</WindowElementType>");
73          puts("<FileType>BSDF</FileType>");
74          puts("<Optical>");
75          puts("<Layer>");
76          puts("\t<Material>");
77 <        puts("\t\t<Name>Name</Name>");
78 <        puts("\t\t<Manufacturer>Manufacturer</Manufacturer>");
77 >        printf("\t\t<Name>%s</Name>\n", matn);
78 >        printf("\t\t<Manufacturer>%s</Manufacturer>\n", makr);
79 >        if (sd && sd->dim[2] > .001) {
80 >                printf("\t\t<Thickness unit=\"meter\">%.3f</Thickness>\n", sd->dim[2]);
81 >                printf("\t\t<Width unit=\"meter\">%.3f</Width>\n", sd->dim[0]);
82 >                printf("\t\t<Height unit=\"meter\">%.3f</Height>\n", sd->dim[1]);
83 >        }
84          puts("\t\t<DeviceType>Other</DeviceType>");
85          puts("\t</Material>");
86 +        if (sd && sd->mgf != NULL) {
87 +                puts("\t<Geometry format=\"MGF\">");
88 +                puts("\t\t<MGFblock unit=\"meter\">");
89 +                fputs(sd->mgf, stdout);
90 +                puts("</MGFblock>");
91 +                puts("\t</Geometry>");
92 +        }
93          puts("\t<DataDefinition>");
94          puts("\t\t<IncidentDataStructure>Columns</IncidentDataStructure>");
95          puts("\t\t<AngleBasis>");
# Line 73 | Line 99 | xml_prologue(int ac, char *av[])
99                  printf("\t\t\t<Theta>%g</Theta>\n", i ?
100                                  .5*(abp->lat[i].tmin + abp->lat[i+1].tmin) :
101                                  .0 );
102 <                printf("\t\t\t<nPhis>%d</nPhis>", abp->lat[i].nphis);
102 >                printf("\t\t\t<nPhis>%d</nPhis>\n", abp->lat[i].nphis);
103                  puts("\t\t\t<ThetaBounds>");
104                  printf("\t\t\t\t<LowerTheta>%g</LowerTheta>\n", abp->lat[i].tmin);
105                  printf("\t\t\t\t<UpperTheta>%g</UpperTheta>\n", abp->lat[i+1].tmin);
# Line 142 | Line 168 | eval_bsdf(const char *fname)
168          SDclearBSDF(&bsd, fname);               /* load BSDF file */
169          if ((ec = SDloadFile(&bsd, fname)) != SDEnone)
170                  goto err;
171 +        xml_prologue(&bsd);                     /* pass geometry */
172                                                  /* front reflection */
173          if (bsd.rf != NULL || bsd.rLambFront.cieY > .002) {
174              input_orient = 1; output_orient = 1;
# Line 151 | Line 178 | eval_bsdf(const char *fname)
178                      sum = 0;                    /* average over patches */
179                      for (n = npsamps; n-- > 0; ) {
180                          fo_getvec(vout, j+(n+frandom())/npsamps, abp);
181 <                        fi_getvec(vin, i+(n+frandom())/npsamps, abp);
181 >                        fi_getvec(vin, i+urand(n), abp);
182                          ec = SDevalBSDF(&sv, vout, vin, &bsd);
183                          if (ec != SDEnone)
184                                  goto err;
# Line 172 | Line 199 | eval_bsdf(const char *fname)
199                      sum = 0;                    /* average over patches */
200                      for (n = npsamps; n-- > 0; ) {
201                          bo_getvec(vout, j+(n+frandom())/npsamps, abp);
202 <                        bi_getvec(vin, i+(n+frandom())/npsamps, abp);
202 >                        bi_getvec(vin, i+urand(n), abp);
203                          ec = SDevalBSDF(&sv, vout, vin, &bsd);
204                          if (ec != SDEnone)
205                                  goto err;
# Line 193 | Line 220 | eval_bsdf(const char *fname)
220                      sum = 0;                    /* average over patches */
221                      for (n = npsamps; n-- > 0; ) {
222                          bo_getvec(vout, j+(n+frandom())/npsamps, abp);
223 <                        fi_getvec(vin, i+(n+frandom())/npsamps, abp);
223 >                        fi_getvec(vin, i+urand(n), abp);
224                          ec = SDevalBSDF(&sv, vout, vin, &bsd);
225                          if (ec != SDEnone)
226                                  goto err;
# Line 206 | Line 233 | eval_bsdf(const char *fname)
233              data_epilogue();
234          }
235                                                  /* back transmission */
236 <        if (bsd.tb != NULL) {
236 >        if ((bsd.tb != NULL) | (bsd.tf != NULL)) {
237              input_orient = -1; output_orient = 1;
238              data_prologue();
239              for (j = 0; j < abp->nangles; j++) {
240                  for (i = 0; i < abp->nangles; i++) {
241 <                    sum = 0;                    /* average over patches */
241 >                    sum = 0;            /* average over patches */
242                      for (n = npsamps; n-- > 0; ) {
243                          fo_getvec(vout, j+(n+frandom())/npsamps, abp);
244 <                        bi_getvec(vin, i+(n+frandom())/npsamps, abp);
244 >                        bi_getvec(vin, i+urand(n), abp);
245                          ec = SDevalBSDF(&sv, vout, vin, &bsd);
246                          if (ec != SDEnone)
247                                  goto err;
# Line 238 | Line 265 | static void
265   eval_function(char *funame)
266   {
267          ANGLE_BASIS     *abp = get_basis(kbasis);
268 +        int             assignD = (fundefined(funame) < 6);
269          double          iovec[6];
270          double          sum;
271          int             i, j, n;
272  
273 +        initurand(npsamps);
274          data_prologue();                        /* begin output */
275          for (j = 0; j < abp->nangles; j++) {    /* run through directions */
276              for (i = 0; i < abp->nangles; i++) {
# Line 253 | Line 282 | eval_function(char *funame)
282                          bo_getvec(iovec+3, j+(n+frandom())/npsamps, abp);
283  
284                      if (input_orient > 0)
285 <                        fi_getvec(iovec, i+(n+frandom())/npsamps, abp);
285 >                        fi_getvec(iovec, i+urand(n), abp);
286                      else
287 <                        bi_getvec(iovec, i+(n+frandom())/npsamps, abp);
287 >                        bi_getvec(iovec, i+urand(n), abp);
288  
289 +                    if (assignD) {
290 +                        varset("Dx", '=', -iovec[3]);
291 +                        varset("Dy", '=', -iovec[4]);
292 +                        varset("Dz", '=', -iovec[5]);
293 +                        ++eclock;
294 +                    }
295                      sum += funvalue(funame, 6, iovec);
296                  }
297                  printf("\t%.3e\n", sum/npsamps);
# Line 270 | Line 305 | eval_function(char *funame)
305   static void
306   eval_rbf(void)
307   {
273 #define MAXPATCHES      145
308          ANGLE_BASIS     *abp = get_basis(kbasis);
309          float           bsdfarr[MAXPATCHES*MAXPATCHES];
310          FVECT           vin, vout;
# Line 289 | Line 323 | eval_rbf(void)
323              else
324                  bi_getvec(vin, i+.5*(i>0), abp);
325  
326 <            rbf = advect_rbf(vin);              /* compute radial basis func */
326 >            rbf = advect_rbf(vin, lobe_lim);    /* compute radial basis func */
327  
328              for (j = 0; j < abp->nangles; j++) {
329                  sum = 0;                        /* sample over exiting patch */
# Line 303 | Line 337 | eval_rbf(void)
337                  }
338                  bsdfarr[j*abp->nangles + i] = sum*output_orient/npsamps;
339              }
340 +            if (rbf != NULL)
341 +                free(rbf);
342          }
343          n = 0;                                  /* write out our matrix */
344          for (j = 0; j < abp->nangles; j++) {
# Line 311 | Line 347 | eval_rbf(void)
347              putchar('\n');
348          }
349          data_epilogue();                        /* finish output */
314 #undef MAXPATCHES
350   }
351  
352   /* Read in BSDF and interpolate as Klems matrix representation */
# Line 354 | Line 389 | main(int argc, char *argv[])
389                  case 'q':
390                          kbasis = "LBNL/Klems Quarter";
391                          break;
392 +                case 'l':
393 +                        lobe_lim = atoi(argv[++i]);
394 +                        break;
395                  default:
396                          goto userr;
397                  }
# Line 362 | Line 400 | main(int argc, char *argv[])
400                          fprintf(stderr,
401          "%s: need single function with 6 arguments: bsdf(ix,iy,iz,ox,oy,oz)\n",
402                                          progname);
403 +                        fprintf(stderr, "\tor 3 arguments using Dx,Dy,Dz: bsdf(ix,iy,iz)\n",
404 +                                        progname);
405                          goto userr;
406                  }
407 <                xml_prologue(argc, argv);       /* start XML output */
407 >                ++eclock;
408 >                xml_header(argc, argv);                 /* start XML output */
409 >                xml_prologue(NULL);
410                  if (dofwd) {
411                          input_orient = -1;
412                          output_orient = -1;
# Line 385 | Line 427 | main(int argc, char *argv[])
427                                                  /* XML input? */
428          if (i == argc-1 && (cp = argv[i]+strlen(argv[i])-4) > argv[i] &&
429                                  !strcasecmp(cp, ".xml")) {
430 <                xml_prologue(argc, argv);       /* start XML output */
430 >                xml_header(argc, argv);         /* start XML output */
431                  eval_bsdf(argv[i]);             /* load & resample BSDF */
432                  xml_epilogue();                 /* finish XML output & exit */
433                  return(0);
# Line 402 | Line 444 | main(int argc, char *argv[])
444                          if (!load_bsdf_rep(fpin))
445                                  return(1);
446                          fclose(fpin);
447 <                        if (!nbsdf++)           /* start XML on first dist. */
448 <                                xml_prologue(argc, argv);
447 >                        if (!nbsdf++) {         /* start XML on first dist. */
448 >                                xml_header(argc, argv);
449 >                                xml_prologue(NULL);
450 >                        }
451                          eval_rbf();
452                  }
453                  xml_epilogue();                 /* finish XML output & exit */
# Line 412 | Line 456 | main(int argc, char *argv[])
456          SET_FILE_BINARY(stdin);                 /* load from stdin */
457          if (!load_bsdf_rep(stdin))
458                  return(1);
459 <        xml_prologue(argc, argv);               /* start XML output */
459 >        xml_header(argc, argv);                 /* start XML output */
460 >        xml_prologue(NULL);
461          eval_rbf();                             /* resample dist. */
462          xml_epilogue();                         /* finish XML output & exit */
463          return(0);
464   userr:
465          fprintf(stderr,
466 <        "Usage: %s [-n spp][-h|-q][bsdf.sir ..] > bsdf.xml\n",
422 <                                progname);
466 >        "Usage: %s [-n spp][-h|-q][-l maxlobes] [bsdf.sir ..] > bsdf.xml\n", progname);
467          fprintf(stderr,
468 <        "   or: %s [-n spp][-h|-q] bsdf_in.xml > bsdf_out.xml\n",
425 <                                progname);
468 >        "   or: %s [-n spp][-h|-q] bsdf_in.xml > bsdf_out.xml\n", progname);
469          fprintf(stderr,
470          "   or: %s [-n spp][-h|-q][{+|-}for[ward]][{+|-}b[ackward]][-e expr][-f file] bsdf_func > bsdf.xml\n",
471                                  progname);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines