239 |
|
} |
240 |
|
|
241 |
|
|
242 |
+ |
static double |
243 |
+ |
to_meters( /* return factor to convert given unit to meters */ |
244 |
+ |
const char *unit |
245 |
+ |
) |
246 |
+ |
{ |
247 |
+ |
if (unit == NULL) return(1.); /* safe assumption? */ |
248 |
+ |
if (!strcasecmp(unit, "Meter")) return(1.); |
249 |
+ |
if (!strcasecmp(unit, "Foot")) return(.3048); |
250 |
+ |
if (!strcasecmp(unit, "Inch")) return(.0254); |
251 |
+ |
if (!strcasecmp(unit, "Centimeter")) return(.01); |
252 |
+ |
sprintf(errmsg, "unknown dimensional unit '%s'", unit); |
253 |
+ |
error(USER, errmsg); |
254 |
+ |
} |
255 |
+ |
|
256 |
+ |
|
257 |
|
static void |
258 |
+ |
load_geometry( /* load geometric dimensions and description (if any) */ |
259 |
+ |
struct BSDF_data *dp, |
260 |
+ |
ezxml_t wdb |
261 |
+ |
) |
262 |
+ |
{ |
263 |
+ |
ezxml_t geom; |
264 |
+ |
double cfact; |
265 |
+ |
const char *fmt, *mgfstr; |
266 |
+ |
|
267 |
+ |
dp->dim[0] = dp->dim[1] = dp->dim[2] = 0; |
268 |
+ |
dp->mgf = NULL; |
269 |
+ |
if ((geom = ezxml_child(wdb, "Width")) != NULL) |
270 |
+ |
dp->dim[0] = atof(ezxml_txt(geom)) * |
271 |
+ |
to_meters(ezxml_attr(geom, "unit")); |
272 |
+ |
if ((geom = ezxml_child(wdb, "Height")) != NULL) |
273 |
+ |
dp->dim[1] = atof(ezxml_txt(geom)) * |
274 |
+ |
to_meters(ezxml_attr(geom, "unit")); |
275 |
+ |
if ((geom = ezxml_child(wdb, "Thickness")) != NULL) |
276 |
+ |
dp->dim[2] = atof(ezxml_txt(geom)) * |
277 |
+ |
to_meters(ezxml_attr(geom, "unit")); |
278 |
+ |
if ((geom = ezxml_child(wdb, "Geometry")) == NULL || |
279 |
+ |
(mgfstr = ezxml_txt(geom)) == NULL) |
280 |
+ |
return; |
281 |
+ |
if ((fmt = ezxml_attr(geom, "format")) != NULL && |
282 |
+ |
strcasecmp(fmt, "MGF")) { |
283 |
+ |
sprintf(errmsg, "unrecognized geometry format '%s'", fmt); |
284 |
+ |
error(WARNING, errmsg); |
285 |
+ |
return; |
286 |
+ |
} |
287 |
+ |
cfact = to_meters(ezxml_attr(geom, "unit")); |
288 |
+ |
dp->mgf = (char *)malloc(strlen(mgfstr)+32); |
289 |
+ |
if (dp->mgf == NULL) |
290 |
+ |
error(SYSTEM, "out of memory in load_geometry"); |
291 |
+ |
if (cfact < 0.99 || cfact > 1.01) |
292 |
+ |
sprintf(dp->mgf, "xf -s %.5f\n%s\nxf\n", cfact, mgfstr); |
293 |
+ |
else |
294 |
+ |
strcpy(dp->mgf, mgfstr); |
295 |
+ |
} |
296 |
+ |
|
297 |
+ |
|
298 |
+ |
static void |
299 |
|
load_bsdf_data( /* load BSDF distribution for this wavelength */ |
300 |
|
struct BSDF_data *dp, |
301 |
|
ezxml_t wdb |
473 |
|
return(1); |
474 |
|
} |
475 |
|
|
476 |
+ |
|
477 |
|
struct BSDF_data * |
478 |
|
load_BSDF( /* load BSDF data from file */ |
479 |
|
char *fname |
513 |
|
load_angle_basis(ezxml_child(ezxml_child(wtl, |
514 |
|
"DataDefinition"), "AngleBasis")); |
515 |
|
dp = (struct BSDF_data *)calloc(1, sizeof(struct BSDF_data)); |
516 |
+ |
load_geometry(dp, ezxml_child(wtl, "Material")); |
517 |
|
for (wld = ezxml_child(wtl, "WavelengthData"); |
518 |
|
wld != NULL; wld = wld->next) { |
519 |
|
if (strcmp(ezxml_txt(ezxml_child(wld,"Wavelength")), "Visible")) |
544 |
|
{ |
545 |
|
if (b == NULL) |
546 |
|
return; |
547 |
+ |
if (b->mgf != NULL) |
548 |
+ |
free(b->mgf); |
549 |
|
if (b->bsdf != NULL) |
550 |
|
free(b->bsdf); |
551 |
|
free(b); |
652 |
|
getBSDF_xfm( /* compute BSDF orient. -> world orient. transform */ |
653 |
|
MAT4 xm, |
654 |
|
FVECT nrm, |
655 |
< |
UpDir ud |
655 |
> |
UpDir ud, |
656 |
> |
char *xfbuf |
657 |
|
) |
658 |
|
{ |
659 |
|
char *xfargs[7]; |
660 |
|
XF myxf; |
661 |
|
FVECT updir, xdest, ydest; |
662 |
+ |
int i; |
663 |
|
|
664 |
|
updir[0] = updir[1] = updir[2] = 0.; |
665 |
|
switch (ud) { |
690 |
|
fcross(ydest, nrm, xdest); |
691 |
|
xf(&myxf, addrot(xfargs, xdest, ydest, nrm), xfargs); |
692 |
|
copymat4(xm, myxf.xfm); |
693 |
+ |
if (xfbuf == NULL) |
694 |
+ |
return(1); |
695 |
+ |
/* return xf arguments as well */ |
696 |
+ |
for (i = 0; xfargs[i] != NULL; i++) { |
697 |
+ |
*xfbuf++ = ' '; |
698 |
+ |
strcpy(xfbuf, xfargs[i]); |
699 |
+ |
while (*xfbuf) ++xfbuf; |
700 |
+ |
} |
701 |
|
return(1); |
702 |
|
} |