| 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")) { |
| 72 |
< |
inpfile[i].isDSF = 1; |
| 73 |
> |
if (sscanf(buf, "sample_name \"%[^\"]\"", bsdf_name) == 1) |
| 74 |
|
continue; |
| 75 |
+ |
if (sscanf(buf, "format: theta phi %s", typ) == 1) { |
| 76 |
+ |
if (!strcasecmp(typ, "DSF")) { |
| 77 |
+ |
inpfile[i].isDSF = 1; |
| 78 |
+ |
continue; |
| 79 |
+ |
} |
| 80 |
+ |
if (!strcasecmp(typ, "BSDF")) { |
| 81 |
+ |
inpfile[i].isDSF = 0; |
| 82 |
+ |
continue; |
| 83 |
+ |
} |
| 84 |
|
} |
| 75 |
– |
if (!strcmp(buf, "format: theta phi BSDF\n")) { |
| 76 |
– |
inpfile[i].isDSF = 0; |
| 77 |
– |
continue; |
| 78 |
– |
} |
| 85 |
|
if (sscanf(buf, "intheta %lf", &inpfile[i].theta) == 1) |
| 86 |
|
continue; |
| 87 |
|
if (sscanf(buf, "inphi %lf", &inpfile[i].phi) == 1) |
| 102 |
|
fputs(": unknown incident angle\n", stderr); |
| 103 |
|
return(0); |
| 104 |
|
} |
| 105 |
+ |
while (inpfile[i].phi < 0) /* normalize phi direction */ |
| 106 |
+ |
inpfile[i].phi += 360.; |
| 107 |
|
return(1); |
| 108 |
|
} |
| 109 |
|
|
| 120 |
|
fputs(": cannot open\n", stderr); |
| 121 |
|
return(0); |
| 122 |
|
} |
| 115 |
– |
#ifdef DEBUG |
| 116 |
– |
fprintf(stderr, "Loading measurements from '%s'...\n", inpfile[i].fname); |
| 117 |
– |
#endif |
| 123 |
|
/* prepare input grid */ |
| 124 |
|
if (!i || cmp_inang(&inpfile[i-1], &inpfile[i])) { |
| 125 |
|
if (i) /* need to process previous incidence */ |
| 130 |
|
#endif |
| 131 |
|
new_bsdf_data(inpfile[i].theta, inpfile[i].phi); |
| 132 |
|
} |
| 133 |
+ |
#ifdef DEBUG |
| 134 |
+ |
fprintf(stderr, "Loading measurements from '%s'...\n", inpfile[i].fname); |
| 135 |
+ |
#endif |
| 136 |
|
/* read scattering data */ |
| 137 |
|
while (fscanf(fp, "%lf %lf %lf\n", &theta_out, &phi_out, &val) == 3) |
| 138 |
|
add_bsdf_data(theta_out, phi_out, val, inpfile[i].isDSF); |
| 147 |
|
return(1); |
| 148 |
|
} |
| 149 |
|
|
| 150 |
+ |
#ifndef TEST_MAIN |
| 151 |
|
/* Read in PAB-Opto BSDF files and output RBF interpolant */ |
| 152 |
|
int |
| 153 |
|
main(int argc, char *argv[]) |
| 194 |
|
progname); |
| 195 |
|
return(1); |
| 196 |
|
} |
| 197 |
+ |
#else |
| 198 |
+ |
/* Test main produces a Radiance model from the given input file */ |
| 199 |
+ |
int |
| 200 |
+ |
main(int argc, char *argv[]) |
| 201 |
+ |
{ |
| 202 |
+ |
PGINPUT pginp; |
| 203 |
+ |
char buf[128]; |
| 204 |
+ |
FILE *pfp; |
| 205 |
+ |
double bsdf, min_log; |
| 206 |
+ |
FVECT dir; |
| 207 |
+ |
int i, j, n; |
| 208 |
+ |
|
| 209 |
+ |
if (argc != 2) { |
| 210 |
+ |
fprintf(stderr, "Usage: %s input.dat > output.rad\n", argv[0]); |
| 211 |
+ |
return(1); |
| 212 |
+ |
} |
| 213 |
+ |
ninpfiles = 1; |
| 214 |
+ |
inpfile = &pginp; |
| 215 |
+ |
if (!init_pabopto_inp(0, argv[1]) || !add_pabopto_inp(0)) |
| 216 |
+ |
return(1); |
| 217 |
+ |
/* reduce data set */ |
| 218 |
+ |
make_rbfrep(); |
| 219 |
+ |
#ifdef DEBUG |
| 220 |
+ |
fprintf(stderr, "Minimum BSDF = %.4f\n", bsdf_min); |
| 221 |
+ |
#endif |
| 222 |
+ |
/* produce spheres at meas. */ |
| 223 |
+ |
puts("void plastic yellow\n0\n0\n5 .6 .4 .01 .04 .08\n"); |
| 224 |
+ |
min_log = log(bsdf_min*.5); |
| 225 |
+ |
n = 0; |
| 226 |
+ |
for (i = 0; i < GRIDRES; i++) |
| 227 |
+ |
for (j = 0; j < GRIDRES; j++) |
| 228 |
+ |
if (dsf_grid[i][j].nval > 0) { |
| 229 |
+ |
ovec_from_pos(dir, i, j); |
| 230 |
+ |
bsdf = dsf_grid[i][j].vsum / |
| 231 |
+ |
(dsf_grid[i][j].nval*output_orient*dir[2]); |
| 232 |
+ |
if (bsdf <= bsdf_min*.6) |
| 233 |
+ |
continue; |
| 234 |
+ |
bsdf = log(bsdf) - min_log; |
| 235 |
+ |
ovec_from_pos(dir, i, j); |
| 236 |
+ |
printf("yellow sphere s%04d\n0\n0\n", ++n); |
| 237 |
+ |
printf("4 %.6g %.6g %.6g %.6g\n\n", |
| 238 |
+ |
dir[0]*bsdf, dir[1]*bsdf, dir[2]*bsdf, |
| 239 |
+ |
.007*bsdf); |
| 240 |
+ |
} |
| 241 |
+ |
/* output continuous surface */ |
| 242 |
+ |
puts("void trans tgreen\n0\n0\n7 .7 1 .7 .04 .04 .9 1\n"); |
| 243 |
+ |
fflush(stdout); |
| 244 |
+ |
sprintf(buf, "gensurf tgreen bsdf - - - %d %d", GRIDRES-1, GRIDRES-1); |
| 245 |
+ |
pfp = popen(buf, "w"); |
| 246 |
+ |
if (pfp == NULL) { |
| 247 |
+ |
fprintf(stderr, "%s: cannot open '| %s'\n", argv[0], buf); |
| 248 |
+ |
return(1); |
| 249 |
+ |
} |
| 250 |
+ |
for (i = 0; i < GRIDRES; i++) |
| 251 |
+ |
for (j = 0; j < GRIDRES; j++) { |
| 252 |
+ |
ovec_from_pos(dir, i, j); |
| 253 |
+ |
bsdf = eval_rbfrep(dsf_list, dir) / (output_orient*dir[2]); |
| 254 |
+ |
bsdf = log(bsdf) - min_log; |
| 255 |
+ |
fprintf(pfp, "%.8e %.8e %.8e\n", |
| 256 |
+ |
dir[0]*bsdf, dir[1]*bsdf, dir[2]*bsdf); |
| 257 |
+ |
} |
| 258 |
+ |
return(pclose(pfp)==0 ? 0 : 1); |
| 259 |
+ |
} |
| 260 |
+ |
#endif |