| 17 |
|
int ttrank = 4; /* tensor tree rank */ |
| 18 |
|
int log2g = 4; /* log2 of grid resolution */ |
| 19 |
|
int infmt = 'a'; /* input format ('a','f','d') */ |
| 20 |
< |
double pctcull = 99.; /* target culling percentile */ |
| 20 |
> |
double pctcull = 95.; /* target culling percentile */ |
| 21 |
|
|
| 22 |
|
#define dval3(ix,ox,oy) datarr[((((ix)<<log2g)+(ox))<<log2g)+(oy)] |
| 23 |
|
#define dval4(ix,iy,ox,oy) datarr[((((((ix)<<log2g)+(iy))<<log2g)+(ox))<<log2g)+(oy)] |
| 152 |
|
for (i = 0; i < 1<<ttrank; i++) { |
| 153 |
|
float val; |
| 154 |
|
for (j = ttrank; j--; ) |
| 155 |
< |
bkmin[j] = bmin[j] + (i>>j & 1); |
| 155 |
> |
bkmin[j] = bmin[j] + (i>>(ttrank-1-j) & 1); |
| 156 |
|
val = (ttrank == 3) ? dval3(bkmin[0],bkmin[1],bkmin[2]) |
| 157 |
|
: dval4(bkmin[0],bkmin[1],bkmin[2],bkmin[3]); |
| 158 |
|
printf(" %.4e", val); |
| 260 |
|
error(SYSTEM, "out of memory in load_data"); |
| 261 |
|
if (ttrank == 3) { |
| 262 |
|
int ix, ox; |
| 263 |
< |
for (ix = 0; ix < 1<<log2g; ix++) |
| 263 |
> |
for (ix = 0; ix < 1<<(log2g-1); ix++) |
| 264 |
|
for (ox = 0; ox < 1<<log2g; ox++) |
| 265 |
< |
(*readf)(datarr+((((ix)<<log2g)+(ox))<<log2g), |
| 266 |
< |
1<<(log2g-1)); |
| 265 |
> |
(*readf)(datarr+(((ix<<log2g)+ox)<<log2g), |
| 266 |
> |
1<<log2g); |
| 267 |
|
} else /* ttrank == 4 */ { |
| 268 |
|
int ix, iy, ox; |
| 269 |
|
for (ix = 0; ix < 1<<log2g; ix++) |
| 270 |
|
for (iy = 0; iy < 1<<log2g; iy++) |
| 271 |
|
for (ox = 0; ox < 1<<log2g; ox++) |
| 272 |
|
(*readf)(datarr + |
| 273 |
< |
((((((ix)<<log2g)+(iy))<<log2g)+(ox))<<log2g), |
| 273 |
> |
(((((ix<<log2g)+iy)<<log2g)+ox)<<log2g), |
| 274 |
|
1<<log2g); |
| 275 |
|
} |
| 276 |
|
(*readf)(NULL, 0); /* releases any buffers */ |
| 291 |
|
error(WARNING, "binary data past end of expected input"); |
| 292 |
|
} |
| 293 |
|
|
| 294 |
+ |
/* Enforce reciprocity by averaging data values */ |
| 295 |
+ |
static void |
| 296 |
+ |
do_reciprocity() |
| 297 |
+ |
{ |
| 298 |
+ |
const int siz = 1<<log2g; |
| 299 |
+ |
float *v1p, *v2p; |
| 300 |
+ |
|
| 301 |
+ |
if (ttrank == 3) { |
| 302 |
+ |
int ix, ox, oy; |
| 303 |
+ |
for (ix = 0; ix < siz>>1; ix++) |
| 304 |
+ |
for (ox = 0; ox < siz; ox++) |
| 305 |
+ |
for (oy = 0; oy < siz>>1; oy++) { |
| 306 |
+ |
v1p = &dval3(ix,ox,oy); |
| 307 |
+ |
v2p = &dval3(ix,ox,siz-1-oy); |
| 308 |
+ |
*v1p = *v2p = .5f*( *v1p + *v2p ); |
| 309 |
+ |
} |
| 310 |
+ |
} else /* ttrank == 4 */ { |
| 311 |
+ |
int ix, iy, ox, oy; |
| 312 |
+ |
for (ix = 1; ix < siz; ix++) |
| 313 |
+ |
for (iy = 1; iy < siz; iy++) |
| 314 |
+ |
for (ox = 0; ox < ix; ox++) |
| 315 |
+ |
for (oy = 0; oy < iy; oy++) { |
| 316 |
+ |
v1p = &dval4(siz-1-ix,siz-1-iy,ox,oy); |
| 317 |
+ |
v2p = &dval4(siz-1-ox,siz-1-oy,ix,iy); |
| 318 |
+ |
*v1p = *v2p = .5f*( *v1p + *v2p ); |
| 319 |
+ |
} |
| 320 |
+ |
} |
| 321 |
+ |
} |
| 322 |
+ |
|
| 323 |
|
/* Load BSDF array, coalesce uniform regions and format as tensor tree */ |
| 324 |
|
int |
| 325 |
|
main(int argc, char *argv[]) |
| 326 |
|
{ |
| 327 |
|
int doheader = 1; |
| 328 |
+ |
int recipavg = 0; |
| 329 |
|
int bmin[4]; |
| 330 |
|
TNODE gtree; |
| 331 |
|
int i; |
| 332 |
|
/* get options and parameters */ |
| 333 |
|
for (i = 1; i < argc && argv[i][0] == '-'; i++) |
| 334 |
|
switch (argv[i][1]) { |
| 335 |
+ |
case 'a': |
| 336 |
+ |
recipavg = !recipavg; |
| 337 |
+ |
break; |
| 338 |
|
case 'h': |
| 339 |
|
doheader = !doheader; |
| 340 |
|
break; |
| 364 |
|
if (i < argc-1) |
| 365 |
|
goto userr; |
| 366 |
|
/* load input data */ |
| 367 |
< |
if (i == argc-1 && freopen(argv[i], "rb", stdin) == NULL) { |
| 367 |
> |
if (i == argc-1 && freopen(argv[i], "r", stdin) == NULL) { |
| 368 |
|
sprintf(errmsg, "cannot open input file '%s'", argv[i]); |
| 369 |
|
error(SYSTEM, errmsg); |
| 370 |
|
} |
| 371 |
|
if (infmt != 'a') |
| 372 |
|
SET_FILE_BINARY(stdin); |
| 373 |
+ |
#ifdef getc_unlocked /* avoid lock/unlock overhead */ |
| 374 |
+ |
flockfile(stdin); |
| 375 |
+ |
#endif |
| 376 |
|
load_data(); |
| 377 |
+ |
if (recipavg) |
| 378 |
+ |
do_reciprocity(); |
| 379 |
|
if (doheader) { |
| 380 |
|
for (i = 0; i < argc; i++) { |
| 381 |
|
fputs(argv[i], stdout); |
| 397 |
|
*/ |
| 398 |
|
return(0); |
| 399 |
|
userr: |
| 400 |
< |
fprintf(stderr, "Usage: %s [-h][-f{a|f|d}][-r {3|4}][-g log2grid][-t trim%%] [input]\n", |
| 400 |
> |
fprintf(stderr, "Usage: %s [-h][-a][-f{a|f|d}][-r {3|4}][-g log2grid][-t trim%%] [input]\n", |
| 401 |
|
argv[0]); |
| 402 |
|
return(1); |
| 403 |
|
} |