36 |
|
return NULL; |
37 |
|
} |
38 |
|
|
39 |
< |
/* Output XML prologue to stdout */ |
39 |
> |
/* Output XML header to stdout */ |
40 |
|
static void |
41 |
< |
xml_prologue(int ac, char *av[]) |
41 |
> |
xml_header(int ac, char *av[]) |
42 |
|
{ |
43 |
– |
ANGLE_BASIS *abp = get_basis(kbasis); |
44 |
– |
int i; |
45 |
– |
|
46 |
– |
if (abp == NULL) { |
47 |
– |
fprintf(stderr, "%s: unknown angle basis '%s'\n", progname, kbasis); |
48 |
– |
exit(1); |
49 |
– |
} |
43 |
|
puts("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); |
44 |
|
puts("<WindowElement xmlns=\"http://windows.lbl.gov\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://windows.lbl.gov/BSDF-v1.4.xsd\">"); |
45 |
|
fputs("<!-- File produced by:", stdout); |
48 |
|
fputs(*av++, stdout); |
49 |
|
} |
50 |
|
puts(" -->"); |
51 |
+ |
} |
52 |
+ |
|
53 |
+ |
/* Output XML prologue to stdout */ |
54 |
+ |
static void |
55 |
+ |
xml_prologue(const SDData *sd) |
56 |
+ |
{ |
57 |
+ |
const char *matn = (sd && sd->matn[0]) ? sd->matn : "Name"; |
58 |
+ |
const char *makr = (sd && sd->makr[0]) ? sd->makr : "Manufacturer"; |
59 |
+ |
ANGLE_BASIS *abp = get_basis(kbasis); |
60 |
+ |
int i; |
61 |
+ |
|
62 |
+ |
if (abp == NULL) { |
63 |
+ |
fprintf(stderr, "%s: unknown angle basis '%s'\n", progname, kbasis); |
64 |
+ |
exit(1); |
65 |
+ |
} |
66 |
|
puts("<WindowElementType>System</WindowElementType>"); |
67 |
|
puts("<FileType>BSDF</FileType>"); |
68 |
|
puts("<Optical>"); |
69 |
|
puts("<Layer>"); |
70 |
|
puts("\t<Material>"); |
71 |
< |
puts("\t\t<Name>Name</Name>"); |
72 |
< |
puts("\t\t<Manufacturer>Manufacturer</Manufacturer>"); |
71 |
> |
printf("\t\t<Name>%s</Name>\n", matn); |
72 |
> |
printf("\t\t<Manufacturer>%s</Manufacturer>\n", makr); |
73 |
> |
if (sd && sd->dim[2] > .001) { |
74 |
> |
printf("\t\t<Thickness unit=\"meter\">%.3f</Thickness>\n", sd->dim[2]); |
75 |
> |
printf("\t\t<Width unit=\"meter\">%.3f</Width>\n", sd->dim[0]); |
76 |
> |
printf("\t\t<Height unit=\"meter\">%.3f</Height>\n", sd->dim[1]); |
77 |
> |
} |
78 |
|
puts("\t\t<DeviceType>Other</DeviceType>"); |
79 |
|
puts("\t</Material>"); |
80 |
+ |
if (sd && sd->mgf != NULL) { |
81 |
+ |
puts("\t<Geometry format=\"MGF\">"); |
82 |
+ |
puts("\t\t<MGFblock unit=\"meter\">"); |
83 |
+ |
fputs(sd->mgf, stdout); |
84 |
+ |
puts("</MGFblock>"); |
85 |
+ |
puts("\t</Geometry>"); |
86 |
+ |
} |
87 |
|
puts("\t<DataDefinition>"); |
88 |
|
puts("\t\t<IncidentDataStructure>Columns</IncidentDataStructure>"); |
89 |
|
puts("\t\t<AngleBasis>"); |
93 |
|
printf("\t\t\t<Theta>%g</Theta>\n", i ? |
94 |
|
.5*(abp->lat[i].tmin + abp->lat[i+1].tmin) : |
95 |
|
.0 ); |
96 |
< |
printf("\t\t\t<nPhis>%d</nPhis>", abp->lat[i].nphis); |
96 |
> |
printf("\t\t\t<nPhis>%d</nPhis>\n", abp->lat[i].nphis); |
97 |
|
puts("\t\t\t<ThetaBounds>"); |
98 |
|
printf("\t\t\t\t<LowerTheta>%g</LowerTheta>\n", abp->lat[i].tmin); |
99 |
|
printf("\t\t\t\t<UpperTheta>%g</UpperTheta>\n", abp->lat[i+1].tmin); |
147 |
|
puts("</WindowElement>"); |
148 |
|
} |
149 |
|
|
150 |
< |
/* Load and resample XML BSDF description */ |
150 |
> |
/* Load and resample XML BSDF description using Klems basis */ |
151 |
|
static void |
152 |
|
eval_bsdf(const char *fname) |
153 |
|
{ |
162 |
|
SDclearBSDF(&bsd, fname); /* load BSDF file */ |
163 |
|
if ((ec = SDloadFile(&bsd, fname)) != SDEnone) |
164 |
|
goto err; |
165 |
+ |
xml_prologue(&bsd); /* pass geometry */ |
166 |
|
/* front reflection */ |
167 |
|
if (bsd.rf != NULL || bsd.rLambFront.cieY > .002) { |
168 |
|
input_orient = 1; output_orient = 1; |
254 |
|
exit(1); |
255 |
|
} |
256 |
|
|
257 |
< |
/* Interpolate and output a BSDF function */ |
257 |
> |
/* Interpolate and output a BSDF function using Klems basis */ |
258 |
|
static void |
259 |
|
eval_function(char *funame) |
260 |
|
{ |
274 |
|
bo_getvec(iovec+3, j+(n+frandom())/npsamps, abp); |
275 |
|
|
276 |
|
if (input_orient > 0) |
277 |
< |
fi_getvec(iovec, j+(n+frandom())/npsamps, abp); |
277 |
> |
fi_getvec(iovec, i+(n+frandom())/npsamps, abp); |
278 |
|
else |
279 |
< |
bi_getvec(iovec, j+(n+frandom())/npsamps, abp); |
279 |
> |
bi_getvec(iovec, i+(n+frandom())/npsamps, abp); |
280 |
|
|
281 |
|
sum += funvalue(funame, 6, iovec); |
282 |
|
} |
291 |
|
static void |
292 |
|
eval_rbf(void) |
293 |
|
{ |
294 |
+ |
#define MAXPATCHES 145 |
295 |
|
ANGLE_BASIS *abp = get_basis(kbasis); |
296 |
< |
double iovec[6]; |
296 |
> |
float bsdfarr[MAXPATCHES*MAXPATCHES]; |
297 |
> |
FVECT vin, vout; |
298 |
> |
RBFNODE *rbf; |
299 |
|
double sum; |
300 |
|
int i, j, n; |
301 |
+ |
/* sanity check */ |
302 |
+ |
if (abp->nangles > MAXPATCHES) { |
303 |
+ |
fprintf(stderr, "%s: too many patches!\n", progname); |
304 |
+ |
exit(1); |
305 |
+ |
} |
306 |
+ |
data_prologue(); /* begin output */ |
307 |
+ |
for (i = 0; i < abp->nangles; i++) { |
308 |
+ |
if (input_orient > 0) /* use incident patch center */ |
309 |
+ |
fi_getvec(vin, i+.5*(i>0), abp); |
310 |
+ |
else |
311 |
+ |
bi_getvec(vin, i+.5*(i>0), abp); |
312 |
|
|
313 |
< |
fprintf(stder, "%s: RBF evaluation currently unimplemented\n", progname); |
314 |
< |
exit(1); |
313 |
> |
rbf = advect_rbf(vin); /* compute radial basis func */ |
314 |
> |
|
315 |
> |
for (j = 0; j < abp->nangles; j++) { |
316 |
> |
sum = 0; /* sample over exiting patch */ |
317 |
> |
for (n = npsamps; n--; ) { |
318 |
> |
if (output_orient > 0) |
319 |
> |
fo_getvec(vout, j+(n+frandom())/npsamps, abp); |
320 |
> |
else |
321 |
> |
bo_getvec(vout, j+(n+frandom())/npsamps, abp); |
322 |
> |
|
323 |
> |
sum += eval_rbfrep(rbf, vout) / vout[2]; |
324 |
> |
} |
325 |
> |
bsdfarr[j*abp->nangles + i] = sum*output_orient/npsamps; |
326 |
> |
} |
327 |
> |
} |
328 |
> |
n = 0; /* write out our matrix */ |
329 |
> |
for (j = 0; j < abp->nangles; j++) { |
330 |
> |
for (i = 0; i < abp->nangles; i++) |
331 |
> |
printf("\t%.3e\n", bsdfarr[n++]); |
332 |
> |
putchar('\n'); |
333 |
> |
} |
334 |
> |
data_epilogue(); /* finish output */ |
335 |
> |
#undef MAXPATCHES |
336 |
|
} |
337 |
|
|
338 |
|
/* Read in BSDF and interpolate as Klems matrix representation */ |
348 |
|
esupport &= ~(E_INCHAN|E_OUTCHAN); |
349 |
|
scompile("PI:3.14159265358979323846", NULL, 0); |
350 |
|
biggerlib(); |
351 |
< |
for (i = 1; i < argc-1 && (argv[i][0] == '-') | (argv[i][0] == '+'); i++) |
351 |
> |
for (i = 1; i < argc && (argv[i][0] == '-') | (argv[i][0] == '+'); i++) |
352 |
|
switch (argv[i][1]) { /* get options */ |
353 |
|
case 'n': |
354 |
|
npsamps = atoi(argv[++i]); |
385 |
|
progname); |
386 |
|
goto userr; |
387 |
|
} |
388 |
< |
xml_prologue(argc, argv); /* start XML output */ |
388 |
> |
xml_header(argc, argv); /* start XML output */ |
389 |
> |
xml_prologue(NULL); |
390 |
|
if (dofwd) { |
391 |
|
input_orient = -1; |
392 |
|
output_orient = -1; |
404 |
|
xml_epilogue(); /* finish XML output & exit */ |
405 |
|
return(0); |
406 |
|
} |
407 |
< |
if (i == argc-1 && (cp = strstr(argv[i], ".xml")) != NULL && |
408 |
< |
strlen(cp) == 4) { /* XML input? */ |
409 |
< |
xml_prologue(argc, argv); /* start XML output */ |
407 |
> |
/* XML input? */ |
408 |
> |
if (i == argc-1 && (cp = argv[i]+strlen(argv[i])-4) > argv[i] && |
409 |
> |
!strcasecmp(cp, ".xml")) { |
410 |
> |
xml_header(argc, argv); /* start XML output */ |
411 |
|
eval_bsdf(argv[i]); /* load & resample BSDF */ |
412 |
|
xml_epilogue(); /* finish XML output & exit */ |
413 |
|
return(0); |
424 |
|
if (!load_bsdf_rep(fpin)) |
425 |
|
return(1); |
426 |
|
fclose(fpin); |
427 |
< |
if (!nbsdf++) /* start XML on first dist. */ |
428 |
< |
xml_prologue(argc, argv); |
427 |
> |
if (!nbsdf++) { /* start XML on first dist. */ |
428 |
> |
xml_header(argc, argv); |
429 |
> |
xml_prologue(NULL); |
430 |
> |
} |
431 |
|
eval_rbf(); |
432 |
|
} |
433 |
|
xml_epilogue(); /* finish XML output & exit */ |
436 |
|
SET_FILE_BINARY(stdin); /* load from stdin */ |
437 |
|
if (!load_bsdf_rep(stdin)) |
438 |
|
return(1); |
439 |
< |
xml_prologue(argc, argv); /* start XML output */ |
439 |
> |
xml_header(argc, argv); /* start XML output */ |
440 |
> |
xml_prologue(NULL); |
441 |
|
eval_rbf(); /* resample dist. */ |
442 |
|
xml_epilogue(); /* finish XML output & exit */ |
443 |
|
return(0); |
444 |
|
userr: |
445 |
|
fprintf(stderr, |
446 |
< |
"Usage: %s [-n spp][-h|-q][bsdf.sir ..] > bsdf.xml\n", |
386 |
< |
progname); |
446 |
> |
"Usage: %s [-n spp][-h|-q][bsdf.sir ..] > bsdf.xml\n", progname); |
447 |
|
fprintf(stderr, |
448 |
< |
" or: %s [-n spp][-h|-q] bsdf_in.xml > bsdf_out.xml\n", |
389 |
< |
progname); |
448 |
> |
" or: %s [-n spp][-h|-q] bsdf_in.xml > bsdf_out.xml\n", progname); |
449 |
|
fprintf(stderr, |
450 |
|
" or: %s [-n spp][-h|-q][{+|-}for[ward]][{+|-}b[ackward]][-e expr][-f file] bsdf_func > bsdf.xml\n", |
451 |
|
progname); |