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.35 by greg, Wed Jul 26 15:50:03 2023 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 197 | Line 196 | eval_bsdf(const char *fname)
196                      for (n = npsamps; n-- > 0; ) {
197                          fo_getvec(vout, j+(n+frandom())/npsamps, abp);
198                          fi_getvec(vin, i+urand(n), abp);
199 <                        ec = SDevalBSDF(&sdv, vout, vin, &bsd);
199 >                        ec = SDevalBSDF(&sdv, vin, vout, &bsd);
200                          if (ec != SDEnone)
201                                  goto err;
202                          sum += sdv.cieY;
# Line 246 | Line 245 | eval_bsdf(const char *fname)
245                      for (n = npsamps; n-- > 0; ) {
246                          bo_getvec(vout, j+(n+frandom())/npsamps, abp);
247                          bi_getvec(vin, i+urand(n), abp);
248 <                        ec = SDevalBSDF(&sdv, vout, vin, &bsd);
248 >                        ec = SDevalBSDF(&sdv, vin, vout, &bsd);
249                          if (ec != SDEnone)
250                                  goto err;
251                          sum += sdv.cieY;
# Line 278 | Line 277 | eval_bsdf(const char *fname)
277              }
278          }
279                                                  /* front transmission */
280 <        if (bsd.tf != NULL || bsd.tLamb.cieY > .002) {
280 >        if (bsd.tf != NULL || bsd.tLambFront.cieY > .002) {
281              input_orient = 1; output_orient = -1;
282              cfp[CIE_Y] = open_component_file(CIE_Y);
283              if (bsd.tf != NULL && bsd.tf->comp[0].cspec[2].flags) {
# Line 294 | Line 293 | eval_bsdf(const char *fname)
293                      for (n = npsamps; n-- > 0; ) {
294                          bo_getvec(vout, j+(n+frandom())/npsamps, abp);
295                          fi_getvec(vin, i+urand(n), abp);
296 <                        ec = SDevalBSDF(&sdv, vout, vin, &bsd);
296 >                        ec = SDevalBSDF(&sdv, vin, vout, &bsd);
297                          if (ec != SDEnone)
298                                  goto err;
299                          sum += sdv.cieY;
# Line 343 | Line 342 | eval_bsdf(const char *fname)
342                      for (n = npsamps; n-- > 0; ) {
343                          fo_getvec(vout, j+(n+frandom())/npsamps, abp);
344                          bi_getvec(vin, i+urand(n), abp);
345 <                        ec = SDevalBSDF(&sdv, vout, vin, &bsd);
345 >                        ec = SDevalBSDF(&sdv, vin, vout, &bsd);
346                          if (ec != SDEnone)
347                                  goto err;
348                          sum += sdv.cieY;
# Line 526 | Line 525 | eval_rbf(void)
525   static int
526   wrap_up(void)
527   {
528 <        char    cmd[8192];
528 >        char    cmd[32700];
529  
530          if (bsdf_manuf[0]) {
531                  add_wbsdf("-f", 1);
# Line 577 | Line 576 | wrap_up(void)
576   }
577   #endif
578  
579 + #define HEAD_BUFLEN     10240
580 + static char     head_buf[HEAD_BUFLEN];
581 + static int      cur_headlen = 0;
582 +
583 + /* Record header line as comment associated with this SIR input */
584 + static int
585 + record2header(char *s)
586 + {
587 +        int     len = strlen(s);
588 +
589 +        if (cur_headlen+len >= HEAD_BUFLEN-6)
590 +                return(0);
591 +                                        /* includes EOL */
592 +        strcpy(head_buf+cur_headlen, s);
593 +        cur_headlen += len;
594 +
595 + #if defined(_WIN32) || defined(_WIN64)
596 +        if (head_buf[cur_headlen-1] == '\n')
597 +                head_buf[cur_headlen-1] = '\t';
598 + #endif
599 +        return(1);
600 + }
601 +
602 + /* Finish off header for this file */
603 + static void
604 + done_header(void)
605 + {
606 +        while (cur_headlen > 0 && isspace(head_buf[cur_headlen-1]))
607 +                --cur_headlen;
608 +        head_buf[cur_headlen] = '\0';
609 +        if (!cur_headlen)
610 +                return;
611 +        add_wbsdf("-C", 1);
612 +        add_wbsdf(head_buf, 0);
613 +        head_buf[cur_headlen=0] = '\0';
614 + }
615 +
616   /* Read in BSDF and interpolate as Klems matrix representation */
617   int
618   main(int argc, char *argv[])
619   {
620          int     dofwd = 0, dobwd = 1;
621 <        char    buf[2048];
621 >        char    buf[1024];
622          char    *cp;
623          int     i, na;
624  
# Line 603 | Line 639 | main(int argc, char *argv[])
639                          single_plane_incident = 0;
640                          break;
641                  case 'f':
642 <                        if (!argv[i][2]) {
642 >                        if ((argv[i][0] == '-') & !argv[i][2]) {
643                                  if (strchr(argv[++i], '=') != NULL) {
644                                          add_wbsdf("-f", 1);
645                                          add_wbsdf(argv[i], 1);
# Line 694 | Line 730 | main(int argc, char *argv[])
730          if (i < argc) {                         /* open input files if given */
731                  int     nbsdf = 0;
732                  for ( ; i < argc; i++) {        /* interpolate each component */
697                        char    pbuf[256];
733                          FILE    *fpin = fopen(argv[i], "rb");
734                          if (fpin == NULL) {
735                                  fprintf(stderr, "%s: cannot open BSDF interpolant '%s'\n",
736                                                  progname, argv[i]);
737                                  return(1);
738                          }
739 +                        sprintf(buf, "%s:\n", argv[i]);
740 +                        record2header(buf);
741 +                        sir_headshare = &record2header;
742                          if (!load_bsdf_rep(fpin))
743                                  return(1);
744                          fclose(fpin);
745 <                        sprintf(pbuf, "Interpolating component '%s'", argv[i]);
746 <                        prog_start(pbuf);
745 >                        done_header();
746 >                        sprintf(buf, "Interpolating component '%s'", argv[i]);
747 >                        prog_start(buf);
748                          eval_rbf();
749                  }
750                  return(wrap_up());
751          }
752          SET_FILE_BINARY(stdin);                 /* load from stdin */
753 +        record2header("<stdin>:\n");
754 +        sir_headshare = &record2header;
755          if (!load_bsdf_rep(stdin))
756                  return(1);
757 +        done_header();
758          prog_start("Interpolating from standard input");
759          eval_rbf();                             /* resample dist. */
760          return(wrap_up());

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines