16 |
|
/* global argv[0] */ |
17 |
|
char *progname; |
18 |
|
/* percentage to cull (<0 to turn off) */ |
19 |
< |
int pctcull = 90; |
19 |
> |
double pctcull = 90.; |
20 |
|
/* sampling order */ |
21 |
|
int samp_order = 6; |
22 |
|
|
29 |
|
char cmd[128]; |
30 |
|
int ix, ox, oy; |
31 |
|
FVECT ivec, ovec; |
32 |
< |
double bsdf; |
32 |
> |
float bsdf; |
33 |
|
#if DEBUG |
34 |
|
fprintf(stderr, "Writing isotropic order %d ", samp_order); |
35 |
< |
if (pctcull >= 0) fprintf(stderr, "data with %d%% culling\n", pctcull); |
35 |
> |
if (pctcull >= 0) fprintf(stderr, "data with %.1f%% culling\n", pctcull); |
36 |
|
else fputs("raw data\n", stderr); |
37 |
|
#endif |
38 |
|
if (pctcull >= 0) { /* begin output */ |
39 |
< |
sprintf(cmd, "rttree_reduce -h -a -fd -r 3 -t %d -g %d", |
39 |
> |
sprintf(cmd, "rttree_reduce -h -a -ff -r 3 -t %f -g %d", |
40 |
|
pctcull, samp_order); |
41 |
|
fflush(stdout); |
42 |
|
ofp = popen(cmd, "w"); |
60 |
|
SDsquare2disk(ovec, (ox+.5)/sqres, (oy+.5)/sqres); |
61 |
|
ovec[2] = output_orient * |
62 |
|
sqrt(1. - ovec[0]*ovec[0] - ovec[1]*ovec[1]); |
63 |
< |
bsdf = eval_rbfrep(rbf, ovec) / fabs(ovec[2]); |
63 |
> |
bsdf = eval_rbfrep(rbf, ovec) * output_orient/ovec[2]; |
64 |
|
if (pctcull >= 0) |
65 |
|
fwrite(&bsdf, sizeof(bsdf), 1, ofp); |
66 |
|
else |
67 |
|
printf("\t%.3e\n", bsdf); |
68 |
|
} |
69 |
< |
free(rbf); |
69 |
> |
if (rbf != NULL) |
70 |
> |
free(rbf); |
71 |
|
} |
72 |
|
if (pctcull >= 0) { /* finish output */ |
73 |
|
if (pclose(ofp)) { |
91 |
|
char cmd[128]; |
92 |
|
int ix, iy, ox, oy; |
93 |
|
FVECT ivec, ovec; |
94 |
< |
double bsdf; |
94 |
> |
float bsdf; |
95 |
|
#if DEBUG |
96 |
|
fprintf(stderr, "Writing anisotropic order %d ", samp_order); |
97 |
< |
if (pctcull >= 0) fprintf(stderr, "data with %d%% culling\n", pctcull); |
97 |
> |
if (pctcull >= 0) fprintf(stderr, "data with %.1f%% culling\n", pctcull); |
98 |
|
else fputs("raw data\n", stderr); |
99 |
|
#endif |
100 |
|
if (pctcull >= 0) { /* begin output */ |
101 |
< |
sprintf(cmd, "rttree_reduce -h -a -fd -r 4 -t %d -g %d", |
101 |
> |
sprintf(cmd, "rttree_reduce -h -a -ff -r 4 -t %f -g %d", |
102 |
|
pctcull, samp_order); |
103 |
|
fflush(stdout); |
104 |
|
ofp = popen(cmd, "w"); |
112 |
|
/* run through directions */ |
113 |
|
for (ix = 0; ix < sqres; ix++) |
114 |
|
for (iy = 0; iy < sqres; iy++) { |
115 |
< |
RBFNODE *rbf; |
115 |
> |
RBFNODE *rbf; /* Klems reversal */ |
116 |
|
SDsquare2disk(ivec, (ix+.5)/sqres, (iy+.5)/sqres); |
117 |
+ |
ivec[0] = -ivec[0]; ivec[1] = -ivec[1]; |
118 |
|
ivec[2] = input_orient * |
119 |
|
sqrt(1. - ivec[0]*ivec[0] - ivec[1]*ivec[1]); |
120 |
|
rbf = advect_rbf(ivec); |
123 |
|
SDsquare2disk(ovec, (ox+.5)/sqres, (oy+.5)/sqres); |
124 |
|
ovec[2] = output_orient * |
125 |
|
sqrt(1. - ovec[0]*ovec[0] - ovec[1]*ovec[1]); |
126 |
< |
bsdf = eval_rbfrep(rbf, ovec) / fabs(ovec[2]); |
126 |
> |
bsdf = eval_rbfrep(rbf, ovec) * output_orient/ovec[2]; |
127 |
|
if (pctcull >= 0) |
128 |
|
fwrite(&bsdf, sizeof(bsdf), 1, ofp); |
129 |
|
else |
130 |
|
printf("\t%.3e\n", bsdf); |
131 |
|
} |
132 |
< |
free(rbf); |
132 |
> |
if (rbf != NULL) |
133 |
> |
free(rbf); |
134 |
|
} |
135 |
|
if (pctcull >= 0) { /* finish output */ |
136 |
|
if (pclose(ofp)) { |
142 |
|
fputs("}\n", stdout); |
143 |
|
} |
144 |
|
|
145 |
+ |
/* Output XML prologue to stdout */ |
146 |
+ |
static void |
147 |
+ |
xml_prologue(int ac, char *av[]) |
148 |
+ |
{ |
149 |
+ |
static const char *bsdf_type[4] = { |
150 |
+ |
"Reflection Front", |
151 |
+ |
"Transmission Front", |
152 |
+ |
"Transmission Back", |
153 |
+ |
"Reflection Back" |
154 |
+ |
}; |
155 |
+ |
|
156 |
+ |
puts("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); |
157 |
+ |
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\">"); |
158 |
+ |
fputs("<!-- File produced by:", stdout); |
159 |
+ |
while (ac-- > 0) { |
160 |
+ |
fputc(' ', stdout); |
161 |
+ |
fputs(*av++, stdout); |
162 |
+ |
} |
163 |
+ |
puts(" -->"); |
164 |
+ |
puts("<WindowElementType>System</WindowElementType>"); |
165 |
+ |
puts("<FileType>BSDF</FileType>"); |
166 |
+ |
puts("<Optical>"); |
167 |
+ |
puts("<Layer>"); |
168 |
+ |
puts("\t<Material>"); |
169 |
+ |
puts("\t\t<Name>Name</Name>"); |
170 |
+ |
puts("\t\t<Manufacturer>Manufacturer</Manufacturer>"); |
171 |
+ |
puts("\t\t<DeviceType>Other</DeviceType>"); |
172 |
+ |
puts("\t</Material>"); |
173 |
+ |
puts("\t<DataDefinition>"); |
174 |
+ |
printf("\t\t<IncidentDataStructure>TensorTree%c</IncidentDataStructure>\n", |
175 |
+ |
single_plane_incident ? '3' : '4'); |
176 |
+ |
puts("\t</DataDefinition>"); |
177 |
+ |
puts("\t<WavelengthData>"); |
178 |
+ |
puts("\t\t<LayerNumber>System</LayerNumber>"); |
179 |
+ |
puts("\t\t<Wavelength unit=\"Integral\">Visible</Wavelength>"); |
180 |
+ |
puts("\t\t<SourceSpectrum>CIE Illuminant D65 1nm.ssp</SourceSpectrum>"); |
181 |
+ |
puts("\t\t<DetectorSpectrum>ASTM E308 1931 Y.dsp</DetectorSpectrum>"); |
182 |
+ |
puts("\t\t<WavelengthDataBlock>"); |
183 |
+ |
printf("\t\t\t<WavelengthDataDirection>%s</WavelengthDataDirection>\n", |
184 |
+ |
bsdf_type[(input_orient>0)<<1 | (output_orient>0)]); |
185 |
+ |
puts("\t\t\t<AngleBasis>LBNL/Shirley-Chiu</AngleBasis>"); |
186 |
+ |
puts("\t\t\t<ScatteringDataType>BTDF</ScatteringDataType>"); |
187 |
+ |
puts("\t\t\t<ScatteringData>"); |
188 |
+ |
} |
189 |
+ |
|
190 |
+ |
/* Output XML epilogue to stdout */ |
191 |
+ |
static void |
192 |
+ |
xml_epilogue(void) |
193 |
+ |
{ |
194 |
+ |
puts("\t\t\t</ScatteringData>"); |
195 |
+ |
puts("\t\t</WavelengthDataBlock>"); |
196 |
+ |
puts("\t</WavelengthData>"); |
197 |
+ |
puts("</Layer>"); |
198 |
+ |
puts("</Optical>"); |
199 |
+ |
puts("</WindowElement>"); |
200 |
+ |
} |
201 |
+ |
|
202 |
|
/* Read in BSDF and interpolate as tensor tree representation */ |
203 |
|
int |
204 |
|
main(int argc, char *argv[]) |
206 |
|
FILE *fpin = stdin; |
207 |
|
int i; |
208 |
|
|
209 |
< |
progname = argv[0]; /* get options */ |
210 |
< |
while (argc > 2 && argv[1][0] == '-') { |
211 |
< |
switch (argv[1][1]) { |
209 |
> |
progname = argv[0]; |
210 |
> |
for (i = 1; i < argc-1 && argv[i][0] == '-'; i++) |
211 |
> |
switch (argv[i][1]) { /* get option */ |
212 |
|
case 't': |
213 |
< |
pctcull = atoi(argv[2]); |
213 |
> |
pctcull = atof(argv[++i]); |
214 |
|
break; |
215 |
|
case 'g': |
216 |
< |
samp_order = atoi(argv[2]); |
216 |
> |
samp_order = atoi(argv[++i]); |
217 |
|
break; |
218 |
|
default: |
219 |
|
goto userr; |
220 |
|
} |
221 |
< |
argv += 2; argc -= 2; |
222 |
< |
} |
223 |
< |
if (argc == 2) |
224 |
< |
fpin = fopen(argv[1], "r"); |
225 |
< |
else if (argc != 1) |
221 |
> |
|
222 |
> |
if (i == argc-1) { /* open input if given */ |
223 |
> |
fpin = fopen(argv[i], "r"); |
224 |
> |
if (fpin == NULL) { |
225 |
> |
fprintf(stderr, "%s: cannot open BSDF interpolant '%s'\n", |
226 |
> |
progname, argv[1]); |
227 |
> |
return(1); |
228 |
> |
} |
229 |
> |
} else if (i < argc-1) |
230 |
|
goto userr; |
231 |
|
SET_FILE_BINARY(fpin); /* load BSDF interpolant */ |
232 |
|
if (!load_bsdf_rep(fpin)) |
233 |
|
return(1); |
234 |
< |
draw_edges(); |
235 |
< |
/* xml_prologue(); /* start XML output */ |
234 |
> |
fclose(fpin); |
235 |
> |
xml_prologue(argc, argv); /* start XML output */ |
236 |
|
if (single_plane_incident) /* resample dist. */ |
237 |
|
interp_isotropic(); |
238 |
|
else |
239 |
|
interp_anisotropic(); |
240 |
< |
/* xml_epilogue(); /* finish XML output */ |
240 |
> |
xml_epilogue(); /* finish XML output */ |
241 |
|
return(0); |
242 |
|
userr: |
243 |
|
fprintf(stderr, |