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.21 by greg, Thu Feb 4 00:45:47 2016 UTC vs.
Revision 2.27 by greg, Mon Jun 17 23:58:32 2019 UTC

# Line 31 | Line 31 | static const char      klems_half[] = "LBNL/Klems Half";
31   static const char       klems_quarter[] = "LBNL/Klems Quarter";
32   static const char       *kbasis = klems_full;
33                                  /* number of BSDF samples per patch */
34 < static int              npsamps = 256;
34 > static int              npsamps = 1024;
35                                  /* limit on number of RBF lobes */
36   static int              lobe_lim = 15000;
37                                  /* progress bar length */
# Line 41 | Line 41 | static int             do_prog = 79;
41   static char             *wrapBSDF[MAXCARG] = {"wrapBSDF", "-W", "-UU"};
42   static int              wbsdfac = 3;
43  
44 < /* Add argument to wrapBSDF, allocating space if isstatic */
44 > /* Add argument to wrapBSDF, allocating space if !isstatic */
45   static void
46   add_wbsdf(const char *arg, int isstatic)
47   {
# Line 202 | Line 202 | eval_bsdf(const char *fname)
202                                  goto err;
203                          sum += sdv.cieY;
204                          if (rbf_colorimetry == RBCtristimulus) {
205                                c_ccvt(&sdv.spec, C_CSXY);
205                                  xsum += sdv.cieY * sdv.spec.cx;
206                                  ysum += sdv.cieY * sdv.spec.cy;
207                          }
# Line 252 | Line 251 | eval_bsdf(const char *fname)
251                                  goto err;
252                          sum += sdv.cieY;
253                          if (rbf_colorimetry == RBCtristimulus) {
255                                c_ccvt(&sdv.spec, C_CSXY);
254                                  xsum += sdv.cieY * sdv.spec.cx;
255                                  ysum += sdv.cieY * sdv.spec.cy;
256                          }
# Line 301 | Line 299 | eval_bsdf(const char *fname)
299                                  goto err;
300                          sum += sdv.cieY;
301                          if (rbf_colorimetry == RBCtristimulus) {
304                                c_ccvt(&sdv.spec, C_CSXY);
302                                  xsum += sdv.cieY * sdv.spec.cx;
303                                  ysum += sdv.cieY * sdv.spec.cy;
304                          }
# Line 351 | Line 348 | eval_bsdf(const char *fname)
348                                  goto err;
349                          sum += sdv.cieY;
350                          if (rbf_colorimetry == RBCtristimulus) {
354                                c_ccvt(&sdv.spec, C_CSXY);
351                                  xsum += sdv.cieY * sdv.spec.cx;
352                                  ysum += sdv.cieY * sdv.spec.cy;
353                          }
# Line 435 | Line 431 | eval_function(char *funame)
431   static void
432   eval_rbf(void)
433   {
434 <        ANGLE_BASIS     *abp = get_basis(kbasis);
435 <        float           (*XZarr)[2] = NULL;
436 <        float           bsdfarr[MAXPATCHES*MAXPATCHES];
437 <        FILE            *cfp[3];
438 <        FVECT           vin, vout;
439 <        double          sum, xsum, ysum;
440 <        int             i, j, n;
441 <                                                /* sanity check */
442 <        if (abp->nangles > MAXPATCHES) {
443 <                fprintf(stderr, "%s: too many patches!\n", progname);
444 <                exit(1);
445 <        }
446 <        if (rbf_colorimetry == RBCtristimulus)
447 <                XZarr = (float (*)[2])malloc(sizeof(float)*2*abp->nangles*abp->nangles);
448 <        for (i = 0; i < abp->nangles; i++) {
449 <            RBFNODE     *rbf;
450 <            if (input_orient > 0)               /* use incident patch center */
451 <                fi_getvec(vin, i+.5*(i>0), abp);
452 <            else
453 <                bi_getvec(vin, i+.5*(i>0), abp);
434 >    ANGLE_BASIS *abp = get_basis(kbasis);
435 >    float       (*XZarr)[2] = NULL;
436 >    float       bsdfarr[MAXPATCHES*MAXPATCHES];
437 >    FILE        *cfp[3];
438 >    FVECT       vin, vout;
439 >    double      sum, xsum, ysum, normf;
440 >    int         i, j, ni, no, nisamps, nosamps;
441 >                                        /* sanity check */
442 >    if (abp->nangles > MAXPATCHES) {
443 >        fprintf(stderr, "%s: too many patches!\n", progname);
444 >        exit(1);
445 >    }
446 >    memset(bsdfarr, 0, sizeof(bsdfarr));
447 >    if (rbf_colorimetry == RBCtristimulus)
448 >        XZarr = (float (*)[2])calloc(abp->nangles*abp->nangles, 2*sizeof(float));
449 >    nosamps = (int)(pow((double)npsamps, 0.67) + .5);
450 >    nisamps = (npsamps + (nosamps>>1)) / nosamps;
451 >    normf = 1./(double)(nisamps*nosamps);
452 >    for (i = 0; i < abp->nangles; i++) {
453 >        for (ni = nisamps; ni--; ) {            /* sample over incident patch */
454 >            RBFNODE     *rbf;
455 >            if (input_orient > 0)               /* vary incident patch loc. */
456 >                fi_getvec(vin, i+urand(ni), abp);
457 >            else
458 >                bi_getvec(vin, i+urand(ni), abp);
459  
460 <            rbf = advect_rbf(vin, lobe_lim);    /* compute radial basis func */
460 >            rbf = advect_rbf(vin, lobe_lim);    /* compute radial basis func */
461  
462 <            for (j = 0; j < abp->nangles; j++) {
463 <                sum = 0;                        /* sample over exiting patch */
462 >            for (j = 0; j < abp->nangles; j++) {
463 >                sum = 0;                        /* sample over exiting patch */
464                  xsum = ysum = 0;
465 <                for (n = npsamps; n--; ) {
465 >                for (no = nosamps; no--; ) {
466                      SDValue     sdv;
467                      if (output_orient > 0)
468 <                        fo_getvec(vout, j+(n+frandom())/npsamps, abp);
468 >                        fo_getvec(vout, j+(no+frandom())/nosamps, abp);
469                      else
470 <                        bo_getvec(vout, j+(n+frandom())/npsamps, abp);
470 >                        bo_getvec(vout, j+(no+frandom())/nosamps, abp);
471  
472                      eval_rbfcol(&sdv, rbf, vout);
473                      sum += sdv.cieY;
474 <                    if (XZarr != NULL) {
474 <                        c_ccvt(&sdv.spec, C_CSXY);
474 >                    if (rbf_colorimetry == RBCtristimulus) {
475                          xsum += sdv.cieY * sdv.spec.cx;
476                          ysum += sdv.cieY * sdv.spec.cy;
477 <                    }
477 >                    }
478                  }
479 <                n = j*abp->nangles + i;
480 <                bsdfarr[n] = sum / npsamps;
481 <                if (XZarr != NULL) {
482 <                    XZarr[n][0] = xsum*sum/(npsamps*ysum);
483 <                    XZarr[n][1] = (sum - xsum - ysum)*sum/(npsamps*ysum);
479 >                no = j*abp->nangles + i;
480 >                bsdfarr[no] += sum * normf;
481 >                if (rbf_colorimetry == RBCtristimulus) {
482 >                    XZarr[no][0] += xsum*sum*normf/ysum;
483 >                    XZarr[no][1] += (sum - xsum - ysum)*sum*normf/ysum;
484                  }
485              }
486 <            if (rbf != NULL)
486 >            if (rbf != NULL)
487                  free(rbf);
488            prog_show((i+1.)/abp->nangles);
488          }
489 <                                                /* write out our matrix */
490 <        cfp[CIE_Y] = open_component_file(CIE_Y);
491 <        n = 0;
492 <        for (j = 0; j < abp->nangles; j++) {
493 <            for (i = 0; i < abp->nangles; i++, n++)
494 <                fprintf(cfp[CIE_Y], "\t%.3e\n", bsdfarr[n]);
495 <            fputc('\n', cfp[CIE_Y]);
496 <        }
497 <        prog_done();
498 <        if (fclose(cfp[CIE_Y])) {
499 <                fprintf(stderr, "%s: error writing Y output\n", progname);
500 <                exit(1);
501 <        }
502 <        if (XZarr == NULL)                      /* no color? */
503 <                return;
504 <        cfp[CIE_X] = open_component_file(CIE_X);
505 <        cfp[CIE_Z] = open_component_file(CIE_Z);
506 <        n = 0;
507 <        for (j = 0; j < abp->nangles; j++) {
508 <            for (i = 0; i < abp->nangles; i++, n++) {
509 <                fprintf(cfp[CIE_X], "\t%.3e\n", XZarr[n][0]);
510 <                fprintf(cfp[CIE_Z], "\t%.3e\n", XZarr[n][1]);
511 <            }
512 <            fputc('\n', cfp[CIE_X]);
513 <            fputc('\n', cfp[CIE_Z]);
514 <        }
515 <        free(XZarr);
516 <        if (fclose(cfp[CIE_X]) || fclose(cfp[CIE_Z])) {
517 <                fprintf(stderr, "%s: error writing X/Z output\n", progname);
518 <                exit(1);
519 <        }
489 >        prog_show((i+1.)/abp->nangles);
490 >    }
491 >                                        /* write out our matrix */
492 >    cfp[CIE_Y] = open_component_file(CIE_Y);
493 >    no = 0;
494 >    for (j = 0; j < abp->nangles; j++) {
495 >        for (i = 0; i < abp->nangles; i++, no++)
496 >        fprintf(cfp[CIE_Y], "\t%.3e\n", bsdfarr[no]);
497 >        fputc('\n', cfp[CIE_Y]);
498 >    }
499 >    prog_done();
500 >    if (fclose(cfp[CIE_Y])) {
501 >        fprintf(stderr, "%s: error writing Y output\n", progname);
502 >        exit(1);
503 >    }
504 >    if (XZarr == NULL)                  /* no color? */
505 >        return;
506 >    cfp[CIE_X] = open_component_file(CIE_X);
507 >    cfp[CIE_Z] = open_component_file(CIE_Z);
508 >    no = 0;
509 >    for (j = 0; j < abp->nangles; j++) {
510 >        for (i = 0; i < abp->nangles; i++, no++) {
511 >        fprintf(cfp[CIE_X], "\t%.3e\n", XZarr[no][0]);
512 >        fprintf(cfp[CIE_Z], "\t%.3e\n", XZarr[no][1]);
513 >        }
514 >        fputc('\n', cfp[CIE_X]);
515 >        fputc('\n', cfp[CIE_Z]);
516 >    }
517 >    free(XZarr);
518 >    if (fclose(cfp[CIE_X]) || fclose(cfp[CIE_Z])) {
519 >        fprintf(stderr, "%s: error writing X/Z output\n", progname);
520 >        exit(1);
521 >    }
522   }
523  
524 < #ifdef _WIN32
524 > #if defined(_WIN32) || defined(_WIN64)
525   /* Execute wrapBSDF command (may never return) */
526   static int
527   wrap_up(void)
# Line 607 | Line 608 | main(int argc, char *argv[])
608                                          add_wbsdf("-f", 1);
609                                          add_wbsdf(argv[i], 1);
610                                  } else {
611 <                                        fcompile(argv[i]);
611 >                                        char    *fpath = getpath(argv[i],
612 >                                                            getrlibpath(), 0);
613 >                                        if (fpath == NULL) {
614 >                                                fprintf(stderr,
615 >                                                "%s: cannot find file '%s'\n",
616 >                                                        argv[0], argv[i]);
617 >                                                return(1);
618 >                                        }
619 >                                        fcompile(fpath);
620                                          single_plane_incident = 0;
621                                  }
622                          } else

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines