| 19 |
|
/* global argv[0] */ |
| 20 |
|
char *progname; |
| 21 |
|
/* percentage to cull (<0 to turn off) */ |
| 22 |
< |
double pctcull = 90.; |
| 22 |
> |
static double pctcull = 90.; |
| 23 |
|
/* sampling order */ |
| 24 |
< |
int samp_order = 6; |
| 24 |
> |
static int samp_order = 6; |
| 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 |
|
|
| 32 |
– |
/* Output XML prologue to stdout */ |
| 33 |
– |
static void |
| 34 |
– |
xml_prologue(int ac, char *av[]) |
| 35 |
– |
{ |
| 36 |
– |
puts("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); |
| 37 |
– |
puts("<WindowElement xmlns=\"http://windows.lbl.gov\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://windows.lbl.gov/BSDF-v1.4.xsd\">"); |
| 38 |
– |
fputs("<!-- File produced by:", stdout); |
| 39 |
– |
while (ac-- > 0) { |
| 40 |
– |
fputc(' ', stdout); |
| 41 |
– |
fputs(*av++, stdout); |
| 42 |
– |
} |
| 43 |
– |
puts(" -->"); |
| 44 |
– |
puts("<WindowElementType>System</WindowElementType>"); |
| 45 |
– |
puts("<FileType>BSDF</FileType>"); |
| 46 |
– |
puts("<Optical>"); |
| 47 |
– |
puts("<Layer>"); |
| 48 |
– |
puts("\t<Material>"); |
| 49 |
– |
printf("\t\t<Name>%s</Name>\n", bsdf_name[0] ? bsdf_name : "Unknown"); |
| 50 |
– |
printf("\t\t<Manufacturer>%s</Manufacturer>\n", |
| 51 |
– |
bsdf_manuf[0] ? bsdf_manuf : "Unknown"); |
| 52 |
– |
puts("\t\t<DeviceType>Other</DeviceType>"); |
| 53 |
– |
puts("\t</Material>"); |
| 54 |
– |
puts("\t<DataDefinition>"); |
| 55 |
– |
printf("\t\t<IncidentDataStructure>TensorTree%c</IncidentDataStructure>\n", |
| 56 |
– |
single_plane_incident ? '3' : '4'); |
| 57 |
– |
puts("\t</DataDefinition>"); |
| 58 |
– |
} |
| 36 |
|
|
| 60 |
– |
/* Output XML data prologue to stdout */ |
| 61 |
– |
static void |
| 62 |
– |
data_prologue() |
| 63 |
– |
{ |
| 64 |
– |
static const char *bsdf_type[4] = { |
| 65 |
– |
"Reflection Front", |
| 66 |
– |
"Transmission Front", |
| 67 |
– |
"Transmission Back", |
| 68 |
– |
"Reflection Back" |
| 69 |
– |
}; |
| 37 |
|
|
| 38 |
< |
puts("\t<WavelengthData>"); |
| 39 |
< |
puts("\t\t<LayerNumber>System</LayerNumber>"); |
| 73 |
< |
puts("\t\t<Wavelength unit=\"Integral\">Visible</Wavelength>"); |
| 74 |
< |
puts("\t\t<SourceSpectrum>CIE Illuminant D65 1nm.ssp</SourceSpectrum>"); |
| 75 |
< |
puts("\t\t<DetectorSpectrum>ASTM E308 1931 Y.dsp</DetectorSpectrum>"); |
| 76 |
< |
puts("\t\t<WavelengthDataBlock>"); |
| 77 |
< |
printf("\t\t\t<WavelengthDataDirection>%s</WavelengthDataDirection>\n", |
| 78 |
< |
bsdf_type[(input_orient>0)<<1 | (output_orient>0)]); |
| 79 |
< |
puts("\t\t\t<AngleBasis>LBNL/Shirley-Chiu</AngleBasis>"); |
| 80 |
< |
puts("\t\t\t<ScatteringDataType>BTDF</ScatteringDataType>"); |
| 81 |
< |
puts("\t\t\t<ScatteringData>"); |
| 82 |
< |
} |
| 38 |
> |
/* Start new progress bar */ |
| 39 |
> |
#define prog_start(s) if (do_prog) fprintf(stderr, "%s: %s...\n", progname, s); else |
| 40 |
|
|
| 41 |
< |
/* Output XML data epilogue to stdout */ |
| 41 |
> |
/* Draw progress bar of the appropriate length */ |
| 42 |
|
static void |
| 43 |
< |
data_epilogue(void) |
| 43 |
> |
prog_show(double frac) |
| 44 |
|
{ |
| 45 |
< |
puts("\t\t\t</ScatteringData>"); |
| 46 |
< |
puts("\t\t</WavelengthDataBlock>"); |
| 47 |
< |
puts("\t</WavelengthData>"); |
| 45 |
> |
static unsigned call_cnt = 0; |
| 46 |
> |
static char lastc[] = "-\\|/"; |
| 47 |
> |
char pbar[256]; |
| 48 |
> |
int nchars; |
| 49 |
> |
|
| 50 |
> |
if (do_prog <= 1) return; |
| 51 |
> |
if (do_prog > sizeof(pbar)-2) |
| 52 |
> |
do_prog = sizeof(pbar)-2; |
| 53 |
> |
if (frac < 0) frac = 0; |
| 54 |
> |
else if (frac >= 1) frac = .9999; |
| 55 |
> |
nchars = do_prog*frac; |
| 56 |
> |
pbar[0] = '\r'; |
| 57 |
> |
memset(pbar+1, '*', nchars); |
| 58 |
> |
pbar[nchars+1] = lastc[call_cnt++ & 3]; |
| 59 |
> |
memset(pbar+2+nchars, '-', do_prog-nchars-1); |
| 60 |
> |
pbar[do_prog+1] = '\0'; |
| 61 |
> |
fputs(pbar, stderr); |
| 62 |
|
} |
| 63 |
|
|
| 64 |
< |
/* Output XML epilogue to stdout */ |
| 64 |
> |
/* Finish progress bar */ |
| 65 |
|
static void |
| 66 |
< |
xml_epilogue(void) |
| 66 |
> |
prog_done(void) |
| 67 |
|
{ |
| 68 |
< |
puts("</Layer>"); |
| 69 |
< |
puts("</Optical>"); |
| 70 |
< |
puts("</WindowElement>"); |
| 68 |
> |
int n = do_prog; |
| 69 |
> |
|
| 70 |
> |
if (n <= 1) return; |
| 71 |
> |
fputc('\r', stderr); |
| 72 |
> |
while (n--) |
| 73 |
> |
fputc(' ', stderr); |
| 74 |
> |
fputc('\r', stderr); |
| 75 |
|
} |
| 76 |
|
|
| 77 |
|
/* Compute absolute relative difference */ |
| 110 |
|
exit(1); |
| 111 |
|
} |
| 112 |
|
SET_FILE_BINARY(ofp); |
| 113 |
+ |
#ifdef getc_unlocked /* avoid lock/unlock overhead */ |
| 114 |
+ |
flockfile(ofp); |
| 115 |
+ |
#endif |
| 116 |
|
} else |
| 117 |
|
fputs("{\n", stdout); |
| 118 |
|
/* need to assign Dx, Dy, Dz? */ |
| 133 |
|
iovec[5] = output_orient * |
| 134 |
|
sqrt(1. - iovec[3]*iovec[3] - iovec[4]*iovec[4]); |
| 135 |
|
if (funame == NULL) |
| 136 |
< |
bsdf = eval_rbfrep(rbf, iovec+3) * |
| 159 |
< |
output_orient/iovec[5]; |
| 136 |
> |
bsdf = eval_rbfrep(rbf, iovec+3); |
| 137 |
|
else { |
| 161 |
– |
double ssa[3], ssvec[6], sum; |
| 162 |
– |
int ssi; |
| 138 |
|
if (assignD) { |
| 139 |
|
varset("Dx", '=', -iovec[3]); |
| 140 |
|
varset("Dy", '=', -iovec[4]); |
| 142 |
|
++eclock; |
| 143 |
|
} |
| 144 |
|
bsdf = funvalue(funame, 6, iovec); |
| 145 |
+ |
#if (NSSAMP > 0) |
| 146 |
|
if (abs_diff(bsdf, last_bsdf) > ssamp_thresh) { |
| 147 |
< |
sum = 0; /* super-sample voxel */ |
| 148 |
< |
for (ssi = nssamp; ssi--; ) { |
| 149 |
< |
SDmultiSamp(ssa, 3, (ssi+frandom())/nssamp); |
| 147 |
> |
int ssi; |
| 148 |
> |
double ssa[3], ssvec[6], sum = 0; |
| 149 |
> |
/* super-sample voxel */ |
| 150 |
> |
for (ssi = NSSAMP; ssi--; ) { |
| 151 |
> |
SDmultiSamp(ssa, 3, (ssi+frandom()) * |
| 152 |
> |
(1./NSSAMP)); |
| 153 |
|
ssvec[0] = 2.*(ix+ssa[0])/sqres - 1.; |
| 154 |
|
ssvec[1] = .0; |
| 155 |
|
ssvec[2] = input_orient * |
| 160 |
|
sqrt(1. - ssvec[3]*ssvec[3] - |
| 161 |
|
ssvec[4]*ssvec[4]); |
| 162 |
|
if (assignD) { |
| 163 |
< |
varset("Dx", '=', -iovec[3]); |
| 164 |
< |
varset("Dy", '=', -iovec[4]); |
| 165 |
< |
varset("Dz", '=', -iovec[5]); |
| 163 |
> |
varset("Dx", '=', -ssvec[3]); |
| 164 |
> |
varset("Dy", '=', -ssvec[4]); |
| 165 |
> |
varset("Dz", '=', -ssvec[5]); |
| 166 |
|
++eclock; |
| 167 |
|
} |
| 168 |
|
sum += funvalue(funame, 6, ssvec); |
| 169 |
|
} |
| 170 |
< |
bsdf = sum/nssamp; |
| 170 |
> |
bsdf = sum/NSSAMP; |
| 171 |
|
} |
| 172 |
+ |
#endif |
| 173 |
|
} |
| 174 |
|
if (pctcull >= 0) |
| 175 |
|
fwrite(&bsdf, sizeof(bsdf), 1, ofp); |
| 180 |
|
} |
| 181 |
|
if (rbf != NULL) |
| 182 |
|
free(rbf); |
| 183 |
+ |
prog_show((ix+1.)*(2./sqres)); |
| 184 |
|
} |
| 185 |
|
if (pctcull >= 0) { /* finish output */ |
| 186 |
|
if (pclose(ofp)) { |
| 194 |
|
fputs("}\n", stdout); |
| 195 |
|
} |
| 196 |
|
data_epilogue(); |
| 197 |
+ |
prog_done(); |
| 198 |
|
} |
| 199 |
|
|
| 200 |
|
/* Interpolate and output anisotropic BSDF data */ |
| 221 |
|
progname); |
| 222 |
|
exit(1); |
| 223 |
|
} |
| 224 |
+ |
SET_FILE_BINARY(ofp); |
| 225 |
+ |
#ifdef getc_unlocked /* avoid lock/unlock overhead */ |
| 226 |
+ |
flockfile(ofp); |
| 227 |
+ |
#endif |
| 228 |
|
} else |
| 229 |
|
fputs("{\n", stdout); |
| 230 |
|
/* need to assign Dx, Dy, Dz? */ |
| 246 |
|
iovec[5] = output_orient * |
| 247 |
|
sqrt(1. - iovec[3]*iovec[3] - iovec[4]*iovec[4]); |
| 248 |
|
if (funame == NULL) |
| 249 |
< |
bsdf = eval_rbfrep(rbf, iovec+3) * |
| 264 |
< |
output_orient/iovec[5]; |
| 249 |
> |
bsdf = eval_rbfrep(rbf, iovec+3); |
| 250 |
|
else { |
| 266 |
– |
double ssa[4], ssvec[6], sum; |
| 267 |
– |
int ssi; |
| 251 |
|
if (assignD) { |
| 252 |
|
varset("Dx", '=', -iovec[3]); |
| 253 |
|
varset("Dy", '=', -iovec[4]); |
| 255 |
|
++eclock; |
| 256 |
|
} |
| 257 |
|
bsdf = funvalue(funame, 6, iovec); |
| 258 |
+ |
#if (NSSAMP > 0) |
| 259 |
|
if (abs_diff(bsdf, last_bsdf) > ssamp_thresh) { |
| 260 |
< |
sum = 0; /* super-sample voxel */ |
| 261 |
< |
for (ssi = nssamp; ssi--; ) { |
| 262 |
< |
SDmultiSamp(ssa, 4, (ssi+frandom())/nssamp); |
| 260 |
> |
int ssi; |
| 261 |
> |
double ssa[4], ssvec[6], sum = 0; |
| 262 |
> |
/* super-sample voxel */ |
| 263 |
> |
for (ssi = NSSAMP; ssi--; ) { |
| 264 |
> |
SDmultiSamp(ssa, 4, (ssi+frandom()) * |
| 265 |
> |
(1./NSSAMP)); |
| 266 |
|
SDsquare2disk(ssvec, 1.-(ix+ssa[0])/sqres, |
| 267 |
|
1.-(iy+ssa[1])/sqres); |
| 268 |
< |
ssvec[2] = output_orient * |
| 268 |
> |
ssvec[2] = input_orient * |
| 269 |
|
sqrt(1. - ssvec[0]*ssvec[0] - |
| 270 |
|
ssvec[1]*ssvec[1]); |
| 271 |
|
SDsquare2disk(ssvec+3, (ox+ssa[2])/sqres, |
| 274 |
|
sqrt(1. - ssvec[3]*ssvec[3] - |
| 275 |
|
ssvec[4]*ssvec[4]); |
| 276 |
|
if (assignD) { |
| 277 |
< |
varset("Dx", '=', -iovec[3]); |
| 278 |
< |
varset("Dy", '=', -iovec[4]); |
| 279 |
< |
varset("Dz", '=', -iovec[5]); |
| 277 |
> |
varset("Dx", '=', -ssvec[3]); |
| 278 |
> |
varset("Dy", '=', -ssvec[4]); |
| 279 |
> |
varset("Dz", '=', -ssvec[5]); |
| 280 |
|
++eclock; |
| 281 |
|
} |
| 282 |
|
sum += funvalue(funame, 6, ssvec); |
| 283 |
|
} |
| 284 |
< |
bsdf = sum/nssamp; |
| 284 |
> |
bsdf = sum/NSSAMP; |
| 285 |
|
} |
| 286 |
+ |
#endif |
| 287 |
|
} |
| 288 |
|
if (pctcull >= 0) |
| 289 |
|
fwrite(&bsdf, sizeof(bsdf), 1, ofp); |
| 294 |
|
} |
| 295 |
|
if (rbf != NULL) |
| 296 |
|
free(rbf); |
| 297 |
+ |
prog_show((ix*sqres+iy+1.)/(sqres*sqres)); |
| 298 |
|
} |
| 299 |
|
if (pctcull >= 0) { /* finish output */ |
| 300 |
|
if (pclose(ofp)) { |
| 305 |
|
} else |
| 306 |
|
fputs("}\n", stdout); |
| 307 |
|
data_epilogue(); |
| 308 |
+ |
prog_done(); |
| 309 |
|
} |
| 310 |
|
|
| 311 |
|
/* Read in BSDF and interpolate as tensor tree representation */ |
| 355 |
|
case 'l': |
| 356 |
|
lobe_lim = atoi(argv[++i]); |
| 357 |
|
break; |
| 358 |
+ |
case 'p': |
| 359 |
+ |
do_prog = atoi(argv[i]+2); |
| 360 |
+ |
break; |
| 361 |
|
default: |
| 362 |
|
goto userr; |
| 363 |
|
} |
| 368 |
|
fprintf(stderr, |
| 369 |
|
"%s: need single function with 6 arguments: bsdf(ix,iy,iz,ox,oy,oz)\n", |
| 370 |
|
progname); |
| 371 |
< |
fprintf(stderr, "\tor 3 arguments using Dx,Dy,Dz: bsdf(ix,iy,iz)\n", |
| 379 |
< |
progname); |
| 371 |
> |
fprintf(stderr, "\tor 3 arguments using Dx,Dy,Dz: bsdf(ix,iy,iz)\n"); |
| 372 |
|
goto userr; |
| 373 |
|
} |
| 374 |
|
++eclock; |
| 376 |
|
if (dofwd) { |
| 377 |
|
input_orient = -1; |
| 378 |
|
output_orient = -1; |
| 379 |
< |
(*evf)(argv[i]); /* outside reflectance */ |
| 379 |
> |
prog_start("Evaluating outside reflectance"); |
| 380 |
> |
(*evf)(argv[i]); |
| 381 |
|
output_orient = 1; |
| 382 |
< |
(*evf)(argv[i]); /* outside -> inside */ |
| 382 |
> |
prog_start("Evaluating outside->inside transmission"); |
| 383 |
> |
(*evf)(argv[i]); |
| 384 |
|
} |
| 385 |
|
if (dobwd) { |
| 386 |
|
input_orient = 1; |
| 387 |
|
output_orient = 1; |
| 388 |
< |
(*evf)(argv[i]); /* inside reflectance */ |
| 388 |
> |
prog_start("Evaluating inside reflectance"); |
| 389 |
> |
(*evf)(argv[i]); |
| 390 |
|
output_orient = -1; |
| 391 |
< |
(*evf)(argv[i]); /* inside -> outside */ |
| 391 |
> |
prog_start("Evaluating inside->outside transmission"); |
| 392 |
> |
(*evf)(argv[i]); |
| 393 |
|
} |
| 394 |
|
xml_epilogue(); /* finish XML output & exit */ |
| 395 |
|
return(0); |
| 397 |
|
if (i < argc) { /* open input files if given */ |
| 398 |
|
int nbsdf = 0; |
| 399 |
|
for ( ; i < argc; i++) { /* interpolate each component */ |
| 400 |
+ |
char pbuf[256]; |
| 401 |
|
FILE *fpin = fopen(argv[i], "rb"); |
| 402 |
|
if (fpin == NULL) { |
| 403 |
|
fprintf(stderr, "%s: cannot open BSDF interpolant '%s'\n", |
| 409 |
|
fclose(fpin); |
| 410 |
|
if (!nbsdf++) /* start XML on first dist. */ |
| 411 |
|
xml_prologue(argc, argv); |
| 412 |
+ |
sprintf(pbuf, "Interpolating component '%s'", argv[i]); |
| 413 |
+ |
prog_start(pbuf); |
| 414 |
|
if (single_plane_incident) |
| 415 |
|
eval_isotropic(NULL); |
| 416 |
|
else |
| 423 |
|
if (!load_bsdf_rep(stdin)) |
| 424 |
|
return(1); |
| 425 |
|
xml_prologue(argc, argv); /* start XML output */ |
| 426 |
+ |
prog_start("Interpolating from standard input"); |
| 427 |
|
if (single_plane_incident) /* resample dist. */ |
| 428 |
|
eval_isotropic(NULL); |
| 429 |
|
else |