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.11 by greg, Wed Apr 20 14:44:05 2011 UTC vs.
Revision 3.14 by greg, Mon Apr 25 15:48:05 2011 UTC

# Line 352 | Line 352 | load_angle_basis(ezxml_t wab)
352                                          "ThetaBounds"), "LowerTheta"))),
353                                  abase_list[nabases].lat[i].tmin)) {
354                          sprintf(SDerrorDetail, "Theta values disagree in '%s'",
355 <                                abname);
355 >                                        abname);
356                          return RC_DATERR;
357                  }
358                  abase_list[nabases].nangles +=
# Line 362 | Line 362 | load_angle_basis(ezxml_t wab)
362                                  (abase_list[nabases].lat[i].nphis == 1 &&
363                                  abase_list[nabases].lat[i].tmin > FTINY)) {
364                          sprintf(SDerrorDetail, "Illegal phi count in '%s'",
365 <                                abname);
365 >                                        abname);
366                          return RC_DATERR;
367                  }
368          }
# Line 631 | Line 631 | SDloadMtx(SDData *sd, ezxml_t wtl)
631   /* Get Matrix BSDF value */
632   static int
633   SDgetMtxBSDF(float coef[SDmaxCh], const FVECT outVec,
634 <                                const FVECT inVec, const void *dist)
634 >                                const FVECT inVec, SDComponent *sdc)
635   {
636 <        const SDMat     *dp = (const SDMat *)dist;
636 >        const SDMat     *dp;
637          int             i_ndx, o_ndx;
638 +                                        /* check arguments */
639 +        if ((coef == NULL) | (outVec == NULL) | (inVec == NULL) | (sdc == NULL)
640 +                        || (dp = (SDMat *)sdc->dist) == NULL)
641 +                return 0;
642                                          /* get angle indices */
643          i_ndx = mBSDF_incndx(dp, inVec);
644          o_ndx = mBSDF_outndx(dp, outVec);
# Line 649 | Line 653 | SDgetMtxBSDF(float coef[SDmaxCh], const FVECT outVec,
653          return 1;                       /* XXX monochrome for now */
654   }
655  
656 < /* Query solid angle for vector */
656 > /* Query solid angle for vector(s) */
657   static SDError
658   SDqueryMtxProjSA(double *psa, const FVECT v1, const RREAL *v2,
659 <                                        int qflags, const void *dist)
659 >                                        int qflags, SDComponent *sdc)
660   {
661 <        const SDMat     *dp = (const SDMat *)dist;
661 >        const SDMat     *dp;
662          double          inc_psa, out_psa;
663                                          /* check arguments */
664 <        if ((psa == NULL) | (v1 == NULL) | (dp == NULL))
664 >        if ((psa == NULL) | (v1 == NULL) | (sdc == NULL) ||
665 >                        (dp = (SDMat *)sdc->dist) == NULL)
666                  return SDEargument;
667          if (v2 == NULL)
668                  v2 = v1;
669                                          /* get projected solid angles */
670          out_psa = mBSDF_outohm(dp, mBSDF_outndx(dp, v1));
671          inc_psa = mBSDF_incohm(dp, mBSDF_incndx(dp, v2));
672 <        if ((out_psa <= 0) & (inc_psa <= 0)) {
672 >        if ((v1 != v2) & (out_psa <= 0) & (inc_psa <= 0)) {
673                  inc_psa = mBSDF_outohm(dp, mBSDF_outndx(dp, v2));
674                  out_psa = mBSDF_incohm(dp, mBSDF_incndx(dp, v1));
675          }
676  
677          switch (qflags) {               /* record based on flag settings */
673        case SDqueryVal:
674                psa[0] = .0;
675                /* fall through */
678          case SDqueryMax:
679                  if (inc_psa > psa[0])
680                          psa[0] = inc_psa;
# Line 680 | Line 682 | SDqueryMtxProjSA(double *psa, const FVECT v1, const RR
682                          psa[0] = out_psa;
683                  break;
684          case SDqueryMin+SDqueryMax:
685 <                if (inc_psa > psa[0])
685 >                if (inc_psa > psa[1])
686                          psa[1] = inc_psa;
687 <                if (out_psa > psa[0])
687 >                if (out_psa > psa[1])
688                          psa[1] = out_psa;
689                  /* fall through */
690 +        case SDqueryVal:
691 +                if (qflags == SDqueryVal)
692 +                        psa[0] = M_PI;
693 +                /* fall through */
694          case SDqueryMin:
695                  if ((inc_psa > 0) & (inc_psa < psa[0]))
696                          psa[0] = inc_psa;
# Line 731 | Line 737 | make_cdist(SDMatCDst *cd, const FVECT inVec, SDMat *dp
737   static const SDCDst *
738   SDgetMtxCDist(const FVECT inVec, SDComponent *sdc)
739   {
740 <        SDMat           *dp = (SDMat *)sdc->dist;
740 >        SDMat           *dp;
741          int             reverse;
742          SDMatCDst       myCD;
743          SDMatCDst       *cd, *cdlast;
744                                          /* check arguments */
745 <        if ((inVec == NULL) | (dp == NULL))
745 >        if ((inVec == NULL) | (sdc == NULL) ||
746 >                        (dp = (SDMat *)sdc->dist) == NULL)
747                  return NULL;
748          memset(&myCD, 0, sizeof(myCD));
749          myCD.indx = mBSDF_incndx(dp, inVec);
# Line 755 | Line 762 | SDgetMtxCDist(const FVECT inVec, SDComponent *sdc)
762                  reverse = 1;
763          }
764          cdlast = NULL;                  /* check for it in cache list */
765 <        for (cd = (SDMatCDst *)sdc->cdList;
766 <                                cd != NULL; cd = (SDMatCDst *)cd->next) {
765 >        for (cd = (SDMatCDst *)sdc->cdList; cd != NULL;
766 >                                cdlast = cd, cd = (SDMatCDst *)cd->next)
767                  if (cd->indx == myCD.indx && (cd->calen == myCD.calen) &
768                                          (cd->ob_priv == myCD.ob_priv) &
769                                          (cd->ob_vec == myCD.ob_vec))
770                          break;
764                cdlast = cd;
765        }
771          if (cd == NULL) {               /* need to allocate new entry */
772                  cd = (SDMatCDst *)malloc(sizeof(SDMatCDst) +
773 <                                        myCD.calen*sizeof(myCD.carr[0]));
773 >                                        sizeof(myCD.carr[0])*myCD.calen);
774                  if (cd == NULL)
775                          return NULL;
776                  *cd = myCD;             /* compute cumulative distribution */
# Line 785 | Line 790 | SDgetMtxCDist(const FVECT inVec, SDComponent *sdc)
790  
791   /* Sample cumulative distribution */
792   static SDError
793 < SDsampMtxCDist(FVECT outVec, double randX, const SDCDst *cdp)
793 > SDsampMtxCDist(FVECT ioVec, double randX, const SDCDst *cdp)
794   {
795          const unsigned  maxval = ~0;
796          const SDMatCDst *mcd = (const SDMatCDst *)cdp;
797          const unsigned  target = randX*maxval;
798          int             i, iupper, ilower;
799                                          /* check arguments */
800 <        if ((outVec == NULL) | (mcd == NULL))
800 >        if ((ioVec == NULL) | (mcd == NULL))
801                  return SDEargument;
802                                          /* binary search to find index */
803          ilower = 0; iupper = mcd->calen;
# Line 805 | Line 810 | SDsampMtxCDist(FVECT outVec, double randX, const SDCDs
810          randX = (randX*maxval - mcd->carr[ilower]) /
811                          (double)(mcd->carr[iupper] - mcd->carr[ilower]);
812                                          /* convert index to vector */
813 <        if ((*mcd->ob_vec)(outVec, i+randX, mcd->ob_priv))
813 >        if ((*mcd->ob_vec)(ioVec, i+randX, mcd->ob_priv))
814                  return SDEnone;
815 <        strcpy(SDerrorDetail, "BSDF sampling fault");
815 >        strcpy(SDerrorDetail, "Matrix BSDF sampling fault");
816          return SDEinternal;
817   }
818  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines