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

Comparing ray/src/common/bsdf_t.c (file contents):
Revision 3.10 by greg, Thu Apr 28 04:05:11 2011 UTC vs.
Revision 3.13 by greg, Wed Jun 1 00:29:40 2011 UTC

# Line 61 | Line 61 | SDnewNode(int nd, int lg)
61          if (lg < 0) {
62                  st = (SDNode *)malloc(sizeof(SDNode) +
63                                  sizeof(st->u.t[0])*((1<<nd) - 1));
64 <                if (st != NULL)
65 <                        memset(st->u.t, 0, sizeof(st->u.t[0])<<nd);
66 <        } else
67 <                st = (SDNode *)malloc(sizeof(SDNode) +
68 <                                sizeof(st->u.v[0])*((1 << nd*lg) - 1));
69 <                
70 <        if (st == NULL) {
71 <                if (lg < 0)
64 >                if (st == NULL) {
65                          sprintf(SDerrorDetail,
66                                  "Cannot allocate %d branch BSDF tree", 1<<nd);
67 <                else
67 >                        return NULL;
68 >                }
69 >                memset(st->u.t, 0, sizeof(st->u.t[0])<<nd);
70 >        } else {
71 >                st = (SDNode *)malloc(sizeof(SDNode) +
72 >                                sizeof(st->u.v[0])*((1 << nd*lg) - 1));        
73 >                if (st == NULL) {
74                          sprintf(SDerrorDetail,
75                                  "Cannot allocate %d BSDF leaves", 1 << nd*lg);
76 <                return NULL;
76 >                        return NULL;
77 >                }
78          }
79          st->ndim = nd;
80          st->log2GR = lg;
# Line 85 | Line 85 | SDnewNode(int nd, int lg)
85   static void
86   SDfreeTre(SDNode *st)
87   {
88 <        int     i;
88 >        int     n;
89  
90          if (st == NULL)
91                  return;
92 <        for (i = (st->log2GR < 0) << st->ndim; i--; )
93 <                SDfreeTre(st->u.t[i]);
92 >        for (n = (st->log2GR < 0) << st->ndim; n--; )
93 >                SDfreeTre(st->u.t[n]);
94          free((void *)st);
95   }
96  
# Line 214 | Line 214 | SDavgTreBox(const SDNode *st, const double *bmin, cons
214          for (i = st->ndim; i--; ) {
215                  if (bmin[i] >= 1.)
216                          return .0;
217 <                if (bmax[i] <= .0)
217 >                if (bmax[i] <= 0)
218                          return .0;
219                  if (bmin[i] >= bmax[i])
220                          return .0;
# Line 234 | Line 234 | SDavgTreBox(const SDNode *st, const double *bmin, cons
234                                  }
235                                  if (sbmin[i] < .0) sbmin[i] = .0;
236                                  if (sbmax[i] > 1.) sbmax[i] = 1.;
237 +                                if (sbmin[i] >= sbmax[i]) {
238 +                                        w = .0;
239 +                                        break;
240 +                                }
241                                  w *= sbmax[i] - sbmin[i];
242                          }
243                          if (w > 1e-10) {
# Line 269 | Line 273 | SDdotravTre(const SDNode *st, const double *pos, int c
273                                          /* in branches? */
274          if (st->log2GR < 0) {
275                  unsigned        skipmask = 0;
272
276                  csiz *= .5;
277                  for (i = st->ndim; i--; )
278                          if (1<<i & cmask)
279                                  if (pos[i] < cmin[i] + csiz)
280 <                                        for (n = 1 << st->ndim; n--; )
280 >                                        for (n = 1 << st->ndim; n--; ) {
281                                                  if (n & 1<<i)
282                                                          skipmask |= 1<<n;
283 +                                        }
284                                  else
285 <                                        for (n = 1 << st->ndim; n--; )
285 >                                        for (n = 1 << st->ndim; n--; ) {
286                                                  if (!(n & 1<<i))
287                                                          skipmask |= 1<<n;
288 +                                        }
289                  for (n = 1 << st->ndim; n--; ) {
290                          if (1<<n & skipmask)
291                                  continue;
# Line 473 | Line 478 | build_scaffold(float val, const double *cmin, double c
478                  sp->wmax = wid;
479          if (sp->alen >= sp->nall) {     /* need more space? */
480                  struct outdir_s *ndarr;
481 <                sp->nall += 8192;
481 >                sp->nall += 1024;
482                  ndarr = (struct outdir_s *)realloc(sp->darr,
483                                          sizeof(struct outdir_s)*sp->nall);
484 <                if (ndarr == NULL)
484 >                if (ndarr == NULL) {
485 >                        sprintf(SDerrorDetail,
486 >                                "Cannot grow scaffold to %u entries", sp->nall);
487                          return -1;      /* abort build */
488 +                }
489                  sp->darr = ndarr;
490          }
491                                          /* find Hilbert entry index */
# Line 505 | Line 513 | sscmp(const void *p1, const void *p2)
513          if (h1 < h2)
514                  return -1;
515          return 0;
508 /*
509        return (int)((*(const struct outdir_s *)p1).hent -
510                        (*(const struct outdir_s *)p2).hent);
511 */
516   }
517  
518   /* Create a new cumulative distribution for the given input direction */
# Line 525 | Line 529 | make_cdist(const SDTre *sdt, const double *pos)
529          myScaffold.wmax = 0;
530          myScaffold.nic = sdt->st->ndim - 2;
531          myScaffold.alen = 0;
532 <        myScaffold.nall = 8192;
532 >        myScaffold.nall = 512;
533          myScaffold.darr = (struct outdir_s *)malloc(sizeof(struct outdir_s) *
534                                                          myScaffold.nall);
535          if (myScaffold.darr == NULL)
# Line 540 | Line 544 | make_cdist(const SDTre *sdt, const double *pos)
544          cd = (SDTreCDst *)malloc(sizeof(SDTreCDst) +
545                                  sizeof(cd->carr[0])*myScaffold.alen);
546          if (cd == NULL) {
547 +                sprintf(SDerrorDetail,
548 +                        "Cannot allocate %u entry cumulative distribution",
549 +                                myScaffold.alen);
550                  free(myScaffold.darr);
551                  return NULL;
552          }
# Line 721 | Line 728 | next_token(char **spp)
728          return **spp;
729   }
730  
731 < #define eat_token(spp,c)        (next_token(spp)==(c) ? *(*(spp))++ : 0)
731 > /* Advance pointer past matching token (or any token if c==0) */
732 > #define eat_token(spp,c)        (next_token(spp)==(c) ^ !(c) ? *(*(spp))++ : 0)
733  
734   /* Count words from this point in string to '}' */
735   static int
# Line 730 | Line 738 | count_values(char *cp)
738          int     n = 0;
739  
740          while (next_token(&cp) != '}' && *cp) {
741 <                if (*cp == '{')
742 <                        return -1;
743 <                while (*cp && (*cp != ',') & (*cp != '}') & !isspace(*cp))
736 <                        ++cp;
741 >                while (!isspace(*cp) & (*cp != ',') & (*cp != '}'))
742 >                        if (!*++cp)
743 >                                break;
744                  ++n;
745                  eat_token(&cp, ',');
746          }
# Line 778 | Line 785 | load_tree_data(char **spp, int nd)
785          } else {                        /* else load value grid */
786                  int     bsiz;
787                  n = count_values(*spp); /* see how big the grid is */
781                if (n <= 0) {
782                        strcpy(SDerrorDetail, "Bad tensor tree data");
783                        return NULL;
784                }
788                  for (bsiz = 0; bsiz < 8*sizeof(size_t)-1; bsiz += nd)
789                          if (1<<bsiz == n)
790                                  break;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines