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) |
100 |
|
fputs(": unknown incident angle\n", stderr); |
101 |
|
return(0); |
102 |
|
} |
103 |
+ |
while (inpfile[i].phi < 0) /* normalize phi direction */ |
104 |
+ |
inpfile[i].phi += 360.; |
105 |
|
return(1); |
106 |
|
} |
107 |
|
|
118 |
|
fputs(": cannot open\n", stderr); |
119 |
|
return(0); |
120 |
|
} |
115 |
– |
#ifdef DEBUG |
116 |
– |
fprintf(stderr, "Loading measurements from '%s'...\n", inpfile[i].fname); |
117 |
– |
#endif |
121 |
|
/* prepare input grid */ |
122 |
|
if (!i || cmp_inang(&inpfile[i-1], &inpfile[i])) { |
123 |
|
if (i) /* need to process previous incidence */ |
128 |
|
#endif |
129 |
|
new_bsdf_data(inpfile[i].theta, inpfile[i].phi); |
130 |
|
} |
131 |
+ |
#ifdef DEBUG |
132 |
+ |
fprintf(stderr, "Loading measurements from '%s'...\n", inpfile[i].fname); |
133 |
+ |
#endif |
134 |
|
/* read scattering data */ |
135 |
|
while (fscanf(fp, "%lf %lf %lf\n", &theta_out, &phi_out, &val) == 3) |
136 |
|
add_bsdf_data(theta_out, phi_out, val, inpfile[i].isDSF); |
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 |
+ |
/* produce spheres at meas. */ |
218 |
+ |
puts("void plastic yellow\n0\n0\n5 .6 .4 .01 .04 .08\n"); |
219 |
+ |
min_log = log(bsdf_min*.5); |
220 |
+ |
n = 0; |
221 |
+ |
for (i = 0; i < GRIDRES; i++) |
222 |
+ |
for (j = 0; j < GRIDRES; j++) |
223 |
+ |
if (dsf_grid[i][j].nval > 0) { |
224 |
+ |
ovec_from_pos(dir, i, j); |
225 |
+ |
bsdf = dsf_grid[i][j].vsum / |
226 |
+ |
(dsf_grid[i][j].nval*output_orient*dir[2]); |
227 |
+ |
if (bsdf <= bsdf_min*.6) |
228 |
+ |
continue; |
229 |
+ |
bsdf = log(bsdf) - min_log; |
230 |
+ |
ovec_from_pos(dir, i, j); |
231 |
+ |
printf("yellow sphere s%04d\n0\n0\n", ++n); |
232 |
+ |
printf("4 %.6g %.6g %.6g %.6g\n\n", |
233 |
+ |
dir[0]*bsdf, dir[1]*bsdf, dir[2]*bsdf, |
234 |
+ |
.007*bsdf); |
235 |
+ |
} |
236 |
+ |
/* output continuous surface */ |
237 |
+ |
puts("void trans tgreen\n0\n0\n7 .7 1 .7 .04 .04 .9 1\n"); |
238 |
+ |
fflush(stdout); |
239 |
+ |
sprintf(buf, "gensurf tgreen bsdf - - - %d %d", GRIDRES-1, GRIDRES-1); |
240 |
+ |
pfp = popen(buf, "w"); |
241 |
+ |
if (pfp == NULL) { |
242 |
+ |
fprintf(stderr, "%s: cannot open '| %s'\n", argv[0], buf); |
243 |
+ |
return(1); |
244 |
+ |
} |
245 |
+ |
for (i = 0; i < GRIDRES; i++) |
246 |
+ |
for (j = 0; j < GRIDRES; j++) { |
247 |
+ |
ovec_from_pos(dir, i, j); |
248 |
+ |
bsdf = eval_rbfrep(dsf_list, dir) / (output_orient*dir[2]); |
249 |
+ |
bsdf = log(bsdf) - min_log; |
250 |
+ |
fprintf(pfp, "%.8e %.8e %.8e\n", |
251 |
+ |
dir[0]*bsdf, dir[1]*bsdf, dir[2]*bsdf); |
252 |
+ |
} |
253 |
+ |
return(pclose(pfp)==0 ? 0 : 1); |
254 |
+ |
} |
255 |
+ |
#endif |