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.25 by greg, Sun Apr 24 20:16:52 2011 UTC vs.
Revision 2.37 by greg, Sun Mar 4 20:11:10 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 106 | Line 109 | SDloadGeometry(SDData *sd, ezxml_t wdb)
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,
# Line 164 | Line 171 | SDloadFile(SDData *sd, const char *fname)
171          }
172                                  /* load geometry if present */
173          lastErr = SDloadGeometry(sd, ezxml_child(wtl, "Material"));
174 <        if (lastErr)
174 >        if (lastErr) {
175 >                ezxml_free(fl);
176                  return lastErr;
177 +        }
178                                  /* try loading variable resolution data */
179          lastErr = SDloadTre(sd, wtl);
180                                  /* check our result */
181 <        switch (lastErr) {
173 <        case SDEformat:
174 <        case SDEdata:
175 <        case SDEsupport:        /* possibly we just tried the wrong format */
181 >        if (lastErr == SDEsupport)      /* try matrix BSDF if not tree data */
182                  lastErr = SDloadMtx(sd, wtl);
183 <                break;
178 <        default:                /* variable res. OK else serious error */
179 <                break;
180 <        }
183 >                
184                                  /* done with XML file */
185          ezxml_free(fl);
186          
# Line 223 | Line 226 | SDnewSpectralDF(int nc)
226          return df;
227   }
228  
229 + /* Add component(s) to spectral distribution function */
230 + SDSpectralDF *
231 + SDaddComponent(SDSpectralDF *odf, int nadd)
232 + {
233 +        SDSpectralDF    *df;
234 +
235 +        if (odf == NULL)
236 +                return SDnewSpectralDF(nadd);
237 +        if (nadd <= 0)
238 +                return odf;
239 +        df = (SDSpectralDF *)realloc(odf, sizeof(SDSpectralDF) +
240 +                                (odf->ncomp+nadd-1)*sizeof(SDComponent));
241 +        if (df == NULL) {
242 +                sprintf(SDerrorDetail,
243 +                        "Cannot add %d component(s) to spectral DF", nadd);
244 +                SDfreeSpectralDF(odf);
245 +                return NULL;
246 +        }
247 +        memset(df->comp+df->ncomp, 0, nadd*sizeof(SDComponent));
248 +        df->ncomp += nadd;
249 +        return df;
250 + }
251 +
252   /* Free cached cumulative distributions for BSDF component */
253   void
254   SDfreeCumulativeCache(SDSpectralDF *df)
# Line 249 | Line 275 | SDfreeSpectralDF(SDSpectralDF *df)
275                  return;
276          SDfreeCumulativeCache(df);
277          for (n = df->ncomp; n-- > 0; )
278 <                (*df->comp[n].func->freeSC)(df->comp[n].dist);
278 >                if (df->comp[n].dist != NULL)
279 >                        (*df->comp[n].func->freeSC)(df->comp[n].dist);
280          free(df);
281   }
282  
# Line 421 | Line 448 | SDsampComponent(SDValue *sv, FVECT ioVec, double randX
448          cd = (*sdc->func->getCDist)(inVec, sdc);
449          if (cd == NULL)
450                  return SDEmemory;
451 <        if (cd->cTotal <= 1e-7) {       /* anything to sample? */
451 >        if (cd->cTotal <= 1e-6) {       /* anything to sample? */
452                  sv->spec = c_dfcolor;
453                  sv->cieY = .0;
454                  memset(ioVec, 0, 3*sizeof(double));
# Line 496 | Line 523 | SDsizeBSDF(double *projSA, const FVECT v1, const RREAL
523          SDError         ec;
524          int             i;
525                                          /* check arguments */
526 <        if ((projSA == NULL) | (v1 == NULL))
526 >        if ((projSA == NULL) | (v1 == NULL) | (sd == NULL))
527                  return SDEargument;
528                                          /* initialize extrema */
529          switch (qflags) {
# Line 516 | Line 543 | SDsizeBSDF(double *projSA, const FVECT v1, const RREAL
543                  rdf = sd->rf;
544          else
545                  rdf = sd->rb;
546 <        tdf = NULL;                     /* transmitted component? */
547 <        if (v2 != NULL && v1[2] > 0 ^ v2[2] > 0) {
548 <                rdf = NULL;
549 <                tdf = sd->tf;
550 <        }
546 >        tdf = sd->tf;
547 >        if (v2 != NULL)                 /* bidirectional? */
548 >                if (v1[2] > 0 ^ v2[2] > 0)
549 >                        rdf = NULL;
550 >                else
551 >                        tdf = NULL;
552          ec = SDEdata;                   /* run through components */
553          for (i = (rdf==NULL) ? 0 : rdf->ncomp; i--; ) {
554                  ec = (*rdf->comp[i].func->queryProjSA)(projSA, v1, v2,
# Line 682 | Line 710 | SDsampBSDF(SDValue *sv, FVECT ioVec, double randX, int
710                  }
711                  sv->cieY += cdarr[i]->cTotal;
712          }
713 <        if (sv->cieY <= 1e-7) {         /* anything to sample? */
713 >        if (sv->cieY <= 1e-6) {         /* anything to sample? */
714                  sv->cieY = .0;
715                  memset(ioVec, 0, 3*sizeof(double));
716                  return SDEnone;
# Line 812 | Line 840 | SDmapDir(FVECT resVec, RREAL vMtx[3][3], const FVECT i
840  
841   #include "standard.h"
842   #include "paths.h"
815 #include <ctype.h>
843  
844   #define MAXLATS         46              /* maximum number of latitudes */
845  
# Line 932 | Line 959 | ab_getndx(             /* get index corresponding to the given ve
959   {
960          ANGLE_BASIS  *ab = (ANGLE_BASIS *)p;
961          int     li, ndx;
962 <        double  pol, azi, d;
962 >        double  pol, azi;
963  
964          if ((v[2] < -1.0) | (v[2] > 1.0))
965                  return(-1);
# Line 1172 | Line 1199 | check_bsdf_data(       /* check that BSDF data is sane */
1199   )
1200   {
1201          double          *omega_iarr, *omega_oarr;
1202 <        double          dom, contrib, hemi_total, full_total;
1202 >        double          dom, hemi_total, full_total;
1203          int             nneg;
1204          FVECT           v;
1205          int             i, o;
# Line 1322 | Line 1349 | load_BSDF(             /* load BSDF data from file */
1349                  error(WARNING, errmsg);
1350                  ezxml_free(fl);
1351                  return(NULL);
1352 <        }              
1353 <        load_angle_basis(ezxml_child(ezxml_child(wtl,
1354 <                                "DataDefinition"), "AngleBasis"));
1352 >        }
1353 >        for (wld = ezxml_child(ezxml_child(wtl,
1354 >                                "DataDefinition"), "AngleBasis");
1355 >                        wld != NULL; wld = wld->next)
1356 >                load_angle_basis(wld);
1357          dp = (struct BSDF_data *)calloc(1, sizeof(struct BSDF_data));
1358          load_geometry(dp, ezxml_child(wtl, "Material"));
1359          for (wld = ezxml_child(wtl, "WavelengthData");

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines