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.26 by greg, Tue Mar 19 22:03:24 2019 UTC vs.
Revision 2.27 by greg, Mon Jun 17 23:58:32 2019 UTC

# Line 431 | 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 (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;
479 >                no = j*abp->nangles + i;
480 >                bsdfarr[no] += sum * normf;
481                  if (rbf_colorimetry == RBCtristimulus) {
482 <                    XZarr[n][0] = xsum*sum/(npsamps*ysum);
483 <                    XZarr[n][1] = (sum - xsum - ysum)*sum/(npsamps*ysum);
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);
483            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   #if defined(_WIN32) || defined(_WIN64)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines