27 |
|
static int npsamps = 256; |
28 |
|
/* limit on number of RBF lobes */ |
29 |
|
static int lobe_lim = 15000; |
30 |
+ |
/* progress bar length */ |
31 |
+ |
static int do_prog = 79; |
32 |
|
|
33 |
+ |
|
34 |
+ |
/* Start new progress bar */ |
35 |
+ |
#define prog_start(s) if (do_prog) fprintf(stderr, "%s: %s...\n", progname, s); else |
36 |
+ |
|
37 |
+ |
/* Draw progress bar of the appropriate length */ |
38 |
+ |
static void |
39 |
+ |
prog_show(double frac) |
40 |
+ |
{ |
41 |
+ |
static unsigned call_cnt = 0; |
42 |
+ |
static char lastc[] = "-\\|/"; |
43 |
+ |
char pbar[256]; |
44 |
+ |
int nchars; |
45 |
+ |
|
46 |
+ |
if (do_prog <= 1) return; |
47 |
+ |
if (do_prog > sizeof(pbar)-2) |
48 |
+ |
do_prog = sizeof(pbar)-2; |
49 |
+ |
if (frac < 0) frac = 0; |
50 |
+ |
else if (frac >= 1) frac = .9999; |
51 |
+ |
nchars = do_prog*frac; |
52 |
+ |
pbar[0] = '\r'; |
53 |
+ |
memset(pbar+1, '*', nchars); |
54 |
+ |
pbar[nchars+1] = lastc[call_cnt++ & 3]; |
55 |
+ |
memset(pbar+2+nchars, '-', do_prog-nchars-1); |
56 |
+ |
pbar[do_prog+1] = '\0'; |
57 |
+ |
fputs(pbar, stderr); |
58 |
+ |
} |
59 |
+ |
|
60 |
+ |
/* Finish progress bar */ |
61 |
+ |
static void |
62 |
+ |
prog_done(void) |
63 |
+ |
{ |
64 |
+ |
int n = do_prog; |
65 |
+ |
|
66 |
+ |
if (n <= 1) return; |
67 |
+ |
fputc('\r', stderr); |
68 |
+ |
while (n--) |
69 |
+ |
fputc(' ', stderr); |
70 |
+ |
fputc('\r', stderr); |
71 |
+ |
} |
72 |
+ |
|
73 |
|
/* Return angle basis corresponding to the given name */ |
74 |
< |
ANGLE_BASIS * |
74 |
> |
static ANGLE_BASIS * |
75 |
|
get_basis(const char *bn) |
76 |
|
{ |
77 |
|
int n = nabases; |
339 |
|
printf("\t%.3e\n", sum/npsamps); |
340 |
|
} |
341 |
|
putchar('\n'); |
342 |
+ |
prog_show((j+1.)/abp->nangles); |
343 |
|
} |
344 |
|
data_epilogue(); /* finish output */ |
345 |
+ |
prog_done(); |
346 |
|
} |
347 |
|
|
348 |
|
/* Interpolate and output a radial basis function BSDF representation */ |
377 |
|
else |
378 |
|
bo_getvec(vout, j+(n+frandom())/npsamps, abp); |
379 |
|
|
380 |
< |
sum += eval_rbfrep(rbf, vout) / vout[2]; |
380 |
> |
sum += eval_rbfrep(rbf, vout); |
381 |
|
} |
382 |
< |
bsdfarr[j*abp->nangles + i] = sum*output_orient/npsamps; |
382 |
> |
bsdfarr[j*abp->nangles + i] = sum / (double)npsamps; |
383 |
|
} |
384 |
|
if (rbf != NULL) |
385 |
|
free(rbf); |
386 |
+ |
prog_show((i+1.)/abp->nangles); |
387 |
|
} |
388 |
|
n = 0; /* write out our matrix */ |
389 |
|
for (j = 0; j < abp->nangles; j++) { |
392 |
|
putchar('\n'); |
393 |
|
} |
394 |
|
data_epilogue(); /* finish output */ |
395 |
+ |
prog_done(); |
396 |
|
} |
397 |
|
|
398 |
|
/* Read in BSDF and interpolate as Klems matrix representation */ |
438 |
|
case 'l': |
439 |
|
lobe_lim = atoi(argv[++i]); |
440 |
|
break; |
441 |
+ |
case 'p': |
442 |
+ |
do_prog = atoi(argv[i]+2); |
443 |
+ |
break; |
444 |
|
default: |
445 |
|
goto userr; |
446 |
|
} |
449 |
|
fprintf(stderr, |
450 |
|
"%s: need single function with 6 arguments: bsdf(ix,iy,iz,ox,oy,oz)\n", |
451 |
|
progname); |
452 |
< |
fprintf(stderr, "\tor 3 arguments using Dx,Dy,Dz: bsdf(ix,iy,iz)\n", |
404 |
< |
progname); |
452 |
> |
fprintf(stderr, "\tor 3 arguments using Dx,Dy,Dz: bsdf(ix,iy,iz)\n"); |
453 |
|
goto userr; |
454 |
|
} |
455 |
|
++eclock; |
458 |
|
if (dofwd) { |
459 |
|
input_orient = -1; |
460 |
|
output_orient = -1; |
461 |
< |
eval_function(argv[i]); /* outside reflectance */ |
461 |
> |
prog_start("Evaluating outside reflectance"); |
462 |
> |
eval_function(argv[i]); |
463 |
|
output_orient = 1; |
464 |
< |
eval_function(argv[i]); /* outside -> inside */ |
464 |
> |
prog_start("Evaluating outside->inside transmission"); |
465 |
> |
eval_function(argv[i]); |
466 |
|
} |
467 |
|
if (dobwd) { |
468 |
|
input_orient = 1; |
469 |
|
output_orient = 1; |
470 |
< |
eval_function(argv[i]); /* inside reflectance */ |
470 |
> |
prog_start("Evaluating inside reflectance"); |
471 |
> |
eval_function(argv[i]); |
472 |
|
output_orient = -1; |
473 |
< |
eval_function(argv[i]); /* inside -> outside */ |
473 |
> |
prog_start("Evaluating inside->outside transmission"); |
474 |
> |
eval_function(argv[i]); |
475 |
|
} |
476 |
|
xml_epilogue(); /* finish XML output & exit */ |
477 |
|
return(0); |
487 |
|
if (i < argc) { /* open input files if given */ |
488 |
|
int nbsdf = 0; |
489 |
|
for ( ; i < argc; i++) { /* interpolate each component */ |
490 |
+ |
char pbuf[256]; |
491 |
|
FILE *fpin = fopen(argv[i], "rb"); |
492 |
|
if (fpin == NULL) { |
493 |
|
fprintf(stderr, "%s: cannot open BSDF interpolant '%s'\n", |
501 |
|
xml_header(argc, argv); |
502 |
|
xml_prologue(NULL); |
503 |
|
} |
504 |
+ |
sprintf(pbuf, "Interpolating component '%s'", argv[i]); |
505 |
+ |
prog_start(pbuf); |
506 |
|
eval_rbf(); |
507 |
|
} |
508 |
|
xml_epilogue(); /* finish XML output & exit */ |
513 |
|
return(1); |
514 |
|
xml_header(argc, argv); /* start XML output */ |
515 |
|
xml_prologue(NULL); |
516 |
+ |
prog_start("Interpolating from standard input"); |
517 |
|
eval_rbf(); /* resample dist. */ |
518 |
|
xml_epilogue(); /* finish XML output & exit */ |
519 |
|
return(0); |