| 11 |  | #include <stdlib.h> | 
| 12 |  | #include <string.h> | 
| 13 |  | #include <ctype.h> | 
| 14 | + | #include <math.h> | 
| 15 |  | #include "platform.h" | 
| 16 |  | #include "bsdfrep.h" | 
| 17 |  | /* global argv[0] */ | 
| 63 |  | inpfile[i].theta = inpfile[i].phi = -10001.; | 
| 64 |  | /* read header information */ | 
| 65 |  | while ((c = getc(fp)) == '#' || c == EOF) { | 
| 66 | + | char    typ[32]; | 
| 67 |  | if (fgets(buf, sizeof(buf), fp) == NULL) { | 
| 68 |  | fputs(fname, stderr); | 
| 69 |  | fputs(": unexpected EOF\n", stderr); | 
| 70 |  | fclose(fp); | 
| 71 |  | return(0); | 
| 72 |  | } | 
| 73 | < | if (!strcmp(buf, "format: theta phi DSF\n")) { | 
| 74 | < | inpfile[i].isDSF = 1; | 
| 75 | < | continue; | 
| 73 | > | if (sscanf(buf, "format: theta phi %s", typ) == 1) { | 
| 74 | > | if (!strcasecmp(typ, "DSF")) { | 
| 75 | > | inpfile[i].isDSF = 1; | 
| 76 | > | continue; | 
| 77 | > | } | 
| 78 | > | if (!strcasecmp(typ, "BSDF")) { | 
| 79 | > | inpfile[i].isDSF = 0; | 
| 80 | > | continue; | 
| 81 | > | } | 
| 82 |  | } | 
| 75 | – | if (!strcmp(buf, "format: theta phi BSDF\n")) { | 
| 76 | – | inpfile[i].isDSF = 0; | 
| 77 | – | continue; | 
| 78 | – | } | 
| 83 |  | if (sscanf(buf, "intheta %lf", &inpfile[i].theta) == 1) | 
| 84 |  | continue; | 
| 85 |  | if (sscanf(buf, "inphi %lf", &inpfile[i].phi) == 1) | 
| 145 |  | return(1); | 
| 146 |  | } | 
| 147 |  |  | 
| 148 | + | #ifndef TEST_MAIN | 
| 149 |  | /* Read in PAB-Opto BSDF files and output RBF interpolant */ | 
| 150 |  | int | 
| 151 |  | main(int argc, char *argv[]) | 
| 192 |  | progname); | 
| 193 |  | return(1); | 
| 194 |  | } | 
| 195 | + | #else | 
| 196 | + | /* Test main produces a Radiance model from the given input file */ | 
| 197 | + | int | 
| 198 | + | main(int argc, char *argv[]) | 
| 199 | + | { | 
| 200 | + | PGINPUT pginp; | 
| 201 | + | char    buf[128]; | 
| 202 | + | FILE    *pfp; | 
| 203 | + | double  bsdf, min_log; | 
| 204 | + | FVECT   dir; | 
| 205 | + | int     i, j, n; | 
| 206 | + |  | 
| 207 | + | if (argc != 2) { | 
| 208 | + | fprintf(stderr, "Usage: %s input.dat > output.rad\n", argv[0]); | 
| 209 | + | return(1); | 
| 210 | + | } | 
| 211 | + | ninpfiles = 1; | 
| 212 | + | inpfile = &pginp; | 
| 213 | + | if (!init_pabopto_inp(0, argv[1]) || !add_pabopto_inp(0)) | 
| 214 | + | return(1); | 
| 215 | + | /* reduce data set */ | 
| 216 | + | make_rbfrep(); | 
| 217 | + | #ifdef DEBUG | 
| 218 | + | fprintf(stderr, "Minimum BSDF = %.4f\n", bsdf_min); | 
| 219 | + | #endif | 
| 220 | + | /* produce spheres at meas. */ | 
| 221 | + | puts("void plastic yellow\n0\n0\n5 .6 .4 .01 .04 .08\n"); | 
| 222 | + | min_log = log(bsdf_min*.5); | 
| 223 | + | n = 0; | 
| 224 | + | for (i = 0; i < GRIDRES; i++) | 
| 225 | + | for (j = 0; j < GRIDRES; j++) | 
| 226 | + | if (dsf_grid[i][j].nval > 0) { | 
| 227 | + | ovec_from_pos(dir, i, j); | 
| 228 | + | bsdf = dsf_grid[i][j].vsum / | 
| 229 | + | (dsf_grid[i][j].nval*output_orient*dir[2]); | 
| 230 | + | if (bsdf <= bsdf_min*.6) | 
| 231 | + | continue; | 
| 232 | + | bsdf = log(bsdf) - min_log; | 
| 233 | + | ovec_from_pos(dir, i, j); | 
| 234 | + | printf("yellow sphere s%04d\n0\n0\n", ++n); | 
| 235 | + | printf("4 %.6g %.6g %.6g %.6g\n\n", | 
| 236 | + | dir[0]*bsdf, dir[1]*bsdf, dir[2]*bsdf, | 
| 237 | + | .007*bsdf); | 
| 238 | + | } | 
| 239 | + | /* output continuous surface */ | 
| 240 | + | puts("void trans tgreen\n0\n0\n7 .7 1 .7 .04 .04 .9 1\n"); | 
| 241 | + | fflush(stdout); | 
| 242 | + | sprintf(buf, "gensurf tgreen bsdf - - - %d %d", GRIDRES-1, GRIDRES-1); | 
| 243 | + | pfp = popen(buf, "w"); | 
| 244 | + | if (pfp == NULL) { | 
| 245 | + | fprintf(stderr, "%s: cannot open '| %s'\n", argv[0], buf); | 
| 246 | + | return(1); | 
| 247 | + | } | 
| 248 | + | for (i = 0; i < GRIDRES; i++) | 
| 249 | + | for (j = 0; j < GRIDRES; j++) { | 
| 250 | + | ovec_from_pos(dir, i, j); | 
| 251 | + | bsdf = eval_rbfrep(dsf_list, dir) / (output_orient*dir[2]); | 
| 252 | + | bsdf = log(bsdf) - min_log; | 
| 253 | + | fprintf(pfp, "%.8e %.8e %.8e\n", | 
| 254 | + | dir[0]*bsdf, dir[1]*bsdf, dir[2]*bsdf); | 
| 255 | + | } | 
| 256 | + | return(pclose(pfp)==0 ? 0 : 1); | 
| 257 | + | } | 
| 258 | + | #endif |