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

Comparing ray/src/common/bsdf.c (file contents):
Revision 2.15 by greg, Fri Feb 18 00:40:25 2011 UTC vs.
Revision 2.35 by greg, Sun Aug 21 22:38:12 2011 UTC

# Line 10 | Line 10 | static const char RCSid[] = "$Id$";
10   *
11   */
12  
13 + #define _USE_MATH_DEFINES
14   #include <stdio.h>
15   #include <stdlib.h>
16 + #include <string.h>
17   #include <math.h>
18 + #include <ctype.h>
19   #include "ezxml.h"
20   #include "hilbert.h"
21   #include "bsdf.h"
# Line 45 | Line 48 | int                    SDretainSet = SDretainNone;
48   SDError
49   SDreportEnglish(SDError ec, FILE *fp)
50   {
48        if (fp == NULL)
49                return ec;
51          if (!ec)
52                  return SDEnone;
53 +        if ((ec < SDEnone) | (ec > SDEunknown)) {
54 +                SDerrorDetail[0] = '\0';
55 +                ec = SDEunknown;
56 +        }
57 +        if (fp == NULL)
58 +                return ec;
59          fputs(SDerrorEnglish[ec], fp);
60          if (SDerrorDetail[0]) {
61                  fputs(": ", fp);
# Line 77 | Line 84 | to_meters(             /* return factor to convert given unit to
84  
85   /* Load geometric dimensions and description (if any) */
86   static SDError
87 < SDloadGeometry(SDData *dp, ezxml_t wdb)
87 > SDloadGeometry(SDData *sd, ezxml_t wdb)
88   {
89          ezxml_t         geom;
90          double          cfact;
91          const char      *fmt, *mgfstr;
92  
93 <        sprintf(SDerrorDetail, "Negative size in \"%s\"", dp->name);
94 <        dp->dim[0] = dp->dim[1] = dp->dim[2] = .0;
93 >        if (wdb == NULL)                /* no geometry section? */
94 >                return SDEnone;
95 >        sd->dim[0] = sd->dim[1] = sd->dim[2] = .0;
96          if ((geom = ezxml_child(wdb, "Width")) != NULL)
97 <                dp->dim[0] = atof(ezxml_txt(geom)) *
97 >                sd->dim[0] = atof(ezxml_txt(geom)) *
98                                  to_meters(ezxml_attr(geom, "unit"));
99          if ((geom = ezxml_child(wdb, "Height")) != NULL)
100 <                dp->dim[1] = atof(ezxml_txt(geom)) *
100 >                sd->dim[1] = atof(ezxml_txt(geom)) *
101                                  to_meters(ezxml_attr(geom, "unit"));
102          if ((geom = ezxml_child(wdb, "Thickness")) != NULL)
103 <                dp->dim[2] = atof(ezxml_txt(geom)) *
103 >                sd->dim[2] = atof(ezxml_txt(geom)) *
104                                  to_meters(ezxml_attr(geom, "unit"));
105 <        if ((dp->dim[0] < .0) | (dp->dim[1] < .0) | (dp->dim[2] < .0))
105 >        if ((sd->dim[0] < 0) | (sd->dim[1] < 0) | (sd->dim[2] < 0)) {
106 >                sprintf(SDerrorDetail, "Negative size in \"%s\"", sd->name);
107                  return SDEdata;
108 +        }
109          if ((geom = ezxml_child(wdb, "Geometry")) == NULL ||
110                          (mgfstr = ezxml_txt(geom)) == NULL)
111                  return SDEnone;
112 +        while (isspace(*mgfstr))
113 +                ++mgfstr;
114 +        if (!*mgfstr)
115 +                return SDEnone;
116          if ((fmt = ezxml_attr(geom, "format")) != NULL &&
117                          strcasecmp(fmt, "MGF")) {
118                  sprintf(SDerrorDetail,
119                          "Unrecognized geometry format '%s' in \"%s\"",
120 <                                        fmt, dp->name);
120 >                                        fmt, sd->name);
121                  return SDEsupport;
122          }
123          cfact = to_meters(ezxml_attr(geom, "unit"));
124 <        dp->mgf = (char *)malloc(strlen(mgfstr)+32);
125 <        if (dp->mgf == NULL) {
124 >        sd->mgf = (char *)malloc(strlen(mgfstr)+32);
125 >        if (sd->mgf == NULL) {
126                  strcpy(SDerrorDetail, "Out of memory in SDloadGeometry");
127                  return SDEmemory;
128          }
129          if (cfact < 0.99 || cfact > 1.01)
130 <                sprintf(dp->mgf, "xf -s %.5f\n%s\nxf\n", cfact, mgfstr);
130 >                sprintf(sd->mgf, "xf -s %.5f\n%s\nxf\n", cfact, mgfstr);
131          else
132 <                strcpy(dp->mgf, mgfstr);
132 >                strcpy(sd->mgf, mgfstr);
133          return SDEnone;
134   }
135  
122
136   /* Load a BSDF struct from the given file (free first and keep name) */
137   SDError
138   SDloadFile(SDData *sd, const char *fname)
139   {
140          SDError         lastErr;
141 <        ezxml_t         fl;
141 >        ezxml_t         fl, wtl;
142  
143          if ((sd == NULL) | (fname == NULL || !*fname))
144                  return SDEargument;
# Line 142 | Line 155 | SDloadFile(SDData *sd, const char *fname)
155                  ezxml_free(fl);
156                  return SDEformat;
157          }
158 +        if (strcmp(ezxml_name(fl), "WindowElement")) {
159 +                sprintf(SDerrorDetail,
160 +                        "BSDF \"%s\": top level node not 'WindowElement'",
161 +                                sd->name);
162 +                ezxml_free(fl);
163 +                return SDEformat;
164 +        }
165 +        wtl = ezxml_child(ezxml_child(fl, "Optical"), "Layer");
166 +        if (wtl == NULL) {
167 +                sprintf(SDerrorDetail, "BSDF \"%s\": no optical layer'",
168 +                                sd->name);
169 +                ezxml_free(fl);
170 +                return SDEformat;
171 +        }
172                                  /* load geometry if present */
173 <        if ((lastErr = SDloadGeometry(sd, fl)))
173 >        lastErr = SDloadGeometry(sd, ezxml_child(wtl, "Material"));
174 >        if (lastErr)
175                  return lastErr;
176                                  /* try loading variable resolution data */
177 <        lastErr = SDloadTre(sd, fl);
177 >        lastErr = SDloadTre(sd, wtl);
178                                  /* check our result */
179 <        switch (lastErr) {
180 <        case SDEformat:
181 <        case SDEdata:
154 <        case SDEsupport:        /* possibly we just tried the wrong format */
155 <                lastErr = SDloadMtx(sd, fl);
156 <                break;
157 <        default:                /* variable res. OK else serious error */
158 <                break;
159 <        }
179 >        if (lastErr == SDEsupport)      /* try matrix BSDF if not tree data */
180 >                lastErr = SDloadMtx(sd, wtl);
181 >                
182                                  /* done with XML file */
183          ezxml_free(fl);
184 <                                /* return success or failure */
185 <        return lastErr;
184 >        
185 >        if (lastErr) {          /* was there a load error? */
186 >                SDfreeBSDF(sd);
187 >                return lastErr;
188 >        }
189 >                                /* remove any insignificant components */
190 >        if (sd->rf != NULL && sd->rf->maxHemi <= .001) {
191 >                SDfreeSpectralDF(sd->rf); sd->rf = NULL;
192 >        }
193 >        if (sd->rb != NULL && sd->rb->maxHemi <= .001) {
194 >                SDfreeSpectralDF(sd->rb); sd->rb = NULL;
195 >        }
196 >        if (sd->tf != NULL && sd->tf->maxHemi <= .001) {
197 >                SDfreeSpectralDF(sd->tf); sd->tf = NULL;
198 >        }
199 >                                /* return success */
200 >        return SDEnone;
201   }
202  
203   /* Allocate new spectral distribution function */
# Line 213 | Line 250 | SDfreeSpectralDF(SDSpectralDF *df)
250                  return;
251          SDfreeCumulativeCache(df);
252          for (n = df->ncomp; n-- > 0; )
253 <                (*df->comp[n].func->freeSC)(df->comp[n].dist);
253 >                if (df->comp[n].dist != NULL)
254 >                        (*df->comp[n].func->freeSC)(df->comp[n].dist);
255          free(df);
256   }
257  
258   /* Shorten file path to useable BSDF name, removing suffix */
259   void
260 < SDclipName(char res[SDnameLn], const char *fname)
260 > SDclipName(char *res, const char *fname)
261   {
262          const char      *cp, *dot = NULL;
263          
# Line 237 | Line 275 | SDclipName(char res[SDnameLn], const char *fname)
275  
276   /* Initialize an unused BSDF struct (simply clears to zeroes) */
277   void
278 < SDclearBSDF(SDData *sd)
278 > SDclearBSDF(SDData *sd, const char *fname)
279   {
280 <        if (sd != NULL)
281 <                memset(sd, 0, sizeof(SDData));
280 >        if (sd == NULL)
281 >                return;
282 >        memset(sd, 0, sizeof(SDData));
283 >        if (fname == NULL)
284 >                return;
285 >        SDclipName(sd->name, fname);
286   }
287  
288   /* Free data associated with BSDF struct */
# Line 266 | Line 308 | SDfreeBSDF(SDData *sd)
308                  sd->tf = NULL;
309          }
310          sd->rLambFront.cieY = .0;
311 <        sd->rLambFront.spec.clock = 0;
311 >        sd->rLambFront.spec.flags = 0;
312          sd->rLambBack.cieY = .0;
313 <        sd->rLambBack.spec.clock = 0;
313 >        sd->rLambBack.spec.flags = 0;
314          sd->tLamb.cieY = .0;
315 <        sd->tLamb.spec.clock = 0;
315 >        sd->tLamb.spec.flags = 0;
316   }
317  
318   /* Find writeable BSDF by name, or allocate new cache entry if absent */
# Line 298 | Line 340 | SDgetCache(const char *bname)
340          sdl->next = SDcacheList;
341          SDcacheList = sdl;
342  
343 <        sdl->refcnt++;
343 >        sdl->refcnt = 1;
344          return &sdl->bsdf;
345   }
346  
# Line 342 | Line 384 | SDfreeCache(const SDData *sd)
384          for (sdl = SDcacheList; sdl != NULL; sdl = (sdLast=sdl)->next)
385                  if (&sdl->bsdf == sd)
386                          break;
387 <        if (sdl == NULL || --sdl->refcnt)
387 >        if (sdl == NULL || (sdl->refcnt -= (sdl->refcnt > 0)))
388                  return;                 /* missing or still in use */
389                                          /* keep unreferenced data? */
390          if (SDisLoaded(sd) && SDretainSet) {
# Line 365 | Line 407 | SDfreeCache(const SDData *sd)
407  
408   /* Sample an individual BSDF component */
409   SDError
410 < SDsampComponent(SDValue *sv, FVECT outVec, const FVECT inVec,
369 <                        double randX, SDComponent *sdc)
410 > SDsampComponent(SDValue *sv, FVECT ioVec, double randX, SDComponent *sdc)
411   {
412          float           coef[SDmaxCh];
413          SDError         ec;
414 +        FVECT           inVec;
415          const SDCDst    *cd;
416          double          d;
417          int             n;
418                                          /* check arguments */
419 <        if ((sv == NULL) | (outVec == NULL) | (inVec == NULL) | (sdc == NULL))
419 >        if ((sv == NULL) | (ioVec == NULL) | (sdc == NULL))
420                  return SDEargument;
421                                          /* get cumulative distribution */
422 +        VCOPY(inVec, ioVec);
423          cd = (*sdc->func->getCDist)(inVec, sdc);
424          if (cd == NULL)
425                  return SDEmemory;
426 <        if (cd->cTotal <= 1e-7) {       /* anything to sample? */
426 >        if (cd->cTotal <= 1e-6) {       /* anything to sample? */
427                  sv->spec = c_dfcolor;
428                  sv->cieY = .0;
429 <                memset(outVec, 0, 3*sizeof(double));
429 >                memset(ioVec, 0, 3*sizeof(double));
430                  return SDEnone;
431          }
432          sv->cieY = cd->cTotal;
433                                          /* compute sample direction */
434 <        ec = (*sdc->func->sampCDist)(outVec, randX, cd);
434 >        ec = (*sdc->func->sampCDist)(ioVec, randX, cd);
435          if (ec)
436                  return ec;
437                                          /* get BSDF color */
438 <        n = (*sdc->func->getBSDFs)(coef, outVec, inVec, sdc->dist);
438 >        n = (*sdc->func->getBSDFs)(coef, ioVec, inVec, sdc);
439          if (n <= 0) {
440                  strcpy(SDerrorDetail, "BSDF sample value error");
441                  return SDEinternal;
# Line 419 | Line 462 | SDmultiSamp(double t[], int n, double randX)
462          bitmask_t       ndx, coord[MS_MAXDIM];
463          
464          while (n > MS_MAXDIM)           /* punt for higher dimensions */
465 <                t[--n] = drand48();
465 >                t[--n] = rand()*(1./(RAND_MAX+.5));
466          nBits = (8*sizeof(bitmask_t) - 1) / n;
467          ndx = randX * (double)((bitmask_t)1 << (nBits*n));
468                                          /* get coordinate on Hilbert curve */
# Line 427 | Line 470 | SDmultiSamp(double t[], int n, double randX)
470                                          /* convert back to [0,1) range */
471          scale = 1. / (double)((bitmask_t)1 << nBits);
472          while (n--)
473 <                t[n] = scale * ((double)coord[n] + drand48());
473 >                t[n] = scale * ((double)coord[n] + rand()*(1./(RAND_MAX+.5)));
474   }
475  
476   #undef MS_MAXDIM
# Line 440 | Line 483 | SDdiffuseSamp(FVECT outVec, int outFront, double randX
483          SDmultiSamp(outVec, 2, randX);
484          SDsquare2disk(outVec, outVec[0], outVec[1]);
485          outVec[2] = 1. - outVec[0]*outVec[0] - outVec[1]*outVec[1];
486 <        if (outVec[2] > .0)             /* a bit of paranoia */
486 >        if (outVec[2] > 0)              /* a bit of paranoia */
487                  outVec[2] = sqrt(outVec[2]);
488          if (!outFront)                  /* going out back? */
489                  outVec[2] = -outVec[2];
# Line 448 | Line 491 | SDdiffuseSamp(FVECT outVec, int outFront, double randX
491  
492   /* Query projected solid angle coverage for non-diffuse BSDF direction */
493   SDError
494 < SDsizeBSDF(double *projSA, const FVECT vec, int qflags, const SDData *sd)
494 > SDsizeBSDF(double *projSA, const FVECT v1, const RREAL *v2,
495 >                                int qflags, const SDData *sd)
496   {
497 <        SDSpectralDF    *rdf;
497 >        SDSpectralDF    *rdf, *tdf;
498          SDError         ec;
499          int             i;
500                                          /* check arguments */
501 <        if ((projSA == NULL) | (vec == NULL) | (sd == NULL))
501 >        if ((projSA == NULL) | (v1 == NULL) | (sd == NULL))
502                  return SDEargument;
503                                          /* initialize extrema */
504 <        switch (qflags & SDqueryMin+SDqueryMax) {
504 >        switch (qflags) {
505          case SDqueryMax:
506                  projSA[0] = .0;
507                  break;
# Line 470 | Line 514 | SDsizeBSDF(double *projSA, const FVECT vec, int qflags
514          case 0:
515                  return SDEargument;
516          }
517 <        if (vec[2] > .0)                /* front surface query? */
517 >        if (v1[2] > 0)                  /* front surface query? */
518                  rdf = sd->rf;
519          else
520                  rdf = sd->rb;
521 +        tdf = sd->tf;
522 +        if (v2 != NULL)                 /* bidirectional? */
523 +                if (v1[2] > 0 ^ v2[2] > 0)
524 +                        rdf = NULL;
525 +                else
526 +                        tdf = NULL;
527          ec = SDEdata;                   /* run through components */
528          for (i = (rdf==NULL) ? 0 : rdf->ncomp; i--; ) {
529 <                ec = (*rdf->comp[i].func->queryProjSA)(projSA, vec, qflags,
530 <                                                        rdf->comp[i].dist);
529 >                ec = (*rdf->comp[i].func->queryProjSA)(projSA, v1, v2,
530 >                                                qflags, &rdf->comp[i]);
531                  if (ec)
532                          return ec;
533          }
534 <        for (i = (sd->tf==NULL) ? 0 : sd->tf->ncomp; i--; ) {
535 <                ec = (*sd->tf->comp[i].func->queryProjSA)(projSA, vec, qflags,
536 <                                                        sd->tf->comp[i].dist);
534 >        for (i = (tdf==NULL) ? 0 : tdf->ncomp; i--; ) {
535 >                ec = (*tdf->comp[i].func->queryProjSA)(projSA, v1, v2,
536 >                                                qflags, &tdf->comp[i]);
537                  if (ec)
538                          return ec;
539          }
540 <        return ec;
540 >        if (ec) {                       /* all diffuse? */
541 >                projSA[0] = M_PI;
542 >                if (qflags == SDqueryMin+SDqueryMax)
543 >                        projSA[1] = M_PI;
544 >        }
545 >        return SDEnone;
546   }
547  
548   /* Return BSDF for the given incident and scattered ray vectors */
# Line 502 | Line 557 | SDevalBSDF(SDValue *sv, const FVECT outVec, const FVEC
557          if ((sv == NULL) | (outVec == NULL) | (inVec == NULL) | (sd == NULL))
558                  return SDEargument;
559                                          /* whose side are we on? */
560 <        inFront = (inVec[2] > .0);
561 <        outFront = (outVec[2] > .0);
560 >        inFront = (inVec[2] > 0);
561 >        outFront = (outVec[2] > 0);
562                                          /* start with diffuse portion */
563          if (inFront & outFront) {
564                  *sv = sd->rLambFront;
# Line 520 | Line 575 | SDevalBSDF(SDValue *sv, const FVECT outVec, const FVEC
575          i = (sdf != NULL) ? sdf->ncomp : 0;
576          while (i-- > 0) {
577                  nch = (*sdf->comp[i].func->getBSDFs)(coef, outVec, inVec,
578 <                                                        sdf->comp[i].dist);
578 >                                                        &sdf->comp[i]);
579                  while (nch-- > 0) {
580                          c_cmix(&sv->spec, sv->cieY, &sv->spec,
581                                          coef[nch], &sdf->comp[i].cspec[nch]);
# Line 544 | Line 599 | SDdirectHemi(const FVECT inVec, int sflags, const SDDa
599          if ((inVec == NULL) | (sd == NULL))
600                  return .0;
601                                          /* gather diffuse components */
602 <        if (inVec[2] > .0) {
602 >        if (inVec[2] > 0) {
603                  hsum = sd->rLambFront.cieY;
604                  rdf = sd->rf;
605          } else /* !inFront */ {
# Line 575 | Line 630 | SDdirectHemi(const FVECT inVec, int sflags, const SDDa
630  
631   /* Sample BSDF direction based on the given random variable */
632   SDError
633 < SDsampBSDF(SDValue *sv, FVECT outVec, const FVECT inVec,
579 <                        double randX, int sflags, const SDData *sd)
633 > SDsampBSDF(SDValue *sv, FVECT ioVec, double randX, int sflags, const SDData *sd)
634   {
635          SDError         ec;
636 +        FVECT           inVec;
637          int             inFront;
638          SDSpectralDF    *rdf;
639          double          rdiff;
# Line 587 | Line 642 | SDsampBSDF(SDValue *sv, FVECT outVec, const FVECT inVe
642          SDComponent     *sdc;
643          const SDCDst    **cdarr = NULL;
644                                          /* check arguments */
645 <        if ((sv == NULL) | (outVec == NULL) | (inVec == NULL) | (sd == NULL) |
646 <                        (randX < .0) | (randX >= 1.))
645 >        if ((sv == NULL) | (ioVec == NULL) | (sd == NULL) |
646 >                        (randX < 0) | (randX >= 1.))
647                  return SDEargument;
648                                          /* whose side are we on? */
649 <        inFront = (inVec[2] > .0);
649 >        VCOPY(inVec, ioVec);
650 >        inFront = (inVec[2] > 0);
651                                          /* remember diffuse portions */
652          if (inFront) {
653                  *sv = sd->rLambFront;
# Line 629 | Line 685 | SDsampBSDF(SDValue *sv, FVECT outVec, const FVECT inVe
685                  }
686                  sv->cieY += cdarr[i]->cTotal;
687          }
688 <        if (sv->cieY <= 1e-7) {         /* anything to sample? */
688 >        if (sv->cieY <= 1e-6) {         /* anything to sample? */
689                  sv->cieY = .0;
690 <                memset(outVec, 0, 3*sizeof(double));
690 >                memset(ioVec, 0, 3*sizeof(double));
691                  return SDEnone;
692          }
693                                          /* scale random variable */
694          randX *= sv->cieY;
695                                          /* diffuse reflection? */
696          if (randX < rdiff) {
697 <                SDdiffuseSamp(outVec, inFront, randX/rdiff);
697 >                SDdiffuseSamp(ioVec, inFront, randX/rdiff);
698                  goto done;
699          }
700          randX -= rdiff;
# Line 646 | Line 702 | SDsampBSDF(SDValue *sv, FVECT outVec, const FVECT inVe
702          if ((sflags & SDsampDf+SDsampT) == SDsampDf+SDsampT) {
703                  if (randX < sd->tLamb.cieY) {
704                          sv->spec = sd->tLamb.spec;
705 <                        SDdiffuseSamp(outVec, !inFront, randX/sd->tLamb.cieY);
705 >                        SDdiffuseSamp(ioVec, !inFront, randX/sd->tLamb.cieY);
706                          goto done;
707                  }
708                  randX -= sd->tLamb.cieY;
# Line 658 | Line 714 | SDsampBSDF(SDValue *sv, FVECT outVec, const FVECT inVe
714                  return SDEinternal;
715                                          /* compute sample direction */
716          sdc = (i < nr) ? &rdf->comp[i] : &sd->tf->comp[i-nr];
717 <        ec = (*sdc->func->sampCDist)(outVec, randX/cdarr[i]->cTotal, cdarr[i]);
717 >        ec = (*sdc->func->sampCDist)(ioVec, randX/cdarr[i]->cTotal, cdarr[i]);
718          if (ec)
719                  return ec;
720                                          /* compute color */
721 <        j = (*sdc->func->getBSDFs)(coef, outVec, inVec, sdc->dist);
721 >        j = (*sdc->func->getBSDFs)(coef, ioVec, inVec, sdc);
722          if (j <= 0) {
723                  sprintf(SDerrorDetail, "BSDF \"%s\" sampling value error",
724                                  sd->name);
# Line 689 | Line 745 | SDcompXform(RREAL vMtx[3][3], const FVECT sNrm, const
745          if ((vMtx == NULL) | (sNrm == NULL) | (uVec == NULL))
746                  return SDEargument;
747          VCOPY(vMtx[2], sNrm);
748 <        if (normalize(vMtx[2]) == .0)
748 >        if (normalize(vMtx[2]) == 0)
749                  return SDEargument;
750          fcross(vMtx[0], uVec, vMtx[2]);
751 <        if (normalize(vMtx[0]) == .0)
751 >        if (normalize(vMtx[0]) == 0)
752                  return SDEargument;
753          fcross(vMtx[1], vMtx[2], vMtx[0]);
754          return SDEnone;
# Line 712 | Line 768 | SDinvXform(RREAL iMtx[3][3], RREAL vMtx[3][3])
768          mTmp[0][1] = vMtx[2][1]*vMtx[0][2] - vMtx[2][2]*vMtx[0][1];
769          mTmp[0][2] = vMtx[1][2]*vMtx[0][1] - vMtx[1][1]*vMtx[0][2];
770          d = vMtx[0][0]*mTmp[0][0] + vMtx[1][0]*mTmp[0][1] + vMtx[2][0]*mTmp[0][2];
771 <        if (d == .0) {
771 >        if (d == 0) {
772                  strcpy(SDerrorDetail, "Zero determinant in matrix inversion");
773                  return SDEargument;
774          }
# Line 739 | Line 795 | SDmapDir(FVECT resVec, RREAL vMtx[3][3], const FVECT i
795          if (vMtx == NULL) {             /* assume they just want to normalize */
796                  if (resVec != inpVec)
797                          VCOPY(resVec, inpVec);
798 <                return (normalize(resVec) > .0) ? SDEnone : SDEargument;
798 >                return (normalize(resVec) > 0) ? SDEnone : SDEargument;
799          }
800          vTmp[0] = DOT(vMtx[0], inpVec);
801          vTmp[1] = DOT(vMtx[1], inpVec);
802          vTmp[2] = DOT(vMtx[2], inpVec);
803 <        if (normalize(vTmp) == .0)
803 >        if (normalize(vTmp) == 0)
804                  return SDEargument;
805          VCOPY(resVec, vTmp);
806          return SDEnone;
# Line 759 | Line 815 | SDmapDir(FVECT resVec, RREAL vMtx[3][3], const FVECT i
815  
816   #include "standard.h"
817   #include "paths.h"
762 #include <ctype.h>
818  
819   #define MAXLATS         46              /* maximum number of latitudes */
820  
# Line 816 | Line 871 | static int     nabases = 3;    /* current number of defined b
871   static int
872   fequal(double a, double b)
873   {
874 <        if (b != .0)
874 >        if (b != 0)
875                  a = a/b - 1.;
876          return((a <= 1e-6) & (a >= -1e-6));
877   }
# Line 879 | Line 934 | ab_getndx(             /* get index corresponding to the given ve
934   {
935          ANGLE_BASIS  *ab = (ANGLE_BASIS *)p;
936          int     li, ndx;
937 <        double  pol, azi, d;
937 >        double  pol, azi;
938  
939          if ((v[2] < -1.0) | (v[2] > 1.0))
940                  return(-1);
# Line 1077 | Line 1132 | load_bsdf_data(                /* load BSDF distribution for this wa
1132                          break;
1133                  }
1134          if (i < 0) {
1135 <                sprintf(errmsg, "undefined RowAngleBasis '%s'", cbasis);
1135 >                sprintf(errmsg, "undefined RowAngleBasis '%s'", rbasis);
1136                  error(WARNING, errmsg);
1137                  return;
1138          }
# Line 1119 | Line 1174 | check_bsdf_data(       /* check that BSDF data is sane */
1174   )
1175   {
1176          double          *omega_iarr, *omega_oarr;
1177 <        double          dom, contrib, hemi_total, full_total;
1177 >        double          dom, hemi_total, full_total;
1178          int             nneg;
1179          FVECT           v;
1180          int             i, o;
# Line 1134 | Line 1189 | check_bsdf_data(       /* check that BSDF data is sane */
1189          hemi_total = .0;
1190          for (i = dp->ninc; i--; ) {
1191                  dom = getBSDF_incohm(dp,i);
1192 <                if (dom <= .0) {
1192 >                if (dom <= 0) {
1193                          error(WARNING, "zero/negative incoming solid angle");
1194                          continue;
1195                  }
# Line 1157 | Line 1212 | check_bsdf_data(       /* check that BSDF data is sane */
1212          hemi_total = .0;
1213          for (o = dp->nout; o--; ) {
1214                  dom = getBSDF_outohm(dp,o);
1215 <                if (dom <= .0) {
1215 >                if (dom <= 0) {
1216                          error(WARNING, "zero/negative outgoing solid angle");
1217                          continue;
1218                  }
# Line 1181 | Line 1236 | check_bsdf_data(       /* check that BSDF data is sane */
1236                  hemi_total = .0;
1237                  for (o = dp->nout; o--; ) {
1238                          double  f = BSDF_value(dp,i,o);
1239 <                        if (f >= .0)
1239 >                        if (f >= 0)
1240                                  hemi_total += f*omega_oarr[o];
1241                          else {
1242                                  nneg += (f < -FTINY);
# Line 1269 | Line 1324 | load_BSDF(             /* load BSDF data from file */
1324                  error(WARNING, errmsg);
1325                  ezxml_free(fl);
1326                  return(NULL);
1327 <        }              
1328 <        load_angle_basis(ezxml_child(ezxml_child(wtl,
1329 <                                "DataDefinition"), "AngleBasis"));
1327 >        }
1328 >        for (wld = ezxml_child(ezxml_child(wtl,
1329 >                                "DataDefinition"), "AngleBasis");
1330 >                        wld != NULL; wld = wld->next)
1331 >                load_angle_basis(wld);
1332          dp = (struct BSDF_data *)calloc(1, sizeof(struct BSDF_data));
1333          load_geometry(dp, ezxml_child(wtl, "Material"));
1334          for (wld = ezxml_child(wtl, "WavelengthData");

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines