--- ray/src/util/rttree_reduce.c 2015/08/12 00:10:51 2.12 +++ ray/src/util/rttree_reduce.c 2020/05/11 20:26:12 2.19 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: rttree_reduce.c,v 2.12 2015/08/12 00:10:51 greg Exp $"; +static const char RCSid[] = "$Id: rttree_reduce.c,v 2.19 2020/05/11 20:26:12 greg Exp $"; #endif /* * A utility called by genBSDF.pl to reduce tensor tree samples and output @@ -19,8 +19,8 @@ int log2g = 4; /* log2 of grid resolution */ int infmt = 'a'; /* input format ('a','f','d') */ double pctcull = 95.; /* target culling percentile */ -#define dval3(ix,ox,oy) datarr[((((ix)<vmax - (tp)->vmin) / \ +#define var_measure(tp) sqrt( ((tp)->vmax - (tp)->vmin) / \ (sqrt((tp)->vavg) + .03) ) #define above_threshold(tp) (var_measure(tp) > tthresh) @@ -44,7 +44,7 @@ double tthresh; /* acceptance threshold (TBD) */ static void new_kids(TNODE *pn) { - pn->kid = (TNODE *)calloc(1<kid = (TNODE *)calloc((size_t)1<kid == NULL) error(SYSTEM, "out of memory in new_kids"); } @@ -201,7 +201,7 @@ read_float(float *rowp, int n) if ((rowp == NULL) | (n <= 0)) return(0); - nread = fread(rowp, sizeof(float), n, stdin); + nread = getbinary(rowp, sizeof(float), n, stdin); if (nread != n) error(USER, "unexpected EOF on float input"); return(nread); @@ -223,11 +223,12 @@ read_double(float *rowp, int n) return(0); } if (rblen < n) { - rowbuf = (double *)realloc(rowbuf, sizeof(double)*(rblen=n)); + if (rblen) free(rowbuf); + rowbuf = (double *)malloc(sizeof(double)*(rblen=n)); if (rowbuf == NULL) error(SYSTEM, "out of memory in read_double"); } - nread = fread(rowbuf, sizeof(double), n, stdin); + nread = getbinary(rowbuf, sizeof(double), n, stdin); if (nread != n) error(USER, "unexpected EOF on double input"); for (i = 0; i < nread; i++) @@ -276,23 +277,20 @@ load_data(void) error(COMMAND, "unsupported input format"); break; } - datarr = (float *)calloc(1<<(log2g*ttrank), sizeof(float)); + datarr = (float *)calloc((size_t)1<<(log2g*ttrank), sizeof(float)); if (datarr == NULL) error(SYSTEM, "out of memory in load_data"); if (ttrank == 3) { int ix, ox; for (ix = 0; ix < 1<<(log2g-1); ix++) for (ox = 0; ox < 1< 0; ox++) + for (oy = 0; oy < siz; oy++) { v1p = &dval4(siz-1-ix,siz-1-iy,ox,oy); v2p = &dval4(siz-1-ox,siz-1-oy,ix,iy); *v1p = *v2p = .5f*( *v1p + *v2p ); + if (--cnt <= 0) + break; } + } } }