--- ray/src/cv/bsdf2rad.c 2013/10/22 04:29:27 2.1 +++ ray/src/cv/bsdf2rad.c 2013/10/31 18:03:13 2.2 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: bsdf2rad.c,v 2.1 2013/10/22 04:29:27 greg Exp $"; +static const char RCSid[] = "$Id: bsdf2rad.c,v 2.2 2013/10/31 18:03:13 greg Exp $"; #endif /* * Plot 3-D BSDF output based on scattering interpolant representation @@ -26,6 +26,7 @@ char *progname; int main(int argc, char *argv[]) { + int showPeaks = 0; char buf[128]; FILE *fp; RBFNODE *rbf; @@ -34,31 +35,26 @@ main(int argc, char *argv[]) int i, j, n; progname = argv[0]; + if (argc > 1 && !strcmp(argv[1], "-p")) { + ++showPeaks; + ++argv; --argc; + } if (argc < 4) { - fprintf(stderr, "Usage: %s bsdf.sir theta1 phi1 .. > output.rad\n", argv[0]); + fprintf(stderr, "Usage: %s [-p] bsdf.sir theta1 phi1 .. > output.rad\n", progname); return(1); } /* load input */ if ((fp = fopen(argv[1], "rb")) == NULL) { fprintf(stderr, "%s: cannot open BSDF interpolant '%s'\n", - argv[0], argv[1]); + progname, argv[1]); return(1); } if (!load_bsdf_rep(fp)) return(1); fclose(fp); min_log = log(bsdf_min*.5); - /* output surface(s) */ + /* output BSDF rep. */ for (n = 0; (n < 6) & (2*n+3 < argc); n++) { - printf("void trans tmat\n0\n0\n7 %f %f %f .04 .04 .9 1\n", - colarr[n][0], colarr[n][1], colarr[n][2]); - fflush(stdout); - sprintf(buf, "gensurf tmat bsdf - - - %d %d", GRIDRES-1, GRIDRES-1); - fp = popen(buf, "w"); - if (fp == NULL) { - fprintf(stderr, "%s: cannot open '| %s'\n", argv[0], buf); - return(1); - } dir[2] = sin((M_PI/180.)*atof(argv[2*n+2])); dir[0] = dir[2] * cos((M_PI/180.)*atof(argv[2*n+3])); dir[1] = dir[2] * sin((M_PI/180.)*atof(argv[2*n+3])); @@ -70,6 +66,27 @@ main(int argc, char *argv[]) fputs("NULL RBF\n", stderr); else fprintf(stderr, "Hemispherical reflectance: %.3f\n", rbf->vtotal); + printf("void trans tmat\n0\n0\n7 %f %f %f .04 .04 .9 1\n", + colarr[n][0], colarr[n][1], colarr[n][2]); + if (showPeaks && rbf != NULL) { + printf("void plastic pmat\n0\n0\n5 %f %f %f .04 .08\n", + 1.-colarr[n][0], 1.-colarr[n][1], 1.-colarr[n][2]); + for (i = 0; i < rbf->nrbf; i++) { + ovec_from_pos(dir, rbf->rbfa[i].gx, rbf->rbfa[i].gy); + bsdf = eval_rbfrep(rbf, dir) / (output_orient*dir[2]); + bsdf = log(bsdf) - min_log; + printf("pmat sphere p%d\n0\n0\n4 %f %f %f %f\n", + i+1, dir[0]*bsdf, dir[1]*bsdf, dir[2]*bsdf, + .007*bsdf); + } + } + fflush(stdout); + sprintf(buf, "gensurf tmat bsdf - - - %d %d", GRIDRES-1, GRIDRES-1); + fp = popen(buf, "w"); + if (fp == NULL) { + fprintf(stderr, "%s: cannot open '| %s'\n", progname, buf); + return(1); + } for (i = 0; i < GRIDRES; i++) for (j = 0; j < GRIDRES; j++) { ovec_from_pos(dir, i, j);