--- ray/src/cv/bsdf2ttree.c 2013/05/15 03:22:31 2.15 +++ ray/src/cv/bsdf2ttree.c 2013/10/03 17:01:02 2.19 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: bsdf2ttree.c,v 2.15 2013/05/15 03:22:31 greg Exp $"; +static const char RCSid[] = "$Id: bsdf2ttree.c,v 2.19 2013/10/03 17:01:02 greg Exp $"; #endif /* * Load measured BSDF interpolant and write out as XML file with tensor tree. @@ -24,6 +24,8 @@ int samp_order = 6; const double ssamp_thresh = 0.35; /* number of super-samples */ const int nssamp = 100; + /* limit on number of RBF lobes */ +static int lobe_lim = 15000; /* Output XML prologue to stdout */ static void @@ -112,6 +114,7 @@ eval_isotropic(char *funame) { const int sqres = 1<= 0) { - sprintf(cmd, "rttree_reduce -h -a -ff -r 3 -t %f -g %d", + sprintf(cmd, "rttree_reduce%s -h -ff -r 3 -t %f -g %d", + (input_orient>0 ^ output_orient>0) ? "" : " -a", pctcull, samp_order); fflush(stdout); ofp = popen(cmd, "w"); @@ -131,6 +135,9 @@ eval_isotropic(char *funame) SET_FILE_BINARY(ofp); } else fputs("{\n", stdout); + /* need to assign Dx, Dy, Dz? */ + if (funame != NULL) + assignD = (fundefined(funame) < 6); /* run through directions */ for (ix = 0; ix < sqres/2; ix++) { RBFNODE *rbf = NULL; @@ -138,7 +145,7 @@ eval_isotropic(char *funame) iovec[1] = .0; iovec[2] = input_orient * sqrt(1. - iovec[0]*iovec[0]); if (funame == NULL) - rbf = advect_rbf(iovec); + rbf = advect_rbf(iovec, lobe_lim); for (ox = 0; ox < sqres; ox++) { float last_bsdf = -1; for (oy = 0; oy < sqres; oy++) { @@ -149,11 +156,17 @@ eval_isotropic(char *funame) bsdf = eval_rbfrep(rbf, iovec+3) * output_orient/iovec[5]; else { - double ssa[3], ssvec[6]; + double ssa[3], ssvec[6], sum; int ssi; + if (assignD) { + varset("Dx", '=', -iovec[3]); + varset("Dy", '=', -iovec[4]); + varset("Dz", '=', -iovec[5]); + ++eclock; + } bsdf = funvalue(funame, 6, iovec); if (abs_diff(bsdf, last_bsdf) > ssamp_thresh) { - bsdf = 0; /* super-sample voxel */ + sum = 0; /* super-sample voxel */ for (ssi = nssamp; ssi--; ) { SDmultiSamp(ssa, 3, (ssi+drand48())/nssamp); ssvec[0] = 2.*(ix+ssa[0])/sqres - 1.; @@ -165,9 +178,15 @@ eval_isotropic(char *funame) ssvec[5] = output_orient * sqrt(1. - ssvec[3]*ssvec[3] - ssvec[4]*ssvec[4]); - bsdf += funvalue(funame, 6, ssvec); + if (assignD) { + varset("Dx", '=', -iovec[3]); + varset("Dy", '=', -iovec[4]); + varset("Dz", '=', -iovec[5]); + ++eclock; + } + sum += funvalue(funame, 6, ssvec); } - bsdf /= (float)nssamp; + bsdf = sum/nssamp; } } if (pctcull >= 0) @@ -200,6 +219,7 @@ eval_anisotropic(char *funame) { const int sqres = 1<= 0) { - sprintf(cmd, "rttree_reduce -h -a -ff -r 4 -t %f -g %d", + sprintf(cmd, "rttree_reduce%s -h -ff -r 4 -t %f -g %d", + (input_orient>0 ^ output_orient>0) ? "" : " -a", pctcull, samp_order); fflush(stdout); ofp = popen(cmd, "w"); @@ -218,6 +239,9 @@ eval_anisotropic(char *funame) } } else fputs("{\n", stdout); + /* need to assign Dx, Dy, Dz? */ + if (funame != NULL) + assignD = (fundefined(funame) < 6); /* run through directions */ for (ix = 0; ix < sqres; ix++) for (iy = 0; iy < sqres; iy++) { @@ -226,7 +250,7 @@ eval_anisotropic(char *funame) iovec[2] = input_orient * sqrt(1. - iovec[0]*iovec[0] - iovec[1]*iovec[1]); if (funame == NULL) - rbf = advect_rbf(iovec); + rbf = advect_rbf(iovec, lobe_lim); for (ox = 0; ox < sqres; ox++) { float last_bsdf = -1; for (oy = 0; oy < sqres; oy++) { @@ -237,11 +261,17 @@ eval_anisotropic(char *funame) bsdf = eval_rbfrep(rbf, iovec+3) * output_orient/iovec[5]; else { - double ssa[4], ssvec[6]; + double ssa[4], ssvec[6], sum; int ssi; + if (assignD) { + varset("Dx", '=', -iovec[3]); + varset("Dy", '=', -iovec[4]); + varset("Dz", '=', -iovec[5]); + ++eclock; + } bsdf = funvalue(funame, 6, iovec); if (abs_diff(bsdf, last_bsdf) > ssamp_thresh) { - bsdf = 0; /* super-sample voxel */ + sum = 0; /* super-sample voxel */ for (ssi = nssamp; ssi--; ) { SDmultiSamp(ssa, 4, (ssi+drand48())/nssamp); SDsquare2disk(ssvec, 1.-(ix+ssa[0])/sqres, @@ -254,9 +284,15 @@ eval_anisotropic(char *funame) ssvec[5] = output_orient * sqrt(1. - ssvec[3]*ssvec[3] - ssvec[4]*ssvec[4]); - bsdf += funvalue(funame, 6, ssvec); + if (assignD) { + varset("Dx", '=', -iovec[3]); + varset("Dy", '=', -iovec[4]); + varset("Dz", '=', -iovec[5]); + ++eclock; + } + sum += funvalue(funame, 6, ssvec); } - bsdf /= (float)nssamp; + bsdf = sum/nssamp; } } if (pctcull >= 0) @@ -324,18 +360,24 @@ main(int argc, char *argv[]) case 'g': samp_order = atoi(argv[++i]); break; + case 'l': + lobe_lim = atoi(argv[++i]); + break; default: goto userr; } if (single_plane_incident >= 0) { /* function-based BSDF? */ void (*evf)(char *s) = single_plane_incident ? &eval_isotropic : &eval_anisotropic; - if (i != argc-1 || fundefined(argv[i]) != 6) { + if (i != argc-1 || fundefined(argv[i]) < 3) { 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_prologue(argc, argv); /* start XML output */ if (dofwd) { input_orient = -1; @@ -388,7 +430,7 @@ main(int argc, char *argv[]) return(0); userr: fprintf(stderr, - "Usage: %s [-g Nlog2][-t pctcull] [bsdf.sir ..] > bsdf.xml\n", + "Usage: %s [-g Nlog2][-t pctcull][-l maxlobes] [bsdf.sir ..] > bsdf.xml\n", progname); fprintf(stderr, " or: %s -t{3|4} [-g Nlog2][-t pctcull][{+|-}for[ward]][{+|-}b[ackward]][-e expr][-f file] bsdf_func > bsdf.xml\n",