11 |
|
#include <stdio.h> |
12 |
|
#include <stdlib.h> |
13 |
|
#include <math.h> |
14 |
+ |
#include "random.h" |
15 |
|
#include "platform.h" |
16 |
+ |
#include "rtprocess.h" |
17 |
|
#include "calcomp.h" |
18 |
|
#include "bsdfrep.h" |
19 |
|
/* global argv[0] */ |
28 |
|
const int nssamp = 100; |
29 |
|
/* limit on number of RBF lobes */ |
30 |
|
static int lobe_lim = 15000; |
31 |
+ |
/* progress bar length */ |
32 |
+ |
static int do_prog = 79; |
33 |
|
|
34 |
+ |
|
35 |
+ |
/* Start new progress bar */ |
36 |
+ |
#define prog_start(s) if (do_prog) fprintf(stderr, "%s: %s...\n", progname, s); else |
37 |
+ |
|
38 |
+ |
/* Draw progress bar of the appropriate length */ |
39 |
+ |
static void |
40 |
+ |
prog_show(double frac) |
41 |
+ |
{ |
42 |
+ |
char pbar[256]; |
43 |
+ |
int nchars; |
44 |
+ |
|
45 |
+ |
if (do_prog <= 0) return; |
46 |
+ |
if (do_prog > sizeof(pbar)-2) |
47 |
+ |
do_prog = sizeof(pbar)-2; |
48 |
+ |
if (frac < 0) frac = 0; |
49 |
+ |
else if (frac > 1) frac = 1; |
50 |
+ |
nchars = do_prog*frac + .5; |
51 |
+ |
pbar[0] = '\r'; |
52 |
+ |
memset(pbar+1, '*', nchars); |
53 |
+ |
memset(pbar+1+nchars, '-', do_prog-nchars); |
54 |
+ |
pbar[do_prog+1] = '\0'; |
55 |
+ |
fputs(pbar, stderr); |
56 |
+ |
} |
57 |
+ |
|
58 |
+ |
/* Finish progress bar */ |
59 |
+ |
static void |
60 |
+ |
prog_done(void) |
61 |
+ |
{ |
62 |
+ |
int n = do_prog; |
63 |
+ |
|
64 |
+ |
if (n <= 1) return; |
65 |
+ |
fputc('\r', stderr); |
66 |
+ |
while (n--) |
67 |
+ |
fputc(' ', stderr); |
68 |
+ |
fputc('\r', stderr); |
69 |
+ |
} |
70 |
+ |
|
71 |
|
/* Output XML prologue to stdout */ |
72 |
|
static void |
73 |
|
xml_prologue(int ac, char *av[]) |
85 |
|
puts("<Optical>"); |
86 |
|
puts("<Layer>"); |
87 |
|
puts("\t<Material>"); |
88 |
< |
puts("\t\t<Name>Name</Name>"); |
89 |
< |
puts("\t\t<Manufacturer>Manufacturer</Manufacturer>"); |
88 |
> |
printf("\t\t<Name>%s</Name>\n", bsdf_name[0] ? bsdf_name : "Unknown"); |
89 |
> |
printf("\t\t<Manufacturer>%s</Manufacturer>\n", |
90 |
> |
bsdf_manuf[0] ? bsdf_manuf : "Unknown"); |
91 |
|
puts("\t\t<DeviceType>Other</DeviceType>"); |
92 |
|
puts("\t</Material>"); |
93 |
|
puts("\t<DataDefinition>"); |
164 |
|
|
165 |
|
data_prologue(); /* begin output */ |
166 |
|
if (pctcull >= 0) { |
167 |
< |
sprintf(cmd, "rttree_reduce%s -h -ff -r 3 -t %f -g %d", |
126 |
< |
(input_orient>0 ^ output_orient>0) ? "" : " -a", |
167 |
> |
sprintf(cmd, "rttree_reduce -a -h -ff -r 3 -t %f -g %d", |
168 |
|
pctcull, samp_order); |
169 |
|
fflush(stdout); |
170 |
|
ofp = popen(cmd, "w"); |
174 |
|
exit(1); |
175 |
|
} |
176 |
|
SET_FILE_BINARY(ofp); |
177 |
+ |
#ifdef getc_unlocked /* avoid lock/unlock overhead */ |
178 |
+ |
flockfile(ofp); |
179 |
+ |
#endif |
180 |
|
} else |
181 |
|
fputs("{\n", stdout); |
182 |
|
/* need to assign Dx, Dy, Dz? */ |
212 |
|
if (abs_diff(bsdf, last_bsdf) > ssamp_thresh) { |
213 |
|
sum = 0; /* super-sample voxel */ |
214 |
|
for (ssi = nssamp; ssi--; ) { |
215 |
< |
SDmultiSamp(ssa, 3, (ssi+drand48())/nssamp); |
215 |
> |
SDmultiSamp(ssa, 3, (ssi+frandom())/nssamp); |
216 |
|
ssvec[0] = 2.*(ix+ssa[0])/sqres - 1.; |
217 |
|
ssvec[1] = .0; |
218 |
|
ssvec[2] = input_orient * |
242 |
|
} |
243 |
|
if (rbf != NULL) |
244 |
|
free(rbf); |
245 |
+ |
prog_show((ix+1.)*(2./sqres)); |
246 |
|
} |
247 |
|
if (pctcull >= 0) { /* finish output */ |
248 |
|
if (pclose(ofp)) { |
256 |
|
fputs("}\n", stdout); |
257 |
|
} |
258 |
|
data_epilogue(); |
259 |
+ |
prog_done(); |
260 |
|
} |
261 |
|
|
262 |
|
/* Interpolate and output anisotropic BSDF data */ |
283 |
|
progname); |
284 |
|
exit(1); |
285 |
|
} |
286 |
+ |
SET_FILE_BINARY(ofp); |
287 |
+ |
#ifdef getc_unlocked /* avoid lock/unlock overhead */ |
288 |
+ |
flockfile(ofp); |
289 |
+ |
#endif |
290 |
|
} else |
291 |
|
fputs("{\n", stdout); |
292 |
|
/* need to assign Dx, Dy, Dz? */ |
323 |
|
if (abs_diff(bsdf, last_bsdf) > ssamp_thresh) { |
324 |
|
sum = 0; /* super-sample voxel */ |
325 |
|
for (ssi = nssamp; ssi--; ) { |
326 |
< |
SDmultiSamp(ssa, 4, (ssi+drand48())/nssamp); |
326 |
> |
SDmultiSamp(ssa, 4, (ssi+frandom())/nssamp); |
327 |
|
SDsquare2disk(ssvec, 1.-(ix+ssa[0])/sqres, |
328 |
|
1.-(iy+ssa[1])/sqres); |
329 |
|
ssvec[2] = output_orient * |
354 |
|
} |
355 |
|
if (rbf != NULL) |
356 |
|
free(rbf); |
357 |
+ |
prog_show((ix*sqres+iy+1.)/(sqres*sqres)); |
358 |
|
} |
359 |
|
if (pctcull >= 0) { /* finish output */ |
360 |
|
if (pclose(ofp)) { |
365 |
|
} else |
366 |
|
fputs("}\n", stdout); |
367 |
|
data_epilogue(); |
368 |
+ |
prog_done(); |
369 |
|
} |
370 |
|
|
371 |
|
/* Read in BSDF and interpolate as tensor tree representation */ |
415 |
|
case 'l': |
416 |
|
lobe_lim = atoi(argv[++i]); |
417 |
|
break; |
418 |
+ |
case 'p': |
419 |
+ |
do_prog = atoi(argv[i]+2); |
420 |
+ |
break; |
421 |
|
default: |
422 |
|
goto userr; |
423 |
|
} |
428 |
|
fprintf(stderr, |
429 |
|
"%s: need single function with 6 arguments: bsdf(ix,iy,iz,ox,oy,oz)\n", |
430 |
|
progname); |
431 |
< |
fprintf(stderr, "\tor 3 arguments using Dx,Dy,Dz: bsdf(ix,iy,iz)\n", |
377 |
< |
progname); |
431 |
> |
fprintf(stderr, "\tor 3 arguments using Dx,Dy,Dz: bsdf(ix,iy,iz)\n"); |
432 |
|
goto userr; |
433 |
|
} |
434 |
|
++eclock; |
436 |
|
if (dofwd) { |
437 |
|
input_orient = -1; |
438 |
|
output_orient = -1; |
439 |
< |
(*evf)(argv[i]); /* outside reflectance */ |
439 |
> |
prog_start("Evaluating outside reflectance"); |
440 |
> |
(*evf)(argv[i]); |
441 |
|
output_orient = 1; |
442 |
< |
(*evf)(argv[i]); /* outside -> inside */ |
442 |
> |
prog_start("Evaluating outside->inside transmission"); |
443 |
> |
(*evf)(argv[i]); |
444 |
|
} |
445 |
|
if (dobwd) { |
446 |
|
input_orient = 1; |
447 |
|
output_orient = 1; |
448 |
< |
(*evf)(argv[i]); /* inside reflectance */ |
448 |
> |
prog_start("Evaluating inside reflectance"); |
449 |
> |
(*evf)(argv[i]); |
450 |
|
output_orient = -1; |
451 |
< |
(*evf)(argv[i]); /* inside -> outside */ |
451 |
> |
prog_start("Evaluating inside->outside transmission"); |
452 |
> |
(*evf)(argv[i]); |
453 |
|
} |
454 |
|
xml_epilogue(); /* finish XML output & exit */ |
455 |
|
return(0); |
457 |
|
if (i < argc) { /* open input files if given */ |
458 |
|
int nbsdf = 0; |
459 |
|
for ( ; i < argc; i++) { /* interpolate each component */ |
460 |
+ |
char pbuf[256]; |
461 |
|
FILE *fpin = fopen(argv[i], "rb"); |
462 |
|
if (fpin == NULL) { |
463 |
|
fprintf(stderr, "%s: cannot open BSDF interpolant '%s'\n", |
469 |
|
fclose(fpin); |
470 |
|
if (!nbsdf++) /* start XML on first dist. */ |
471 |
|
xml_prologue(argc, argv); |
472 |
+ |
sprintf(pbuf, "Interpolating component '%s'", argv[i]); |
473 |
+ |
prog_start(pbuf); |
474 |
|
if (single_plane_incident) |
475 |
|
eval_isotropic(NULL); |
476 |
|
else |
483 |
|
if (!load_bsdf_rep(stdin)) |
484 |
|
return(1); |
485 |
|
xml_prologue(argc, argv); /* start XML output */ |
486 |
+ |
prog_start("Interpolating from standard input"); |
487 |
|
if (single_plane_incident) /* resample dist. */ |
488 |
|
eval_isotropic(NULL); |
489 |
|
else |