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.2 by greg, Fri Jun 19 06:49:25 2009 UTC vs.
Revision 2.3 by greg, Sat Jul 3 02:50:22 2010 UTC

# Line 23 | Line 23 | typedef struct {
23          }       lat[MAXLATS+1];         /* latitudes */
24   } ANGLE_BASIS;
25  
26 < #define MAXABASES       3               /* limit on defined bases */
26 > #define MAXABASES       5               /* limit on defined bases */
27  
28   static ANGLE_BASIS      abase_list[MAXABASES] = {
29          {
# Line 61 | Line 61 | static ANGLE_BASIS     abase_list[MAXABASES] = {
61  
62   static int      nabases = 3;    /* current number of defined bases */
63  
64 + #define  FEQ(a,b)       ((a)-(b) <= 1e-7 && (b)-(a) <= 1e-7)
65  
66 + // returns the name of the given tag
67 + #ifdef ezxml_name
68 + #undef ezxml_name
69 + static char *
70 + ezxml_name(ezxml_t xml)
71 + {
72 +        if (xml == NULL)
73 +                return(NULL);
74 +        return(xml->name);
75 + }
76 + #endif
77 +
78 + // returns the given tag's character content or empty string if none
79 + #ifdef ezxml_txt
80 + #undef ezxml_txt
81 + static char *
82 + ezxml_txt(ezxml_t xml)
83 + {
84 +        if (xml == NULL)
85 +                return("");
86 +        return(xml->txt);
87 + }
88 + #endif
89 +
90 +
91   static int
92   ab_getvec(              /* get vector for this angle basis index */
93          FVECT v,
# Line 174 | Line 200 | ab_getndxR(            /* get index corresponding to the reverse
200  
201  
202   static void
203 + load_angle_basis(       /* load BSDF angle basis */
204 +        ezxml_t wab
205 + )
206 + {
207 +        char    *abname = ezxml_txt(ezxml_child(wab, "AngleBasisName"));
208 +        ezxml_t wbb;
209 +        int     i;
210 +        
211 +        if (abname == NULL || !*abname)
212 +                return;
213 +        for (i = nabases; i--; )
214 +                if (!strcmp(abname, abase_list[i].name))
215 +                        return;         /* XXX assume it's the same */
216 +        if (nabases >= MAXABASES)
217 +                error(INTERNAL, "too many angle bases");
218 +        strcpy(abase_list[nabases].name, abname);
219 +        abase_list[nabases].nangles = 0;
220 +        for (i = 0, wbb = ezxml_child(wab, "AngleBasisBlock");
221 +                        wbb != NULL; i++, wbb = wbb->next) {
222 +                if (i >= MAXLATS)
223 +                        error(INTERNAL, "too many latitudes in custom basis");
224 +                abase_list[nabases].lat[i+1].tmin = atof(ezxml_txt(
225 +                                ezxml_child(ezxml_child(wbb,
226 +                                        "ThetaBounds"), "UpperTheta")));
227 +                if (!i)
228 +                        abase_list[nabases].lat[i].tmin =
229 +                                        -abase_list[nabases].lat[i+1].tmin;
230 +                else if (!FEQ(atof(ezxml_txt(ezxml_child(ezxml_child(wbb,
231 +                                        "ThetaBounds"), "LowerTheta"))),
232 +                                abase_list[nabases].lat[i].tmin))
233 +                        error(WARNING, "theta values disagree in custom basis");
234 +                abase_list[nabases].nangles +=
235 +                        abase_list[nabases].lat[i].nphis =
236 +                                atoi(ezxml_txt(ezxml_child(wbb, "nPhis")));
237 +        }
238 +        abase_list[nabases++].lat[i].nphis = 0;
239 + }
240 +
241 +
242 + static void
243   load_bsdf_data(         /* load BSDF distribution for this wavelength */
244          struct BSDF_data *dp,
245          ezxml_t wdb
# Line 184 | Line 250 | load_bsdf_data(                /* load BSDF distribution for this wa
250          char  *sdata;
251          int  i;
252          
253 <        if ((cbasis == NULL) | (rbasis == NULL)) {
253 >        if ((cbasis == NULL || !*cbasis) | (rbasis == NULL || !*rbasis)) {
254                  error(WARNING, "missing column/row basis for BSDF");
255                  return;
256          }
# Line 219 | Line 285 | load_bsdf_data(                /* load BSDF distribution for this wa
285          }
286                                  /* read BSDF data */
287          sdata  = ezxml_txt(ezxml_child(wdb,"ScatteringData"));
288 <        if (sdata == NULL) {
288 >        if (sdata == NULL || !*sdata) {
289                  error(WARNING, "missing BSDF ScatteringData");
290                  return;
291          }
# Line 388 | Line 454 | load_BSDF(             /* load BSDF data from file */
454                  return(NULL);
455          }
456          wtl = ezxml_child(ezxml_child(fl, "Optical"), "Layer");
457 +        load_angle_basis(ezxml_child(ezxml_child(wtl,
458 +                                "DataDefinition"), "AngleBasis"));
459          dp = (struct BSDF_data *)calloc(1, sizeof(struct BSDF_data));
460          for (wld = ezxml_child(wtl, "WavelengthData");
461                                  wld != NULL; wld = wld->next) {
# Line 474 | Line 542 | r_BSDF_outvec(         /* compute random output vector at giv
542          return(normalize(v) != 0.0);
543   }
544  
477
478 #define  FEQ(a,b)       ((a)-(b) <= 1e-7 && (b)-(a) <= 1e-7)
545  
546   static int
547   addrot(                 /* compute rotation (x,y,z) => (xp,yp,zp) */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines