--- ray/src/cv/pabopto2bsdf.c 2013/06/29 22:35:15 2.2 +++ ray/src/cv/pabopto2bsdf.c 2014/01/30 18:19:43 2.11 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: pabopto2bsdf.c,v 2.2 2013/06/29 22:35:15 greg Exp $"; +static const char RCSid[] = "$Id: pabopto2bsdf.c,v 2.11 2014/01/30 18:19:43 greg Exp $"; #endif /* * Load measured BSDF data in PAB-Opto format. @@ -11,6 +11,7 @@ static const char RCSid[] = "$Id: pabopto2bsdf.c,v 2.2 #include #include #include +#include #include "platform.h" #include "bsdfrep.h" /* global argv[0] */ @@ -62,20 +63,25 @@ init_pabopto_inp(const int i, const char *fname) inpfile[i].theta = inpfile[i].phi = -10001.; /* read header information */ while ((c = getc(fp)) == '#' || c == EOF) { + char typ[32]; if (fgets(buf, sizeof(buf), fp) == NULL) { fputs(fname, stderr); fputs(": unexpected EOF\n", stderr); fclose(fp); return(0); } - if (!strcmp(buf, "format: theta phi DSF\n")) { - inpfile[i].isDSF = 1; + if (sscanf(buf, "sample_name \"%[^\"]\"", bsdf_name) == 1) continue; + if (sscanf(buf, "format: theta phi %s", typ) == 1) { + if (!strcasecmp(typ, "DSF")) { + inpfile[i].isDSF = 1; + continue; + } + if (!strcasecmp(typ, "BSDF")) { + inpfile[i].isDSF = 0; + continue; + } } - if (!strcmp(buf, "format: theta phi BSDF\n")) { - inpfile[i].isDSF = 0; - continue; - } if (sscanf(buf, "intheta %lf", &inpfile[i].theta) == 1) continue; if (sscanf(buf, "inphi %lf", &inpfile[i].phi) == 1) @@ -96,6 +102,8 @@ init_pabopto_inp(const int i, const char *fname) fputs(": unknown incident angle\n", stderr); return(0); } + while (inpfile[i].phi < 0) /* normalize phi direction */ + inpfile[i].phi += 360.; return(1); } @@ -112,9 +120,6 @@ add_pabopto_inp(const int i) fputs(": cannot open\n", stderr); return(0); } -#ifdef DEBUG - fprintf(stderr, "Loading measurements from '%s'...\n", inpfile[i].fname); -#endif /* prepare input grid */ if (!i || cmp_inang(&inpfile[i-1], &inpfile[i])) { if (i) /* need to process previous incidence */ @@ -125,6 +130,9 @@ add_pabopto_inp(const int i) #endif new_bsdf_data(inpfile[i].theta, inpfile[i].phi); } +#ifdef DEBUG + fprintf(stderr, "Loading measurements from '%s'...\n", inpfile[i].fname); +#endif /* read scattering data */ while (fscanf(fp, "%lf %lf %lf\n", &theta_out, &phi_out, &val) == 3) add_bsdf_data(theta_out, phi_out, val, inpfile[i].isDSF); @@ -139,6 +147,7 @@ add_pabopto_inp(const int i) return(1); } +#ifndef TEST_MAIN /* Read in PAB-Opto BSDF files and output RBF interpolant */ int main(int argc, char *argv[]) @@ -185,3 +194,84 @@ userr: progname); return(1); } +#else +/* Test main produces a Radiance model from the given input file */ +int +main(int argc, char *argv[]) +{ + PGINPUT pginp; + char buf[128]; + FILE *pfp; + double bsdf, min_log; + FVECT dir; + int i, j, n; + + if (argc != 2) { + fprintf(stderr, "Usage: %s input.dat > output.rad\n", argv[0]); + return(1); + } + ninpfiles = 1; + inpfile = &pginp; + if (!init_pabopto_inp(0, argv[1]) || !add_pabopto_inp(0)) + return(1); + /* reduce data set */ + make_rbfrep(); +#ifdef DEBUG + fprintf(stderr, "Minimum BSDF = %.4f\n", bsdf_min); +#endif +#if 1 /* produce spheres at meas. */ + puts("void plastic yellow\n0\n0\n5 .6 .4 .01 .04 .08\n"); + min_log = log(bsdf_min*.5); + n = 0; + for (i = 0; i < GRIDRES; i++) + for (j = 0; j < GRIDRES; j++) + if (dsf_grid[i][j].nval > 0) { + ovec_from_pos(dir, i, j); + bsdf = dsf_grid[i][j].vsum / + (dsf_grid[i][j].nval*output_orient*dir[2]); + if (bsdf <= bsdf_min*.6) + continue; + bsdf = log(bsdf) - min_log; + ovec_from_pos(dir, i, j); + printf("yellow sphere s%04d\n0\n0\n", ++n); + printf("4 %.6g %.6g %.6g %.6g\n\n", + dir[0]*bsdf, dir[1]*bsdf, dir[2]*bsdf, + .007*bsdf); + } +#endif +#if 1 /* spheres at RBF peaks */ + puts("void plastic red\n0\n0\n5 .8 .01 .01 .04 .08\n"); + for (n = 0; n < dsf_list->nrbf; n++) { + RBFVAL *rbf = &dsf_list->rbfa[n]; + ovec_from_pos(dir, rbf->gx, rbf->gy); + bsdf = eval_rbfrep(dsf_list, dir) / (output_orient*dir[2]); + bsdf = log(bsdf) - min_log; + printf("red sphere p%04d\n0\n0\n", ++n); + printf("4 %.6g %.6g %.6g %.6g\n\n", + dir[0]*bsdf, dir[1]*bsdf, dir[2]*bsdf, + .011*bsdf); + } +#endif +#if 1 /* output continuous surface */ + puts("void trans tgreen\n0\n0\n7 .7 1 .7 .04 .04 .9 1\n"); + fflush(stdout); + sprintf(buf, "gensurf tgreen bsdf - - - %d %d", GRIDRES-1, GRIDRES-1); + pfp = popen(buf, "w"); + if (pfp == NULL) { + fprintf(stderr, "%s: cannot open '| %s'\n", argv[0], buf); + return(1); + } + for (i = 0; i < GRIDRES; i++) + for (j = 0; j < GRIDRES; j++) { + ovec_from_pos(dir, i, j); + bsdf = eval_rbfrep(dsf_list, dir) / (output_orient*dir[2]); + bsdf = log(bsdf) - min_log; + fprintf(pfp, "%.8e %.8e %.8e\n", + dir[0]*bsdf, dir[1]*bsdf, dir[2]*bsdf); + } + if (pclose(pfp) != 0) + return(1); +#endif + return(0); +} +#endif