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.5 by greg, Thu Apr 25 03:14:52 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 */
# Line 36 | Line 38 | get_basis(const char *bn)
38          return NULL;
39   }
40  
41 < /* Output XML prologue to stdout */
41 > /* Output XML header to stdout */
42   static void
43 < xml_prologue(int ac, char *av[])
43 > xml_header(int ac, char *av[])
44   {
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        }
45          puts("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
46          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\">");
47          fputs("<!-- File produced by:", stdout);
# Line 55 | Line 50 | xml_prologue(int ac, char *av[])
50                  fputs(*av++, stdout);
51          }
52          puts(" -->");
53 + }
54 +
55 + /* Output XML prologue to stdout */
56 + static void
57 + xml_prologue(const SDData *sd)
58 + {
59 +        const char      *matn = (sd && sd->matn[0]) ? sd->matn : "Name";
60 +        const char      *makr = (sd && sd->makr[0]) ? sd->makr : "Manufacturer";
61 +        ANGLE_BASIS     *abp = get_basis(kbasis);
62 +        int             i;
63 +
64 +        if (abp == NULL) {
65 +                fprintf(stderr, "%s: unknown angle basis '%s'\n", progname, kbasis);
66 +                exit(1);
67 +        }
68          puts("<WindowElementType>System</WindowElementType>");
69          puts("<FileType>BSDF</FileType>");
70          puts("<Optical>");
71          puts("<Layer>");
72          puts("\t<Material>");
73 <        puts("\t\t<Name>Name</Name>");
74 <        puts("\t\t<Manufacturer>Manufacturer</Manufacturer>");
73 >        printf("\t\t<Name>%s</Name>\n", matn);
74 >        printf("\t\t<Manufacturer>%s</Manufacturer>\n", makr);
75 >        if (sd && sd->dim[2] > .001) {
76 >                printf("\t\t<Thickness unit=\"meter\">%.3f</Thickness>\n", sd->dim[2]);
77 >                printf("\t\t<Width unit=\"meter\">%.3f</Width>\n", sd->dim[0]);
78 >                printf("\t\t<Height unit=\"meter\">%.3f</Height>\n", sd->dim[1]);
79 >        }
80          puts("\t\t<DeviceType>Other</DeviceType>");
81          puts("\t</Material>");
82 +        if (sd && sd->mgf != NULL) {
83 +                puts("\t<Geometry format=\"MGF\">");
84 +                puts("\t\t<MGFblock unit=\"meter\">");
85 +                fputs(sd->mgf, stdout);
86 +                puts("</MGFblock>");
87 +                puts("\t</Geometry>");
88 +        }
89          puts("\t<DataDefinition>");
90          puts("\t\t<IncidentDataStructure>Columns</IncidentDataStructure>");
91          puts("\t\t<AngleBasis>");
# Line 73 | Line 95 | xml_prologue(int ac, char *av[])
95                  printf("\t\t\t<Theta>%g</Theta>\n", i ?
96                                  .5*(abp->lat[i].tmin + abp->lat[i+1].tmin) :
97                                  .0 );
98 <                printf("\t\t\t<nPhis>%d</nPhis>", abp->lat[i].nphis);
98 >                printf("\t\t\t<nPhis>%d</nPhis>\n", abp->lat[i].nphis);
99                  puts("\t\t\t<ThetaBounds>");
100                  printf("\t\t\t\t<LowerTheta>%g</LowerTheta>\n", abp->lat[i].tmin);
101                  printf("\t\t\t\t<UpperTheta>%g</UpperTheta>\n", abp->lat[i+1].tmin);
# Line 142 | Line 164 | eval_bsdf(const char *fname)
164          SDclearBSDF(&bsd, fname);               /* load BSDF file */
165          if ((ec = SDloadFile(&bsd, fname)) != SDEnone)
166                  goto err;
167 +        xml_prologue(&bsd);                     /* pass geometry */
168                                                  /* front reflection */
169          if (bsd.rf != NULL || bsd.rLambFront.cieY > .002) {
170              input_orient = 1; output_orient = 1;
# Line 151 | Line 174 | eval_bsdf(const char *fname)
174                      sum = 0;                    /* average over patches */
175                      for (n = npsamps; n-- > 0; ) {
176                          fo_getvec(vout, j+(n+frandom())/npsamps, abp);
177 <                        fi_getvec(vin, i+(n+frandom())/npsamps, abp);
177 >                        fi_getvec(vin, i+urand(n), abp);
178                          ec = SDevalBSDF(&sv, vout, vin, &bsd);
179                          if (ec != SDEnone)
180                                  goto err;
# Line 172 | Line 195 | eval_bsdf(const char *fname)
195                      sum = 0;                    /* average over patches */
196                      for (n = npsamps; n-- > 0; ) {
197                          bo_getvec(vout, j+(n+frandom())/npsamps, abp);
198 <                        bi_getvec(vin, i+(n+frandom())/npsamps, abp);
198 >                        bi_getvec(vin, i+urand(n), abp);
199                          ec = SDevalBSDF(&sv, vout, vin, &bsd);
200                          if (ec != SDEnone)
201                                  goto err;
# Line 193 | Line 216 | eval_bsdf(const char *fname)
216                      sum = 0;                    /* average over patches */
217                      for (n = npsamps; n-- > 0; ) {
218                          bo_getvec(vout, j+(n+frandom())/npsamps, abp);
219 <                        fi_getvec(vin, i+(n+frandom())/npsamps, abp);
219 >                        fi_getvec(vin, i+urand(n), abp);
220                          ec = SDevalBSDF(&sv, vout, vin, &bsd);
221                          if (ec != SDEnone)
222                                  goto err;
# Line 214 | Line 237 | eval_bsdf(const char *fname)
237                      sum = 0;                    /* average over patches */
238                      for (n = npsamps; n-- > 0; ) {
239                          fo_getvec(vout, j+(n+frandom())/npsamps, abp);
240 <                        bi_getvec(vin, i+(n+frandom())/npsamps, abp);
240 >                        bi_getvec(vin, i+urand(n), abp);
241                          ec = SDevalBSDF(&sv, vout, vin, &bsd);
242                          if (ec != SDEnone)
243                                  goto err;
# Line 242 | Line 265 | eval_function(char *funame)
265          double          sum;
266          int             i, j, n;
267  
268 +        initurand(npsamps);
269          data_prologue();                        /* begin output */
270          for (j = 0; j < abp->nangles; j++) {    /* run through directions */
271              for (i = 0; i < abp->nangles; i++) {
# Line 253 | Line 277 | eval_function(char *funame)
277                          bo_getvec(iovec+3, j+(n+frandom())/npsamps, abp);
278  
279                      if (input_orient > 0)
280 <                        fi_getvec(iovec, i+(n+frandom())/npsamps, abp);
280 >                        fi_getvec(iovec, i+urand(n), abp);
281                      else
282 <                        bi_getvec(iovec, i+(n+frandom())/npsamps, abp);
282 >                        bi_getvec(iovec, i+urand(n), abp);
283  
284                      sum += funvalue(funame, 6, iovec);
285                  }
# Line 270 | Line 294 | eval_function(char *funame)
294   static void
295   eval_rbf(void)
296   {
273 #define MAXPATCHES      145
297          ANGLE_BASIS     *abp = get_basis(kbasis);
298          float           bsdfarr[MAXPATCHES*MAXPATCHES];
299          FVECT           vin, vout;
# Line 311 | Line 334 | eval_rbf(void)
334              putchar('\n');
335          }
336          data_epilogue();                        /* finish output */
314 #undef MAXPATCHES
337   }
338  
339   /* Read in BSDF and interpolate as Klems matrix representation */
# Line 364 | Line 386 | main(int argc, char *argv[])
386                                          progname);
387                          goto userr;
388                  }
389 <                xml_prologue(argc, argv);       /* start XML output */
389 >                xml_header(argc, argv);                 /* start XML output */
390 >                xml_prologue(NULL);
391                  if (dofwd) {
392                          input_orient = -1;
393                          output_orient = -1;
# Line 385 | Line 408 | main(int argc, char *argv[])
408                                                  /* XML input? */
409          if (i == argc-1 && (cp = argv[i]+strlen(argv[i])-4) > argv[i] &&
410                                  !strcasecmp(cp, ".xml")) {
411 <                xml_prologue(argc, argv);       /* start XML output */
411 >                xml_header(argc, argv);         /* start XML output */
412                  eval_bsdf(argv[i]);             /* load & resample BSDF */
413                  xml_epilogue();                 /* finish XML output & exit */
414                  return(0);
# Line 402 | Line 425 | main(int argc, char *argv[])
425                          if (!load_bsdf_rep(fpin))
426                                  return(1);
427                          fclose(fpin);
428 <                        if (!nbsdf++)           /* start XML on first dist. */
429 <                                xml_prologue(argc, argv);
428 >                        if (!nbsdf++) {         /* start XML on first dist. */
429 >                                xml_header(argc, argv);
430 >                                xml_prologue(NULL);
431 >                        }
432                          eval_rbf();
433                  }
434                  xml_epilogue();                 /* finish XML output & exit */
# Line 412 | Line 437 | main(int argc, char *argv[])
437          SET_FILE_BINARY(stdin);                 /* load from stdin */
438          if (!load_bsdf_rep(stdin))
439                  return(1);
440 <        xml_prologue(argc, argv);               /* start XML output */
440 >        xml_header(argc, argv);                 /* start XML output */
441 >        xml_prologue(NULL);
442          eval_rbf();                             /* resample dist. */
443          xml_epilogue();                         /* finish XML output & exit */
444          return(0);
445   userr:
446          fprintf(stderr,
447 <        "Usage: %s [-n spp][-h|-q][bsdf.sir ..] > bsdf.xml\n",
422 <                                progname);
447 >        "Usage: %s [-n spp][-h|-q][bsdf.sir ..] > bsdf.xml\n", progname);
448          fprintf(stderr,
449 <        "   or: %s [-n spp][-h|-q] bsdf_in.xml > bsdf_out.xml\n",
425 <                                progname);
449 >        "   or: %s [-n spp][-h|-q] bsdf_in.xml > bsdf_out.xml\n", progname);
450          fprintf(stderr,
451          "   or: %s [-n spp][-h|-q][{+|-}for[ward]][{+|-}b[ackward]][-e expr][-f file] bsdf_func > bsdf.xml\n",
452                                  progname);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines