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.16 by greg, Thu Jun 9 17:09:39 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 418 | Line 419 | load_bsdf_data(SDData *sd, ezxml_t wdb, int rowinc)
419          int             i;
420                                          /* allocate BSDF component */
421          sdata = ezxml_txt(ezxml_child(wdb, "WavelengthDataDirection"));
422 +        if (!sdata)
423 +                return RC_FAIL;
424          /*
425           * Remember that front and back are reversed from WINDOW 6 orientations
426           * Favor their "Front" (incoming light) since that's more often valid
# Line 507 | Line 510 | load_bsdf_data(SDData *sd, ezxml_t wdb, int rowinc)
510          df->comp[0].dist = dp;
511          df->comp[0].func = &SDhandleMtx;
512                                          /* read BSDF data */
513 <        sdata = ezxml_txt(ezxml_child(wdb,"ScatteringData"));
513 >        sdata = ezxml_txt(ezxml_child(wdb, "ScatteringData"));
514          if (!sdata || !*sdata) {
515                  sprintf(SDerrorDetail, "Missing BSDF ScatteringData in '%s'",
516                                  sd->name);
# Line 521 | Line 524 | load_bsdf_data(SDData *sd, ezxml_t wdb, int rowinc)
524                                          sd->name);
525                          return RC_FORMERR;
526                  }
527 <                while (*sdnext && isspace(*sdnext))
527 >                while (isspace(*sdnext))
528                          sdnext++;
529                  if (*sdnext == ',') sdnext++;
530                  if (rowinc) {
531                          int     r = i/dp->nout;
532 <                        int     c = i - c*dp->nout;
532 >                        int     c = i - r*dp->nout;
533                          mBSDF_value(dp,r,c) = atof(sdata);
534                  } else
535                          dp->bsdf[i] = atof(sdata);
# Line 546 | Line 549 | subtract_min(SDMat *sm)
549          for (i = n; --i; )
550                  if (sm->bsdf[i] < minv)
551                          minv = sm->bsdf[i];
552 +        
553 +        if (minv <= FTINY)
554 +                return .0;
555 +
556          for (i = n; i--; )
557                  sm->bsdf[i] -= minv;
558  
# Line 571 | Line 578 | extract_diffuse(SDValue *dv, SDSpectralDF *df)
578                  c_cmix(&dv->spec, dv->cieY, &dv->spec, ymin, &df->comp[n].cspec[0]);
579                  dv->cieY += ymin;
580          }
581 <        df->maxHemi -= dv->cieY;        /* adjust minimum hemispherical */
581 >        df->maxHemi -= dv->cieY;        /* adjust maximum hemispherical */
582                                          /* make sure everything is set */
583          c_ccvt(&dv->spec, C_CSXY+C_CSSPEC);
584   }
# Line 580 | Line 587 | extract_diffuse(SDValue *dv, SDSpectralDF *df)
587   SDError
588   SDloadMtx(SDData *sd, ezxml_t wtl)
589   {
590 <        ezxml_t                 wld, wdb;
591 <        int                     rowIn;
592 <        struct BSDF_data        *dp;
593 <        char                    *txt;
594 <        int                     rval;
588 <        
590 >        ezxml_t         wld, wdb;
591 >        int             rowIn;
592 >        char            *txt;
593 >        int             rval;
594 >                                        /* basic checks and data ordering */
595          txt = ezxml_txt(ezxml_child(ezxml_child(wtl,
596                          "DataDefinition"), "IncidentDataStructure"));
597          if (txt == NULL || !*txt) {
# Line 604 | Line 610 | SDloadMtx(SDData *sd, ezxml_t wtl)
610                                  sd->name);
611                  return SDEsupport;
612          }
613 <                                /* get angle basis */
613 >                                        /* get angle basis */
614          rval = load_angle_basis(ezxml_child(ezxml_child(wtl,
615                                  "DataDefinition"), "AngleBasis"));
616          if (rval < 0)
617                  return convert_errcode(rval);
618 <                                /* load BSDF components */
618 >                                        /* load BSDF components */
619          for (wld = ezxml_child(wtl, "WavelengthData");
620                                  wld != NULL; wld = wld->next) {
621                  if (strcasecmp(ezxml_txt(ezxml_child(wld,"Wavelength")),
# Line 620 | Line 626 | SDloadMtx(SDData *sd, ezxml_t wtl)
626                          if ((rval = load_bsdf_data(sd, wdb, rowIn)) < 0)
627                                  return convert_errcode(rval);
628          }
629 <                                /* separate diffuse components */
629 >                                        /* separate diffuse components */
630          extract_diffuse(&sd->rLambFront, sd->rf);
631          extract_diffuse(&sd->rLambBack, sd->rb);
632          extract_diffuse(&sd->tLamb, sd->tf);
633 <                                /* return success */
633 >                                        /* return success */
634          return SDEnone;
635   }
636  
# Line 687 | Line 693 | SDqueryMtxProjSA(double *psa, const FVECT v1, const RR
693                  if (out_psa > psa[1])
694                          psa[1] = out_psa;
695                  /* fall through */
690        case SDqueryMin:
696          case SDqueryVal:
697                  if (qflags == SDqueryVal)
698                          psa[0] = M_PI;
699 +                /* fall through */
700 +        case SDqueryMin:
701                  if ((inc_psa > 0) & (inc_psa < psa[0]))
702                          psa[0] = inc_psa;
703                  if ((out_psa > 0) & (out_psa < psa[0]))
# Line 761 | Line 768 | SDgetMtxCDist(const FVECT inVec, SDComponent *sdc)
768                  reverse = 1;
769          }
770          cdlast = NULL;                  /* check for it in cache list */
771 <        for (cd = (SDMatCDst *)sdc->cdList;
772 <                                cd != NULL; cd = (SDMatCDst *)cd->next) {
771 >        for (cd = (SDMatCDst *)sdc->cdList; cd != NULL;
772 >                                cdlast = cd, cd = (SDMatCDst *)cd->next)
773                  if (cd->indx == myCD.indx && (cd->calen == myCD.calen) &
774                                          (cd->ob_priv == myCD.ob_priv) &
775                                          (cd->ob_vec == myCD.ob_vec))
776                          break;
770                cdlast = cd;
771        }
777          if (cd == NULL) {               /* need to allocate new entry */
778                  cd = (SDMatCDst *)malloc(sizeof(SDMatCDst) +
779 <                                        myCD.calen*sizeof(myCD.carr[0]));
779 >                                        sizeof(myCD.carr[0])*myCD.calen);
780                  if (cd == NULL)
781                          return NULL;
782                  *cd = myCD;             /* compute cumulative distribution */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines