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.14 by greg, Wed Jun 1 05:21:18 2011 UTC vs.
Revision 3.15 by greg, Fri Jun 3 18:12:58 2011 UTC

# Line 28 | Line 28 | static const unsigned  iwbits = sizeof(unsigned)*4;
28   static const unsigned   iwmax = (1<<(sizeof(unsigned)*4))-1;
29                                          /* maximum cumulative value */
30   static const unsigned   cumlmax = ~0;
31 +                                        /* constant z-vector */
32 + static const FVECT      zvec = {.0, .0, 1.};
33  
34   /* Struct used for our distribution-building callback */
35   typedef struct {
# Line 190 | Line 192 | SDiterSum(const float *va, int nd, int shft, const int
192          const unsigned  skipsiz = 1 << --nd*shft;
193          double          sum = .0;
194          int             i;
195 <        
195 >
196 >        va += *imin * skipsiz;
197 >
198          if (skipsiz == 1)
199                  for (i = *imin; i < *imax; i++)
200 <                        sum += va[i];
200 >                        sum += *va++;
201          else
202 <                for (i = *imin; i < *imax; i++)
203 <                        sum += SDiterSum(va + i*skipsiz, nd, shft, imin+1, imax+1);
202 >                for (i = *imin; i < *imax; i++, va += skipsiz)
203 >                        sum += SDiterSum(va, nd, shft, imin+1, imax+1);
204          return sum;
205   }
206  
# Line 204 | Line 208 | SDiterSum(const float *va, int nd, int shft, const int
208   static double
209   SDavgTreBox(const SDNode *st, const double *bmin, const double *bmax)
210   {
207        int             imin[SD_MAXDIM], imax[SD_MAXDIM];
211          unsigned        n;
212          int             i;
213  
# Line 222 | Line 225 | SDavgTreBox(const SDNode *st, const double *bmin, cons
225          if (st->log2GR < 0) {           /* iterate on subtree */
226                  double          sum = .0, wsum = 1e-20;
227                  double          sbmin[SD_MAXDIM], sbmax[SD_MAXDIM], w;
225
228                  for (n = 1 << st->ndim; n--; ) {
229                          w = 1.;
230                          for (i = st->ndim; i--; ) {
# Line 246 | Line 248 | SDavgTreBox(const SDNode *st, const double *bmin, cons
248                          }
249                  }
250                  return sum / wsum;
251 +        } else {                        /* iterate over leaves */
252 +                int             imin[SD_MAXDIM], imax[SD_MAXDIM];
253 +
254 +                n = 1;
255 +                for (i = st->ndim; i--; ) {
256 +                        imin[i] = (bmin[i] <= 0) ? 0 :
257 +                                        (int)((1 << st->log2GR)*bmin[i]);
258 +                        imax[i] = (bmax[i] >= 1.) ? (1 << st->log2GR) :
259 +                                (int)((1 << st->log2GR)*bmax[i] + .999999);
260 +                        n *= imax[i] - imin[i];
261 +                }
262 +                if (n)
263 +                        return SDiterSum(st->u.v, st->ndim,
264 +                                        st->log2GR, imin, imax) / (double)n;
265          }
266 <        n = 1;                          /* iterate over leaves */
251 <        for (i = st->ndim; i--; ) {
252 <                imin[i] = (bmin[i] <= 0) ? 0
253 <                                : (int)((1 << st->log2GR)*bmin[i]);
254 <                imax[i] = (bmax[i] >= 1.) ? (1 << st->log2GR)
255 <                                : (int)((1 << st->log2GR)*bmax[i] + .999999);
256 <                n *= imax[i] - imin[i];
257 <        }
258 <        if (!n)
259 <                return .0;
260 <        
261 <        return SDiterSum(st->u.v, st->ndim, st->log2GR, imin, imax) / (double)n;
266 >        return .0;
267   }
268  
269   /* Recursive call for SDtraverseTre() */
# Line 294 | Line 299 | SDdotravTre(const SDNode *st, const double *pos, int c
299                                          bmin[i] = cmin[i] + csiz;
300                                  else
301                                          bmin[i] = cmin[i];
302 +                        for (i = SD_MAXDIM; i-- > st->ndim; )
303 +                                bmin[i] = .0;
304  
305                          rval += rv = SDdotravTre(st->u.t[n], pos, cmask,
306                                                          cf, cptr, bmin, csiz);
# Line 415 | Line 422 | SDlookupTre(const SDNode *st, const double *pos, doubl
422   static float
423   SDqueryTre(const SDTre *sdt, const FVECT outVec, const FVECT inVec, double *hc)
424   {
418        static const FVECT      zvec = {.0, .0, 1.};
425          FVECT                   rOutVec;
426          double                  gridPos[4];
427  
# Line 437 | Line 443 | SDqueryTre(const SDTre *sdt, const FVECT outVec, const
443          }
444                                          /* convert vector coordinates */
445          if (sdt->st->ndim == 3) {
446 <                spinvector(rOutVec, outVec, zvec, -atan2(inVec[1],inVec[0]));
446 >                spinvector(rOutVec, outVec, zvec, -atan2(-inVec[1],-inVec[0]));
447                  gridPos[0] = .5 - .5*sqrt(inVec[0]*inVec[0] + inVec[1]*inVec[1]);
448                  SDdisk2square(gridPos+1, rOutVec[0], rOutVec[1]);
449          } else if (sdt->st->ndim == 4) {
# Line 550 | Line 556 | make_cdist(const SDTre *sdt, const double *pos)
556                  free(myScaffold.darr);
557                  return NULL;
558          }
559 +        cd->isodist = (myScaffold.nic == 1);
560                                          /* sort the distribution */
561          qsort(myScaffold.darr, cd->calen = myScaffold.alen,
562                                  sizeof(struct outdir_s), &sscmp);
# Line 560 | Line 567 | make_cdist(const SDTre *sdt, const double *pos)
567                  cd->clim[i][0] = floor(pos[i]/scale) * scale;
568                  cd->clim[i][1] = cd->clim[i][0] + scale;
569          }
570 +        if (cd->isodist) {              /* avoid issue in SDqueryTreProjSA() */
571 +                cd->clim[1][0] = cd->clim[0][0];
572 +                cd->clim[1][1] = cd->clim[0][1];
573 +        }
574          cd->max_psa = myScaffold.wmax / (double)iwmax;
575          cd->max_psa *= cd->max_psa * M_PI;
576          cd->sidef = sdt->sidef;
# Line 679 | Line 690 | SDsampTreCDist(FVECT ioVec, double randX, const SDCDst
690          const SDTreCDst *cd = (const SDTreCDst *)cdp;
691          const unsigned  target = randX*cumlmax;
692          bitmask_t       hndx, hcoord[2];
693 <        double          gpos[3];
693 >        double          gpos[3], rotangle;
694          int             i, iupper, ilower;
695                                          /* check arguments */
696          if ((ioVec == NULL) | (cd == NULL))
# Line 715 | Line 726 | SDsampTreCDist(FVECT ioVec, double randX, const SDCDst
726                                          /* emit from back? */
727          if (ioVec[2] > 0 ^ cd->sidef != SD_XMIT)
728                  gpos[2] = -gpos[2];
729 <        VCOPY(ioVec, gpos);
729 >        if (cd->isodist) {              /* rotate isotropic result */
730 >                rotangle = atan2(-ioVec[1],-ioVec[0]);
731 >                VCOPY(ioVec, gpos);
732 >                spinvector(ioVec, ioVec, zvec, rotangle);
733 >        } else
734 >                VCOPY(ioVec, gpos);
735          return SDEnone;
736   }
737  
# Line 785 | Line 801 | load_tree_data(char **spp, int nd)
801          } else {                        /* else load value grid */
802                  int     bsiz;
803                  n = count_values(*spp); /* see how big the grid is */
804 <                for (bsiz = 0; bsiz < 8*sizeof(size_t)-1; bsiz += nd)
804 >                for (bsiz = 0; bsiz < 8*sizeof(size_t); bsiz += nd)
805                          if (1<<bsiz == n)
806                                  break;
807                  if (bsiz >= 8*sizeof(size_t)) {
# Line 962 | Line 978 | SDsubtractTreVal(SDNode *st, float val)
978                          SDsubtractTreVal(st->u.t[n], val);
979          } else {
980                  for (n = 1<<(st->ndim*st->log2GR); n--; )
981 <                        st->u.v[n] -= val;
981 >                        if ((st->u.v[n] -= val) < 0)
982 >                                st->u.v[n] = .0f;
983          }
984   }
985  
# Line 976 | Line 993 | subtract_min(SDNode *st)
993                  int     n;
994                  vmin = 1./M_PI;
995                  if (st->log2GR < 0) {
996 <                        for (n = 0; n < 4; n++) {
996 >                        for (n = 0; n < 8; n += 2) {
997                                  float   v = SDgetTreMin(st->u.t[n]);
998                                  if (v < vmin)
999                                          vmin = v;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines