23 |
|
} lat[MAXLATS+1]; /* latitudes */ |
24 |
|
} ANGLE_BASIS; |
25 |
|
|
26 |
< |
#define MAXABASES 3 /* limit on defined bases */ |
26 |
> |
#define MAXABASES 7 /* limit on defined bases */ |
27 |
|
|
28 |
|
static ANGLE_BASIS abase_list[MAXABASES] = { |
29 |
|
{ |
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, |
200 |
|
|
201 |
|
|
202 |
|
static void |
203 |
+ |
load_angle_basis( /* load custom 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 || !*abname) |
212 |
+ |
return; |
213 |
+ |
for (i = nabases; i--; ) |
214 |
+ |
if (!strcmp(abname, abase_list[i].name)) |
215 |
+ |
return; /* 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 |
250 |
|
char *sdata; |
251 |
|
int i; |
252 |
|
|
253 |
< |
if ((cbasis == NULL) | (rbasis == NULL)) { |
253 |
> |
if ((!cbasis || !*cbasis) | (!rbasis || !*rbasis)) { |
254 |
|
error(WARNING, "missing column/row basis for BSDF"); |
255 |
|
return; |
256 |
|
} |
191 |
– |
/* XXX need to add routines for loading in foreign bases */ |
257 |
|
for (i = nabases; i--; ) |
258 |
|
if (!strcmp(cbasis, abase_list[i].name)) { |
259 |
|
dp->ninc = abase_list[i].nangles; |
264 |
|
break; |
265 |
|
} |
266 |
|
if (i < 0) { |
267 |
< |
sprintf(errmsg, "unsupported ColumnAngleBasis '%s'", cbasis); |
267 |
> |
sprintf(errmsg, "undefined ColumnAngleBasis '%s'", cbasis); |
268 |
|
error(WARNING, errmsg); |
269 |
|
return; |
270 |
|
} |
278 |
|
break; |
279 |
|
} |
280 |
|
if (i < 0) { |
281 |
< |
sprintf(errmsg, "unsupported RowAngleBasis '%s'", cbasis); |
281 |
> |
sprintf(errmsg, "undefined RowAngleBasis '%s'", cbasis); |
282 |
|
error(WARNING, errmsg); |
283 |
|
return; |
284 |
|
} |
285 |
|
/* read BSDF data */ |
286 |
|
sdata = ezxml_txt(ezxml_child(wdb,"ScatteringData")); |
287 |
< |
if (sdata == NULL) { |
287 |
> |
if (!sdata || !*sdata) { |
288 |
|
error(WARNING, "missing BSDF ScatteringData"); |
289 |
|
return; |
290 |
|
} |
453 |
|
return(NULL); |
454 |
|
} |
455 |
|
wtl = ezxml_child(ezxml_child(fl, "Optical"), "Layer"); |
456 |
+ |
load_angle_basis(ezxml_child(ezxml_child(wtl, |
457 |
+ |
"DataDefinition"), "AngleBasis")); |
458 |
|
dp = (struct BSDF_data *)calloc(1, sizeof(struct BSDF_data)); |
459 |
|
for (wld = ezxml_child(wtl, "WavelengthData"); |
460 |
|
wld != NULL; wld = wld->next) { |
541 |
|
return(normalize(v) != 0.0); |
542 |
|
} |
543 |
|
|
477 |
– |
|
478 |
– |
#define FEQ(a,b) ((a)-(b) <= 1e-7 && (b)-(a) <= 1e-7) |
544 |
|
|
545 |
|
static int |
546 |
|
addrot( /* compute rotation (x,y,z) => (xp,yp,zp) */ |