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

Comparing ray/src/common/bsdf_m.c (file contents):
Revision 3.8 by greg, Thu Feb 24 20:14:26 2011 UTC vs.
Revision 3.11 by greg, Wed Apr 20 14:44:05 2011 UTC

# Line 81 | Line 81 | static int     nabases = 3;    /* current number of defined b
81   static int
82   fequal(double a, double b)
83   {
84 <        if (b != .0)
84 >        if (b != 0)
85                  a = a/b - 1.;
86          return (a <= 1e-6) & (a >= -1e-6);
87   }
88  
89 < /* returns the name of the given tag */
89 > /* Returns the name of the given tag */
90   #ifdef ezxml_name
91   #undef ezxml_name
92   static char *
# Line 98 | Line 98 | ezxml_name(ezxml_t xml)
98   }
99   #endif
100  
101 < /* returns the given tag's character content or empty string if none */
101 > /* Returns the given tag's character content or empty string if none */
102   #ifdef ezxml_txt
103   #undef ezxml_txt
104   static char *
# Line 159 | Line 159 | SDnewMatrix(int ni, int no)
159  
160   /* get vector for this angle basis index (front exiting) */
161   static int
162 < fo_getvec(FVECT v, int ndx, double randX, void *p)
162 > fo_getvec(FVECT v, double ndxr, void *p)
163   {
164 <        ANGLE_BASIS  *ab = (ANGLE_BASIS *)p;
164 >        ANGLE_BASIS     *ab = (ANGLE_BASIS *)p;
165 >        int             ndx = (int)ndxr;
166 >        double          randX = ndxr - ndx;
167          double          rx[2];
168          int             li;
169          double          pol, azi, d;
170          
171 <        if ((ndx < 0) | (ndx >= ab->nangles))
171 >        if ((ndxr < 0) | (ndx >= ab->nangles))
172                  return RC_FAIL;
173          for (li = 0; ndx >= ab->lat[li].nphis; li++)
174                  ndx -= ab->lat[li].nphis;
# Line 185 | Line 187 | fo_getvec(FVECT v, int ndx, double randX, void *p)
187   static int
188   fo_getndx(const FVECT v, void *p)
189   {
190 <        ANGLE_BASIS  *ab = (ANGLE_BASIS *)p;
190 >        ANGLE_BASIS     *ab = (ANGLE_BASIS *)p;
191          int     li, ndx;
192          double  pol, azi, d;
193  
194          if (v == NULL)
195                  return -1;
196 <        if ((v[2] < .0) | (v[2] > 1.0))
196 >        if ((v[2] < 0) | (v[2] > 1.))
197                  return -1;
198          pol = 180.0/M_PI*acos(v[2]);
199          azi = 180.0/M_PI*atan2(v[1], v[0]);
# Line 237 | Line 239 | io_getohm(int ndx, void *p)
239  
240   /* get vector for this angle basis index (back incident) */
241   static int
242 < bi_getvec(FVECT v, int ndx, double randX, void *p)
242 > bi_getvec(FVECT v, double ndxr, void *p)
243   {
244 <        if (!fo_getvec(v, ndx, randX, p))
244 >        if (!fo_getvec(v, ndxr, p))
245                  return RC_FAIL;
246  
247          v[0] = -v[0];
# Line 264 | Line 266 | bi_getndx(const FVECT v, void *p)
266  
267   /* get vector for this angle basis index (back exiting) */
268   static int
269 < bo_getvec(FVECT v, int ndx, double randX, void *p)
269 > bo_getvec(FVECT v, double ndxr, void *p)
270   {
271 <        if (!fo_getvec(v, ndx, randX, p))
271 >        if (!fo_getvec(v, ndxr, p))
272                  return RC_FAIL;
273  
274          v[2] = -v[2];
# Line 289 | Line 291 | bo_getndx(const FVECT v, void *p)
291  
292   /* get vector for this angle basis index (front incident) */
293   static int
294 < fi_getvec(FVECT v, int ndx, double randX, void *p)
294 > fi_getvec(FVECT v, double ndxr, void *p)
295   {
296 <        if (!fo_getvec(v, ndx, randX, p))
296 >        if (!fo_getvec(v, ndxr, p))
297                  return RC_FAIL;
298  
299          v[0] = -v[0];
# Line 418 | Line 420 | load_bsdf_data(SDData *sd, ezxml_t wdb, int rowinc)
420          sdata = ezxml_txt(ezxml_child(wdb, "WavelengthDataDirection"));
421          /*
422           * Remember that front and back are reversed from WINDOW 6 orientations
423 +         * Favor their "Front" (incoming light) since that's more often valid
424           */
425 <        if ((tfront = !strcasecmp(sdata, "Transmission Back")) ||
426 <                        (sd->tf == NULL &&
427 <                                !strcasecmp(sdata, "Transmission Front"))) {
425 >        tfront = !strcasecmp(sdata, "Transmission Back");
426 >        if (!strcasecmp(sdata, "Transmission Front") ||
427 >                        tfront & (sd->tf == NULL)) {
428                  if (sd->tf != NULL)
429                          SDfreeSpectralDF(sd->tf);
430                  if ((sd->tf = SDnewSpectralDF(1)) == NULL)
# Line 504 | Line 507 | load_bsdf_data(SDData *sd, ezxml_t wdb, int rowinc)
507          df->comp[0].dist = dp;
508          df->comp[0].func = &SDhandleMtx;
509                                          /* read BSDF data */
510 <        sdata  = ezxml_txt(ezxml_child(wdb,"ScatteringData"));
510 >        sdata = ezxml_txt(ezxml_child(wdb,"ScatteringData"));
511          if (!sdata || !*sdata) {
512                  sprintf(SDerrorDetail, "Missing BSDF ScatteringData in '%s'",
513                                  sd->name);
# Line 648 | Line 651 | SDgetMtxBSDF(float coef[SDmaxCh], const FVECT outVec,
651  
652   /* Query solid angle for vector */
653   static SDError
654 < SDqueryMtxProjSA(double *psa, const FVECT vec, int qflags, const void *dist)
654 > SDqueryMtxProjSA(double *psa, const FVECT v1, const RREAL *v2,
655 >                                        int qflags, const void *dist)
656   {
657          const SDMat     *dp = (const SDMat *)dist;
658          double          inc_psa, out_psa;
659                                          /* check arguments */
660 <        if ((psa == NULL) | (vec == NULL) | (dp == NULL))
660 >        if ((psa == NULL) | (v1 == NULL) | (dp == NULL))
661                  return SDEargument;
662 +        if (v2 == NULL)
663 +                v2 = v1;
664                                          /* get projected solid angles */
665 <        inc_psa = mBSDF_incohm(dp, mBSDF_incndx(dp, vec));
666 <        out_psa = mBSDF_outohm(dp, mBSDF_outndx(dp, vec));
665 >        out_psa = mBSDF_outohm(dp, mBSDF_outndx(dp, v1));
666 >        inc_psa = mBSDF_incohm(dp, mBSDF_incndx(dp, v2));
667 >        if ((out_psa <= 0) & (inc_psa <= 0)) {
668 >                inc_psa = mBSDF_outohm(dp, mBSDF_outndx(dp, v2));
669 >                out_psa = mBSDF_incohm(dp, mBSDF_incndx(dp, v1));
670 >        }
671  
672          switch (qflags) {               /* record based on flag settings */
673          case SDqueryVal:
# Line 676 | Line 686 | SDqueryMtxProjSA(double *psa, const FVECT vec, int qfl
686                          psa[1] = out_psa;
687                  /* fall through */
688          case SDqueryMin:
689 <                if ((inc_psa > .0) & (inc_psa < psa[0]))
689 >                if ((inc_psa > 0) & (inc_psa < psa[0]))
690                          psa[0] = inc_psa;
691 <                if ((out_psa > .0) & (out_psa < psa[0]))
691 >                if ((out_psa > 0) & (out_psa < psa[0]))
692                          psa[0] = out_psa;
693                  break;
694          }
695                                          /* make sure it's legal */
696 <        return (psa[0] <= .0) ? SDEinternal : SDEnone;
696 >        return (psa[0] <= 0) ? SDEinternal : SDEnone;
697   }
698  
699   /* Compute new cumulative distribution from BSDF */
# Line 795 | Line 805 | SDsampMtxCDist(FVECT outVec, double randX, const SDCDs
805          randX = (randX*maxval - mcd->carr[ilower]) /
806                          (double)(mcd->carr[iupper] - mcd->carr[ilower]);
807                                          /* convert index to vector */
808 <        if ((*mcd->ob_vec)(outVec, i, randX, mcd->ob_priv))
808 >        if ((*mcd->ob_vec)(outVec, i+randX, mcd->ob_priv))
809                  return SDEnone;
810          strcpy(SDerrorDetail, "BSDF sampling fault");
811          return SDEinternal;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines