25 |
|
/* super-sampling threshold */ |
26 |
|
const double ssamp_thresh = 0.35; |
27 |
|
/* number of super-samples */ |
28 |
< |
const int nssamp = 100; |
28 |
> |
#ifndef NSSAMP |
29 |
> |
#define NSSAMP 100 |
30 |
> |
#endif |
31 |
|
/* limit on number of RBF lobes */ |
32 |
|
static int lobe_lim = 15000; |
33 |
+ |
/* progress bar length */ |
34 |
+ |
static int do_prog = 79; |
35 |
|
|
36 |
+ |
|
37 |
+ |
/* Start new progress bar */ |
38 |
+ |
#define prog_start(s) if (do_prog) fprintf(stderr, "%s: %s...\n", progname, s); else |
39 |
+ |
|
40 |
+ |
/* Draw progress bar of the appropriate length */ |
41 |
+ |
static void |
42 |
+ |
prog_show(double frac) |
43 |
+ |
{ |
44 |
+ |
static unsigned call_cnt = 0; |
45 |
+ |
static char lastc[] = "-\\|/"; |
46 |
+ |
char pbar[256]; |
47 |
+ |
int nchars; |
48 |
+ |
|
49 |
+ |
if (do_prog <= 1) return; |
50 |
+ |
if (do_prog > sizeof(pbar)-2) |
51 |
+ |
do_prog = sizeof(pbar)-2; |
52 |
+ |
if (frac < 0) frac = 0; |
53 |
+ |
else if (frac >= 1) frac = .9999; |
54 |
+ |
nchars = do_prog*frac; |
55 |
+ |
pbar[0] = '\r'; |
56 |
+ |
memset(pbar+1, '*', nchars); |
57 |
+ |
pbar[nchars+1] = lastc[call_cnt++ & 3]; |
58 |
+ |
memset(pbar+2+nchars, '-', do_prog-nchars-1); |
59 |
+ |
pbar[do_prog+1] = '\0'; |
60 |
+ |
fputs(pbar, stderr); |
61 |
+ |
} |
62 |
+ |
|
63 |
+ |
/* Finish progress bar */ |
64 |
+ |
static void |
65 |
+ |
prog_done(void) |
66 |
+ |
{ |
67 |
+ |
int n = do_prog; |
68 |
+ |
|
69 |
+ |
if (n <= 1) return; |
70 |
+ |
fputc('\r', stderr); |
71 |
+ |
while (n--) |
72 |
+ |
fputc(' ', stderr); |
73 |
+ |
fputc('\r', stderr); |
74 |
+ |
} |
75 |
+ |
|
76 |
|
/* Output XML prologue to stdout */ |
77 |
|
static void |
78 |
|
xml_prologue(int ac, char *av[]) |
202 |
|
iovec[5] = output_orient * |
203 |
|
sqrt(1. - iovec[3]*iovec[3] - iovec[4]*iovec[4]); |
204 |
|
if (funame == NULL) |
205 |
< |
bsdf = eval_rbfrep(rbf, iovec+3) * |
162 |
< |
output_orient/iovec[5]; |
205 |
> |
bsdf = eval_rbfrep(rbf, iovec+3); |
206 |
|
else { |
164 |
– |
double ssa[3], ssvec[6], sum; |
165 |
– |
int ssi; |
207 |
|
if (assignD) { |
208 |
|
varset("Dx", '=', -iovec[3]); |
209 |
|
varset("Dy", '=', -iovec[4]); |
211 |
|
++eclock; |
212 |
|
} |
213 |
|
bsdf = funvalue(funame, 6, iovec); |
214 |
+ |
#if (NSSAMP > 0) |
215 |
|
if (abs_diff(bsdf, last_bsdf) > ssamp_thresh) { |
216 |
< |
sum = 0; /* super-sample voxel */ |
217 |
< |
for (ssi = nssamp; ssi--; ) { |
218 |
< |
SDmultiSamp(ssa, 3, (ssi+frandom())/nssamp); |
216 |
> |
int ssi; |
217 |
> |
double ssa[3], ssvec[6], sum = 0; |
218 |
> |
/* super-sample voxel */ |
219 |
> |
for (ssi = NSSAMP; ssi--; ) { |
220 |
> |
SDmultiSamp(ssa, 3, (ssi+frandom()) * |
221 |
> |
(1./NSSAMP)); |
222 |
|
ssvec[0] = 2.*(ix+ssa[0])/sqres - 1.; |
223 |
|
ssvec[1] = .0; |
224 |
|
ssvec[2] = input_orient * |
229 |
|
sqrt(1. - ssvec[3]*ssvec[3] - |
230 |
|
ssvec[4]*ssvec[4]); |
231 |
|
if (assignD) { |
232 |
< |
varset("Dx", '=', -iovec[3]); |
233 |
< |
varset("Dy", '=', -iovec[4]); |
234 |
< |
varset("Dz", '=', -iovec[5]); |
232 |
> |
varset("Dx", '=', -ssvec[3]); |
233 |
> |
varset("Dy", '=', -ssvec[4]); |
234 |
> |
varset("Dz", '=', -ssvec[5]); |
235 |
|
++eclock; |
236 |
|
} |
237 |
|
sum += funvalue(funame, 6, ssvec); |
238 |
|
} |
239 |
< |
bsdf = sum/nssamp; |
239 |
> |
bsdf = sum/NSSAMP; |
240 |
|
} |
241 |
+ |
#endif |
242 |
|
} |
243 |
|
if (pctcull >= 0) |
244 |
|
fwrite(&bsdf, sizeof(bsdf), 1, ofp); |
249 |
|
} |
250 |
|
if (rbf != NULL) |
251 |
|
free(rbf); |
252 |
+ |
prog_show((ix+1.)*(2./sqres)); |
253 |
|
} |
254 |
|
if (pctcull >= 0) { /* finish output */ |
255 |
|
if (pclose(ofp)) { |
263 |
|
fputs("}\n", stdout); |
264 |
|
} |
265 |
|
data_epilogue(); |
266 |
+ |
prog_done(); |
267 |
|
} |
268 |
|
|
269 |
|
/* Interpolate and output anisotropic BSDF data */ |
315 |
|
iovec[5] = output_orient * |
316 |
|
sqrt(1. - iovec[3]*iovec[3] - iovec[4]*iovec[4]); |
317 |
|
if (funame == NULL) |
318 |
< |
bsdf = eval_rbfrep(rbf, iovec+3) * |
271 |
< |
output_orient/iovec[5]; |
318 |
> |
bsdf = eval_rbfrep(rbf, iovec+3); |
319 |
|
else { |
273 |
– |
double ssa[4], ssvec[6], sum; |
274 |
– |
int ssi; |
320 |
|
if (assignD) { |
321 |
|
varset("Dx", '=', -iovec[3]); |
322 |
|
varset("Dy", '=', -iovec[4]); |
324 |
|
++eclock; |
325 |
|
} |
326 |
|
bsdf = funvalue(funame, 6, iovec); |
327 |
+ |
#if (NSSAMP > 0) |
328 |
|
if (abs_diff(bsdf, last_bsdf) > ssamp_thresh) { |
329 |
< |
sum = 0; /* super-sample voxel */ |
330 |
< |
for (ssi = nssamp; ssi--; ) { |
331 |
< |
SDmultiSamp(ssa, 4, (ssi+frandom())/nssamp); |
329 |
> |
int ssi; |
330 |
> |
double ssa[4], ssvec[6], sum = 0; |
331 |
> |
/* super-sample voxel */ |
332 |
> |
for (ssi = NSSAMP; ssi--; ) { |
333 |
> |
SDmultiSamp(ssa, 4, (ssi+frandom()) * |
334 |
> |
(1./NSSAMP)); |
335 |
|
SDsquare2disk(ssvec, 1.-(ix+ssa[0])/sqres, |
336 |
|
1.-(iy+ssa[1])/sqres); |
337 |
< |
ssvec[2] = output_orient * |
337 |
> |
ssvec[2] = input_orient * |
338 |
|
sqrt(1. - ssvec[0]*ssvec[0] - |
339 |
|
ssvec[1]*ssvec[1]); |
340 |
|
SDsquare2disk(ssvec+3, (ox+ssa[2])/sqres, |
343 |
|
sqrt(1. - ssvec[3]*ssvec[3] - |
344 |
|
ssvec[4]*ssvec[4]); |
345 |
|
if (assignD) { |
346 |
< |
varset("Dx", '=', -iovec[3]); |
347 |
< |
varset("Dy", '=', -iovec[4]); |
348 |
< |
varset("Dz", '=', -iovec[5]); |
346 |
> |
varset("Dx", '=', -ssvec[3]); |
347 |
> |
varset("Dy", '=', -ssvec[4]); |
348 |
> |
varset("Dz", '=', -ssvec[5]); |
349 |
|
++eclock; |
350 |
|
} |
351 |
|
sum += funvalue(funame, 6, ssvec); |
352 |
|
} |
353 |
< |
bsdf = sum/nssamp; |
353 |
> |
bsdf = sum/NSSAMP; |
354 |
|
} |
355 |
+ |
#endif |
356 |
|
} |
357 |
|
if (pctcull >= 0) |
358 |
|
fwrite(&bsdf, sizeof(bsdf), 1, ofp); |
363 |
|
} |
364 |
|
if (rbf != NULL) |
365 |
|
free(rbf); |
366 |
+ |
prog_show((ix*sqres+iy+1.)/(sqres*sqres)); |
367 |
|
} |
368 |
|
if (pctcull >= 0) { /* finish output */ |
369 |
|
if (pclose(ofp)) { |
374 |
|
} else |
375 |
|
fputs("}\n", stdout); |
376 |
|
data_epilogue(); |
377 |
+ |
prog_done(); |
378 |
|
} |
379 |
|
|
380 |
|
/* Read in BSDF and interpolate as tensor tree representation */ |
424 |
|
case 'l': |
425 |
|
lobe_lim = atoi(argv[++i]); |
426 |
|
break; |
427 |
+ |
case 'p': |
428 |
+ |
do_prog = atoi(argv[i]+2); |
429 |
+ |
break; |
430 |
|
default: |
431 |
|
goto userr; |
432 |
|
} |
445 |
|
if (dofwd) { |
446 |
|
input_orient = -1; |
447 |
|
output_orient = -1; |
448 |
< |
(*evf)(argv[i]); /* outside reflectance */ |
448 |
> |
prog_start("Evaluating outside reflectance"); |
449 |
> |
(*evf)(argv[i]); |
450 |
|
output_orient = 1; |
451 |
< |
(*evf)(argv[i]); /* outside -> inside */ |
451 |
> |
prog_start("Evaluating outside->inside transmission"); |
452 |
> |
(*evf)(argv[i]); |
453 |
|
} |
454 |
|
if (dobwd) { |
455 |
|
input_orient = 1; |
456 |
|
output_orient = 1; |
457 |
< |
(*evf)(argv[i]); /* inside reflectance */ |
457 |
> |
prog_start("Evaluating inside reflectance"); |
458 |
> |
(*evf)(argv[i]); |
459 |
|
output_orient = -1; |
460 |
< |
(*evf)(argv[i]); /* inside -> outside */ |
460 |
> |
prog_start("Evaluating inside->outside transmission"); |
461 |
> |
(*evf)(argv[i]); |
462 |
|
} |
463 |
|
xml_epilogue(); /* finish XML output & exit */ |
464 |
|
return(0); |
466 |
|
if (i < argc) { /* open input files if given */ |
467 |
|
int nbsdf = 0; |
468 |
|
for ( ; i < argc; i++) { /* interpolate each component */ |
469 |
+ |
char pbuf[256]; |
470 |
|
FILE *fpin = fopen(argv[i], "rb"); |
471 |
|
if (fpin == NULL) { |
472 |
|
fprintf(stderr, "%s: cannot open BSDF interpolant '%s'\n", |
478 |
|
fclose(fpin); |
479 |
|
if (!nbsdf++) /* start XML on first dist. */ |
480 |
|
xml_prologue(argc, argv); |
481 |
+ |
sprintf(pbuf, "Interpolating component '%s'", argv[i]); |
482 |
+ |
prog_start(pbuf); |
483 |
|
if (single_plane_incident) |
484 |
|
eval_isotropic(NULL); |
485 |
|
else |
492 |
|
if (!load_bsdf_rep(stdin)) |
493 |
|
return(1); |
494 |
|
xml_prologue(argc, argv); /* start XML output */ |
495 |
+ |
prog_start("Interpolating from standard input"); |
496 |
|
if (single_plane_incident) /* resample dist. */ |
497 |
|
eval_isotropic(NULL); |
498 |
|
else |