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.28 by greg, Sat Dec 28 18:05:14 2019 UTC vs.
Revision 2.38 by greg, Sat Jun 7 05:09:45 2025 UTC

# Line 10 | Line 10 | static const char RCSid[] = "$Id$";
10   #define _USE_MATH_DEFINES
11   #include <stdlib.h>
12   #include <math.h>
13 + #include <ctype.h>
14   #include "random.h"
14 #include "platform.h"
15 #include "paths.h"
15   #include "rtio.h"
16   #include "calcomp.h"
17   #include "bsdfrep.h"
# Line 21 | Line 20 | static const char RCSid[] = "$Id$";
20   enum {CIE_X, CIE_Y, CIE_Z};
21                                  /* assumed maximum # Klems patches */
22   #define MAXPATCHES      145
24                                /* global argv[0] */
25 char                    *progname;
23                                  /* selected basis function name */
24   static const char       klems_full[] = "LBNL/Klems Full";
25   static const char       klems_half[] = "LBNL/Klems Half";
# Line 195 | Line 192 | eval_bsdf(const char *fname)
192                      for (n = npsamps; n-- > 0; ) {
193                          fo_getvec(vout, j+(n+frandom())/npsamps, abp);
194                          fi_getvec(vin, i+urand(n), abp);
195 <                        ec = SDevalBSDF(&sdv, vout, vin, &bsd);
195 >                        ec = SDevalBSDF(&sdv, vin, vout, &bsd);
196                          if (ec != SDEnone)
197                                  goto err;
198                          sum += sdv.cieY;
# Line 244 | Line 241 | eval_bsdf(const char *fname)
241                      for (n = npsamps; n-- > 0; ) {
242                          bo_getvec(vout, j+(n+frandom())/npsamps, abp);
243                          bi_getvec(vin, i+urand(n), abp);
244 <                        ec = SDevalBSDF(&sdv, vout, vin, &bsd);
244 >                        ec = SDevalBSDF(&sdv, vin, vout, &bsd);
245                          if (ec != SDEnone)
246                                  goto err;
247                          sum += sdv.cieY;
# Line 276 | Line 273 | eval_bsdf(const char *fname)
273              }
274          }
275                                                  /* front transmission */
276 <        if (bsd.tf != NULL || bsd.tLamb.cieY > .002) {
276 >        if (bsd.tf != NULL || bsd.tLambFront.cieY > .002) {
277              input_orient = 1; output_orient = -1;
278              cfp[CIE_Y] = open_component_file(CIE_Y);
279              if (bsd.tf != NULL && bsd.tf->comp[0].cspec[2].flags) {
# Line 292 | Line 289 | eval_bsdf(const char *fname)
289                      for (n = npsamps; n-- > 0; ) {
290                          bo_getvec(vout, j+(n+frandom())/npsamps, abp);
291                          fi_getvec(vin, i+urand(n), abp);
292 <                        ec = SDevalBSDF(&sdv, vout, vin, &bsd);
292 >                        ec = SDevalBSDF(&sdv, vin, vout, &bsd);
293                          if (ec != SDEnone)
294                                  goto err;
295                          sum += sdv.cieY;
# Line 341 | Line 338 | eval_bsdf(const char *fname)
338                      for (n = npsamps; n-- > 0; ) {
339                          fo_getvec(vout, j+(n+frandom())/npsamps, abp);
340                          bi_getvec(vin, i+urand(n), abp);
341 <                        ec = SDevalBSDF(&sdv, vout, vin, &bsd);
341 >                        ec = SDevalBSDF(&sdv, vin, vout, &bsd);
342                          if (ec != SDEnone)
343                                  goto err;
344                          sum += sdv.cieY;
# Line 524 | Line 521 | eval_rbf(void)
521   static int
522   wrap_up(void)
523   {
524 <        char    cmd[8192];
524 >        char    cmd[32700];
525  
526          if (bsdf_manuf[0]) {
527                  add_wbsdf("-f", 1);
# Line 575 | Line 572 | wrap_up(void)
572   }
573   #endif
574  
575 + #define HEAD_BUFLEN     10240
576 + static char     head_buf[HEAD_BUFLEN];
577 + static int      cur_headlen = 0;
578 +
579 + /* Record header line as comment associated with this SIR input */
580 + static int
581 + record2header(char *s)
582 + {
583 +        int     len = strlen(s);
584 +
585 +        if (cur_headlen+len >= HEAD_BUFLEN-6)
586 +                return(0);
587 +                                        /* includes EOL */
588 +        strcpy(head_buf+cur_headlen, s);
589 +        cur_headlen += len;
590 +
591 + #if defined(_WIN32) || defined(_WIN64)
592 +        if (head_buf[cur_headlen-1] == '\n')
593 +                head_buf[cur_headlen-1] = '\t';
594 + #endif
595 +        return(1);
596 + }
597 +
598 + /* Finish off header for this file */
599 + static void
600 + done_header(void)
601 + {
602 +        while (cur_headlen > 0 && isspace(head_buf[cur_headlen-1]))
603 +                --cur_headlen;
604 +        head_buf[cur_headlen] = '\0';
605 +        if (!cur_headlen)
606 +                return;
607 +        add_wbsdf("-C", 1);
608 +        add_wbsdf(head_buf, 0);
609 +        head_buf[cur_headlen=0] = '\0';
610 + }
611 +
612   /* Read in BSDF and interpolate as Klems matrix representation */
613   int
614   main(int argc, char *argv[])
615   {
616          int     dofwd = 0, dobwd = 1;
617 <        char    buf[2048];
617 >        char    buf[1024];
618          char    *cp;
619          int     i, na;
620 <
621 <        progname = argv[0];
620 >                                                /* set global progname */
621 >        fixargv0(argv[0]);
622          esupport |= E_VARIABLE|E_FUNCTION|E_RCONST;
623          esupport &= ~(E_INCHAN|E_OUTCHAN);
624          scompile("PI:3.14159265358979323846", NULL, 0);
# Line 601 | Line 635 | main(int argc, char *argv[])
635                          single_plane_incident = 0;
636                          break;
637                  case 'f':
638 <                        if (!argv[i][2]) {
638 >                        if ((argv[i][0] == '-') & !argv[i][2]) {
639                                  if (strchr(argv[++i], '=') != NULL) {
640                                          add_wbsdf("-f", 1);
641                                          add_wbsdf(argv[i], 1);
# Line 662 | Line 696 | main(int argc, char *argv[])
696                          fprintf(stderr, "\tor 3 arguments using Dx,Dy,Dz: bsdf(ix,iy,iz)\n");
697                          goto userr;
698                  }
699 +                doptimize(1);                   /* optimize definitions */
700                  ++eclock;
701                  if (dofwd) {
702                          input_orient = -1;
# Line 692 | Line 727 | main(int argc, char *argv[])
727          if (i < argc) {                         /* open input files if given */
728                  int     nbsdf = 0;
729                  for ( ; i < argc; i++) {        /* interpolate each component */
695                        char    pbuf[256];
730                          FILE    *fpin = fopen(argv[i], "rb");
731                          if (fpin == NULL) {
732                                  fprintf(stderr, "%s: cannot open BSDF interpolant '%s'\n",
733                                                  progname, argv[i]);
734                                  return(1);
735                          }
736 +                        sprintf(buf, "%s:\n", argv[i]);
737 +                        record2header(buf);
738 +                        sir_headshare = &record2header;
739                          if (!load_bsdf_rep(fpin))
740                                  return(1);
741                          fclose(fpin);
742 <                        sprintf(pbuf, "Interpolating component '%s'", argv[i]);
743 <                        prog_start(pbuf);
742 >                        done_header();
743 >                        sprintf(buf, "Interpolating component '%s'", argv[i]);
744 >                        prog_start(buf);
745                          eval_rbf();
746                  }
747                  return(wrap_up());
748          }
749          SET_FILE_BINARY(stdin);                 /* load from stdin */
750 +        record2header("<stdin>:\n");
751 +        sir_headshare = &record2header;
752          if (!load_bsdf_rep(stdin))
753                  return(1);
754 +        done_header();
755          prog_start("Interpolating from standard input");
756          eval_rbf();                             /* resample dist. */
757          return(wrap_up());

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines