ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/cv/bsdf2ttree.c
(Generate patch)

Comparing ray/src/cv/bsdf2ttree.c (file contents):
Revision 2.51 by greg, Fri May 15 03:02:32 2020 UTC vs.
Revision 2.53 by greg, Mon Oct 26 21:12:20 2020 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"
15   #include "platform.h"
16   #include "paths.h"
# Line 27 | Line 28 | static int             samp_order = 6;
28                                  /* super-sampling threshold */
29   static double           ssamp_thresh = 0.35;
30                                  /* number of super-samples */
31 < #ifndef NSSAMP
31 < #define NSSAMP          256
32 < #endif
31 > static int              nssamp = 256;
32                                  /* limit on number of RBF lobes */
33   static int              lobe_lim = 15000;
34                                  /* progress bar length */
# Line 192 | Line 191 | eval_isotropic(char *funame)
191          }
192          if (funame != NULL)                     /* need to assign Dx, Dy, Dz? */
193                  assignD = (fundefined(funame) < 6);
195 #if (NSSAMP > 0)
194          val_last = (float *)calloc(sqres, sizeof(float));
195          if (funame == NULL)
196                  sdv_next = (SDValue *)malloc(sizeof(SDValue)*sqres);
197          else
198                  val_next = (float *)malloc(sizeof(float)*sqres);
201 #endif
199                                                  /* run through directions */
200          for (ix = 0; ix < sqres/2; ix++) {
201                  const int       zipsgn = (ix & 1)*2 - 1;
# Line 242 | Line 239 | eval_isotropic(char *funame)
239                              bsdf = sdv.cieY;
240                              if (ox < sqres-1)
241                                  eval_rbfcol(&sdv_next[oy], rbf, iovec+3);
245 #if (NSSAMP > 0)
242                              if (abs_diff(bsdf, sdv_next[oy].cieY) > ssamp_thresh ||
243                                  (ox && abs_diff(bsdf, val_last[oy]) > ssamp_thresh) ||
244                                  (oy && abs_diff(bsdf, val_last[oy-1]) > ssamp_thresh) ||
# Line 251 | Line 247 | eval_isotropic(char *funame)
247                                  int     ssi;
248                                  double  ssa[2], sum = 0, usum = 0, vsum = 0;
249                                                  /* super-sample voxel */
250 <                                for (ssi = NSSAMP; ssi--; ) {
251 <                                    SDmultiSamp(ssa, 2, (ssi+frandom()) *
252 <                                                        (1./NSSAMP));
250 >                                for (ssi = nssamp; ssi--; ) {
251 >                                    SDmultiSamp(ssa, 2, (ssi+frandom()) /
252 >                                                        (double)nssamp);
253                                      SDsquare2disk(iovec+3, (ox+ssa[0])*sqfact,
254                                                          (oy+ssa[1])*sqfact);
255                                      iovec[5] = output_orient *
# Line 267 | Line 263 | eval_isotropic(char *funame)
263                                          vsum += 9.*sdv.spec.cy * sdv.cieY;
264                                      }
265                                  }
266 <                                bsdf = sum * (1./NSSAMP);
266 >                                bsdf = sum / (double)nssamp;
267                                  if (rbf_colorimetry == RBCtristimulus) {
268                                      uv[0] = usum / (sum+FTINY);
269                                      uv[1] = vsum / (sum+FTINY);
270                                  }
271                              } else
276 #endif
272                              if (rbf_colorimetry == RBCtristimulus) {
273                                  uv[0] = uv[1] = 1. /
274                                      (-2.*sdv.spec.cx + 12.*sdv.spec.cy + 3.);
# Line 291 | Line 286 | eval_isotropic(char *funame)
286                                  }
287                                  val_next[oy] = funvalue(funame, 6, iovec);
288                              }
294 #if (NSSAMP > 0)
289                              if (abs_diff(bsdf, val_next[oy]) > ssamp_thresh ||
290                                  (ox && abs_diff(bsdf, val_last[oy]) > ssamp_thresh) ||
291                                  (oy && abs_diff(bsdf, val_last[oy-1]) > ssamp_thresh) ||
# Line 300 | Line 294 | eval_isotropic(char *funame)
294                                  int     ssi;
295                                  double  ssa[4], ssvec[6], sum = 0;
296                                                  /* super-sample voxel */
297 <                                for (ssi = NSSAMP; ssi--; ) {
298 <                                    SDmultiSamp(ssa, 4, (ssi+frandom()) *
299 <                                                        (1./NSSAMP));
297 >                                for (ssi = nssamp; ssi--; ) {
298 >                                    SDmultiSamp(ssa, 4, (ssi+frandom()) /
299 >                                                        (double)nssamp);
300                                      ssvec[0] = 2.*sqfact*(ix+ssa[0]) - 1.;
301                                      ssvec[1] = zipsgn*sqfact*ssa[1];
302                                      ssvec[2] = 1. - ssvec[0]*ssvec[0]
# Line 325 | Line 319 | eval_isotropic(char *funame)
319                                      }
320                                      sum += funvalue(funame, 6, ssvec);
321                                  }
322 <                                bsdf = sum * (1./NSSAMP);
322 >                                bsdf = sum / (double)nssamp;
323                              }
330 #endif
324                          }
325                          if (pctcull >= 0)
326                                  putbinary(&bsdf, sizeof(bsdf), 1, ofp);
# Line 468 | Line 461 | eval_anisotropic(char *funame)
461          }
462          if (funame != NULL)                     /* need to assign Dx, Dy, Dz? */
463                  assignD = (fundefined(funame) < 6);
471 #if (NSSAMP > 0)
464          val_last = (float *)calloc(sqres, sizeof(float));
465          if (funame == NULL)
466                  sdv_next = (SDValue *)malloc(sizeof(SDValue)*sqres);
467          else
468                  val_next = (float *)malloc(sizeof(float)*sqres);
477 #endif
469                                                  /* run through directions */
470          for (ix = 0; ix < sqres; ix++)
471              for (iy = 0; iy < sqres; iy++) {
# Line 517 | Line 508 | eval_anisotropic(char *funame)
508                              bsdf = sdv.cieY;
509                              if (ox < sqres-1)
510                                  eval_rbfcol(&sdv_next[oy], rbf, iovec+3);
520 #if (NSSAMP > 0)
511                              if (abs_diff(bsdf, sdv_next[oy].cieY) > ssamp_thresh ||
512                                  (ox && abs_diff(bsdf, val_last[oy]) > ssamp_thresh) ||
513                                  (oy && abs_diff(bsdf, val_last[oy-1]) > ssamp_thresh) ||
# Line 526 | Line 516 | eval_anisotropic(char *funame)
516                                  int     ssi;
517                                  double  ssa[2], sum = 0, usum = 0, vsum = 0;
518                                                  /* super-sample voxel */
519 <                                for (ssi = NSSAMP; ssi--; ) {
520 <                                    SDmultiSamp(ssa, 2, (ssi+frandom()) *
521 <                                                        (1./NSSAMP));
519 >                                for (ssi = nssamp; ssi--; ) {
520 >                                    SDmultiSamp(ssa, 2, (ssi+frandom()) /
521 >                                                        (double)nssamp);
522                                      SDsquare2disk(iovec+3, (ox+ssa[0])*sqfact,
523                                                          (oy+ssa[1])*sqfact);
524                                      iovec[5] = output_orient *
# Line 542 | Line 532 | eval_anisotropic(char *funame)
532                                          vsum += 9.*sdv.spec.cy * sdv.cieY;
533                                      }
534                                  }
535 <                                bsdf = sum * (1./NSSAMP);
535 >                                bsdf = sum / (double)nssamp;
536                                  if (rbf_colorimetry == RBCtristimulus) {
537                                      uv[0] = usum / (sum+FTINY);
538                                      uv[1] = vsum / (sum+FTINY);
539                                  }
540                              } else
551 #endif
541                              if (rbf_colorimetry == RBCtristimulus) {
542                                  uv[0] = uv[1] = 1. /
543                                      (-2.*sdv.spec.cx + 12.*sdv.spec.cy + 3.);
# Line 566 | Line 555 | eval_anisotropic(char *funame)
555                                  }
556                                  val_next[oy] = funvalue(funame, 6, iovec);
557                              }
569 #if (NSSAMP > 0)
558                              if (abs_diff(bsdf, val_next[oy]) > ssamp_thresh ||
559                                  (ox && abs_diff(bsdf, val_last[oy]) > ssamp_thresh) ||
560                                  (oy && abs_diff(bsdf, val_last[oy-1]) > ssamp_thresh) ||
# Line 575 | Line 563 | eval_anisotropic(char *funame)
563                                  int     ssi;
564                                  double  ssa[4], ssvec[6], sum = 0;
565                                                  /* super-sample voxel */
566 <                                for (ssi = NSSAMP; ssi--; ) {
567 <                                    SDmultiSamp(ssa, 4, (ssi+frandom()) *
568 <                                                        (1./NSSAMP));
566 >                                for (ssi = nssamp; ssi--; ) {
567 >                                    SDmultiSamp(ssa, 4, (ssi+frandom()) /
568 >                                                        (double)nssamp);
569                                      SDsquare2disk(ssvec, 1.-(ix+ssa[0])*sqfact,
570                                                  1.-(iy+ssa[1])*sqfact);
571                                      ssvec[2] = input_orient *
# Line 596 | Line 584 | eval_anisotropic(char *funame)
584                                      }
585                                      sum += funvalue(funame, 6, ssvec);
586                                  }
587 <                                bsdf = sum * (1./NSSAMP);
587 >                                bsdf = sum / (double)nssamp;
588                              }
601 #endif
589                          }
590                          if (pctcull >= 0)
591                                  putbinary(&bsdf, sizeof(bsdf), 1, ofp);
# Line 715 | Line 702 | wrap_up(void)
702   }
703   #endif
704  
705 + #define HEAD_BUFLEN     8192
706 + static char     head_buf[HEAD_BUFLEN];
707 + static int      cur_headlen = 0;
708 +
709 + /* Record header line as comment associated with this SIR input */
710 + static int
711 + record2header(char *s)
712 + {
713 +        int     len = strlen(s);
714 +
715 +        if (cur_headlen+len >= HEAD_BUFLEN-6)
716 +                return(0);
717 +                                        /* includes EOL */
718 +        strcpy(head_buf+cur_headlen, s);
719 +        cur_headlen += len;
720 +
721 +        return(1);
722 + }
723 +
724 + /* Finish off header for this file */
725 + static void
726 + done_header(void)
727 + {
728 +        while (cur_headlen > 0 && isspace(head_buf[cur_headlen-1]))
729 +                --cur_headlen;
730 +        head_buf[cur_headlen] = '\0';
731 +        if (!cur_headlen)
732 +                return;
733 +        add_wbsdf("-C", 1);
734 +        add_wbsdf(head_buf, 0);
735 +        head_buf[cur_headlen=0] = '\0';
736 + }
737 +
738   /* Read in BSDF and interpolate as tensor tree representation */
739   int
740   main(int argc, char *argv[])
# Line 763 | Line 783 | main(int argc, char *argv[])
783                  case 'b':
784                          dobwd = (argv[i][0] == '+');
785                          break;
786 +                case 'n':
787 +                        nssamp = atoi(argv[++i]);
788 +                        if (nssamp <= 0)
789 +                                goto userr;
790 +                        break;
791 +                case 's':
792 +                        ssamp_thresh = atof(argv[++i]);
793 +                        if (ssamp_thresh <= FTINY)
794 +                                goto userr;
795 +                        break;
796                  case 't':
797                          switch (argv[i][2]) {
798                          case '3':
# Line 813 | Line 843 | main(int argc, char *argv[])
843                          goto userr;
844                  }
845                  ++eclock;
816                ssamp_thresh *= 0.5;            /* lower sampling threshold */
846                  add_wbsdf("-a", 1);
847                  add_wbsdf(tfmt[single_plane_incident], 1);
848                  if (dofwd) {
# Line 846 | Line 875 | main(int argc, char *argv[])
875                                                  progname, argv[i]);
876                                  return(1);
877                          }
878 +                        sprintf(pbuf, "%s:\n", argv[i]);
879 +                        record2header(pbuf);
880 +                        sir_headshare = &record2header;
881                          if (!load_bsdf_rep(fpin))
882                                  return(1);
883                          fclose(fpin);
884 +                        done_header();
885                          sprintf(pbuf, "Interpolating component '%s'", argv[i]);
886                          prog_start(pbuf);
887                          if (!nbsdf++) {
# Line 876 | Line 909 | main(int argc, char *argv[])
909          return(wrap_up());
910   userr:
911          fprintf(stderr,
912 <        "Usage: %s [{+|-}a][-g Nlog2][-t pctcull][-l maxlobes] [bsdf.sir ..] > bsdf.xml\n",
912 >        "Usage: %s [{+|-}a][-g Nlog2][-t pctcull][-n nss][-s thresh][-l maxlobes] [bsdf.sir ..] > bsdf.xml\n",
913                                  progname);
914          fprintf(stderr,
915 <        "   or: %s -t{3|4} [{+|-}a][-g Nlog2][-t pctcull][{+|-}for[ward]][{+|-}b[ackward]][-e expr][-f file] bsdf_func > bsdf.xml\n",
915 >        "   or: %s -t{3|4} [{+|-}a][-g Nlog2][-t pctcull][-n nss][-s thresh][{+|-}for[ward]][{+|-}b[ackward]][-e expr][-f file] bsdf_func > bsdf.xml\n",
916                                  progname);
917          return(1);
918   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines