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.27 by greg, Mon Jun 17 23:58:32 2019 UTC vs.
Revision 2.37 by greg, Tue Jun 3 21:31:51 2025 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines