ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/rttree_reduce.c
(Generate patch)

Comparing ray/src/util/rttree_reduce.c (file contents):
Revision 2.7 by greg, Sun Mar 25 15:23:55 2012 UTC vs.
Revision 2.13 by schorsch, Sun Mar 6 01:13:18 2016 UTC

# Line 44 | Line 44 | double tthresh;                /* acceptance threshold (TBD) */
44   static void
45   new_kids(TNODE *pn)
46   {
47 +        /* XXX VC warns about 32 bit shift coerced to 64 bit */
48          pn->kid = (TNODE *)calloc(1<<ttrank, sizeof(TNODE));
49          if (pn->kid == NULL)
50                  error(SYSTEM, "out of memory in new_kids");
# Line 110 | Line 111 | build_tree(TNODE *tp, const int bmin[], int l2s)
111  
112   /* Set our trimming threshold */
113   static void
114 < set_threshold()
114 > set_threshold(void)
115   {
116          int     hsum = 0;
117          int     i;
# Line 155 | Line 156 | print_tree(const TNODE *tp, const int bmin[], int l2s)
156                                  bkmin[j] = bmin[j] + (i>>(ttrank-1-j) & 1);
157                          val = (ttrank == 3) ? dval3(bkmin[0],bkmin[1],bkmin[2])
158                                  : dval4(bkmin[0],bkmin[1],bkmin[2],bkmin[3]);
159 <                        printf(" %.4e", val);
159 >                        printf((0.001<=val)&(val<10.) ? " %.7f" : " %.3e", val);
160                  }
161                  fputs(" }\n", stdout);
162                  return;
# Line 235 | Line 236 | read_double(float *rowp, int n)
236          return(nread);
237   }
238  
239 + /* Truncate any negative values to zero */
240 + static void
241 + noneg(float *varr, int n)
242 + {
243 +        int     nnan = 0;
244 +
245 +        while (n-- > 0) {
246 + #ifdef isnan
247 +                if (isnan(*varr)) {
248 +                        *varr = 0;
249 +                        ++nnan;
250 +                } else
251 + #endif
252 +                if (*varr < 0) *varr = 0;
253 +                ++varr;
254 +        }
255 +        if (nnan)
256 +                fprintf(stderr, "Warning: BSDF data contains %d NaN values\n",
257 +                                nnan);
258 + }
259 +
260   /* Load data array, filling zeroes for rank 3 demi-tensor */
261   static void
262 < load_data()
262 > load_data(void)
263   {
264          int     (*readf)(float *, int) = NULL;
265          
# Line 255 | Line 277 | load_data()
277                  error(COMMAND, "unsupported input format");
278                  break;
279          }
280 +        /* XXX VC warns about 32 bit shift coerced to 64 bit */
281          datarr = (float *)calloc(1<<(log2g*ttrank), sizeof(float));
282          if (datarr == NULL)
283                  error(SYSTEM, "out of memory in load_data");
# Line 289 | Line 312 | load_data()
312                  }
313          } else if (getc(stdin) != EOF)
314                  error(WARNING, "binary data past end of expected input");
315 +
316 +        noneg(datarr, 1<<(log2g*ttrank));       /* take precautions */
317   }
318  
319   /* Enforce reciprocity by averaging data values */
320   static void
321 < do_reciprocity()
321 > do_reciprocity(void)
322   {
323 <        float   *v1p, *v2p;
323 >        const int       siz = 1<<log2g;
324 >        float           *v1p, *v2p;
325  
326          if (ttrank == 3) {
327                  int     ix, ox, oy;
328 <                for (ix = 0; ix < 1<<(log2g-1); ix++)
329 <                    for (ox = 0; ox < 1<<log2g; ox++)
330 <                        for (oy = 0; oy < 1<<(log2g-1); oy++) {
328 >                for (ix = 0; ix < siz>>1; ix++)
329 >                    for (ox = 0; ox < siz; ox++)
330 >                        for (oy = 0; oy < siz>>1; oy++) {
331                                  v1p = &dval3(ix,ox,oy);
332 <                                v2p = &dval3(ix,ox,(1<<log2g)-1-oy);
332 >                                v2p = &dval3(ix,ox,siz-1-oy);
333                                  *v1p = *v2p = .5f*( *v1p + *v2p );
334                          }
335          } else /* ttrank == 4 */ {
336                  int     ix, iy, ox, oy;
337 <                for (ix = 1; ix < 1<<log2g; ix++)
338 <                    for (iy = 1; iy < 1<<log2g; iy++)
337 >                for (ix = 1; ix < siz; ix++)
338 >                    for (iy = 1; iy < siz; iy++)
339                          for (ox = 0; ox < ix; ox++)
340                              for (oy = 0; oy < iy; oy++) {
341 <                                v1p = &dval4(ix,iy,ox,oy);
342 <                                v2p = &dval4(ox,oy,ix,iy);
341 >                                v1p = &dval4(siz-1-ix,siz-1-iy,ox,oy);
342 >                                v2p = &dval4(siz-1-ox,siz-1-oy,ix,iy);
343                                  *v1p = *v2p = .5f*( *v1p + *v2p );
344                              }
345          }
# Line 363 | Line 389 | main(int argc, char *argv[])
389          if (i < argc-1)
390                  goto userr;
391                                          /* load input data */
392 <        if (i == argc-1 && freopen(argv[i], "rb", stdin) == NULL) {
392 >        if (i == argc-1 && freopen(argv[i], "r", stdin) == NULL) {
393                  sprintf(errmsg, "cannot open input file '%s'", argv[i]);
394                  error(SYSTEM, errmsg);
395          }
396          if (infmt != 'a')
397                  SET_FILE_BINARY(stdin);
398 + #ifdef getc_unlocked                    /* avoid lock/unlock overhead */
399 +        flockfile(stdin);
400 + #endif
401          load_data();
402          if (recipavg)
403                  do_reciprocity();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines