| 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 |
| 122 |
|
SDsquare2disk(ovec, (ox+.5)/sqres, (oy+.5)/sqres); |
| 123 |
|
ovec[2] = output_orient * |
| 124 |
|
sqrt(1. - ovec[0]*ovec[0] - ovec[1]*ovec[1]); |
| 125 |
< |
bsdf = eval_rbfrep(rbf, ovec) / fabs(ovec[2]); |
| 125 |
> |
bsdf = eval_rbfrep(rbf, ovec) * output_orient/ovec[2]; |
| 126 |
|
if (pctcull >= 0) |
| 127 |
|
fwrite(&bsdf, sizeof(bsdf), 1, ofp); |
| 128 |
|
else |
| 141 |
|
fputs("}\n", stdout); |
| 142 |
|
} |
| 143 |
|
|
| 144 |
+ |
/* Output XML prologue to stdout */ |
| 145 |
+ |
static void |
| 146 |
+ |
xml_prologue(int ac, char *av[]) |
| 147 |
+ |
{ |
| 148 |
+ |
static const char *prologue0[] = { |
| 149 |
+ |
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>", |
| 150 |
+ |
"<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\">", |
| 151 |
+ |
NULL}; |
| 152 |
+ |
static const char *prologue1[] = { |
| 153 |
+ |
"<WindowElementType>System</WindowElementType>", |
| 154 |
+ |
"<FileType>BSDF</FileType>", |
| 155 |
+ |
"<Optical>", |
| 156 |
+ |
"<Layer>", |
| 157 |
+ |
"\t<Material>", |
| 158 |
+ |
"\t\t<Name>Name</Name>", |
| 159 |
+ |
"\t\t<Manufacturer>Manufacturer</Manufacturer>", |
| 160 |
+ |
"\t\t<DeviceType>Other</DeviceType>", |
| 161 |
+ |
"\t</Material>", |
| 162 |
+ |
NULL}; |
| 163 |
+ |
static const char *prologue2[] = { |
| 164 |
+ |
"\t<WavelengthData>", |
| 165 |
+ |
"\t\t<LayerNumber>System</LayerNumber>", |
| 166 |
+ |
"\t\t<Wavelength unit=\"Integral\">Visible</Wavelength>", |
| 167 |
+ |
"\t\t<SourceSpectrum>CIE Illuminant D65 1nm.ssp</SourceSpectrum>", |
| 168 |
+ |
"\t\t<DetectorSpectrum>ASTM E308 1931 Y.dsp</DetectorSpectrum>", |
| 169 |
+ |
"\t\t<WavelengthDataBlock>", |
| 170 |
+ |
"\t\t\t<AngleBasis>LBNL/Shirley-Chiu</AngleBasis>", |
| 171 |
+ |
"\t\t\t<ScatteringDataType>BTDF</ScatteringDataType>", |
| 172 |
+ |
NULL}; |
| 173 |
+ |
static const char *bsdf_type[4] = { |
| 174 |
+ |
"Reflection Back", |
| 175 |
+ |
"Transmission Back", |
| 176 |
+ |
"Transmission Front", |
| 177 |
+ |
"Reflection Front" |
| 178 |
+ |
}; |
| 179 |
+ |
int i; |
| 180 |
+ |
|
| 181 |
+ |
for (i = 0; prologue0[i] != NULL; i++) |
| 182 |
+ |
puts(prologue0[i]); |
| 183 |
+ |
fputs("<!-- File produced by:", stdout); |
| 184 |
+ |
while (ac-- > 0) { |
| 185 |
+ |
fputc(' ', stdout); |
| 186 |
+ |
fputs(*av++, stdout); |
| 187 |
+ |
} |
| 188 |
+ |
puts(" -->"); |
| 189 |
+ |
for (i = 0; prologue1[i] != NULL; i++) |
| 190 |
+ |
puts(prologue1[i]); |
| 191 |
+ |
puts("\t<DataDefinition>"); |
| 192 |
+ |
printf("\t\t<IncidentDataStructure>TensorTree%c</IncidentDataStructure>\n", |
| 193 |
+ |
single_plane_incident ? '3' : '4'); |
| 194 |
+ |
puts("\t</DataDefinition>"); |
| 195 |
+ |
for (i = 0; prologue2[i] != NULL; i++) |
| 196 |
+ |
puts(prologue2[i]); |
| 197 |
+ |
printf("\t\t\t<WavelengthDataDirection>%s</WavelengthDataDirection>\n", |
| 198 |
+ |
bsdf_type[(input_orient>0)<<1 | (output_orient>0)]); |
| 199 |
+ |
puts("\t\t\t<ScatteringData>"); |
| 200 |
+ |
} |
| 201 |
+ |
|
| 202 |
+ |
/* Output XML epilogue to stdout */ |
| 203 |
+ |
static void |
| 204 |
+ |
xml_epilogue(void) |
| 205 |
+ |
{ |
| 206 |
+ |
static const char *epilogue[] = { |
| 207 |
+ |
"\t\t\t</ScatteringData>", |
| 208 |
+ |
"\t\t</WavelengthDataBlock>", |
| 209 |
+ |
"\t</WavelengthData>", |
| 210 |
+ |
"</Layer>", |
| 211 |
+ |
"</Optical>", |
| 212 |
+ |
"</WindowElement>", |
| 213 |
+ |
NULL}; |
| 214 |
+ |
int i; |
| 215 |
+ |
|
| 216 |
+ |
for (i = 0; epilogue[i] != NULL; i++) |
| 217 |
+ |
puts(epilogue[i]); |
| 218 |
+ |
} |
| 219 |
+ |
|
| 220 |
|
/* Read in BSDF and interpolate as tensor tree representation */ |
| 221 |
|
int |
| 222 |
|
main(int argc, char *argv[]) |
| 224 |
|
FILE *fpin = stdin; |
| 225 |
|
int i; |
| 226 |
|
|
| 227 |
< |
progname = argv[0]; /* get options */ |
| 228 |
< |
while (argc > 2 && argv[1][0] == '-') { |
| 229 |
< |
switch (argv[1][1]) { |
| 227 |
> |
progname = argv[0]; |
| 228 |
> |
for (i = 1; i < argc-1 && argv[i][0] == '-'; i++) |
| 229 |
> |
switch (argv[i][1]) { /* get option */ |
| 230 |
|
case 't': |
| 231 |
< |
pctcull = atoi(argv[2]); |
| 231 |
> |
pctcull = atoi(argv[++i]); |
| 232 |
|
break; |
| 233 |
|
case 'g': |
| 234 |
< |
samp_order = atoi(argv[2]); |
| 234 |
> |
samp_order = atoi(argv[++i]); |
| 235 |
|
break; |
| 236 |
|
default: |
| 237 |
|
goto userr; |
| 238 |
|
} |
| 239 |
< |
argv += 2; argc -= 2; |
| 240 |
< |
} |
| 241 |
< |
if (argc == 2) { /* open input if given */ |
| 166 |
< |
fpin = fopen(argv[1], "r"); |
| 239 |
> |
|
| 240 |
> |
if (i == argc-1) { /* open input if given */ |
| 241 |
> |
fpin = fopen(argv[i], "r"); |
| 242 |
|
if (fpin == NULL) { |
| 243 |
|
fprintf(stderr, "%s: cannot open BSDF interpolant '%s'\n", |
| 244 |
|
progname, argv[1]); |
| 245 |
|
return(1); |
| 246 |
|
} |
| 247 |
< |
} else if (argc != 1) |
| 247 |
> |
} else if (i < argc-1) |
| 248 |
|
goto userr; |
| 249 |
|
SET_FILE_BINARY(fpin); /* load BSDF interpolant */ |
| 250 |
|
if (!load_bsdf_rep(fpin)) |
| 251 |
|
return(1); |
| 252 |
< |
/* xml_prologue(); /* start XML output */ |
| 252 |
> |
fclose(fpin); |
| 253 |
> |
xml_prologue(argc, argv); /* start XML output */ |
| 254 |
|
if (single_plane_incident) /* resample dist. */ |
| 255 |
|
interp_isotropic(); |
| 256 |
|
else |
| 257 |
|
interp_anisotropic(); |
| 258 |
< |
/* xml_epilogue(); /* finish XML output */ |
| 258 |
> |
xml_epilogue(); /* finish XML output */ |
| 259 |
|
return(0); |
| 260 |
|
userr: |
| 261 |
|
fprintf(stderr, |