14 |
|
#include <math.h> |
15 |
|
#include "platform.h" |
16 |
|
#include "bsdfrep.h" |
17 |
+ |
#include "resolu.h" |
18 |
|
/* global argv[0] */ |
19 |
|
char *progname; |
20 |
|
|
25 |
|
long dstart; /* data start offset in file */ |
26 |
|
} PGINPUT; |
27 |
|
|
28 |
+ |
double angle_eps = 0; /* epsilon for angle comparisons */ |
29 |
+ |
|
30 |
|
PGINPUT *inpfile; /* input files sorted by incidence */ |
31 |
|
int ninpfiles; /* number of input files */ |
32 |
|
|
37 |
|
const PGINPUT *inp1 = (const PGINPUT *)p1; |
38 |
|
const PGINPUT *inp2 = (const PGINPUT *)p2; |
39 |
|
|
40 |
< |
if (inp1->theta > inp2->theta+FTINY) |
40 |
> |
if (inp1->theta > inp2->theta+angle_eps) |
41 |
|
return(1); |
42 |
< |
if (inp1->theta < inp2->theta-FTINY) |
42 |
> |
if (inp1->theta < inp2->theta-angle_eps) |
43 |
|
return(-1); |
44 |
< |
if (inp1->phi > inp2->phi+FTINY) |
44 |
> |
if (inp1->phi > inp2->phi+angle_eps) |
45 |
|
return(1); |
46 |
< |
if (inp1->phi < inp2->phi-FTINY) |
46 |
> |
if (inp1->phi < inp2->phi-angle_eps) |
47 |
|
return(-1); |
48 |
|
return(0); |
49 |
|
} |
73 |
|
fclose(fp); |
74 |
|
return(0); |
75 |
|
} |
76 |
+ |
if (sscanf(buf, "sample_name \"%[^\"]\"", bsdf_name) == 1) |
77 |
+ |
continue; |
78 |
|
if (sscanf(buf, "format: theta phi %s", typ) == 1) { |
79 |
|
if (!strcasecmp(typ, "DSF")) { |
80 |
|
inpfile[i].isDSF = 1; |
114 |
|
static int |
115 |
|
add_pabopto_inp(const int i) |
116 |
|
{ |
117 |
< |
FILE *fp = fopen(inpfile[i].fname, "r"); |
118 |
< |
double theta_out, phi_out, val; |
119 |
< |
int n, c; |
117 |
> |
static int lastnew = -1; |
118 |
> |
FILE *fp = fopen(inpfile[i].fname, "r"); |
119 |
> |
double theta_out, phi_out, val; |
120 |
> |
int n, c; |
121 |
|
|
122 |
|
if (fp == NULL || fseek(fp, inpfile[i].dstart, 0) == EOF) { |
123 |
|
fputs(inpfile[i].fname, stderr); |
125 |
|
return(0); |
126 |
|
} |
127 |
|
/* prepare input grid */ |
128 |
< |
if (!i || cmp_inang(&inpfile[i-1], &inpfile[i])) { |
129 |
< |
if (i) /* need to process previous incidence */ |
128 |
> |
angle_eps = 180./2./GRIDRES; |
129 |
> |
if (lastnew < 0 || cmp_inang(&inpfile[lastnew], &inpfile[i])) { |
130 |
> |
if (lastnew >= 0) /* need to process previous incidence */ |
131 |
|
make_rbfrep(); |
132 |
|
#ifdef DEBUG |
133 |
|
fprintf(stderr, "New incident (theta,phi)=(%f,%f)\n", |
134 |
|
inpfile[i].theta, inpfile[i].phi); |
135 |
|
#endif |
136 |
|
new_bsdf_data(inpfile[i].theta, inpfile[i].phi); |
137 |
+ |
lastnew = i; |
138 |
|
} |
139 |
|
#ifdef DEBUG |
140 |
|
fprintf(stderr, "Loading measurements from '%s'...\n", inpfile[i].fname); |
153 |
|
return(1); |
154 |
|
} |
155 |
|
|
156 |
< |
#if 1 |
156 |
> |
#ifndef TEST_MAIN |
157 |
|
/* Read in PAB-Opto BSDF files and output RBF interpolant */ |
158 |
|
int |
159 |
|
main(int argc, char *argv[]) |
186 |
|
for (i = 0; i < ninpfiles; i++) |
187 |
|
if (!init_pabopto_inp(i, argv[i+1])) |
188 |
|
return(1); |
189 |
+ |
angle_eps = 0; |
190 |
|
qsort(inpfile, ninpfiles, sizeof(PGINPUT), &cmp_inang); |
191 |
|
/* compile measurements */ |
192 |
|
for (i = 0; i < ninpfiles; i++) |
223 |
|
return(1); |
224 |
|
/* reduce data set */ |
225 |
|
make_rbfrep(); |
226 |
< |
/* produce spheres at meas. */ |
226 |
> |
#ifdef DEBUG |
227 |
> |
fprintf(stderr, "Minimum BSDF = %.4f\n", bsdf_min); |
228 |
> |
#endif |
229 |
> |
min_log = log(bsdf_min*.5 + 1e-5); |
230 |
> |
#if 1 /* produce spheres at meas. */ |
231 |
|
puts("void plastic yellow\n0\n0\n5 .6 .4 .01 .04 .08\n"); |
219 |
– |
puts("void plastic pink\n0\n0\n5 .5 .05 .9 .04 .08\n"); |
220 |
– |
min_log = log(bsdf_min*.5); |
232 |
|
n = 0; |
233 |
|
for (i = 0; i < GRIDRES; i++) |
234 |
|
for (j = 0; j < GRIDRES; j++) |
235 |
< |
if (dsf_grid[i][j].vsum > .0f) { |
235 |
> |
if (dsf_grid[i][j].sum.n > 0) { |
236 |
|
ovec_from_pos(dir, i, j); |
237 |
< |
bsdf = dsf_grid[i][j].vsum / dir[2]; |
237 |
> |
bsdf = dsf_grid[i][j].sum.v / |
238 |
> |
(dsf_grid[i][j].sum.n*output_orient*dir[2]); |
239 |
|
if (bsdf <= bsdf_min*.6) |
240 |
|
continue; |
241 |
< |
bsdf = log(bsdf) - min_log; |
242 |
< |
if (dsf_grid[i][j].nval) { |
243 |
< |
printf("pink cone c%04d\n0\n0\n8\n", ++n); |
244 |
< |
printf("\t%.6g %.6g %.6g\n", |
233 |
< |
dir[0]*bsdf, dir[1]*bsdf, dir[2]*bsdf); |
234 |
< |
printf("\t%.6g %.6g %.6g\n", |
235 |
< |
dir[0]*bsdf*1.02, dir[1]*bsdf*1.02, |
236 |
< |
dir[2]*bsdf*1.02); |
237 |
< |
printf("\t%.6g\t0\n", .02*bsdf); |
238 |
< |
} else { |
239 |
< |
ovec_from_pos(dir, i, j); |
240 |
< |
printf("yellow sphere s%04d\n0\n0\n", ++n); |
241 |
< |
printf("4 %.6g %.6g %.6g %.6g\n\n", |
241 |
> |
bsdf = log(bsdf + 1e-5) - min_log; |
242 |
> |
ovec_from_pos(dir, i, j); |
243 |
> |
printf("yellow sphere s%04d\n0\n0\n", ++n); |
244 |
> |
printf("4 %.6g %.6g %.6g %.6g\n\n", |
245 |
|
dir[0]*bsdf, dir[1]*bsdf, dir[2]*bsdf, |
246 |
< |
.01*bsdf); |
244 |
< |
} |
246 |
> |
.007*bsdf); |
247 |
|
} |
248 |
< |
/* output continuous surface */ |
248 |
> |
#endif |
249 |
> |
#if 1 /* spheres at RBF peaks */ |
250 |
> |
puts("void plastic red\n0\n0\n5 .8 .01 .01 .04 .08\n"); |
251 |
> |
for (n = 0; n < dsf_list->nrbf; n++) { |
252 |
> |
RBFVAL *rbf = &dsf_list->rbfa[n]; |
253 |
> |
ovec_from_pos(dir, rbf->gx, rbf->gy); |
254 |
> |
bsdf = eval_rbfrep(dsf_list, dir) / (output_orient*dir[2]); |
255 |
> |
bsdf = log(bsdf + 1e-5) - min_log; |
256 |
> |
printf("red sphere p%04d\n0\n0\n", ++n); |
257 |
> |
printf("4 %.6g %.6g %.6g %.6g\n\n", |
258 |
> |
dir[0]*bsdf, dir[1]*bsdf, dir[2]*bsdf, |
259 |
> |
.011*bsdf); |
260 |
> |
} |
261 |
> |
#endif |
262 |
> |
#if 1 /* output continuous surface */ |
263 |
|
puts("void trans tgreen\n0\n0\n7 .7 1 .7 .04 .04 .9 1\n"); |
264 |
|
fflush(stdout); |
265 |
|
sprintf(buf, "gensurf tgreen bsdf - - - %d %d", GRIDRES-1, GRIDRES-1); |
266 |
|
pfp = popen(buf, "w"); |
267 |
|
if (pfp == NULL) { |
268 |
< |
fputs(buf, stderr); |
253 |
< |
fputs(": cannot start command\n", stderr); |
268 |
> |
fprintf(stderr, "%s: cannot open '| %s'\n", argv[0], buf); |
269 |
|
return(1); |
270 |
|
} |
271 |
|
for (i = 0; i < GRIDRES; i++) |
272 |
|
for (j = 0; j < GRIDRES; j++) { |
273 |
|
ovec_from_pos(dir, i, j); |
274 |
< |
bsdf = eval_rbfrep(dsf_list, dir) / dir[2]; |
275 |
< |
bsdf = log(bsdf) - min_log; |
274 |
> |
bsdf = eval_rbfrep(dsf_list, dir) / (output_orient*dir[2]); |
275 |
> |
bsdf = log(bsdf + 1e-5) - min_log; |
276 |
|
fprintf(pfp, "%.8e %.8e %.8e\n", |
277 |
|
dir[0]*bsdf, dir[1]*bsdf, dir[2]*bsdf); |
278 |
|
} |
279 |
< |
return(pclose(pfp)==0 ? 0 : 1); |
279 |
> |
if (pclose(pfp) != 0) |
280 |
> |
return(1); |
281 |
> |
#endif |
282 |
> |
return(0); |
283 |
|
} |
284 |
|
#endif |