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.52 by greg, Mon May 18 20:08:57 2020 UTC

# Line 27 | Line 27 | static int             samp_order = 6;
27                                  /* super-sampling threshold */
28   static double           ssamp_thresh = 0.35;
29                                  /* number of super-samples */
30 < #ifndef NSSAMP
31 < #define NSSAMP          256
32 < #endif
30 > static int              nssamp = 256;
31                                  /* limit on number of RBF lobes */
32   static int              lobe_lim = 15000;
33                                  /* progress bar length */
# Line 192 | Line 190 | eval_isotropic(char *funame)
190          }
191          if (funame != NULL)                     /* need to assign Dx, Dy, Dz? */
192                  assignD = (fundefined(funame) < 6);
195 #if (NSSAMP > 0)
193          val_last = (float *)calloc(sqres, sizeof(float));
194          if (funame == NULL)
195                  sdv_next = (SDValue *)malloc(sizeof(SDValue)*sqres);
196          else
197                  val_next = (float *)malloc(sizeof(float)*sqres);
201 #endif
198                                                  /* run through directions */
199          for (ix = 0; ix < sqres/2; ix++) {
200                  const int       zipsgn = (ix & 1)*2 - 1;
# Line 242 | Line 238 | eval_isotropic(char *funame)
238                              bsdf = sdv.cieY;
239                              if (ox < sqres-1)
240                                  eval_rbfcol(&sdv_next[oy], rbf, iovec+3);
245 #if (NSSAMP > 0)
241                              if (abs_diff(bsdf, sdv_next[oy].cieY) > ssamp_thresh ||
242                                  (ox && abs_diff(bsdf, val_last[oy]) > ssamp_thresh) ||
243                                  (oy && abs_diff(bsdf, val_last[oy-1]) > ssamp_thresh) ||
# Line 251 | Line 246 | eval_isotropic(char *funame)
246                                  int     ssi;
247                                  double  ssa[2], sum = 0, usum = 0, vsum = 0;
248                                                  /* super-sample voxel */
249 <                                for (ssi = NSSAMP; ssi--; ) {
250 <                                    SDmultiSamp(ssa, 2, (ssi+frandom()) *
251 <                                                        (1./NSSAMP));
249 >                                for (ssi = nssamp; ssi--; ) {
250 >                                    SDmultiSamp(ssa, 2, (ssi+frandom()) /
251 >                                                        (double)nssamp);
252                                      SDsquare2disk(iovec+3, (ox+ssa[0])*sqfact,
253                                                          (oy+ssa[1])*sqfact);
254                                      iovec[5] = output_orient *
# Line 267 | Line 262 | eval_isotropic(char *funame)
262                                          vsum += 9.*sdv.spec.cy * sdv.cieY;
263                                      }
264                                  }
265 <                                bsdf = sum * (1./NSSAMP);
265 >                                bsdf = sum / (double)nssamp;
266                                  if (rbf_colorimetry == RBCtristimulus) {
267                                      uv[0] = usum / (sum+FTINY);
268                                      uv[1] = vsum / (sum+FTINY);
269                                  }
270                              } else
276 #endif
271                              if (rbf_colorimetry == RBCtristimulus) {
272                                  uv[0] = uv[1] = 1. /
273                                      (-2.*sdv.spec.cx + 12.*sdv.spec.cy + 3.);
# Line 291 | Line 285 | eval_isotropic(char *funame)
285                                  }
286                                  val_next[oy] = funvalue(funame, 6, iovec);
287                              }
294 #if (NSSAMP > 0)
288                              if (abs_diff(bsdf, val_next[oy]) > ssamp_thresh ||
289                                  (ox && abs_diff(bsdf, val_last[oy]) > ssamp_thresh) ||
290                                  (oy && abs_diff(bsdf, val_last[oy-1]) > ssamp_thresh) ||
# Line 300 | Line 293 | eval_isotropic(char *funame)
293                                  int     ssi;
294                                  double  ssa[4], ssvec[6], sum = 0;
295                                                  /* super-sample voxel */
296 <                                for (ssi = NSSAMP; ssi--; ) {
297 <                                    SDmultiSamp(ssa, 4, (ssi+frandom()) *
298 <                                                        (1./NSSAMP));
296 >                                for (ssi = nssamp; ssi--; ) {
297 >                                    SDmultiSamp(ssa, 4, (ssi+frandom()) /
298 >                                                        (double)nssamp);
299                                      ssvec[0] = 2.*sqfact*(ix+ssa[0]) - 1.;
300                                      ssvec[1] = zipsgn*sqfact*ssa[1];
301                                      ssvec[2] = 1. - ssvec[0]*ssvec[0]
# Line 325 | Line 318 | eval_isotropic(char *funame)
318                                      }
319                                      sum += funvalue(funame, 6, ssvec);
320                                  }
321 <                                bsdf = sum * (1./NSSAMP);
321 >                                bsdf = sum / (double)nssamp;
322                              }
330 #endif
323                          }
324                          if (pctcull >= 0)
325                                  putbinary(&bsdf, sizeof(bsdf), 1, ofp);
# Line 468 | Line 460 | eval_anisotropic(char *funame)
460          }
461          if (funame != NULL)                     /* need to assign Dx, Dy, Dz? */
462                  assignD = (fundefined(funame) < 6);
471 #if (NSSAMP > 0)
463          val_last = (float *)calloc(sqres, sizeof(float));
464          if (funame == NULL)
465                  sdv_next = (SDValue *)malloc(sizeof(SDValue)*sqres);
466          else
467                  val_next = (float *)malloc(sizeof(float)*sqres);
477 #endif
468                                                  /* run through directions */
469          for (ix = 0; ix < sqres; ix++)
470              for (iy = 0; iy < sqres; iy++) {
# Line 517 | Line 507 | eval_anisotropic(char *funame)
507                              bsdf = sdv.cieY;
508                              if (ox < sqres-1)
509                                  eval_rbfcol(&sdv_next[oy], rbf, iovec+3);
520 #if (NSSAMP > 0)
510                              if (abs_diff(bsdf, sdv_next[oy].cieY) > ssamp_thresh ||
511                                  (ox && abs_diff(bsdf, val_last[oy]) > ssamp_thresh) ||
512                                  (oy && abs_diff(bsdf, val_last[oy-1]) > ssamp_thresh) ||
# Line 526 | Line 515 | eval_anisotropic(char *funame)
515                                  int     ssi;
516                                  double  ssa[2], sum = 0, usum = 0, vsum = 0;
517                                                  /* super-sample voxel */
518 <                                for (ssi = NSSAMP; ssi--; ) {
519 <                                    SDmultiSamp(ssa, 2, (ssi+frandom()) *
520 <                                                        (1./NSSAMP));
518 >                                for (ssi = nssamp; ssi--; ) {
519 >                                    SDmultiSamp(ssa, 2, (ssi+frandom()) /
520 >                                                        (double)nssamp);
521                                      SDsquare2disk(iovec+3, (ox+ssa[0])*sqfact,
522                                                          (oy+ssa[1])*sqfact);
523                                      iovec[5] = output_orient *
# Line 542 | Line 531 | eval_anisotropic(char *funame)
531                                          vsum += 9.*sdv.spec.cy * sdv.cieY;
532                                      }
533                                  }
534 <                                bsdf = sum * (1./NSSAMP);
534 >                                bsdf = sum / (double)nssamp;
535                                  if (rbf_colorimetry == RBCtristimulus) {
536                                      uv[0] = usum / (sum+FTINY);
537                                      uv[1] = vsum / (sum+FTINY);
538                                  }
539                              } else
551 #endif
540                              if (rbf_colorimetry == RBCtristimulus) {
541                                  uv[0] = uv[1] = 1. /
542                                      (-2.*sdv.spec.cx + 12.*sdv.spec.cy + 3.);
# Line 566 | Line 554 | eval_anisotropic(char *funame)
554                                  }
555                                  val_next[oy] = funvalue(funame, 6, iovec);
556                              }
569 #if (NSSAMP > 0)
557                              if (abs_diff(bsdf, val_next[oy]) > ssamp_thresh ||
558                                  (ox && abs_diff(bsdf, val_last[oy]) > ssamp_thresh) ||
559                                  (oy && abs_diff(bsdf, val_last[oy-1]) > ssamp_thresh) ||
# Line 575 | Line 562 | eval_anisotropic(char *funame)
562                                  int     ssi;
563                                  double  ssa[4], ssvec[6], sum = 0;
564                                                  /* super-sample voxel */
565 <                                for (ssi = NSSAMP; ssi--; ) {
566 <                                    SDmultiSamp(ssa, 4, (ssi+frandom()) *
567 <                                                        (1./NSSAMP));
565 >                                for (ssi = nssamp; ssi--; ) {
566 >                                    SDmultiSamp(ssa, 4, (ssi+frandom()) /
567 >                                                        (double)nssamp);
568                                      SDsquare2disk(ssvec, 1.-(ix+ssa[0])*sqfact,
569                                                  1.-(iy+ssa[1])*sqfact);
570                                      ssvec[2] = input_orient *
# Line 596 | Line 583 | eval_anisotropic(char *funame)
583                                      }
584                                      sum += funvalue(funame, 6, ssvec);
585                                  }
586 <                                bsdf = sum * (1./NSSAMP);
586 >                                bsdf = sum / (double)nssamp;
587                              }
601 #endif
588                          }
589                          if (pctcull >= 0)
590                                  putbinary(&bsdf, sizeof(bsdf), 1, ofp);
# Line 763 | Line 749 | main(int argc, char *argv[])
749                  case 'b':
750                          dobwd = (argv[i][0] == '+');
751                          break;
752 +                case 'n':
753 +                        nssamp = atoi(argv[++i]);
754 +                        if (nssamp <= 0)
755 +                                goto userr;
756 +                        break;
757 +                case 's':
758 +                        ssamp_thresh = atof(argv[++i]);
759 +                        if (ssamp_thresh <= FTINY)
760 +                                goto userr;
761 +                        break;
762                  case 't':
763                          switch (argv[i][2]) {
764                          case '3':
# Line 813 | Line 809 | main(int argc, char *argv[])
809                          goto userr;
810                  }
811                  ++eclock;
816                ssamp_thresh *= 0.5;            /* lower sampling threshold */
812                  add_wbsdf("-a", 1);
813                  add_wbsdf(tfmt[single_plane_incident], 1);
814                  if (dofwd) {
# Line 876 | Line 871 | main(int argc, char *argv[])
871          return(wrap_up());
872   userr:
873          fprintf(stderr,
874 <        "Usage: %s [{+|-}a][-g Nlog2][-t pctcull][-l maxlobes] [bsdf.sir ..] > bsdf.xml\n",
874 >        "Usage: %s [{+|-}a][-g Nlog2][-t pctcull][-n nss][-s thresh][-l maxlobes] [bsdf.sir ..] > bsdf.xml\n",
875                                  progname);
876          fprintf(stderr,
877 <        "   or: %s -t{3|4} [{+|-}a][-g Nlog2][-t pctcull][{+|-}for[ward]][{+|-}b[ackward]][-e expr][-f file] bsdf_func > bsdf.xml\n",
877 >        "   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",
878                                  progname);
879          return(1);
880   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines