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.23 by greg, Sun Sep 2 15:33:15 2012 UTC vs.
Revision 3.28 by greg, Fri Mar 21 17:49:53 2014 UTC

# Line 29 | Line 29 | static const char RCSid[] = "$Id$";
29   #define RC_INTERR       (-4)
30   #define RC_MEMERR       (-5)
31  
32 < #define MAXLATS         46              /* maximum number of latitudes */
33 <
34 < /* BSDF angle specification */
35 < typedef struct {
36 <        char    name[64];               /* basis name */
37 <        int     nangles;                /* total number of directions */
38 <        struct {
39 <                float   tmin;                   /* starting theta */
40 <                int     nphis;                  /* number of phis (0 term) */
41 <        } lat[MAXLATS+1];               /* latitudes */
42 < } ANGLE_BASIS;
43 <
44 < #define MAXABASES       7               /* limit on defined bases */
45 <
46 < static ANGLE_BASIS      abase_list[MAXABASES] = {
32 > ANGLE_BASIS     abase_list[MAXABASES] = {
33          {
34                  "LBNL/Klems Full", 145,
35                  { {0., 1},
# Line 77 | Line 63 | static ANGLE_BASIS     abase_list[MAXABASES] = {
63          }
64   };
65  
66 < static int      nabases = 3;    /* current number of defined bases */
66 > int             nabases = 3;            /* current number of defined bases */
67  
68   static int
69   fequal(double a, double b)
# Line 146 | Line 132 | SDnewMatrix(int ni, int no)
132   /* Free a BSDF matrix */
133   #define SDfreeMatrix            free
134  
135 < /* get vector for this angle basis index (front exiting) */
136 < static int
135 > /* Get vector for this angle basis index (front exiting) */
136 > int
137   fo_getvec(FVECT v, double ndxr, void *p)
138   {
139          ANGLE_BASIS     *ab = (ANGLE_BASIS *)p;
# Line 172 | Line 158 | fo_getvec(FVECT v, double ndxr, void *p)
158          return RC_GOOD;
159   }
160  
161 < /* get index corresponding to the given vector (front exiting) */
162 < static int
161 > /* Get index corresponding to the given vector (front exiting) */
162 > int
163   fo_getndx(const FVECT v, void *p)
164   {
165          ANGLE_BASIS     *ab = (ANGLE_BASIS *)p;
# Line 184 | Line 170 | fo_getndx(const FVECT v, void *p)
170                  return -1;
171          if ((v[2] < 0) | (v[2] > 1.))
172                  return -1;
173 <        pol = 180.0/M_PI*acos(v[2]);
173 >        pol = 180.0/M_PI*Acos(v[2]);
174          azi = 180.0/M_PI*atan2(v[1], v[0]);
175          if (azi < 0.0) azi += 360.0;
176          for (li = 1; ab->lat[li].tmin <= pol; li++)
# Line 201 | Line 187 | fo_getndx(const FVECT v, void *p)
187   /* compute square of real value */
188   static double sq(double x) { return x*x; }
189  
190 < /* get projected solid angle for this angle basis index (universal) */
191 < static double
190 > /* Get projected solid angle for this angle basis index (universal) */
191 > double
192   io_getohm(int ndx, void *p)
193   {
194          static int      last_li = -1;
# Line 224 | Line 210 | io_getohm(int ndx, void *p)
210                                  (double)ab->lat[li].nphis;
211   }
212  
213 < /* get vector for this angle basis index (back incident) */
214 < static int
213 > /* Get vector for this angle basis index (back incident) */
214 > int
215   bi_getvec(FVECT v, double ndxr, void *p)
216   {
217          if (!fo_getvec(v, ndxr, p))
# Line 238 | Line 224 | bi_getvec(FVECT v, double ndxr, void *p)
224          return RC_GOOD;
225   }
226  
227 < /* get index corresponding to the vector (back incident) */
228 < static int
227 > /* Get index corresponding to the vector (back incident) */
228 > int
229   bi_getndx(const FVECT v, void *p)
230   {
231          FVECT  v2;
# Line 251 | Line 237 | bi_getndx(const FVECT v, void *p)
237          return fo_getndx(v2, p);
238   }
239  
240 < /* get vector for this angle basis index (back exiting) */
241 < static int
240 > /* Get vector for this angle basis index (back exiting) */
241 > int
242   bo_getvec(FVECT v, double ndxr, void *p)
243   {
244          if (!fo_getvec(v, ndxr, p))
# Line 263 | Line 249 | bo_getvec(FVECT v, double ndxr, void *p)
249          return RC_GOOD;
250   }
251  
252 < /* get index corresponding to the vector (back exiting) */
253 < static int
252 > /* Get index corresponding to the vector (back exiting) */
253 > int
254   bo_getndx(const FVECT v, void *p)
255   {
256          FVECT  v2;
# Line 276 | Line 262 | bo_getndx(const FVECT v, void *p)
262          return fo_getndx(v2, p);
263   }
264  
265 < /* get vector for this angle basis index (front incident) */
266 < static int
265 > /* Get vector for this angle basis index (front incident) */
266 > int
267   fi_getvec(FVECT v, double ndxr, void *p)
268   {
269          if (!fo_getvec(v, ndxr, p))
# Line 289 | Line 275 | fi_getvec(FVECT v, double ndxr, void *p)
275          return RC_GOOD;
276   }
277  
278 < /* get index corresponding to the vector (front incident) */
279 < static int
278 > /* Get index corresponding to the vector (front incident) */
279 > int
280   fi_getndx(const FVECT v, void *p)
281   {
282          FVECT  v2;
# Line 409 | Line 395 | load_bsdf_data(SDData *sd, ezxml_t wdb, int rowinc)
395           * Remember that front and back are reversed from WINDOW 6 orientations
396           */
397          if (!strcasecmp(sdata, "Transmission Front")) {
412                if (sd->tf != NULL)
413                        SDfreeSpectralDF(sd->tf);
414                if ((sd->tf = SDnewSpectralDF(1)) == NULL)
415                        return RC_MEMERR;
416                df = sd->tf;
417        } else if (!strcasecmp(sdata, "Transmission Back")) {
398                  if (sd->tb != NULL)
399                          SDfreeSpectralDF(sd->tb);
400                  if ((sd->tb = SDnewSpectralDF(1)) == NULL)
401                          return RC_MEMERR;
402                  df = sd->tb;
403 +        } else if (!strcasecmp(sdata, "Transmission Back")) {
404 +                if (sd->tf != NULL)
405 +                        SDfreeSpectralDF(sd->tf);
406 +                if ((sd->tf = SDnewSpectralDF(1)) == NULL)
407 +                        return RC_MEMERR;
408 +                df = sd->tf;
409          } else if (!strcasecmp(sdata, "Reflection Front")) {
410 <                if (sd->rb != NULL)     /* note back-front reversal */
410 >                if (sd->rb != NULL)
411                          SDfreeSpectralDF(sd->rb);
412                  if ((sd->rb = SDnewSpectralDF(1)) == NULL)
413                          return RC_MEMERR;
414                  df = sd->rb;
415          } else if (!strcasecmp(sdata, "Reflection Back")) {
416 <                if (sd->rf != NULL)     /* note front-back reversal */
416 >                if (sd->rf != NULL)
417                          SDfreeSpectralDF(sd->rf);
418                  if ((sd->rf = SDnewSpectralDF(1)) == NULL)
419                          return RC_MEMERR;
# Line 502 | Line 488 | load_bsdf_data(SDData *sd, ezxml_t wdb, int rowinc)
488                  return RC_FORMERR;
489          }
490          for (i = 0; i < dp->ninc*dp->nout; i++) {
491 <                char  *sdnext = fskip(sdata);
491 >                char    *sdnext = fskip(sdata);
492 >                double  val;
493                  if (sdnext == NULL) {
494                          sprintf(SDerrorDetail,
495                                  "Bad/missing BSDF ScatteringData in '%s'",
# Line 512 | Line 499 | load_bsdf_data(SDData *sd, ezxml_t wdb, int rowinc)
499                  while (isspace(*sdnext))
500                          sdnext++;
501                  if (*sdnext == ',') sdnext++;
502 +                if ((val = atof(sdata)) < 0)
503 +                        val = 0;        /* don't allow negative values */
504                  if (rowinc) {
505                          int     r = i/dp->nout;
506                          int     c = i - r*dp->nout;
507 <                        mBSDF_value(dp,r,c) = atof(sdata);
507 >                        mBSDF_value(dp,r,c) = val;
508                  } else
509 <                        dp->bsdf[i] = atof(sdata);
509 >                        dp->bsdf[i] = val;
510                  sdata = sdnext;
511          }
512          return get_extrema(df);
# Line 616 | Line 605 | SDloadMtx(SDData *sd, ezxml_t wtl)
605                                          /* separate diffuse components */
606          extract_diffuse(&sd->rLambFront, sd->rf);
607          extract_diffuse(&sd->rLambBack, sd->rb);
608 <        extract_diffuse(&sd->tLamb, (sd->tf != NULL) ? sd->tf : sd->tb);
608 >        if (sd->tf != NULL)
609 >                extract_diffuse(&sd->tLamb, sd->tf);
610 >        if (sd->tb != NULL)
611 >                extract_diffuse(&sd->tLamb, sd->tb);
612                                          /* return success */
613          return SDEnone;
614   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines