--- ray/src/util/rttree_reduce.c 2011/05/31 20:50:26 2.2 +++ ray/src/util/rttree_reduce.c 2011/06/01 16:51:03 2.3 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: rttree_reduce.c,v 2.2 2011/05/31 20:50:26 greg Exp $"; +static const char RCSid[] = "$Id: rttree_reduce.c,v 2.3 2011/06/01 16:51:03 greg Exp $"; #endif /* * A utility called by genBSDF.pl to reduce tensor tree samples and output @@ -11,6 +11,7 @@ static const char RCSid[] = "$Id: rttree_reduce.c,v 2. #include "rterror.h" #include "platform.h" #include +#include float *datarr; /* our loaded BSDF data array */ int ttrank = 4; /* tensor tree rank */ @@ -18,18 +19,9 @@ int log2g = 4; /* log2 of grid resolution */ int infmt = 'a'; /* input format ('a','f','d') */ double pctcull = 99.; /* target culling percentile */ -#define HISTLEN 300 /* histogram resolution */ -#define HISTMAX 10. /* maximum recorded value in histogram */ - -int histo[HISTLEN]; /* histogram freq. of max-min BSDF */ - -double tthresh; /* acceptance threshold (TBD) */ - #define dval3(ix,ox,oy) datarr[((((ix)<vmax - (tp)->vmin > tthresh) - /* Tensor tree node */ typedef struct ttree_s { float vmin, vmax; /* value extrema */ @@ -37,6 +29,17 @@ typedef struct ttree_s { struct ttree_s *kid; /* 2^ttrank children */ } TNODE; +#define HISTLEN 300 /* histogram resolution */ +#define HISTMAX 10. /* maximum recorded measure in histogram */ + +int histo[HISTLEN]; /* histogram freq. of variance measure */ + +double tthresh; /* acceptance threshold (TBD) */ + +#define var_measure(tp) ( ((tp)->vmax - (tp)->vmin) / \ + (sqrt((tp)->vavg) + .03) ) +#define above_threshold(tp) (var_measure(tp) > tthresh) + /* Allocate a new set of children for the given node (no checks) */ static void new_kids(TNODE *pn) @@ -85,7 +88,7 @@ build_tree(TNODE *tp, const int bmin[], int l2s) } tp->vavg /= (float)(1<vmax - tp->vmin); + i = (HISTLEN/HISTMAX) * var_measure(tp); if (i >= HISTLEN) i = HISTLEN-1; ++histo[i]; return;