--- ray/src/util/rttree_reduce.c 2012/03/25 15:23:55 2.7 +++ ray/src/util/rttree_reduce.c 2016/03/06 01:13:18 2.13 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: rttree_reduce.c,v 2.7 2012/03/25 15:23:55 greg Exp $"; +static const char RCSid[] = "$Id: rttree_reduce.c,v 2.13 2016/03/06 01:13:18 schorsch Exp $"; #endif /* * A utility called by genBSDF.pl to reduce tensor tree samples and output @@ -44,6 +44,7 @@ double tthresh; /* acceptance threshold (TBD) */ static void new_kids(TNODE *pn) { + /* XXX VC warns about 32 bit shift coerced to 64 bit */ pn->kid = (TNODE *)calloc(1<kid == NULL) error(SYSTEM, "out of memory in new_kids"); @@ -110,7 +111,7 @@ build_tree(TNODE *tp, const int bmin[], int l2s) /* Set our trimming threshold */ static void -set_threshold() +set_threshold(void) { int hsum = 0; int i; @@ -155,7 +156,7 @@ print_tree(const TNODE *tp, const int bmin[], int l2s) bkmin[j] = bmin[j] + (i>>(ttrank-1-j) & 1); val = (ttrank == 3) ? dval3(bkmin[0],bkmin[1],bkmin[2]) : dval4(bkmin[0],bkmin[1],bkmin[2],bkmin[3]); - printf(" %.4e", val); + printf((0.001<=val)&(val<10.) ? " %.7f" : " %.3e", val); } fputs(" }\n", stdout); return; @@ -235,9 +236,30 @@ read_double(float *rowp, int n) return(nread); } +/* Truncate any negative values to zero */ +static void +noneg(float *varr, int n) +{ + int nnan = 0; + + while (n-- > 0) { +#ifdef isnan + if (isnan(*varr)) { + *varr = 0; + ++nnan; + } else +#endif + if (*varr < 0) *varr = 0; + ++varr; + } + if (nnan) + fprintf(stderr, "Warning: BSDF data contains %d NaN values\n", + nnan); +} + /* Load data array, filling zeroes for rank 3 demi-tensor */ static void -load_data() +load_data(void) { int (*readf)(float *, int) = NULL; @@ -255,6 +277,7 @@ load_data() error(COMMAND, "unsupported input format"); break; } + /* XXX VC warns about 32 bit shift coerced to 64 bit */ datarr = (float *)calloc(1<<(log2g*ttrank), sizeof(float)); if (datarr == NULL) error(SYSTEM, "out of memory in load_data"); @@ -289,31 +312,34 @@ load_data() } } else if (getc(stdin) != EOF) error(WARNING, "binary data past end of expected input"); + + noneg(datarr, 1<<(log2g*ttrank)); /* take precautions */ } /* Enforce reciprocity by averaging data values */ static void -do_reciprocity() +do_reciprocity(void) { - float *v1p, *v2p; + const int siz = 1<>1; ix++) + for (ox = 0; ox < siz; ox++) + for (oy = 0; oy < siz>>1; oy++) { v1p = &dval3(ix,ox,oy); - v2p = &dval3(ix,ox,(1<