/* Interpolate and output a radial basis function BSDF representation */ static void eval_rbf(void) { ANGLE_BASIS *abp = get_basis(kbasis); float bsdfarr[MAXPATCHES*MAXPATCHES]; FVECT vin, vout; RBFNODE *rbf; double sum; int i, j, n; /* sanity check */ if (abp->nangles > MAXPATCHES) { fprintf(stderr, "%s: too many patches!\n", progname); exit(1); } data_prologue(); /* begin output */ for (i = 0; i < abp->nangles; i++) { if (input_orient > 0) /* use incident patch center */ fi_getvec(vin, i+.5*(i>0), abp); else bi_getvec(vin, i+.5*(i>0), abp); rbf = advect_rbf(vin); /* compute radial basis func */ for (j = 0; j < abp->nangles; j++) { sum = 0; /* sample over exiting patch */ for (n = npsamps; n--; ) { if (output_orient > 0) fo_getvec(vout, j+(n+frandom())/npsamps, abp); else bo_getvec(vout, j+(n+frandom())/npsamps, abp); sum += eval_rbfrep(rbf, vout) / vout[2]; } bsdfarr[j*abp->nangles + i] = sum*output_orient/npsamps; } if (rbf != NULL) free(rbf); } n = 0; /* write out our matrix */ for (j = 0; j < abp->nangles; j++) { for (i = 0; i < abp->nangles; i++) printf("\t%.3e\n", bsdfarr[n++]); putchar('\n'); } data_epilogue(); /* finish output */ }
/* Interpolate and output a radial basis function BSDF representation */ static void eval_rbf(void) { ANGLE_BASIS *abp = get_basis(kbasis); float (*XZarr)[2] = NULL; float bsdfarr[MAXPATCHES*MAXPATCHES]; FILE *cfp[3]; FVECT vin, vout; double sum, xsum, ysum; int i, j, n; /* sanity check */ if (abp->nangles > MAXPATCHES) { fprintf(stderr, "%s: too many patches!\n", progname); exit(1); } if (rbf_colorimetry == RBCtristimulus) XZarr = (float (*)[2])malloc(sizeof(float)*2*abp->nangles*abp->nangles); for (i = 0; i < abp->nangles; i++) { RBFNODE *rbf; if (input_orient > 0) /* use incident patch center */ fi_getvec(vin, i+.5*(i>0), abp); else bi_getvec(vin, i+.5*(i>0), abp); rbf = advect_rbf(vin, lobe_lim); /* compute radial basis func */ for (j = 0; j < abp->nangles; j++) { sum = 0; /* sample over exiting patch */ xsum = ysum = 0; for (n = npsamps; n--; ) { SDValue sdv; if (output_orient > 0) fo_getvec(vout, j+(n+frandom())/npsamps, abp); else bo_getvec(vout, j+(n+frandom())/npsamps, abp); eval_rbfcol(&sdv, rbf, vout); sum += sdv.cieY; if (rbf_colorimetry == RBCtristimulus) { xsum += sdv.cieY * sdv.spec.cx; ysum += sdv.cieY * sdv.spec.cy; } } n = j*abp->nangles + i; bsdfarr[n] = sum / npsamps; if (rbf_colorimetry == RBCtristimulus) { XZarr[n][0] = xsum*sum/(npsamps*ysum); XZarr[n][1] = (sum - xsum - ysum)*sum/(npsamps*ysum); } } if (rbf != NULL) free(rbf); prog_show((i+1.)/abp->nangles); } /* write out our matrix */ cfp[CIE_Y] = open_component_file(CIE_Y); n = 0; for (j = 0; j < abp->nangles; j++) { for (i = 0; i < abp->nangles; i++, n++) fprintf(cfp[CIE_Y], "\t%.3e\n", bsdfarr[n]); fputc('\n', cfp[CIE_Y]); } prog_done(); if (fclose(cfp[CIE_Y])) { fprintf(stderr, "%s: error writing Y output\n", progname); exit(1); } if (XZarr == NULL) /* no color? */ return; cfp[CIE_X] = open_component_file(CIE_X); cfp[CIE_Z] = open_component_file(CIE_Z); n = 0; for (j = 0; j < abp->nangles; j++) { for (i = 0; i < abp->nangles; i++, n++) { fprintf(cfp[CIE_X], "\t%.3e\n", XZarr[n][0]); fprintf(cfp[CIE_Z], "\t%.3e\n", XZarr[n][1]); } fputc('\n', cfp[CIE_X]); fputc('\n', cfp[CIE_Z]); } free(XZarr); if (fclose(cfp[CIE_X]) || fclose(cfp[CIE_Z])) { fprintf(stderr, "%s: error writing X/Z output\n", progname); exit(1); } }