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.17 by greg, Tue Jun 28 21:13:46 2011 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 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 418 | Line 407 | load_bsdf_data(SDData *sd, ezxml_t wdb, int rowinc)
407          int             i;
408                                          /* allocate BSDF component */
409          sdata = ezxml_txt(ezxml_child(wdb, "WavelengthDataDirection"));
410 +        if (!sdata)
411 +                return RC_FAIL;
412          /*
413           * Remember that front and back are reversed from WINDOW 6 orientations
414           * Favor their "Front" (incoming light) since that's more often valid
# Line 507 | Line 498 | load_bsdf_data(SDData *sd, ezxml_t wdb, int rowinc)
498          df->comp[0].dist = dp;
499          df->comp[0].func = &SDhandleMtx;
500                                          /* read BSDF data */
501 <        sdata = ezxml_txt(ezxml_child(wdb,"ScatteringData"));
501 >        sdata = ezxml_txt(ezxml_child(wdb, "ScatteringData"));
502          if (!sdata || !*sdata) {
503                  sprintf(SDerrorDetail, "Missing BSDF ScatteringData in '%s'",
504                                  sd->name);
# Line 521 | Line 512 | load_bsdf_data(SDData *sd, ezxml_t wdb, int rowinc)
512                                          sd->name);
513                          return RC_FORMERR;
514                  }
515 <                while (*sdnext && isspace(*sdnext))
515 >                while (isspace(*sdnext))
516                          sdnext++;
517                  if (*sdnext == ',') sdnext++;
518                  if (rowinc) {
519                          int     r = i/dp->nout;
520 <                        int     c = i - c*dp->nout;
520 >                        int     c = i - r*dp->nout;
521                          mBSDF_value(dp,r,c) = atof(sdata);
522                  } else
523                          dp->bsdf[i] = atof(sdata);
# Line 546 | Line 537 | subtract_min(SDMat *sm)
537          for (i = n; --i; )
538                  if (sm->bsdf[i] < minv)
539                          minv = sm->bsdf[i];
540 +        
541 +        if (minv <= FTINY)
542 +                return .0;
543 +
544          for (i = n; i--; )
545                  sm->bsdf[i] -= minv;
546  
# Line 571 | Line 566 | extract_diffuse(SDValue *dv, SDSpectralDF *df)
566                  c_cmix(&dv->spec, dv->cieY, &dv->spec, ymin, &df->comp[n].cspec[0]);
567                  dv->cieY += ymin;
568          }
569 <        df->maxHemi -= dv->cieY;        /* adjust minimum hemispherical */
569 >        df->maxHemi -= dv->cieY;        /* adjust maximum hemispherical */
570                                          /* make sure everything is set */
571          c_ccvt(&dv->spec, C_CSXY+C_CSSPEC);
572   }
# Line 580 | Line 575 | extract_diffuse(SDValue *dv, SDSpectralDF *df)
575   SDError
576   SDloadMtx(SDData *sd, ezxml_t wtl)
577   {
578 <        ezxml_t                 wld, wdb;
579 <        int                     rowIn;
580 <        struct BSDF_data        *dp;
581 <        char                    *txt;
582 <        int                     rval;
588 <        
578 >        ezxml_t         wld, wdb;
579 >        int             rowIn;
580 >        char            *txt;
581 >        int             rval;
582 >                                        /* basic checks and data ordering */
583          txt = ezxml_txt(ezxml_child(ezxml_child(wtl,
584                          "DataDefinition"), "IncidentDataStructure"));
585          if (txt == NULL || !*txt) {
# Line 604 | Line 598 | SDloadMtx(SDData *sd, ezxml_t wtl)
598                                  sd->name);
599                  return SDEsupport;
600          }
601 <                                /* get angle basis */
601 >                                        /* get angle basis */
602          rval = load_angle_basis(ezxml_child(ezxml_child(wtl,
603                                  "DataDefinition"), "AngleBasis"));
604          if (rval < 0)
605                  return convert_errcode(rval);
606 <                                /* load BSDF components */
606 >                                        /* load BSDF components */
607          for (wld = ezxml_child(wtl, "WavelengthData");
608                                  wld != NULL; wld = wld->next) {
609                  if (strcasecmp(ezxml_txt(ezxml_child(wld,"Wavelength")),
# Line 620 | Line 614 | SDloadMtx(SDData *sd, ezxml_t wtl)
614                          if ((rval = load_bsdf_data(sd, wdb, rowIn)) < 0)
615                                  return convert_errcode(rval);
616          }
617 <                                /* separate diffuse components */
617 >                                        /* separate diffuse components */
618          extract_diffuse(&sd->rLambFront, sd->rf);
619          extract_diffuse(&sd->rLambBack, sd->rb);
620          extract_diffuse(&sd->tLamb, sd->tf);
621 <                                /* return success */
621 >                                        /* return success */
622          return SDEnone;
623   }
624  
# Line 687 | Line 681 | SDqueryMtxProjSA(double *psa, const FVECT v1, const RR
681                  if (out_psa > psa[1])
682                          psa[1] = out_psa;
683                  /* fall through */
690        case SDqueryMin:
684          case SDqueryVal:
685                  if (qflags == SDqueryVal)
686                          psa[0] = M_PI;
687 +                /* fall through */
688 +        case SDqueryMin:
689                  if ((inc_psa > 0) & (inc_psa < psa[0]))
690                          psa[0] = inc_psa;
691                  if ((out_psa > 0) & (out_psa < psa[0]))
# Line 761 | Line 756 | SDgetMtxCDist(const FVECT inVec, SDComponent *sdc)
756                  reverse = 1;
757          }
758          cdlast = NULL;                  /* check for it in cache list */
759 <        for (cd = (SDMatCDst *)sdc->cdList;
760 <                                cd != NULL; cd = (SDMatCDst *)cd->next) {
759 >        for (cd = (SDMatCDst *)sdc->cdList; cd != NULL;
760 >                                cdlast = cd, cd = (SDMatCDst *)cd->next)
761                  if (cd->indx == myCD.indx && (cd->calen == myCD.calen) &
762                                          (cd->ob_priv == myCD.ob_priv) &
763                                          (cd->ob_vec == myCD.ob_vec))
764                          break;
770                cdlast = cd;
771        }
765          if (cd == NULL) {               /* need to allocate new entry */
766                  cd = (SDMatCDst *)malloc(sizeof(SDMatCDst) +
767 <                                        myCD.calen*sizeof(myCD.carr[0]));
767 >                                        sizeof(myCD.carr[0])*myCD.calen);
768                  if (cd == NULL)
769                          return NULL;
770                  *cd = myCD;             /* compute cumulative distribution */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines