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.13 by greg, Sun Apr 24 20:16:52 2011 UTC vs.
Revision 3.22 by greg, Mon May 7 23:17:59 2012 UTC

# Line 11 | Line 11 | static const char RCSid[] = "$Id$";
11   *
12   */
13  
14 + #define _USE_MATH_DEFINES
15   #include "rtio.h"
16   #include <stdlib.h>
17   #include <math.h>
# Line 45 | Line 46 | typedef struct {
46   static ANGLE_BASIS      abase_list[MAXABASES] = {
47          {
48                  "LBNL/Klems Full", 145,
49 <                { {-5., 1},
49 >                { {0., 1},
50                  {5., 8},
51                  {15., 16},
52                  {25., 20},
# Line 57 | Line 58 | static ANGLE_BASIS     abase_list[MAXABASES] = {
58                  {90., 0} }
59          }, {
60                  "LBNL/Klems Half", 73,
61 <                { {-6.5, 1},
61 >                { {0., 1},
62                  {6.5, 8},
63                  {19.5, 12},
64                  {32.5, 16},
# Line 67 | Line 68 | static ANGLE_BASIS     abase_list[MAXABASES] = {
68                  {90., 0} }
69          }, {
70                  "LBNL/Klems Quarter", 41,
71 <                { {-9., 1},
71 >                { {0., 1},
72                  {9., 8},
73                  {27., 12},
74                  {46., 12},
# Line 86 | Line 87 | fequal(double a, double b)
87          return (a <= 1e-6) & (a >= -1e-6);
88   }
89  
89 /* Returns the name of the given tag */
90 #ifdef ezxml_name
91 #undef ezxml_name
92 static char *
93 ezxml_name(ezxml_t xml)
94 {
95        if (xml == NULL)
96                return NULL;
97        return xml->name;
98 }
99 #endif
100
90   /* Returns the given tag's character content or empty string if none */
91   #ifdef ezxml_txt
92   #undef ezxml_txt
# Line 189 | Line 178 | fo_getndx(const FVECT v, void *p)
178   {
179          ANGLE_BASIS     *ab = (ANGLE_BASIS *)p;
180          int     li, ndx;
181 <        double  pol, azi, d;
181 >        double  pol, azi;
182  
183          if (v == NULL)
184                  return -1;
# Line 229 | Line 218 | io_getohm(int ndx, void *p)
218          if (li == last_li)                      /* cached latitude? */
219                  return last_ohm;
220          last_li = li;
232        theta1 = M_PI/180. * ab->lat[li+1].tmin;
233        if (ab->lat[li].nphis == 1)             /* special case */
234                return last_ohm = M_PI*(1. - sq(cos(theta1)));
221          theta = M_PI/180. * ab->lat[li].tmin;
222 +        theta1 = M_PI/180. * ab->lat[li+1].tmin;
223          return last_ohm = M_PI*(sq(cos(theta)) - sq(cos(theta1))) /
224                                  (double)ab->lat[li].nphis;
225   }
# Line 346 | Line 333 | load_angle_basis(ezxml_t wab)
333                                  ezxml_child(ezxml_child(wbb,
334                                          "ThetaBounds"), "UpperTheta")));
335                  if (!i)
336 <                        abase_list[nabases].lat[i].tmin =
350 <                                        -abase_list[nabases].lat[i+1].tmin;
336 >                        abase_list[nabases].lat[0].tmin = 0;
337                  else if (!fequal(atof(ezxml_txt(ezxml_child(ezxml_child(wbb,
338                                          "ThetaBounds"), "LowerTheta"))),
339                                  abase_list[nabases].lat[i].tmin)) {
# Line 418 | Line 404 | load_bsdf_data(SDData *sd, ezxml_t wdb, int rowinc)
404          int             i;
405                                          /* allocate BSDF component */
406          sdata = ezxml_txt(ezxml_child(wdb, "WavelengthDataDirection"));
407 +        if (!sdata)
408 +                return RC_FAIL;
409          /*
410           * Remember that front and back are reversed from WINDOW 6 orientations
411           * Favor their "Front" (incoming light) since that's more often valid
# Line 507 | Line 495 | load_bsdf_data(SDData *sd, ezxml_t wdb, int rowinc)
495          df->comp[0].dist = dp;
496          df->comp[0].func = &SDhandleMtx;
497                                          /* read BSDF data */
498 <        sdata = ezxml_txt(ezxml_child(wdb,"ScatteringData"));
498 >        sdata = ezxml_txt(ezxml_child(wdb, "ScatteringData"));
499          if (!sdata || !*sdata) {
500                  sprintf(SDerrorDetail, "Missing BSDF ScatteringData in '%s'",
501                                  sd->name);
# Line 521 | Line 509 | load_bsdf_data(SDData *sd, ezxml_t wdb, int rowinc)
509                                          sd->name);
510                          return RC_FORMERR;
511                  }
512 <                while (*sdnext && isspace(*sdnext))
512 >                while (isspace(*sdnext))
513                          sdnext++;
514                  if (*sdnext == ',') sdnext++;
515                  if (rowinc) {
516                          int     r = i/dp->nout;
517 <                        int     c = i - c*dp->nout;
517 >                        int     c = i - r*dp->nout;
518                          mBSDF_value(dp,r,c) = atof(sdata);
519                  } else
520                          dp->bsdf[i] = atof(sdata);
# Line 546 | Line 534 | subtract_min(SDMat *sm)
534          for (i = n; --i; )
535                  if (sm->bsdf[i] < minv)
536                          minv = sm->bsdf[i];
537 +        
538 +        if (minv <= FTINY)
539 +                return .0;
540 +
541          for (i = n; i--; )
542                  sm->bsdf[i] -= minv;
543  
# Line 571 | Line 563 | extract_diffuse(SDValue *dv, SDSpectralDF *df)
563                  c_cmix(&dv->spec, dv->cieY, &dv->spec, ymin, &df->comp[n].cspec[0]);
564                  dv->cieY += ymin;
565          }
566 <        df->maxHemi -= dv->cieY;        /* adjust minimum hemispherical */
566 >        df->maxHemi -= dv->cieY;        /* adjust maximum hemispherical */
567                                          /* make sure everything is set */
568          c_ccvt(&dv->spec, C_CSXY+C_CSSPEC);
569   }
# Line 580 | Line 572 | extract_diffuse(SDValue *dv, SDSpectralDF *df)
572   SDError
573   SDloadMtx(SDData *sd, ezxml_t wtl)
574   {
575 <        ezxml_t                 wld, wdb;
576 <        int                     rowIn;
577 <        struct BSDF_data        *dp;
578 <        char                    *txt;
579 <        int                     rval;
588 <        
575 >        ezxml_t         wld, wdb;
576 >        int             rowIn;
577 >        char            *txt;
578 >        int             rval;
579 >                                        /* basic checks and data ordering */
580          txt = ezxml_txt(ezxml_child(ezxml_child(wtl,
581                          "DataDefinition"), "IncidentDataStructure"));
582          if (txt == NULL || !*txt) {
# Line 604 | Line 595 | SDloadMtx(SDData *sd, ezxml_t wtl)
595                                  sd->name);
596                  return SDEsupport;
597          }
598 <                                /* get angle basis */
599 <        rval = load_angle_basis(ezxml_child(ezxml_child(wtl,
600 <                                "DataDefinition"), "AngleBasis"));
601 <        if (rval < 0)
602 <                return convert_errcode(rval);
603 <                                /* load BSDF components */
598 >                                        /* get angle bases */
599 >        for (wld = ezxml_child(ezxml_child(wtl, "DataDefinition"), "AngleBasis");
600 >                                wld != NULL; wld = wld->next) {
601 >                rval = load_angle_basis(wld);
602 >                if (rval < 0)
603 >                        return convert_errcode(rval);
604 >        }
605 >                                        /* load BSDF components */
606          for (wld = ezxml_child(wtl, "WavelengthData");
607                                  wld != NULL; wld = wld->next) {
608                  if (strcasecmp(ezxml_txt(ezxml_child(wld,"Wavelength")),
# Line 620 | Line 613 | SDloadMtx(SDData *sd, ezxml_t wtl)
613                          if ((rval = load_bsdf_data(sd, wdb, rowIn)) < 0)
614                                  return convert_errcode(rval);
615          }
616 <                                /* separate diffuse components */
616 >                                        /* separate diffuse components */
617          extract_diffuse(&sd->rLambFront, sd->rf);
618          extract_diffuse(&sd->rLambBack, sd->rb);
619          extract_diffuse(&sd->tLamb, sd->tf);
620 <                                /* return success */
620 >                                        /* return success */
621          return SDEnone;
622   }
623  
# Line 687 | Line 680 | SDqueryMtxProjSA(double *psa, const FVECT v1, const RR
680                  if (out_psa > psa[1])
681                          psa[1] = out_psa;
682                  /* fall through */
690        case SDqueryMin:
683          case SDqueryVal:
684                  if (qflags == SDqueryVal)
685                          psa[0] = M_PI;
686 +                /* fall through */
687 +        case SDqueryMin:
688                  if ((inc_psa > 0) & (inc_psa < psa[0]))
689                          psa[0] = inc_psa;
690                  if ((out_psa > 0) & (out_psa < psa[0]))
# Line 761 | Line 755 | SDgetMtxCDist(const FVECT inVec, SDComponent *sdc)
755                  reverse = 1;
756          }
757          cdlast = NULL;                  /* check for it in cache list */
758 <        for (cd = (SDMatCDst *)sdc->cdList;
759 <                                cd != NULL; cd = (SDMatCDst *)cd->next) {
758 >        for (cd = (SDMatCDst *)sdc->cdList; cd != NULL;
759 >                                        cdlast = cd, cd = cd->next)
760                  if (cd->indx == myCD.indx && (cd->calen == myCD.calen) &
761                                          (cd->ob_priv == myCD.ob_priv) &
762                                          (cd->ob_vec == myCD.ob_vec))
763                          break;
770                cdlast = cd;
771        }
764          if (cd == NULL) {               /* need to allocate new entry */
765                  cd = (SDMatCDst *)malloc(sizeof(SDMatCDst) +
766 <                                        myCD.calen*sizeof(myCD.carr[0]));
766 >                                        sizeof(myCD.carr[0])*myCD.calen);
767                  if (cd == NULL)
768                          return NULL;
769                  *cd = myCD;             /* compute cumulative distribution */
# Line 783 | Line 775 | SDgetMtxCDist(const FVECT inVec, SDComponent *sdc)
775          }
776          if (cdlast != NULL) {           /* move entry to head of cache list */
777                  cdlast->next = cd->next;
778 <                cd->next = sdc->cdList;
778 >                cd->next = (SDMatCDst *)sdc->cdList;
779                  sdc->cdList = (SDCDst *)cd;
780          }
781          return (SDCDst *)cd;            /* ready to go */
# Line 803 | Line 795 | SDsampMtxCDist(FVECT ioVec, double randX, const SDCDst
795                                          /* binary search to find index */
796          ilower = 0; iupper = mcd->calen;
797          while ((i = (iupper + ilower) >> 1) != ilower)
798 <                if ((long)target >= (long)mcd->carr[i])
798 >                if (target >= mcd->carr[i])
799                          ilower = i;
800                  else
801                          iupper = i;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines