--- ray/src/cv/bsdf2rad.c 2013/11/26 17:33:55 2.5 +++ ray/src/cv/bsdf2rad.c 2014/03/30 17:28:04 2.11 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: bsdf2rad.c,v 2.5 2013/11/26 17:33:55 greg Exp $"; +static const char RCSid[] = "$Id: bsdf2rad.c,v 2.11 2014/03/30 17:28:04 greg Exp $"; #endif /* * Plot 3-D BSDF output based on scattering interpolant or XML representation @@ -22,6 +22,12 @@ const float colarr[6][3] = { .5, 1., 1. }; +#ifdef _WIN32 +char validf[] = "-e \"valid(s,t)=X`SYS(s,t)^2+Y`SYS(s,t)^2+Z`SYS(s,t)^2-1e-7\""; +#else +char validf[] = "-e 'valid(s,t)=X`SYS(s,t)^2+Y`SYS(s,t)^2+Z`SYS(s,t)^2-1e-7'"; +#endif + char *progname; /* Produce a Radiance model plotting the indicated incident direction(s) */ @@ -91,17 +97,23 @@ main(int argc, char *argv[]) #ifdef DEBUG fprintf(stderr, "Minimum BSDF set to %.4f\n", bsdf_min); #endif - min_log = log(bsdf_min*.5); + min_log = log(bsdf_min*.5 + 1e-5); /* output BSDF rep. */ for (n = 0; (n < 6) & (2*n+3 < argc); n++) { - double theta = atof(argv[2*n+2]); + double theta = (M_PI/180.)*atof(argv[2*n+2]); + double phi = (M_PI/180.)*atof(argv[2*n+3]); + if (theta < -FTINY) { + fprintf(stderr, "%s: theta values must be positive\n", + progname); + return(1); + } if (inpXML) { - input_orient = (theta <= 90.) ? 1 : -1; + input_orient = (theta <= M_PI/2.) ? 1 : -1; output_orient = doTrans ? -input_orient : input_orient; } - idir[2] = sin((M_PI/180.)*theta); - idir[0] = idir[2] * cos((M_PI/180.)*atof(argv[2*n+3])); - idir[1] = idir[2] * sin((M_PI/180.)*atof(argv[2*n+3])); + idir[2] = sin(theta); + idir[0] = idir[2] * cos(phi); + idir[1] = idir[2] * sin(phi); idir[2] = input_orient * sqrt(1. - idir[2]*idir[2]); #ifdef DEBUG fprintf(stderr, "Computing BSDF for incident direction (%.1f,%.1f)\n", @@ -131,14 +143,15 @@ main(int argc, char *argv[]) for (i = 0; i < rbf->nrbf; i++) { ovec_from_pos(odir, rbf->rbfa[i].gx, rbf->rbfa[i].gy); bsdf = eval_rbfrep(rbf, odir) / (output_orient*odir[2]); - bsdf = log(bsdf) - min_log; + bsdf = log(bsdf + 1e-5) - min_log; printf("pmat sphere p%d\n0\n0\n4 %f %f %f %f\n", i+1, odir[0]*bsdf, odir[1]*bsdf, odir[2]*bsdf, .007*bsdf); } } fflush(stdout); - sprintf(buf, "gensurf tmat bsdf - - - %d %d", GRIDRES-1, GRIDRES-1); + sprintf(buf, "gensurf tmat bsdf%d - - - %d %d %s", n+1, + GRIDRES-1, GRIDRES-1, validf); fp = popen(buf, "w"); if (fp == NULL) { fprintf(stderr, "%s: cannot open '| %s'\n", progname, buf); @@ -156,7 +169,7 @@ main(int argc, char *argv[]) } else bsdf = eval_rbfrep(rbf, odir) / (output_orient*odir[2]); - bsdf = log(bsdf) - min_log; + bsdf = log(bsdf + 1e-5) - min_log; fprintf(fp, "%.8e %.8e %.8e\n", odir[0]*bsdf, odir[1]*bsdf, odir[2]*bsdf); }