--- ray/src/cv/bsdf2ttree.c 2014/03/12 21:15:31 2.26 +++ ray/src/cv/bsdf2ttree.c 2014/08/21 10:33:48 2.29 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: bsdf2ttree.c,v 2.26 2014/03/12 21:15:31 greg Exp $"; +static const char RCSid[] = "$Id: bsdf2ttree.c,v 2.29 2014/08/21 10:33:48 greg Exp $"; #endif /* * Load measured BSDF interpolant and write out as XML file with tensor tree. @@ -25,7 +25,9 @@ int samp_order = 6; /* super-sampling threshold */ const double ssamp_thresh = 0.35; /* number of super-samples */ -const int nssamp = 100; +#ifndef NSSAMP +#define NSSAMP 100 +#endif /* limit on number of RBF lobes */ static int lobe_lim = 15000; /* progress bar length */ @@ -56,8 +58,18 @@ prog_show(double frac) } /* Finish progress bar */ -#define prog_done() if (do_prog) fputc('\n',stderr); else +static void +prog_done(void) +{ + int n = do_prog; + if (n <= 1) return; + fputc('\r', stderr); + while (n--) + fputc(' ', stderr); + fputc('\r', stderr); +} + /* Output XML prologue to stdout */ static void xml_prologue(int ac, char *av[]) @@ -187,11 +199,8 @@ eval_isotropic(char *funame) iovec[5] = output_orient * sqrt(1. - iovec[3]*iovec[3] - iovec[4]*iovec[4]); if (funame == NULL) - bsdf = eval_rbfrep(rbf, iovec+3) * - output_orient/iovec[5]; + bsdf = eval_rbfrep(rbf, iovec+3); else { - double ssa[3], ssvec[6], sum; - int ssi; if (assignD) { varset("Dx", '=', -iovec[3]); varset("Dy", '=', -iovec[4]); @@ -199,10 +208,14 @@ eval_isotropic(char *funame) ++eclock; } bsdf = funvalue(funame, 6, iovec); +#if (NSSAMP > 0) if (abs_diff(bsdf, last_bsdf) > ssamp_thresh) { - sum = 0; /* super-sample voxel */ - for (ssi = nssamp; ssi--; ) { - SDmultiSamp(ssa, 3, (ssi+frandom())/nssamp); + int ssi; + double ssa[3], ssvec[6], sum = 0; + /* super-sample voxel */ + for (ssi = NSSAMP; ssi--; ) { + SDmultiSamp(ssa, 3, (ssi+frandom()) * + (1./NSSAMP)); ssvec[0] = 2.*(ix+ssa[0])/sqres - 1.; ssvec[1] = .0; ssvec[2] = input_orient * @@ -213,15 +226,16 @@ eval_isotropic(char *funame) sqrt(1. - ssvec[3]*ssvec[3] - ssvec[4]*ssvec[4]); if (assignD) { - varset("Dx", '=', -iovec[3]); - varset("Dy", '=', -iovec[4]); - varset("Dz", '=', -iovec[5]); + varset("Dx", '=', -ssvec[3]); + varset("Dy", '=', -ssvec[4]); + varset("Dz", '=', -ssvec[5]); ++eclock; } sum += funvalue(funame, 6, ssvec); } - bsdf = sum/nssamp; + bsdf = sum/NSSAMP; } +#endif } if (pctcull >= 0) fwrite(&bsdf, sizeof(bsdf), 1, ofp); @@ -298,11 +312,8 @@ eval_anisotropic(char *funame) iovec[5] = output_orient * sqrt(1. - iovec[3]*iovec[3] - iovec[4]*iovec[4]); if (funame == NULL) - bsdf = eval_rbfrep(rbf, iovec+3) * - output_orient/iovec[5]; + bsdf = eval_rbfrep(rbf, iovec+3); else { - double ssa[4], ssvec[6], sum; - int ssi; if (assignD) { varset("Dx", '=', -iovec[3]); varset("Dy", '=', -iovec[4]); @@ -310,13 +321,17 @@ eval_anisotropic(char *funame) ++eclock; } bsdf = funvalue(funame, 6, iovec); +#if (NSSAMP > 0) if (abs_diff(bsdf, last_bsdf) > ssamp_thresh) { - sum = 0; /* super-sample voxel */ - for (ssi = nssamp; ssi--; ) { - SDmultiSamp(ssa, 4, (ssi+frandom())/nssamp); + int ssi; + double ssa[4], ssvec[6], sum = 0; + /* super-sample voxel */ + for (ssi = NSSAMP; ssi--; ) { + SDmultiSamp(ssa, 4, (ssi+frandom()) * + (1./NSSAMP)); SDsquare2disk(ssvec, 1.-(ix+ssa[0])/sqres, 1.-(iy+ssa[1])/sqres); - ssvec[2] = output_orient * + ssvec[2] = input_orient * sqrt(1. - ssvec[0]*ssvec[0] - ssvec[1]*ssvec[1]); SDsquare2disk(ssvec+3, (ox+ssa[2])/sqres, @@ -325,15 +340,16 @@ eval_anisotropic(char *funame) sqrt(1. - ssvec[3]*ssvec[3] - ssvec[4]*ssvec[4]); if (assignD) { - varset("Dx", '=', -iovec[3]); - varset("Dy", '=', -iovec[4]); - varset("Dz", '=', -iovec[5]); + varset("Dx", '=', -ssvec[3]); + varset("Dy", '=', -ssvec[4]); + varset("Dz", '=', -ssvec[5]); ++eclock; } sum += funvalue(funame, 6, ssvec); } - bsdf = sum/nssamp; + bsdf = sum/NSSAMP; } +#endif } if (pctcull >= 0) fwrite(&bsdf, sizeof(bsdf), 1, ofp);