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.16 by greg, Thu Jun 9 17:09:39 2011 UTC vs.
Revision 3.25 by greg, Sun Apr 21 22:58:40 2013 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 <                { {-5., 1},
35 >                { {0., 1},
36                  {5., 8},
37                  {15., 16},
38                  {25., 20},
# Line 58 | Line 44 | static ANGLE_BASIS     abase_list[MAXABASES] = {
44                  {90., 0} }
45          }, {
46                  "LBNL/Klems Half", 73,
47 <                { {-6.5, 1},
47 >                { {0., 1},
48                  {6.5, 8},
49                  {19.5, 12},
50                  {32.5, 16},
# Line 68 | Line 54 | static ANGLE_BASIS     abase_list[MAXABASES] = {
54                  {90., 0} }
55          }, {
56                  "LBNL/Klems Quarter", 41,
57 <                { {-9., 1},
57 >                { {0., 1},
58                  {9., 8},
59                  {27., 12},
60                  {46., 12},
# 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 87 | Line 73 | fequal(double a, double b)
73          return (a <= 1e-6) & (a >= -1e-6);
74   }
75  
90 /* Returns the name of the given tag */
91 #ifdef ezxml_name
92 #undef ezxml_name
93 static char *
94 ezxml_name(ezxml_t xml)
95 {
96        if (xml == NULL)
97                return NULL;
98        return xml->name;
99 }
100 #endif
101
76   /* Returns the given tag's character content or empty string if none */
77   #ifdef ezxml_txt
78   #undef ezxml_txt
# Line 158 | 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 184 | 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;
166          int     li, ndx;
167 <        double  pol, azi, d;
167 >        double  pol, azi;
168  
169          if (v == NULL)
170                  return -1;
# Line 213 | 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 230 | Line 204 | io_getohm(int ndx, void *p)
204          if (li == last_li)                      /* cached latitude? */
205                  return last_ohm;
206          last_li = li;
233        theta1 = M_PI/180. * ab->lat[li+1].tmin;
234        if (ab->lat[li].nphis == 1)             /* special case */
235                return last_ohm = M_PI*(1. - sq(cos(theta1)));
207          theta = M_PI/180. * ab->lat[li].tmin;
208 +        theta1 = M_PI/180. * ab->lat[li+1].tmin;
209          return last_ohm = M_PI*(sq(cos(theta)) - sq(cos(theta1))) /
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 252 | 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 265 | 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 277 | 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 290 | 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 303 | 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 347 | Line 319 | load_angle_basis(ezxml_t wab)
319                                  ezxml_child(ezxml_child(wbb,
320                                          "ThetaBounds"), "UpperTheta")));
321                  if (!i)
322 <                        abase_list[nabases].lat[i].tmin =
351 <                                        -abase_list[nabases].lat[i+1].tmin;
322 >                        abase_list[nabases].lat[0].tmin = 0;
323                  else if (!fequal(atof(ezxml_txt(ezxml_child(ezxml_child(wbb,
324                                          "ThetaBounds"), "LowerTheta"))),
325                                  abase_list[nabases].lat[i].tmin)) {
# Line 414 | Line 385 | load_bsdf_data(SDData *sd, ezxml_t wdb, int rowinc)
385          SDSpectralDF    *df;
386          SDMat           *dp;
387          char            *sdata;
417        int             tfront;
388          int             inbi, outbi;
389          int             i;
390                                          /* allocate BSDF component */
# Line 423 | Line 393 | load_bsdf_data(SDData *sd, ezxml_t wdb, int rowinc)
393                  return RC_FAIL;
394          /*
395           * Remember that front and back are reversed from WINDOW 6 orientations
426         * Favor their "Front" (incoming light) since that's more often valid
396           */
397 <        tfront = !strcasecmp(sdata, "Transmission Back");
398 <        if (!strcasecmp(sdata, "Transmission Front") ||
399 <                        tfront & (sd->tf == NULL)) {
397 >        if (!strcasecmp(sdata, "Transmission Front")) {
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 482 | Line 455 | load_bsdf_data(SDData *sd, ezxml_t wdb, int rowinc)
455          dp->ib_priv = &abase_list[inbi];
456          dp->ob_priv = &abase_list[outbi];
457          if (df == sd->tf) {
458 <                if (tfront) {
459 <                        dp->ib_vec = &fi_getvec;
460 <                        dp->ib_ndx = &fi_getndx;
461 <                        dp->ob_vec = &bo_getvec;
462 <                        dp->ob_ndx = &bo_getndx;
463 <                } else {
464 <                        dp->ib_vec = &bi_getvec;
465 <                        dp->ib_ndx = &bi_getndx;
466 <                        dp->ob_vec = &fo_getvec;
494 <                        dp->ob_ndx = &fo_getndx;
495 <                }
458 >                dp->ib_vec = &fi_getvec;
459 >                dp->ib_ndx = &fi_getndx;
460 >                dp->ob_vec = &bo_getvec;
461 >                dp->ob_ndx = &bo_getndx;
462 >        } else if (df == sd->tb) {
463 >                dp->ib_vec = &bi_getvec;
464 >                dp->ib_ndx = &bi_getndx;
465 >                dp->ob_vec = &fo_getvec;
466 >                dp->ob_ndx = &fo_getndx;
467          } else if (df == sd->rf) {
468                  dp->ib_vec = &fi_getvec;
469                  dp->ib_ndx = &fi_getndx;
# Line 610 | Line 581 | SDloadMtx(SDData *sd, ezxml_t wtl)
581                                  sd->name);
582                  return SDEsupport;
583          }
584 <                                        /* get angle basis */
585 <        rval = load_angle_basis(ezxml_child(ezxml_child(wtl,
586 <                                "DataDefinition"), "AngleBasis"));
587 <        if (rval < 0)
588 <                return convert_errcode(rval);
584 >                                        /* get angle bases */
585 >        for (wld = ezxml_child(ezxml_child(wtl, "DataDefinition"), "AngleBasis");
586 >                                wld != NULL; wld = wld->next) {
587 >                rval = load_angle_basis(wld);
588 >                if (rval < 0)
589 >                        return convert_errcode(rval);
590 >        }
591                                          /* load BSDF components */
592          for (wld = ezxml_child(wtl, "WavelengthData");
593                                  wld != NULL; wld = wld->next) {
# Line 629 | Line 602 | SDloadMtx(SDData *sd, ezxml_t wtl)
602                                          /* separate diffuse components */
603          extract_diffuse(&sd->rLambFront, sd->rf);
604          extract_diffuse(&sd->rLambBack, sd->rb);
605 <        extract_diffuse(&sd->tLamb, sd->tf);
605 >        extract_diffuse(&sd->tLamb, (sd->tf != NULL) ? sd->tf : sd->tb);
606                                          /* return success */
607          return SDEnone;
608   }
# Line 769 | Line 742 | SDgetMtxCDist(const FVECT inVec, SDComponent *sdc)
742          }
743          cdlast = NULL;                  /* check for it in cache list */
744          for (cd = (SDMatCDst *)sdc->cdList; cd != NULL;
745 <                                cdlast = cd, cd = (SDMatCDst *)cd->next)
745 >                                        cdlast = cd, cd = cd->next)
746                  if (cd->indx == myCD.indx && (cd->calen == myCD.calen) &
747                                          (cd->ob_priv == myCD.ob_priv) &
748                                          (cd->ob_vec == myCD.ob_vec))
# Line 788 | Line 761 | SDgetMtxCDist(const FVECT inVec, SDComponent *sdc)
761          }
762          if (cdlast != NULL) {           /* move entry to head of cache list */
763                  cdlast->next = cd->next;
764 <                cd->next = sdc->cdList;
764 >                cd->next = (SDMatCDst *)sdc->cdList;
765                  sdc->cdList = (SDCDst *)cd;
766          }
767          return (SDCDst *)cd;            /* ready to go */
# Line 808 | Line 781 | SDsampMtxCDist(FVECT ioVec, double randX, const SDCDst
781                                          /* binary search to find index */
782          ilower = 0; iupper = mcd->calen;
783          while ((i = (iupper + ilower) >> 1) != ilower)
784 <                if ((long)target >= (long)mcd->carr[i])
784 >                if (target >= mcd->carr[i])
785                          ilower = i;
786                  else
787                          iupper = i;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines