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.1 by greg, Sun Apr 21 23:01:14 2013 UTC vs.
Revision 2.4 by greg, Thu Apr 25 03:12:08 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 127 | Line 149 | xml_epilogue(void)
149          puts("</WindowElement>");
150   }
151  
152 < /* Load and resample XML BSDF description */
152 > /* Load and resample XML BSDF description using Klems basis */
153   static void
154   eval_bsdf(const char *fname)
155   {
# 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 233 | Line 256 | err:
256          exit(1);
257   }
258  
259 < /* Interpolate and output a BSDF function */
259 > /* Interpolate and output a BSDF function using Klems basis */
260   static void
261   eval_function(char *funame)
262   {
# 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, j+(n+frandom())/npsamps, abp);
280 >                        fi_getvec(iovec, i+urand(n), abp);
281                      else
282 <                        bi_getvec(iovec, j+(n+frandom())/npsamps, abp);
282 >                        bi_getvec(iovec, i+urand(n), abp);
283  
284                      sum += funvalue(funame, 6, iovec);
285                  }
# Line 271 | Line 295 | static void
295   eval_rbf(void)
296   {
297          ANGLE_BASIS     *abp = get_basis(kbasis);
298 <        double          iovec[6];
298 >        float           bsdfarr[MAXPATCHES*MAXPATCHES];
299 >        FVECT           vin, vout;
300 >        RBFNODE         *rbf;
301          double          sum;
302          int             i, j, n;
303 +                                                /* sanity check */
304 +        if (abp->nangles > MAXPATCHES) {
305 +                fprintf(stderr, "%s: too many patches!\n", progname);
306 +                exit(1);
307 +        }
308 +        data_prologue();                        /* begin output */
309 +        for (i = 0; i < abp->nangles; i++) {
310 +            if (input_orient > 0)               /* use incident patch center */
311 +                fi_getvec(vin, i+.5*(i>0), abp);
312 +            else
313 +                bi_getvec(vin, i+.5*(i>0), abp);
314  
315 < fprintf(stder, "%s: RBF evaluation currently unimplemented\n", progname);
316 < exit(1);
315 >            rbf = advect_rbf(vin);              /* compute radial basis func */
316 >
317 >            for (j = 0; j < abp->nangles; j++) {
318 >                sum = 0;                        /* sample over exiting patch */
319 >                for (n = npsamps; n--; ) {
320 >                    if (output_orient > 0)
321 >                        fo_getvec(vout, j+(n+frandom())/npsamps, abp);
322 >                    else
323 >                        bo_getvec(vout, j+(n+frandom())/npsamps, abp);
324 >
325 >                    sum += eval_rbfrep(rbf, vout) / vout[2];
326 >                }
327 >                bsdfarr[j*abp->nangles + i] = sum*output_orient/npsamps;
328 >            }
329 >        }
330 >        n = 0;                                  /* write out our matrix */
331 >        for (j = 0; j < abp->nangles; j++) {
332 >            for (i = 0; i < abp->nangles; i++)
333 >                printf("\t%.3e\n", bsdfarr[n++]);
334 >            putchar('\n');
335 >        }
336 >        data_epilogue();                        /* finish output */
337   }
338  
339   /* Read in BSDF and interpolate as Klems matrix representation */
# Line 292 | Line 349 | main(int argc, char *argv[])
349          esupport &= ~(E_INCHAN|E_OUTCHAN);
350          scompile("PI:3.14159265358979323846", NULL, 0);
351          biggerlib();
352 <        for (i = 1; i < argc-1 && (argv[i][0] == '-') | (argv[i][0] == '+'); i++)
352 >        for (i = 1; i < argc && (argv[i][0] == '-') | (argv[i][0] == '+'); i++)
353                  switch (argv[i][1]) {           /* get options */
354                  case 'n':
355                          npsamps = atoi(argv[++i]);
# Line 329 | 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 347 | Line 405 | main(int argc, char *argv[])
405                  xml_epilogue();                 /* finish XML output & exit */
406                  return(0);
407          }
408 <        if (i == argc-1 && (cp = strstr(argv[i], ".xml")) != NULL &&
409 <                        strlen(cp) == 4) {      /* XML input? */
410 <                xml_prologue(argc, argv);       /* start XML output */
408 >                                                /* XML input? */
409 >        if (i == argc-1 && (cp = argv[i]+strlen(argv[i])-4) > argv[i] &&
410 >                                !strcasecmp(cp, ".xml")) {
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 366 | 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 376 | 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",
386 <                                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",
389 <                                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