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.8 by greg, Wed Apr 27 20:05:15 2011 UTC vs.
Revision 3.10 by greg, Thu Apr 28 04:05:11 2011 UTC

# Line 129 | Line 129 | grid_branch_start(SDNode *st, int n)
129          float           *vptr = st->u.v;
130          int             i;
131  
132 <        for (i = st->ndim; i--; skipsiz <<= st->log2GR)
133 <                if (1<<i & n)
132 >        for (i = 0; i < st->ndim; skipsiz <<= st->log2GR)
133 >                if (1<<i++ & n)
134                          vptr += skipsiz >> 1;
135          return vptr;
136   }
# Line 151 | Line 151 | SDsimplifyTre(SDNode *st)
151                          return NULL;    /* propogate error up call stack */
152                  match &= (st->u.t[n]->log2GR == st->u.t[0]->log2GR);
153          }
154 <        if (match && st->u.t[0]->log2GR >= 0) {
155 <                SDNode  *stn = SDnewNode(st->ndim, st->u.t[0]->log2GR + 1);
154 >        if (match && (match = st->u.t[0]->log2GR) >= 0) {
155 >                SDNode  *stn = SDnewNode(st->ndim, match + 1);
156                  if (stn == NULL)        /* out of memory? */
157                          return st;
158                                          /* transfer values to new grid */
159                  for (n = 1 << st->ndim; n--; )
160                          fill_grid_branch(grid_branch_start(stn, n),
161 <                                        st->u.t[n]->u.v, st->ndim, st->log2GR);
161 >                                        st->u.t[n]->u.v, stn->ndim, stn->log2GR);
162                  SDfreeTre(st);          /* free old tree */
163                  st = stn;               /* return new one */
164          }
# Line 187 | Line 187 | SDsmallestLeaf(const SDNode *st)
187   static double
188   SDiterSum(const float *va, int nd, int shft, const int *imin, const int *imax)
189   {
190 <        const unsigned  skipsiz = 1 << nd*shft;
190 >        const unsigned  skipsiz = 1 << --nd*shft;
191          double          sum = .0;
192          int             i;
193          
# Line 196 | Line 196 | SDiterSum(const float *va, int nd, int shft, const int
196                          sum += va[i];
197          else
198                  for (i = *imin; i < *imax; i++)
199 <                        sum += SDiterSum(va + i*skipsiz,
200 <                                        nd-1, shft, imin+1, imax+1);
199 >                        sum += SDiterSum(va + i*skipsiz, nd, shft, imin+1, imax+1);
200          return sum;
201   }
202  
# Line 484 | Line 483 | build_scaffold(float val, const double *cmin, double c
483                                          /* find Hilbert entry index */
484          bmin[0] = cmin[0]*(double)iwmax + .5;
485          bmin[1] = cmin[1]*(double)iwmax + .5;
486 <        bmax[0] = bmin[0] + wid;
487 <        bmax[1] = bmin[1] + wid;
486 >        bmax[0] = bmin[0] + wid-1;
487 >        bmax[1] = bmin[1] + wid-1;
488          hilbert_box_vtx(2, sizeof(bitmask_t), iwbits, 1, bmin, bmax);
489          sp->darr[sp->alen].hent = hilbert_c2i(2, iwbits, bmin);
490          sp->darr[sp->alen].wid = wid;
# Line 498 | Line 497 | build_scaffold(float val, const double *cmin, double c
497   static int
498   sscmp(const void *p1, const void *p2)
499   {
500 +        unsigned        h1 = (*(const struct outdir_s *)p1).hent;
501 +        unsigned        h2 = (*(const struct outdir_s *)p2).hent;
502 +
503 +        if (h1 > h2)
504 +                return 1;
505 +        if (h1 < h2)
506 +                return -1;
507 +        return 0;
508 + /*
509          return (int)((*(const struct outdir_s *)p1).hent -
510                          (*(const struct outdir_s *)p2).hent);
511 + */
512   }
513  
514   /* Create a new cumulative distribution for the given input direction */
# Line 712 | Line 721 | next_token(char **spp)
721          return **spp;
722   }
723  
724 + #define eat_token(spp,c)        (next_token(spp)==(c) ? *(*(spp))++ : 0)
725 +
726   /* Count words from this point in string to '}' */
727   static int
728   count_values(char *cp)
729   {
730          int     n = 0;
731  
732 <        while (next_token(&cp) != '}') {
732 >        while (next_token(&cp) != '}' && *cp) {
733                  if (*cp == '{')
734                          return -1;
735 <                while (*cp && !isspace(*cp))
735 >                while (*cp && (*cp != ',') & (*cp != '}') & !isspace(*cp))
736                          ++cp;
737                  ++n;
738 <                cp += (next_token(&cp) == ',');
738 >                eat_token(&cp, ',');
739          }
740          return n;
741   }
# Line 739 | Line 750 | load_values(char **spp, float *va, int n)
750          while (n-- > 0 && (svnext = fskip(*spp)) != NULL) {
751                  *v++ = atof(*spp);
752                  *spp = svnext;
753 <                *spp += (next_token(spp) == ',');
753 >                eat_token(spp, ',');
754          }
755          return v - va;
756   }
# Line 751 | Line 762 | load_tree_data(char **spp, int nd)
762          SDNode  *st;
763          int     n;
764  
765 <        if (next_token(spp) != '{') {
765 >        if (!eat_token(spp, '{')) {
766                  strcpy(SDerrorDetail, "Missing '{' in tensor tree");
767                  return NULL;
768          }
758        ++*spp;                         /* in tree, now */
769          if (next_token(spp) == '{') {   /* tree branches */
770                  st = SDnewNode(nd, -1);
771                  if (st == NULL)
# Line 788 | Line 798 | load_tree_data(char **spp, int nd)
798                          return NULL;
799                  }
800          }
801 <        if (next_token(spp) != '}') {
801 >        if (!eat_token(spp, '}')) {
802                  strcpy(SDerrorDetail, "Missing '}' in tensor tree");
803                  SDfreeTre(st);
804                  return NULL;
805          }
806 <        ++*spp;                         /* walk past close and return */
797 <        *spp += (next_token(spp) == ',');
806 >        eat_token(spp, ',');
807          return st;
808   }
809  
# Line 922 | Line 931 | load_bsdf_data(SDData *sd, ezxml_t wdb, int ndim)
931   static float
932   SDgetTreMin(const SDNode *st)
933   {
934 <        float   vmin = 1./M_PI;
934 >        float   vmin = FHUGE;
935          int     n;
936  
937          if (st->log2GR < 0) {
# Line 960 | Line 969 | subtract_min(SDNode *st)
969   {
970          float   vmin;
971                                          /* be sure to skip unused portion */
972 <        if ((st->ndim == 3) & (st->log2GR < 0)) {
973 <                float   v;
965 <                int     i;
972 >        if (st->ndim == 3) {
973 >                int     n;
974                  vmin = 1./M_PI;
975 <                for (i = 0; i < 4; i++) {
976 <                        v = SDgetTreMin(st->u.t[i]);
977 <                        if (v < vmin)
978 <                                vmin = v;
979 <                }
975 >                if (st->log2GR < 0) {
976 >                        for (n = 0; n < 4; n++) {
977 >                                float   v = SDgetTreMin(st->u.t[n]);
978 >                                if (v < vmin)
979 >                                        vmin = v;
980 >                        }
981 >                } else if (st->log2GR) {
982 >                        for (n = 1 << (3*st->log2GR - 1); n--; )
983 >                                if (st->u.v[n] < vmin)
984 >                                        vmin = st->u.v[n];
985 >                } else
986 >                        vmin = st->u.v[0];
987          } else                          /* anisotropic covers entire tree */
988                  vmin = SDgetTreMin(st);
989  
# Line 992 | Line 1007 | extract_diffuse(SDValue *dv, SDSpectralDF *df)
1007                  return;
1008          }
1009          dv->spec = df->comp[0].cspec[0];
1010 <        dv->cieY = subtract_min((*(SDTre *)df->comp[n].dist).st);
1010 >        dv->cieY = subtract_min((*(SDTre *)df->comp[0].dist).st);
1011                                          /* in case of multiple components */
1012          for (n = df->ncomp; --n; ) {
1013                  double  ymin = subtract_min((*(SDTre *)df->comp[n].dist).st);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines