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.19 by greg, Thu Jul 7 15:25:09 2011 UTC vs.
Revision 3.21 by greg, Mon Aug 22 05:48:39 2011 UTC

# Line 607 | Line 607 | const SDCDst *
607   SDgetTreCDist(const FVECT inVec, SDComponent *sdc)
608   {
609          const SDTre     *sdt;
610 <        double          inCoord[2];
610 >        double          inCoord[2], quantum;
611          int             i;
612          SDTreCDst       *cd, *cdlast;
613                                          /* check arguments */
614          if ((inVec == NULL) | (sdc == NULL) ||
615                          (sdt = (SDTre *)sdc->dist) == NULL)
616                  return NULL;
617 <        if (sdt->st->ndim == 3)         /* isotropic BSDF? */
617 >        if (sdt->st->ndim == 3) {       /* isotropic BSDF? */
618                  inCoord[0] = .5 - .5*sqrt(inVec[0]*inVec[0] + inVec[1]*inVec[1]);
619 <        else if (sdt->st->ndim == 4)
619 >        } else if (sdt->st->ndim == 4) {
620                  SDdisk2square(inCoord, -inVec[0], -inVec[1]);
621 <        else
621 >        } else
622                  return NULL;            /* should be internal error */
623 +                                        /* quantize to avoid f.p. errors */
624 +        quantum = SDsmallestLeaf(sdt->st);
625 +        for (i = sdt->st->ndim - 2; i--; )
626 +                inCoord[i] = floor(inCoord[i]/quantum)*quantum + .5*quantum;
627          cdlast = NULL;                  /* check for direction in cache list */
628          for (cd = (SDTreCDst *)sdc->cdList; cd != NULL;
629 <                                cdlast = cd, cd = (SDTreCDst *)cd->next) {
629 >                                        cdlast = cd, cd = cd->next) {
630                  for (i = sdt->st->ndim - 2; i--; )
631                          if ((cd->clim[i][0] > inCoord[i]) |
632                                          (inCoord[i] >= cd->clim[i][1]))
# Line 634 | Line 638 | SDgetTreCDist(const FVECT inVec, SDComponent *sdc)
638                  cdlast = cd = make_cdist(sdt, inCoord);
639          if (cdlast != NULL) {           /* move entry to head of cache list */
640                  cdlast->next = cd->next;
641 <                cd->next = sdc->cdList;
641 >                cd->next = (SDTreCDst *)sdc->cdList;
642                  sdc->cdList = (SDCDst *)cd;
643          }
644          return (SDCDst *)cd;            /* ready to go */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines