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] */ |
70 |
|
fclose(fp); |
71 |
|
return(0); |
72 |
|
} |
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; |
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 |
+ |
min_log = log(bsdf_min*.5 + 1e-5); |
223 |
+ |
#if 1 /* produce spheres at meas. */ |
224 |
+ |
puts("void plastic yellow\n0\n0\n5 .6 .4 .01 .04 .08\n"); |
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 |
+ |
#endif |
242 |
+ |
#if 1 /* spheres at RBF peaks */ |
243 |
+ |
puts("void plastic red\n0\n0\n5 .8 .01 .01 .04 .08\n"); |
244 |
+ |
for (n = 0; n < dsf_list->nrbf; n++) { |
245 |
+ |
RBFVAL *rbf = &dsf_list->rbfa[n]; |
246 |
+ |
ovec_from_pos(dir, rbf->gx, rbf->gy); |
247 |
+ |
bsdf = eval_rbfrep(dsf_list, dir) / (output_orient*dir[2]); |
248 |
+ |
bsdf = log(bsdf) - min_log; |
249 |
+ |
printf("red sphere p%04d\n0\n0\n", ++n); |
250 |
+ |
printf("4 %.6g %.6g %.6g %.6g\n\n", |
251 |
+ |
dir[0]*bsdf, dir[1]*bsdf, dir[2]*bsdf, |
252 |
+ |
.011*bsdf); |
253 |
+ |
} |
254 |
+ |
#endif |
255 |
+ |
#if 1 /* output continuous surface */ |
256 |
+ |
puts("void trans tgreen\n0\n0\n7 .7 1 .7 .04 .04 .9 1\n"); |
257 |
+ |
fflush(stdout); |
258 |
+ |
sprintf(buf, "gensurf tgreen bsdf - - - %d %d", GRIDRES-1, GRIDRES-1); |
259 |
+ |
pfp = popen(buf, "w"); |
260 |
+ |
if (pfp == NULL) { |
261 |
+ |
fprintf(stderr, "%s: cannot open '| %s'\n", argv[0], buf); |
262 |
+ |
return(1); |
263 |
+ |
} |
264 |
+ |
for (i = 0; i < GRIDRES; i++) |
265 |
+ |
for (j = 0; j < GRIDRES; j++) { |
266 |
+ |
ovec_from_pos(dir, i, j); |
267 |
+ |
bsdf = eval_rbfrep(dsf_list, dir) / (output_orient*dir[2]); |
268 |
+ |
bsdf = log(bsdf) - min_log; |
269 |
+ |
fprintf(pfp, "%.8e %.8e %.8e\n", |
270 |
+ |
dir[0]*bsdf, dir[1]*bsdf, dir[2]*bsdf); |
271 |
+ |
} |
272 |
+ |
if (pclose(pfp) != 0) |
273 |
+ |
return(1); |
274 |
+ |
#endif |
275 |
+ |
return(0); |
276 |
+ |
} |
277 |
+ |
#endif |