--- ray/src/cv/bsdf2klems.c 2013/08/01 16:10:13 2.7 +++ ray/src/cv/bsdf2klems.c 2013/09/26 17:05:00 2.10 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: bsdf2klems.c,v 2.7 2013/08/01 16:10:13 greg Exp $"; +static const char RCSid[] = "$Id: bsdf2klems.c,v 2.10 2013/09/26 17:05:00 greg Exp $"; #endif /* * Load measured BSDF interpolant and write out as XML file with Klems matrix. @@ -25,6 +25,8 @@ char *progname; static const char *kbasis = "LBNL/Klems Full"; /* number of BSDF samples per patch */ static int npsamps = 256; + /* limit on number of RBF lobes */ +static int lobe_lim = 15000; /* Return angle basis corresponding to the given name */ ANGLE_BASIS * @@ -154,7 +156,6 @@ static void eval_bsdf(const char *fname) { ANGLE_BASIS *abp = get_basis(kbasis); - float *trans_mtx = NULL; SDData bsd; SDError ec; FVECT vin, vout; @@ -210,9 +211,6 @@ eval_bsdf(const char *fname) } /* front transmission */ if (bsd.tf != NULL || bsd.tLamb.cieY > .002) { - if (bsd.tb == NULL) - trans_mtx = (float *)malloc(sizeof(float) * - abp->nangles*abp->nangles); input_orient = 1; output_orient = -1; data_prologue(); for (j = 0; j < abp->nangles; j++) { @@ -227,56 +225,33 @@ eval_bsdf(const char *fname) sum += sv.cieY; } printf("\t%.3e\n", sum/npsamps); - if (trans_mtx != NULL) - trans_mtx[j*abp->nangles + i] = sum/npsamps; } putchar('\n'); /* extra space between rows */ } data_epilogue(); } /* back transmission */ - if (bsd.tb != NULL || trans_mtx != NULL) { - if (bsd.tf == NULL) - trans_mtx = (float *)malloc(sizeof(float) * - abp->nangles*abp->nangles); + if ((bsd.tb != NULL) | (bsd.tf != NULL)) { input_orient = -1; output_orient = 1; data_prologue(); for (j = 0; j < abp->nangles; j++) { - for (i = 0; i < abp->nangles; i++) - if (bsd.tb != NULL) { /* use tb if we have it */ - sum = 0; /* average over patches */ - for (n = npsamps; n-- > 0; ) { - fo_getvec(vout, j+(n+frandom())/npsamps, abp); - bi_getvec(vin, i+urand(n), abp); - ec = SDevalBSDF(&sv, vout, vin, &bsd); - if (ec != SDEnone) + for (i = 0; i < abp->nangles; i++) { + sum = 0; /* average over patches */ + for (n = npsamps; n-- > 0; ) { + fo_getvec(vout, j+(n+frandom())/npsamps, abp); + bi_getvec(vin, i+urand(n), abp); + ec = SDevalBSDF(&sv, vout, vin, &bsd); + if (ec != SDEnone) goto err; - sum += sv.cieY; - } - printf("\t%.3e\n", sum/npsamps); - if (trans_mtx != NULL) - trans_mtx[i*abp->nangles + j] = sum/npsamps; - } else { /* else transpose tf */ - printf("\t%.3e\n", trans_mtx[i*abp->nangles + j]); + sum += sv.cieY; } + printf("\t%.3e\n", sum/npsamps); + } putchar('\n'); /* extra space between rows */ } data_epilogue(); } - /* derived front transmission */ - if (bsd.tf == NULL && trans_mtx != NULL) { - input_orient = 1; output_orient = -1; - data_prologue(); - for (j = 0; j < abp->nangles; j++) { - for (i = 0; i < abp->nangles; i++) - printf("\t%.3e\n", trans_mtx[j*abp->nangles + i]); - putchar('\n'); /* extra space between rows */ - } - data_epilogue(); - } SDfreeBSDF(&bsd); /* all done */ - if (trans_mtx != NULL) - free(trans_mtx); return; err: SDreportError(ec, stderr); @@ -288,6 +263,7 @@ static void eval_function(char *funame) { ANGLE_BASIS *abp = get_basis(kbasis); + int assignD = (fundefined(funame) < 6); double iovec[6]; double sum; int i, j, n; @@ -308,6 +284,12 @@ eval_function(char *funame) else bi_getvec(iovec, i+urand(n), abp); + if (assignD) { + varset("Dx", '=', -iovec[3]); + varset("Dy", '=', -iovec[4]); + varset("Dz", '=', -iovec[5]); + ++eclock; + } sum += funvalue(funame, 6, iovec); } printf("\t%.3e\n", sum/npsamps); @@ -339,7 +321,7 @@ eval_rbf(void) else bi_getvec(vin, i+.5*(i>0), abp); - rbf = advect_rbf(vin); /* compute radial basis func */ + rbf = advect_rbf(vin, lobe_lim); /* compute radial basis func */ for (j = 0; j < abp->nangles; j++) { sum = 0; /* sample over exiting patch */ @@ -405,6 +387,9 @@ main(int argc, char *argv[]) case 'q': kbasis = "LBNL/Klems Quarter"; break; + case 'l': + lobe_lim = atoi(argv[++i]); + break; default: goto userr; } @@ -413,8 +398,11 @@ main(int argc, char *argv[]) fprintf(stderr, "%s: need single function with 6 arguments: bsdf(ix,iy,iz,ox,oy,oz)\n", progname); + fprintf(stderr, "\tor 3 arguments using Dx,Dy,Dz: bsdf(ix,iy,iz)\n", + progname); goto userr; } + ++eclock; xml_header(argc, argv); /* start XML output */ xml_prologue(NULL); if (dofwd) { @@ -473,7 +461,7 @@ main(int argc, char *argv[]) return(0); userr: fprintf(stderr, - "Usage: %s [-n spp][-h|-q][bsdf.sir ..] > bsdf.xml\n", progname); + "Usage: %s [-n spp][-h|-q][-l maxlobes] [bsdf.sir ..] > bsdf.xml\n", progname); fprintf(stderr, " or: %s [-n spp][-h|-q] bsdf_in.xml > bsdf_out.xml\n", progname); fprintf(stderr,