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.16 by greg, Sun Jun 5 20:27:14 2011 UTC vs.
Revision 3.23 by greg, Mon Aug 22 18:21:05 2011 UTC

# Line 10 | Line 10 | static const char RCSid[] = "$Id$";
10   *
11   */
12  
13 + #define _USE_MATH_DEFINES
14   #include "rtio.h"
15   #include <stdlib.h>
16   #include <math.h>
# Line 25 | Line 26 | typedef int    SDtreCallback(float val, const double *cmi
26  
27                                          /* reference width maximum (1.0) */
28   static const unsigned   iwbits = sizeof(unsigned)*4;
29 < static const unsigned   iwmax = (1<<(sizeof(unsigned)*4))-1;
29 > static const unsigned   iwmax = 1<<(sizeof(unsigned)*4);
30                                          /* maximum cumulative value */
31   static const unsigned   cumlmax = ~0;
32                                          /* constant z-vector */
33   static const FVECT      zvec = {.0, .0, 1.};
34 +                                        /* quantization value */
35 + static double           quantum = 1./256.;
36  
37   /* Struct used for our distribution-building callback */
38   typedef struct {
# Line 607 | Line 610 | SDgetTreCDist(const FVECT inVec, SDComponent *sdc)
610   {
611          const SDTre     *sdt;
612          double          inCoord[2];
610        int             vflags;
613          int             i;
614          SDTreCDst       *cd, *cdlast;
615                                          /* check arguments */
616          if ((inVec == NULL) | (sdc == NULL) ||
617                          (sdt = (SDTre *)sdc->dist) == NULL)
618                  return NULL;
619 <        if (sdt->st->ndim == 3)         /* isotropic BSDF? */
619 >        if (sdt->st->ndim == 3) {       /* isotropic BSDF? */
620                  inCoord[0] = .5 - .5*sqrt(inVec[0]*inVec[0] + inVec[1]*inVec[1]);
621 <        else if (sdt->st->ndim == 4)
621 >        } else if (sdt->st->ndim == 4) {
622                  SDdisk2square(inCoord, -inVec[0], -inVec[1]);
623 <        else
623 >        } else
624                  return NULL;            /* should be internal error */
625 +                                        /* quantize to avoid f.p. errors */
626 +        for (i = sdt->st->ndim - 2; i--; )
627 +                inCoord[i] = floor(inCoord[i]/quantum)*quantum + .5*quantum;
628          cdlast = NULL;                  /* check for direction in cache list */
629          for (cd = (SDTreCDst *)sdc->cdList; cd != NULL;
630 <                                cdlast = cd, cd = (SDTreCDst *)cd->next) {
630 >                                        cdlast = cd, cd = cd->next) {
631                  for (i = sdt->st->ndim - 2; i--; )
632                          if ((cd->clim[i][0] > inCoord[i]) |
633                                          (inCoord[i] >= cd->clim[i][1]))
# Line 634 | Line 639 | SDgetTreCDist(const FVECT inVec, SDComponent *sdc)
639                  cdlast = cd = make_cdist(sdt, inCoord);
640          if (cdlast != NULL) {           /* move entry to head of cache list */
641                  cdlast->next = cd->next;
642 <                cd->next = sdc->cdList;
642 >                cd->next = (SDTreCDst *)sdc->cdList;
643                  sdc->cdList = (SDCDst *)cd;
644          }
645          return (SDCDst *)cd;            /* ready to go */
# Line 710 | Line 715 | SDsampTreCDist(FVECT ioVec, double randX, const SDCDst
715                                          /* binary search to find position */
716          ilower = 0; iupper = cd->calen;
717          while ((i = (iupper + ilower) >> 1) != ilower)
718 <                if ((long)target >= (long)cd->carr[i].cuml)
718 >                if (target >= cd->carr[i].cuml)
719                          ilower = i;
720                  else
721                          iupper = i;
# Line 841 | Line 846 | get_extrema(SDSpectralDF *df)
846          double  stepWidth, dhemi, bmin[4], bmax[4];
847  
848          stepWidth = SDsmallestLeaf(st);
849 +        if (quantum > stepWidth)        /* adjust quantization factor */
850 +                quantum = stepWidth;
851          df->minProjSA = M_PI*stepWidth*stepWidth;
852          if (stepWidth < .03125)
853                  stepWidth = .03125;     /* 1/32 resolution good enough */
# Line 880 | Line 887 | load_bsdf_data(SDData *sd, ezxml_t wdb, int ndim)
887          SDSpectralDF    *df;
888          SDTre           *sdt;
889          char            *sdata;
883        int             i;
890                                          /* allocate BSDF component */
891          sdata = ezxml_txt(ezxml_child(wdb, "WavelengthDataDirection"));
892          if (!sdata)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines