--- ray/src/cv/bsdf2ttree.c 2013/08/02 20:56:19 2.17 +++ ray/src/cv/bsdf2ttree.c 2014/03/11 19:37:45 2.25 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: bsdf2ttree.c,v 2.17 2013/08/02 20:56:19 greg Exp $"; +static const char RCSid[] = "$Id: bsdf2ttree.c,v 2.25 2014/03/11 19:37:45 greg Exp $"; #endif /* * Load measured BSDF interpolant and write out as XML file with tensor tree. @@ -11,7 +11,9 @@ static const char RCSid[] = "$Id: bsdf2ttree.c,v 2.17 #include #include #include +#include "random.h" #include "platform.h" +#include "rtprocess.h" #include "calcomp.h" #include "bsdfrep.h" /* global argv[0] */ @@ -24,6 +26,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 @@ -42,8 +46,9 @@ xml_prologue(int ac, char *av[]) puts(""); puts(""); puts("\t"); - puts("\t\tName"); - puts("\t\tManufacturer"); + printf("\t\t%s\n", bsdf_name[0] ? bsdf_name : "Unknown"); + printf("\t\t%s\n", + bsdf_manuf[0] ? bsdf_manuf : "Unknown"); puts("\t\tOther"); puts("\t"); puts("\t"); @@ -120,7 +125,7 @@ eval_isotropic(char *funame) data_prologue(); /* begin output */ if (pctcull >= 0) { - sprintf(cmd, "rttree_reduce -h -a -ff -r 3 -t %f -g %d", + sprintf(cmd, "rttree_reduce -a -h -ff -r 3 -t %f -g %d", pctcull, samp_order); fflush(stdout); ofp = popen(cmd, "w"); @@ -130,6 +135,9 @@ eval_isotropic(char *funame) exit(1); } SET_FILE_BINARY(ofp); +#ifdef getc_unlocked /* avoid lock/unlock overhead */ + flockfile(ofp); +#endif } else fputs("{\n", stdout); /* need to assign Dx, Dy, Dz? */ @@ -142,7 +150,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++) { @@ -165,7 +173,7 @@ eval_isotropic(char *funame) if (abs_diff(bsdf, last_bsdf) > ssamp_thresh) { sum = 0; /* super-sample voxel */ for (ssi = nssamp; ssi--; ) { - SDmultiSamp(ssa, 3, (ssi+drand48())/nssamp); + SDmultiSamp(ssa, 3, (ssi+frandom())/nssamp); ssvec[0] = 2.*(ix+ssa[0])/sqres - 1.; ssvec[1] = .0; ssvec[2] = input_orient * @@ -224,7 +232,8 @@ eval_anisotropic(char *funame) data_prologue(); /* begin output */ if (pctcull >= 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"); @@ -233,6 +242,10 @@ eval_anisotropic(char *funame) progname); exit(1); } + SET_FILE_BINARY(ofp); +#ifdef getc_unlocked /* avoid lock/unlock overhead */ + flockfile(ofp); +#endif } else fputs("{\n", stdout); /* need to assign Dx, Dy, Dz? */ @@ -246,7 +259,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++) { @@ -269,7 +282,7 @@ eval_anisotropic(char *funame) if (abs_diff(bsdf, last_bsdf) > ssamp_thresh) { sum = 0; /* super-sample voxel */ for (ssi = nssamp; ssi--; ) { - SDmultiSamp(ssa, 4, (ssi+drand48())/nssamp); + SDmultiSamp(ssa, 4, (ssi+frandom())/nssamp); SDsquare2disk(ssvec, 1.-(ix+ssa[0])/sqres, 1.-(iy+ssa[1])/sqres); ssvec[2] = output_orient * @@ -356,6 +369,9 @@ main(int argc, char *argv[]) case 'g': samp_order = atoi(argv[++i]); break; + case 'l': + lobe_lim = atoi(argv[++i]); + break; default: goto userr; } @@ -366,8 +382,7 @@ 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); + fprintf(stderr, "\tor 3 arguments using Dx,Dy,Dz: bsdf(ix,iy,iz)\n"); goto userr; } ++eclock; @@ -423,7 +438,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",