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.38 by greg, Sun Mar 4 23:28:34 2012 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 >        SDerrorDetail[0] = '\0';
97          if ((geom = ezxml_child(wdb, "Width")) != NULL)
98 <                dp->dim[0] = atof(ezxml_txt(geom)) *
98 >                sd->dim[0] = atof(ezxml_txt(geom)) *
99                                  to_meters(ezxml_attr(geom, "unit"));
100          if ((geom = ezxml_child(wdb, "Height")) != NULL)
101 <                dp->dim[1] = atof(ezxml_txt(geom)) *
101 >                sd->dim[1] = atof(ezxml_txt(geom)) *
102                                  to_meters(ezxml_attr(geom, "unit"));
103          if ((geom = ezxml_child(wdb, "Thickness")) != NULL)
104 <                dp->dim[2] = atof(ezxml_txt(geom)) *
104 >                sd->dim[2] = atof(ezxml_txt(geom)) *
105                                  to_meters(ezxml_attr(geom, "unit"));
106 <        if ((dp->dim[0] < .0) | (dp->dim[1] < .0) | (dp->dim[2] < .0))
106 >        if ((sd->dim[0] < 0) | (sd->dim[1] < 0) | (sd->dim[2] < 0)) {
107 >                if (!SDerrorDetail[0])
108 >                        sprintf(SDerrorDetail, "Negative dimension in \"%s\"",
109 >                                                sd->name);
110                  return SDEdata;
111 +        }
112          if ((geom = ezxml_child(wdb, "Geometry")) == NULL ||
113                          (mgfstr = ezxml_txt(geom)) == NULL)
114                  return SDEnone;
115 +        while (isspace(*mgfstr))
116 +                ++mgfstr;
117 +        if (!*mgfstr)
118 +                return SDEnone;
119          if ((fmt = ezxml_attr(geom, "format")) != NULL &&
120                          strcasecmp(fmt, "MGF")) {
121                  sprintf(SDerrorDetail,
122                          "Unrecognized geometry format '%s' in \"%s\"",
123 <                                        fmt, dp->name);
123 >                                        fmt, sd->name);
124                  return SDEsupport;
125          }
126          cfact = to_meters(ezxml_attr(geom, "unit"));
127 <        dp->mgf = (char *)malloc(strlen(mgfstr)+32);
128 <        if (dp->mgf == NULL) {
127 >        if (cfact <= 0)
128 >                return SDEformat;
129 >        sd->mgf = (char *)malloc(strlen(mgfstr)+32);
130 >        if (sd->mgf == NULL) {
131                  strcpy(SDerrorDetail, "Out of memory in SDloadGeometry");
132                  return SDEmemory;
133          }
134          if (cfact < 0.99 || cfact > 1.01)
135 <                sprintf(dp->mgf, "xf -s %.5f\n%s\nxf\n", cfact, mgfstr);
135 >                sprintf(sd->mgf, "xf -s %.5f\n%s\nxf\n", cfact, mgfstr);
136          else
137 <                strcpy(dp->mgf, mgfstr);
137 >                strcpy(sd->mgf, mgfstr);
138          return SDEnone;
139   }
140  
122
141   /* Load a BSDF struct from the given file (free first and keep name) */
142   SDError
143   SDloadFile(SDData *sd, const char *fname)
144   {
145          SDError         lastErr;
146 <        ezxml_t         fl;
146 >        ezxml_t         fl, wtl;
147  
148          if ((sd == NULL) | (fname == NULL || !*fname))
149                  return SDEargument;
# Line 142 | Line 160 | SDloadFile(SDData *sd, const char *fname)
160                  ezxml_free(fl);
161                  return SDEformat;
162          }
163 +        if (strcmp(ezxml_name(fl), "WindowElement")) {
164 +                sprintf(SDerrorDetail,
165 +                        "BSDF \"%s\": top level node not 'WindowElement'",
166 +                                sd->name);
167 +                ezxml_free(fl);
168 +                return SDEformat;
169 +        }
170 +        wtl = ezxml_child(ezxml_child(fl, "Optical"), "Layer");
171 +        if (wtl == NULL) {
172 +                sprintf(SDerrorDetail, "BSDF \"%s\": no optical layers'",
173 +                                sd->name);
174 +                ezxml_free(fl);
175 +                return SDEformat;
176 +        }
177                                  /* load geometry if present */
178 <        if ((lastErr = SDloadGeometry(sd, fl)))
178 >        lastErr = SDloadGeometry(sd, ezxml_child(wtl, "Material"));
179 >        if (lastErr) {
180 >                ezxml_free(fl);
181                  return lastErr;
182 +        }
183                                  /* try loading variable resolution data */
184 <        lastErr = SDloadTre(sd, fl);
184 >        lastErr = SDloadTre(sd, wtl);
185                                  /* check our result */
186 <        switch (lastErr) {
187 <        case SDEformat:
188 <        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 <        }
186 >        if (lastErr == SDEsupport)      /* try matrix BSDF if not tree data */
187 >                lastErr = SDloadMtx(sd, wtl);
188 >                
189                                  /* done with XML file */
190          ezxml_free(fl);
191 <                                /* return success or failure */
192 <        return lastErr;
191 >        
192 >        if (lastErr) {          /* was there a load error? */
193 >                SDfreeBSDF(sd);
194 >                return lastErr;
195 >        }
196 >                                /* remove any insignificant components */
197 >        if (sd->rf != NULL && sd->rf->maxHemi <= .001) {
198 >                SDfreeSpectralDF(sd->rf); sd->rf = NULL;
199 >        }
200 >        if (sd->rb != NULL && sd->rb->maxHemi <= .001) {
201 >                SDfreeSpectralDF(sd->rb); sd->rb = NULL;
202 >        }
203 >        if (sd->tf != NULL && sd->tf->maxHemi <= .001) {
204 >                SDfreeSpectralDF(sd->tf); sd->tf = NULL;
205 >        }
206 >                                /* return success */
207 >        return SDEnone;
208   }
209  
210   /* Allocate new spectral distribution function */
# Line 187 | Line 231 | SDnewSpectralDF(int nc)
231          return df;
232   }
233  
234 + /* Add component(s) to spectral distribution function */
235 + SDSpectralDF *
236 + SDaddComponent(SDSpectralDF *odf, int nadd)
237 + {
238 +        SDSpectralDF    *df;
239 +
240 +        if (odf == NULL)
241 +                return SDnewSpectralDF(nadd);
242 +        if (nadd <= 0)
243 +                return odf;
244 +        df = (SDSpectralDF *)realloc(odf, sizeof(SDSpectralDF) +
245 +                                (odf->ncomp+nadd-1)*sizeof(SDComponent));
246 +        if (df == NULL) {
247 +                sprintf(SDerrorDetail,
248 +                        "Cannot add %d component(s) to spectral DF", nadd);
249 +                SDfreeSpectralDF(odf);
250 +                return NULL;
251 +        }
252 +        memset(df->comp+df->ncomp, 0, nadd*sizeof(SDComponent));
253 +        df->ncomp += nadd;
254 +        return df;
255 + }
256 +
257   /* Free cached cumulative distributions for BSDF component */
258   void
259   SDfreeCumulativeCache(SDSpectralDF *df)
# Line 213 | Line 280 | SDfreeSpectralDF(SDSpectralDF *df)
280                  return;
281          SDfreeCumulativeCache(df);
282          for (n = df->ncomp; n-- > 0; )
283 <                (*df->comp[n].func->freeSC)(df->comp[n].dist);
283 >                if (df->comp[n].dist != NULL)
284 >                        (*df->comp[n].func->freeSC)(df->comp[n].dist);
285          free(df);
286   }
287  
288   /* Shorten file path to useable BSDF name, removing suffix */
289   void
290 < SDclipName(char res[SDnameLn], const char *fname)
290 > SDclipName(char *res, const char *fname)
291   {
292          const char      *cp, *dot = NULL;
293          
# Line 237 | Line 305 | SDclipName(char res[SDnameLn], const char *fname)
305  
306   /* Initialize an unused BSDF struct (simply clears to zeroes) */
307   void
308 < SDclearBSDF(SDData *sd)
308 > SDclearBSDF(SDData *sd, const char *fname)
309   {
310 <        if (sd != NULL)
311 <                memset(sd, 0, sizeof(SDData));
310 >        if (sd == NULL)
311 >                return;
312 >        memset(sd, 0, sizeof(SDData));
313 >        if (fname == NULL)
314 >                return;
315 >        SDclipName(sd->name, fname);
316   }
317  
318   /* Free data associated with BSDF struct */
# Line 266 | Line 338 | SDfreeBSDF(SDData *sd)
338                  sd->tf = NULL;
339          }
340          sd->rLambFront.cieY = .0;
341 <        sd->rLambFront.spec.clock = 0;
341 >        sd->rLambFront.spec.flags = 0;
342          sd->rLambBack.cieY = .0;
343 <        sd->rLambBack.spec.clock = 0;
343 >        sd->rLambBack.spec.flags = 0;
344          sd->tLamb.cieY = .0;
345 <        sd->tLamb.spec.clock = 0;
345 >        sd->tLamb.spec.flags = 0;
346   }
347  
348   /* Find writeable BSDF by name, or allocate new cache entry if absent */
# Line 298 | Line 370 | SDgetCache(const char *bname)
370          sdl->next = SDcacheList;
371          SDcacheList = sdl;
372  
373 <        sdl->refcnt++;
373 >        sdl->refcnt = 1;
374          return &sdl->bsdf;
375   }
376  
# Line 342 | Line 414 | SDfreeCache(const SDData *sd)
414          for (sdl = SDcacheList; sdl != NULL; sdl = (sdLast=sdl)->next)
415                  if (&sdl->bsdf == sd)
416                          break;
417 <        if (sdl == NULL || --sdl->refcnt)
417 >        if (sdl == NULL || (sdl->refcnt -= (sdl->refcnt > 0)))
418                  return;                 /* missing or still in use */
419                                          /* keep unreferenced data? */
420          if (SDisLoaded(sd) && SDretainSet) {
# Line 365 | Line 437 | SDfreeCache(const SDData *sd)
437  
438   /* Sample an individual BSDF component */
439   SDError
440 < SDsampComponent(SDValue *sv, FVECT outVec, const FVECT inVec,
369 <                        double randX, SDComponent *sdc)
440 > SDsampComponent(SDValue *sv, FVECT ioVec, double randX, SDComponent *sdc)
441   {
442          float           coef[SDmaxCh];
443          SDError         ec;
444 +        FVECT           inVec;
445          const SDCDst    *cd;
446          double          d;
447          int             n;
448                                          /* check arguments */
449 <        if ((sv == NULL) | (outVec == NULL) | (inVec == NULL) | (sdc == NULL))
449 >        if ((sv == NULL) | (ioVec == NULL) | (sdc == NULL))
450                  return SDEargument;
451                                          /* get cumulative distribution */
452 +        VCOPY(inVec, ioVec);
453          cd = (*sdc->func->getCDist)(inVec, sdc);
454          if (cd == NULL)
455                  return SDEmemory;
456 <        if (cd->cTotal <= 1e-7) {       /* anything to sample? */
456 >        if (cd->cTotal <= 1e-6) {       /* anything to sample? */
457                  sv->spec = c_dfcolor;
458                  sv->cieY = .0;
459 <                memset(outVec, 0, 3*sizeof(double));
459 >                memset(ioVec, 0, 3*sizeof(double));
460                  return SDEnone;
461          }
462          sv->cieY = cd->cTotal;
463                                          /* compute sample direction */
464 <        ec = (*sdc->func->sampCDist)(outVec, randX, cd);
464 >        ec = (*sdc->func->sampCDist)(ioVec, randX, cd);
465          if (ec)
466                  return ec;
467                                          /* get BSDF color */
468 <        n = (*sdc->func->getBSDFs)(coef, outVec, inVec, sdc->dist);
468 >        n = (*sdc->func->getBSDFs)(coef, ioVec, inVec, sdc);
469          if (n <= 0) {
470                  strcpy(SDerrorDetail, "BSDF sample value error");
471                  return SDEinternal;
# Line 419 | Line 492 | SDmultiSamp(double t[], int n, double randX)
492          bitmask_t       ndx, coord[MS_MAXDIM];
493          
494          while (n > MS_MAXDIM)           /* punt for higher dimensions */
495 <                t[--n] = drand48();
495 >                t[--n] = rand()*(1./(RAND_MAX+.5));
496          nBits = (8*sizeof(bitmask_t) - 1) / n;
497          ndx = randX * (double)((bitmask_t)1 << (nBits*n));
498                                          /* get coordinate on Hilbert curve */
# Line 427 | Line 500 | SDmultiSamp(double t[], int n, double randX)
500                                          /* convert back to [0,1) range */
501          scale = 1. / (double)((bitmask_t)1 << nBits);
502          while (n--)
503 <                t[n] = scale * ((double)coord[n] + drand48());
503 >                t[n] = scale * ((double)coord[n] + rand()*(1./(RAND_MAX+.5)));
504   }
505  
506   #undef MS_MAXDIM
# Line 440 | Line 513 | SDdiffuseSamp(FVECT outVec, int outFront, double randX
513          SDmultiSamp(outVec, 2, randX);
514          SDsquare2disk(outVec, outVec[0], outVec[1]);
515          outVec[2] = 1. - outVec[0]*outVec[0] - outVec[1]*outVec[1];
516 <        if (outVec[2] > .0)             /* a bit of paranoia */
516 >        if (outVec[2] > 0)              /* a bit of paranoia */
517                  outVec[2] = sqrt(outVec[2]);
518          if (!outFront)                  /* going out back? */
519                  outVec[2] = -outVec[2];
# Line 448 | Line 521 | SDdiffuseSamp(FVECT outVec, int outFront, double randX
521  
522   /* Query projected solid angle coverage for non-diffuse BSDF direction */
523   SDError
524 < SDsizeBSDF(double *projSA, const FVECT vec, int qflags, const SDData *sd)
524 > SDsizeBSDF(double *projSA, const FVECT v1, const RREAL *v2,
525 >                                int qflags, const SDData *sd)
526   {
527 <        SDSpectralDF    *rdf;
527 >        SDSpectralDF    *rdf, *tdf;
528          SDError         ec;
529          int             i;
530                                          /* check arguments */
531 <        if ((projSA == NULL) | (vec == NULL) | (sd == NULL))
531 >        if ((projSA == NULL) | (v1 == NULL) | (sd == NULL))
532                  return SDEargument;
533                                          /* initialize extrema */
534 <        switch (qflags & SDqueryMin+SDqueryMax) {
534 >        switch (qflags) {
535          case SDqueryMax:
536                  projSA[0] = .0;
537                  break;
# Line 470 | Line 544 | SDsizeBSDF(double *projSA, const FVECT vec, int qflags
544          case 0:
545                  return SDEargument;
546          }
547 <        if (vec[2] > .0)                /* front surface query? */
547 >        if (v1[2] > 0)                  /* front surface query? */
548                  rdf = sd->rf;
549          else
550                  rdf = sd->rb;
551 +        tdf = sd->tf;
552 +        if (v2 != NULL)                 /* bidirectional? */
553 +                if (v1[2] > 0 ^ v2[2] > 0)
554 +                        rdf = NULL;
555 +                else
556 +                        tdf = NULL;
557          ec = SDEdata;                   /* run through components */
558          for (i = (rdf==NULL) ? 0 : rdf->ncomp; i--; ) {
559 <                ec = (*rdf->comp[i].func->queryProjSA)(projSA, vec, qflags,
560 <                                                        rdf->comp[i].dist);
559 >                ec = (*rdf->comp[i].func->queryProjSA)(projSA, v1, v2,
560 >                                                qflags, &rdf->comp[i]);
561                  if (ec)
562                          return ec;
563          }
564 <        for (i = (sd->tf==NULL) ? 0 : sd->tf->ncomp; i--; ) {
565 <                ec = (*sd->tf->comp[i].func->queryProjSA)(projSA, vec, qflags,
566 <                                                        sd->tf->comp[i].dist);
564 >        for (i = (tdf==NULL) ? 0 : tdf->ncomp; i--; ) {
565 >                ec = (*tdf->comp[i].func->queryProjSA)(projSA, v1, v2,
566 >                                                qflags, &tdf->comp[i]);
567                  if (ec)
568                          return ec;
569          }
570 <        return ec;
570 >        if (ec) {                       /* all diffuse? */
571 >                projSA[0] = M_PI;
572 >                if (qflags == SDqueryMin+SDqueryMax)
573 >                        projSA[1] = M_PI;
574 >        }
575 >        return SDEnone;
576   }
577  
578   /* Return BSDF for the given incident and scattered ray vectors */
# Line 502 | Line 587 | SDevalBSDF(SDValue *sv, const FVECT outVec, const FVEC
587          if ((sv == NULL) | (outVec == NULL) | (inVec == NULL) | (sd == NULL))
588                  return SDEargument;
589                                          /* whose side are we on? */
590 <        inFront = (inVec[2] > .0);
591 <        outFront = (outVec[2] > .0);
590 >        inFront = (inVec[2] > 0);
591 >        outFront = (outVec[2] > 0);
592                                          /* start with diffuse portion */
593          if (inFront & outFront) {
594                  *sv = sd->rLambFront;
# Line 520 | Line 605 | SDevalBSDF(SDValue *sv, const FVECT outVec, const FVEC
605          i = (sdf != NULL) ? sdf->ncomp : 0;
606          while (i-- > 0) {
607                  nch = (*sdf->comp[i].func->getBSDFs)(coef, outVec, inVec,
608 <                                                        sdf->comp[i].dist);
608 >                                                        &sdf->comp[i]);
609                  while (nch-- > 0) {
610                          c_cmix(&sv->spec, sv->cieY, &sv->spec,
611                                          coef[nch], &sdf->comp[i].cspec[nch]);
# Line 544 | Line 629 | SDdirectHemi(const FVECT inVec, int sflags, const SDDa
629          if ((inVec == NULL) | (sd == NULL))
630                  return .0;
631                                          /* gather diffuse components */
632 <        if (inVec[2] > .0) {
632 >        if (inVec[2] > 0) {
633                  hsum = sd->rLambFront.cieY;
634                  rdf = sd->rf;
635          } else /* !inFront */ {
# Line 575 | Line 660 | SDdirectHemi(const FVECT inVec, int sflags, const SDDa
660  
661   /* Sample BSDF direction based on the given random variable */
662   SDError
663 < SDsampBSDF(SDValue *sv, FVECT outVec, const FVECT inVec,
579 <                        double randX, int sflags, const SDData *sd)
663 > SDsampBSDF(SDValue *sv, FVECT ioVec, double randX, int sflags, const SDData *sd)
664   {
665          SDError         ec;
666 +        FVECT           inVec;
667          int             inFront;
668          SDSpectralDF    *rdf;
669          double          rdiff;
# Line 587 | Line 672 | SDsampBSDF(SDValue *sv, FVECT outVec, const FVECT inVe
672          SDComponent     *sdc;
673          const SDCDst    **cdarr = NULL;
674                                          /* check arguments */
675 <        if ((sv == NULL) | (outVec == NULL) | (inVec == NULL) | (sd == NULL) |
676 <                        (randX < .0) | (randX >= 1.))
675 >        if ((sv == NULL) | (ioVec == NULL) | (sd == NULL) |
676 >                        (randX < 0) | (randX >= 1.))
677                  return SDEargument;
678                                          /* whose side are we on? */
679 <        inFront = (inVec[2] > .0);
679 >        VCOPY(inVec, ioVec);
680 >        inFront = (inVec[2] > 0);
681                                          /* remember diffuse portions */
682          if (inFront) {
683                  *sv = sd->rLambFront;
# Line 629 | Line 715 | SDsampBSDF(SDValue *sv, FVECT outVec, const FVECT inVe
715                  }
716                  sv->cieY += cdarr[i]->cTotal;
717          }
718 <        if (sv->cieY <= 1e-7) {         /* anything to sample? */
718 >        if (sv->cieY <= 1e-6) {         /* anything to sample? */
719                  sv->cieY = .0;
720 <                memset(outVec, 0, 3*sizeof(double));
720 >                memset(ioVec, 0, 3*sizeof(double));
721                  return SDEnone;
722          }
723                                          /* scale random variable */
724          randX *= sv->cieY;
725                                          /* diffuse reflection? */
726          if (randX < rdiff) {
727 <                SDdiffuseSamp(outVec, inFront, randX/rdiff);
727 >                SDdiffuseSamp(ioVec, inFront, randX/rdiff);
728                  goto done;
729          }
730          randX -= rdiff;
# Line 646 | Line 732 | SDsampBSDF(SDValue *sv, FVECT outVec, const FVECT inVe
732          if ((sflags & SDsampDf+SDsampT) == SDsampDf+SDsampT) {
733                  if (randX < sd->tLamb.cieY) {
734                          sv->spec = sd->tLamb.spec;
735 <                        SDdiffuseSamp(outVec, !inFront, randX/sd->tLamb.cieY);
735 >                        SDdiffuseSamp(ioVec, !inFront, randX/sd->tLamb.cieY);
736                          goto done;
737                  }
738                  randX -= sd->tLamb.cieY;
# Line 658 | Line 744 | SDsampBSDF(SDValue *sv, FVECT outVec, const FVECT inVe
744                  return SDEinternal;
745                                          /* compute sample direction */
746          sdc = (i < nr) ? &rdf->comp[i] : &sd->tf->comp[i-nr];
747 <        ec = (*sdc->func->sampCDist)(outVec, randX/cdarr[i]->cTotal, cdarr[i]);
747 >        ec = (*sdc->func->sampCDist)(ioVec, randX/cdarr[i]->cTotal, cdarr[i]);
748          if (ec)
749                  return ec;
750                                          /* compute color */
751 <        j = (*sdc->func->getBSDFs)(coef, outVec, inVec, sdc->dist);
751 >        j = (*sdc->func->getBSDFs)(coef, ioVec, inVec, sdc);
752          if (j <= 0) {
753                  sprintf(SDerrorDetail, "BSDF \"%s\" sampling value error",
754                                  sd->name);
# Line 689 | Line 775 | SDcompXform(RREAL vMtx[3][3], const FVECT sNrm, const
775          if ((vMtx == NULL) | (sNrm == NULL) | (uVec == NULL))
776                  return SDEargument;
777          VCOPY(vMtx[2], sNrm);
778 <        if (normalize(vMtx[2]) == .0)
778 >        if (normalize(vMtx[2]) == 0)
779                  return SDEargument;
780          fcross(vMtx[0], uVec, vMtx[2]);
781 <        if (normalize(vMtx[0]) == .0)
781 >        if (normalize(vMtx[0]) == 0)
782                  return SDEargument;
783          fcross(vMtx[1], vMtx[2], vMtx[0]);
784          return SDEnone;
# Line 712 | Line 798 | SDinvXform(RREAL iMtx[3][3], RREAL vMtx[3][3])
798          mTmp[0][1] = vMtx[2][1]*vMtx[0][2] - vMtx[2][2]*vMtx[0][1];
799          mTmp[0][2] = vMtx[1][2]*vMtx[0][1] - vMtx[1][1]*vMtx[0][2];
800          d = vMtx[0][0]*mTmp[0][0] + vMtx[1][0]*mTmp[0][1] + vMtx[2][0]*mTmp[0][2];
801 <        if (d == .0) {
801 >        if (d == 0) {
802                  strcpy(SDerrorDetail, "Zero determinant in matrix inversion");
803                  return SDEargument;
804          }
# Line 739 | Line 825 | SDmapDir(FVECT resVec, RREAL vMtx[3][3], const FVECT i
825          if (vMtx == NULL) {             /* assume they just want to normalize */
826                  if (resVec != inpVec)
827                          VCOPY(resVec, inpVec);
828 <                return (normalize(resVec) > .0) ? SDEnone : SDEargument;
828 >                return (normalize(resVec) > 0) ? SDEnone : SDEargument;
829          }
830          vTmp[0] = DOT(vMtx[0], inpVec);
831          vTmp[1] = DOT(vMtx[1], inpVec);
832          vTmp[2] = DOT(vMtx[2], inpVec);
833 <        if (normalize(vTmp) == .0)
833 >        if (normalize(vTmp) == 0)
834                  return SDEargument;
835          VCOPY(resVec, vTmp);
836          return SDEnone;
# Line 759 | Line 845 | SDmapDir(FVECT resVec, RREAL vMtx[3][3], const FVECT i
845  
846   #include "standard.h"
847   #include "paths.h"
762 #include <ctype.h>
848  
849   #define MAXLATS         46              /* maximum number of latitudes */
850  
# Line 816 | Line 901 | static int     nabases = 3;    /* current number of defined b
901   static int
902   fequal(double a, double b)
903   {
904 <        if (b != .0)
904 >        if (b != 0)
905                  a = a/b - 1.;
906          return((a <= 1e-6) & (a >= -1e-6));
907   }
# Line 879 | Line 964 | ab_getndx(             /* get index corresponding to the given ve
964   {
965          ANGLE_BASIS  *ab = (ANGLE_BASIS *)p;
966          int     li, ndx;
967 <        double  pol, azi, d;
967 >        double  pol, azi;
968  
969          if ((v[2] < -1.0) | (v[2] > 1.0))
970                  return(-1);
# Line 1077 | Line 1162 | load_bsdf_data(                /* load BSDF distribution for this wa
1162                          break;
1163                  }
1164          if (i < 0) {
1165 <                sprintf(errmsg, "undefined RowAngleBasis '%s'", cbasis);
1165 >                sprintf(errmsg, "undefined RowAngleBasis '%s'", rbasis);
1166                  error(WARNING, errmsg);
1167                  return;
1168          }
# Line 1119 | Line 1204 | check_bsdf_data(       /* check that BSDF data is sane */
1204   )
1205   {
1206          double          *omega_iarr, *omega_oarr;
1207 <        double          dom, contrib, hemi_total, full_total;
1207 >        double          dom, hemi_total, full_total;
1208          int             nneg;
1209          FVECT           v;
1210          int             i, o;
# Line 1134 | Line 1219 | check_bsdf_data(       /* check that BSDF data is sane */
1219          hemi_total = .0;
1220          for (i = dp->ninc; i--; ) {
1221                  dom = getBSDF_incohm(dp,i);
1222 <                if (dom <= .0) {
1222 >                if (dom <= 0) {
1223                          error(WARNING, "zero/negative incoming solid angle");
1224                          continue;
1225                  }
# Line 1157 | Line 1242 | check_bsdf_data(       /* check that BSDF data is sane */
1242          hemi_total = .0;
1243          for (o = dp->nout; o--; ) {
1244                  dom = getBSDF_outohm(dp,o);
1245 <                if (dom <= .0) {
1245 >                if (dom <= 0) {
1246                          error(WARNING, "zero/negative outgoing solid angle");
1247                          continue;
1248                  }
# Line 1181 | Line 1266 | check_bsdf_data(       /* check that BSDF data is sane */
1266                  hemi_total = .0;
1267                  for (o = dp->nout; o--; ) {
1268                          double  f = BSDF_value(dp,i,o);
1269 <                        if (f >= .0)
1269 >                        if (f >= 0)
1270                                  hemi_total += f*omega_oarr[o];
1271                          else {
1272                                  nneg += (f < -FTINY);
# Line 1269 | Line 1354 | load_BSDF(             /* load BSDF data from file */
1354                  error(WARNING, errmsg);
1355                  ezxml_free(fl);
1356                  return(NULL);
1357 <        }              
1358 <        load_angle_basis(ezxml_child(ezxml_child(wtl,
1359 <                                "DataDefinition"), "AngleBasis"));
1357 >        }
1358 >        for (wld = ezxml_child(ezxml_child(wtl,
1359 >                                "DataDefinition"), "AngleBasis");
1360 >                        wld != NULL; wld = wld->next)
1361 >                load_angle_basis(wld);
1362          dp = (struct BSDF_data *)calloc(1, sizeof(struct BSDF_data));
1363          load_geometry(dp, ezxml_child(wtl, "Material"));
1364          for (wld = ezxml_child(wtl, "WavelengthData");

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines