--- ray/src/cv/bsdf2klems.c 2013/06/29 21:03:25 2.6 +++ ray/src/cv/bsdf2klems.c 2013/08/01 16:10:13 2.7 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: bsdf2klems.c,v 2.6 2013/06/29 21:03:25 greg Exp $"; +static const char RCSid[] = "$Id: bsdf2klems.c,v 2.7 2013/08/01 16:10:13 greg Exp $"; #endif /* * Load measured BSDF interpolant and write out as XML file with Klems matrix. @@ -154,6 +154,7 @@ static void eval_bsdf(const char *fname) { ANGLE_BASIS *abp = get_basis(kbasis); + float *trans_mtx = NULL; SDData bsd; SDError ec; FVECT vin, vout; @@ -209,6 +210,9 @@ 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++) { @@ -223,33 +227,56 @@ 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) { + if (bsd.tb != NULL || trans_mtx != NULL) { + if (bsd.tf == 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++) { - 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) + 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) goto err; - sum += sv.cieY; + 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]); } - 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);