--- ray/src/cv/bsdf2ttree.c 2012/10/20 17:01:26 2.2 +++ ray/src/cv/bsdf2ttree.c 2012/11/10 19:47:42 2.7 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: bsdf2ttree.c,v 2.2 2012/10/20 17:01:26 greg Exp $"; +static const char RCSid[] = "$Id: bsdf2ttree.c,v 2.7 2012/11/10 19:47:42 greg Exp $"; #endif /* * Load measured BSDF interpolant and write out as XML file with tensor tree. @@ -16,7 +16,7 @@ static const char RCSid[] = "$Id: bsdf2ttree.c,v 2.2 2 /* global argv[0] */ char *progname; /* percentage to cull (<0 to turn off) */ -int pctcull = 90; +double pctcull = 90.; /* sampling order */ int samp_order = 6; @@ -29,14 +29,14 @@ interp_isotropic() char cmd[128]; int ix, ox, oy; FVECT ivec, ovec; - double bsdf; + float bsdf; #if DEBUG fprintf(stderr, "Writing isotropic order %d ", samp_order); - if (pctcull >= 0) fprintf(stderr, "data with %d%% culling\n", pctcull); + if (pctcull >= 0) fprintf(stderr, "data with %f%% culling\n", pctcull); else fputs("raw data\n", stderr); #endif if (pctcull >= 0) { /* begin output */ - sprintf(cmd, "rttree_reduce -h -a -fd -r 3 -t %d -g %d", + sprintf(cmd, "rttree_reduce -h -a -ff -r 3 -t %f -g %d", pctcull, samp_order); fflush(stdout); ofp = popen(cmd, "w"); @@ -60,13 +60,14 @@ interp_isotropic() SDsquare2disk(ovec, (ox+.5)/sqres, (oy+.5)/sqres); ovec[2] = output_orient * sqrt(1. - ovec[0]*ovec[0] - ovec[1]*ovec[1]); - bsdf = eval_rbfrep(rbf, ovec) / fabs(ovec[2]); + bsdf = eval_rbfrep(rbf, ovec) * output_orient/ovec[2]; if (pctcull >= 0) fwrite(&bsdf, sizeof(bsdf), 1, ofp); else printf("\t%.3e\n", bsdf); } - free(rbf); + if (rbf != NULL) + free(rbf); } if (pctcull >= 0) { /* finish output */ if (pclose(ofp)) { @@ -90,14 +91,14 @@ interp_anisotropic() char cmd[128]; int ix, iy, ox, oy; FVECT ivec, ovec; - double bsdf; + float bsdf; #if DEBUG fprintf(stderr, "Writing anisotropic order %d ", samp_order); - if (pctcull >= 0) fprintf(stderr, "data with %d%% culling\n", pctcull); + if (pctcull >= 0) fprintf(stderr, "data with %f%% culling\n", pctcull); else fputs("raw data\n", stderr); #endif if (pctcull >= 0) { /* begin output */ - sprintf(cmd, "rttree_reduce -h -a -fd -r 4 -t %d -g %d", + sprintf(cmd, "rttree_reduce -h -a -ff -r 4 -t %f -g %d", pctcull, samp_order); fflush(stdout); ofp = popen(cmd, "w"); @@ -121,13 +122,14 @@ interp_anisotropic() SDsquare2disk(ovec, (ox+.5)/sqres, (oy+.5)/sqres); ovec[2] = output_orient * sqrt(1. - ovec[0]*ovec[0] - ovec[1]*ovec[1]); - bsdf = eval_rbfrep(rbf, ovec) / fabs(ovec[2]); + bsdf = eval_rbfrep(rbf, ovec) * output_orient/ovec[2]; if (pctcull >= 0) fwrite(&bsdf, sizeof(bsdf), 1, ofp); else printf("\t%.3e\n", bsdf); } - free(rbf); + if (rbf != NULL) + free(rbf); } if (pctcull >= 0) { /* finish output */ if (pclose(ofp)) { @@ -139,6 +141,63 @@ interp_anisotropic() fputs("}\n", stdout); } +/* Output XML prologue to stdout */ +static void +xml_prologue(int ac, char *av[]) +{ + static const char *bsdf_type[4] = { + "Reflection Front", + "Transmission Front", + "Transmission Back", + "Reflection Back" + }; + + puts(""); + puts(""); + fputs(""); + puts("System"); + puts("BSDF"); + puts(""); + puts(""); + puts("\t"); + puts("\t\tName"); + puts("\t\tManufacturer"); + puts("\t\tOther"); + puts("\t"); + puts("\t"); + printf("\t\tTensorTree%c\n", + single_plane_incident ? '3' : '4'); + puts("\t"); + puts("\t"); + puts("\t\tSystem"); + puts("\t\tVisible"); + puts("\t\tCIE Illuminant D65 1nm.ssp"); + puts("\t\tASTM E308 1931 Y.dsp"); + puts("\t\t"); + printf("\t\t\t%s\n", + bsdf_type[(input_orient>0)<<1 | (output_orient>0)]); + puts("\t\t\tLBNL/Shirley-Chiu"); + puts("\t\t\tBTDF"); + puts("\t\t\t"); +} + +/* Output XML epilogue to stdout */ +static void +xml_epilogue(void) +{ + puts("\t\t\t"); + puts("\t\t"); + puts("\t"); + puts(""); + puts(""); + puts(""); +} + /* Read in BSDF and interpolate as tensor tree representation */ int main(int argc, char *argv[]) @@ -146,39 +205,38 @@ main(int argc, char *argv[]) FILE *fpin = stdin; int i; - progname = argv[0]; /* get options */ - while (argc > 2 && argv[1][0] == '-') { - switch (argv[1][1]) { + progname = argv[0]; + for (i = 1; i < argc-1 && argv[i][0] == '-'; i++) + switch (argv[i][1]) { /* get option */ case 't': - pctcull = atoi(argv[2]); + pctcull = atof(argv[++i]); break; case 'g': - samp_order = atoi(argv[2]); + samp_order = atoi(argv[++i]); break; default: goto userr; } - argv += 2; argc -= 2; - } - if (argc == 2) { /* open input if given */ - fpin = fopen(argv[1], "r"); + + if (i == argc-1) { /* open input if given */ + fpin = fopen(argv[i], "r"); if (fpin == NULL) { fprintf(stderr, "%s: cannot open BSDF interpolant '%s'\n", progname, argv[1]); return(1); } - } else if (argc != 1) + } else if (i < argc-1) goto userr; SET_FILE_BINARY(fpin); /* load BSDF interpolant */ if (!load_bsdf_rep(fpin)) return(1); - draw_edges(); - /* xml_prologue(); /* start XML output */ + fclose(fpin); + xml_prologue(argc, argv); /* start XML output */ if (single_plane_incident) /* resample dist. */ interp_isotropic(); else interp_anisotropic(); - /* xml_epilogue(); /* finish XML output */ + xml_epilogue(); /* finish XML output */ return(0); userr: fprintf(stderr,