13 |
|
#include <math.h> |
14 |
|
#include "random.h" |
15 |
|
#include "platform.h" |
16 |
< |
#include "rtprocess.h" |
16 |
> |
#include "paths.h" |
17 |
> |
#include "rtio.h" |
18 |
|
#include "calcomp.h" |
19 |
|
#include "bsdfrep.h" |
20 |
|
/* global argv[0] */ |
21 |
|
char *progname; |
22 |
|
/* percentage to cull (<0 to turn off) */ |
23 |
< |
double pctcull = 90.; |
23 |
> |
static double pctcull = 90.; |
24 |
|
/* sampling order */ |
25 |
< |
int samp_order = 6; |
25 |
> |
static int samp_order = 6; |
26 |
|
/* super-sampling threshold */ |
27 |
|
const double ssamp_thresh = 0.35; |
28 |
|
/* number of super-samples */ |
34 |
|
/* progress bar length */ |
35 |
|
static int do_prog = 79; |
36 |
|
|
37 |
+ |
#define MAXCARG 512 /* wrapBSDF command */ |
38 |
+ |
static char *wrapBSDF[MAXCARG] = {"wrapBSDF", "-U"}; |
39 |
+ |
static int wbsdfac = 2; |
40 |
|
|
41 |
+ |
/* Add argument to wrapBSDF, allocating space if isstatic */ |
42 |
+ |
static void |
43 |
+ |
add_wbsdf(const char *arg, int isstatic) |
44 |
+ |
{ |
45 |
+ |
if (arg == NULL) |
46 |
+ |
return; |
47 |
+ |
if (wbsdfac >= MAXCARG-1) { |
48 |
+ |
fputs(progname, stderr); |
49 |
+ |
fputs(": too many command arguments to wrapBSDF\n", stderr); |
50 |
+ |
exit(1); |
51 |
+ |
} |
52 |
+ |
if (!*arg) |
53 |
+ |
arg = ""; |
54 |
+ |
else if (!isstatic) |
55 |
+ |
arg = savqstr((char *)arg); |
56 |
+ |
|
57 |
+ |
wrapBSDF[wbsdfac++] = (char *)arg; |
58 |
+ |
} |
59 |
+ |
|
60 |
+ |
/* Create Yuv component file and add appropriate arguments */ |
61 |
+ |
static char * |
62 |
+ |
create_component_file(int c) |
63 |
+ |
{ |
64 |
+ |
static const char sname[3][6] = {"CIE-Y", "CIE-u", "CIE-v"}; |
65 |
+ |
static const char cname[4][4] = {"-rf", "-tf", "-tb", "-rb"}; |
66 |
+ |
char *tfname = mktemp(savqstr(TEMPLATE)); |
67 |
+ |
|
68 |
+ |
add_wbsdf("-s", 1); add_wbsdf(sname[c], 1); |
69 |
+ |
add_wbsdf(cname[(input_orient>0)<<1 | (output_orient>0)], 1); |
70 |
+ |
add_wbsdf(tfname, 1); |
71 |
+ |
return(tfname); |
72 |
+ |
} |
73 |
+ |
|
74 |
|
/* Start new progress bar */ |
75 |
|
#define prog_start(s) if (do_prog) fprintf(stderr, "%s: %s...\n", progname, s); else |
76 |
|
|
110 |
|
fputc('\r', stderr); |
111 |
|
} |
112 |
|
|
76 |
– |
/* Output XML prologue to stdout */ |
77 |
– |
static void |
78 |
– |
xml_prologue(int ac, char *av[]) |
79 |
– |
{ |
80 |
– |
puts("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); |
81 |
– |
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\">"); |
82 |
– |
fputs("<!-- File produced by:", stdout); |
83 |
– |
while (ac-- > 0) { |
84 |
– |
fputc(' ', stdout); |
85 |
– |
fputs(*av++, stdout); |
86 |
– |
} |
87 |
– |
puts(" -->"); |
88 |
– |
puts("<WindowElementType>System</WindowElementType>"); |
89 |
– |
puts("<FileType>BSDF</FileType>"); |
90 |
– |
puts("<Optical>"); |
91 |
– |
puts("<Layer>"); |
92 |
– |
puts("\t<Material>"); |
93 |
– |
printf("\t\t<Name>%s</Name>\n", bsdf_name[0] ? bsdf_name : "Unknown"); |
94 |
– |
printf("\t\t<Manufacturer>%s</Manufacturer>\n", |
95 |
– |
bsdf_manuf[0] ? bsdf_manuf : "Unknown"); |
96 |
– |
puts("\t\t<DeviceType>Other</DeviceType>"); |
97 |
– |
puts("\t</Material>"); |
98 |
– |
puts("\t<DataDefinition>"); |
99 |
– |
printf("\t\t<IncidentDataStructure>TensorTree%c</IncidentDataStructure>\n", |
100 |
– |
single_plane_incident ? '3' : '4'); |
101 |
– |
puts("\t</DataDefinition>"); |
102 |
– |
} |
103 |
– |
|
104 |
– |
/* Output XML data prologue to stdout */ |
105 |
– |
static void |
106 |
– |
data_prologue() |
107 |
– |
{ |
108 |
– |
static const char *bsdf_type[4] = { |
109 |
– |
"Reflection Front", |
110 |
– |
"Transmission Front", |
111 |
– |
"Transmission Back", |
112 |
– |
"Reflection Back" |
113 |
– |
}; |
114 |
– |
|
115 |
– |
puts("\t<WavelengthData>"); |
116 |
– |
puts("\t\t<LayerNumber>System</LayerNumber>"); |
117 |
– |
puts("\t\t<Wavelength unit=\"Integral\">Visible</Wavelength>"); |
118 |
– |
puts("\t\t<SourceSpectrum>CIE Illuminant D65 1nm.ssp</SourceSpectrum>"); |
119 |
– |
puts("\t\t<DetectorSpectrum>ASTM E308 1931 Y.dsp</DetectorSpectrum>"); |
120 |
– |
puts("\t\t<WavelengthDataBlock>"); |
121 |
– |
printf("\t\t\t<WavelengthDataDirection>%s</WavelengthDataDirection>\n", |
122 |
– |
bsdf_type[(input_orient>0)<<1 | (output_orient>0)]); |
123 |
– |
puts("\t\t\t<AngleBasis>LBNL/Shirley-Chiu</AngleBasis>"); |
124 |
– |
puts("\t\t\t<ScatteringDataType>BTDF</ScatteringDataType>"); |
125 |
– |
puts("\t\t\t<ScatteringData>"); |
126 |
– |
} |
127 |
– |
|
128 |
– |
/* Output XML data epilogue to stdout */ |
129 |
– |
static void |
130 |
– |
data_epilogue(void) |
131 |
– |
{ |
132 |
– |
puts("\t\t\t</ScatteringData>"); |
133 |
– |
puts("\t\t</WavelengthDataBlock>"); |
134 |
– |
puts("\t</WavelengthData>"); |
135 |
– |
} |
136 |
– |
|
137 |
– |
/* Output XML epilogue to stdout */ |
138 |
– |
static void |
139 |
– |
xml_epilogue(void) |
140 |
– |
{ |
141 |
– |
puts("</Layer>"); |
142 |
– |
puts("</Optical>"); |
143 |
– |
puts("</WindowElement>"); |
144 |
– |
} |
145 |
– |
|
113 |
|
/* Compute absolute relative difference */ |
114 |
|
static double |
115 |
|
abs_diff(double v1, double v0) |
127 |
|
eval_isotropic(char *funame) |
128 |
|
{ |
129 |
|
const int sqres = 1<<samp_order; |
130 |
< |
FILE *ofp = NULL; |
130 |
> |
FILE *ofp, *uvfp[2]; |
131 |
|
int assignD = 0; |
132 |
|
char cmd[128]; |
133 |
|
int ix, ox, oy; |
134 |
|
double iovec[6]; |
135 |
< |
float bsdf; |
135 |
> |
float bsdf, uv[2]; |
136 |
|
|
170 |
– |
data_prologue(); /* begin output */ |
137 |
|
if (pctcull >= 0) { |
138 |
< |
sprintf(cmd, "rttree_reduce -a -h -ff -r 3 -t %f -g %d", |
139 |
< |
pctcull, samp_order); |
174 |
< |
fflush(stdout); |
138 |
> |
sprintf(cmd, "rttree_reduce -a -h -ff -r 3 -t %f -g %d > %s", |
139 |
> |
pctcull, samp_order, create_component_file(0)); |
140 |
|
ofp = popen(cmd, "w"); |
141 |
|
if (ofp == NULL) { |
142 |
|
fprintf(stderr, "%s: cannot create pipe to rttree_reduce\n", |
147 |
|
#ifdef getc_unlocked /* avoid lock/unlock overhead */ |
148 |
|
flockfile(ofp); |
149 |
|
#endif |
150 |
< |
} else |
151 |
< |
fputs("{\n", stdout); |
152 |
< |
/* need to assign Dx, Dy, Dz? */ |
153 |
< |
if (funame != NULL) |
150 |
> |
if (rbf_colorimetry == RBCtristimulus) { |
151 |
> |
double uvcull = 100. - (100.-pctcull)*.25; |
152 |
> |
sprintf(cmd, "rttree_reduce -a -h -ff -r 3 -t %f -g %d > %s", |
153 |
> |
uvcull, samp_order, create_component_file(1)); |
154 |
> |
uvfp[0] = popen(cmd, "w"); |
155 |
> |
sprintf(cmd, "rttree_reduce -a -h -ff -r 3 -t %f -g %d > %s", |
156 |
> |
uvcull, samp_order, create_component_file(2)); |
157 |
> |
uvfp[1] = popen(cmd, "w"); |
158 |
> |
if ((uvfp[0] == NULL) | (uvfp[1] == NULL)) { |
159 |
> |
fprintf(stderr, "%s: cannot open pipes to uv output\n", |
160 |
> |
progname); |
161 |
> |
exit(1); |
162 |
> |
} |
163 |
> |
SET_FILE_BINARY(uvfp[0]); SET_FILE_BINARY(uvfp[1]); |
164 |
> |
#ifdef getc_unlocked |
165 |
> |
flockfile(uvfp[0]); flockfile(uvfp[1]); |
166 |
> |
#endif |
167 |
> |
} |
168 |
> |
} else { |
169 |
> |
ofp = fopen(create_component_file(0), "w"); |
170 |
> |
if (ofp == NULL) { |
171 |
> |
fprintf(stderr, "%s: cannot create Y output file\n", |
172 |
> |
progname); |
173 |
> |
exit(1); |
174 |
> |
} |
175 |
> |
fputs("{\n", ofp); |
176 |
> |
if (rbf_colorimetry == RBCtristimulus) { |
177 |
> |
uvfp[0] = fopen(create_component_file(1), "w"); |
178 |
> |
uvfp[1] = fopen(create_component_file(2), "w"); |
179 |
> |
if ((uvfp[0] == NULL) | (uvfp[1] == NULL)) { |
180 |
> |
fprintf(stderr, "%s: cannot create uv output file(s)\n", |
181 |
> |
progname); |
182 |
> |
exit(1); |
183 |
> |
} |
184 |
> |
fputs("{\n", uvfp[0]); |
185 |
> |
fputs("{\n", uvfp[1]); |
186 |
> |
} |
187 |
> |
} |
188 |
> |
if (funame != NULL) /* need to assign Dx, Dy, Dz? */ |
189 |
|
assignD = (fundefined(funame) < 6); |
190 |
|
/* run through directions */ |
191 |
|
for (ix = 0; ix < sqres/2; ix++) { |
201 |
|
SDsquare2disk(iovec+3, (ox+.5)/sqres, (oy+.5)/sqres); |
202 |
|
iovec[5] = output_orient * |
203 |
|
sqrt(1. - iovec[3]*iovec[3] - iovec[4]*iovec[4]); |
204 |
< |
if (funame == NULL) |
205 |
< |
bsdf = eval_rbfrep(rbf, iovec+3); |
206 |
< |
else { |
204 |
> |
if (funame == NULL) { |
205 |
> |
SDValue sdv; |
206 |
> |
eval_rbfcol(&sdv, rbf, iovec+3); |
207 |
> |
bsdf = sdv.cieY; |
208 |
> |
if (rbf_colorimetry == RBCtristimulus) { |
209 |
> |
c_ccvt(&sdv.spec, C_CSXY); |
210 |
> |
uv[0] = uv[1] = 1. / |
211 |
> |
(-2.*sdv.spec.cx + 12.*sdv.spec.cy + 3.); |
212 |
> |
uv[0] *= 4.*sdv.spec.cx; |
213 |
> |
uv[1] *= 9.*sdv.spec.cy; |
214 |
> |
} |
215 |
> |
} else { |
216 |
|
if (assignD) { |
217 |
|
varset("Dx", '=', -iovec[3]); |
218 |
|
varset("Dy", '=', -iovec[4]); |
252 |
|
if (pctcull >= 0) |
253 |
|
fwrite(&bsdf, sizeof(bsdf), 1, ofp); |
254 |
|
else |
255 |
< |
printf("\t%.3e\n", bsdf); |
255 |
> |
fprintf(ofp, "\t%.3e\n", bsdf); |
256 |
> |
|
257 |
> |
if (rbf_colorimetry == RBCtristimulus) { |
258 |
> |
if (pctcull >= 0) { |
259 |
> |
fwrite(&uv[0], sizeof(*uv), 1, uvfp[0]); |
260 |
> |
fwrite(&uv[1], sizeof(*uv), 1, uvfp[1]); |
261 |
> |
} else { |
262 |
> |
fprintf(uvfp[0], "\t%.3e\n", uv[0]); |
263 |
> |
fprintf(uvfp[1], "\t%.3e\n", uv[1]); |
264 |
> |
} |
265 |
> |
} |
266 |
|
last_bsdf = bsdf; |
267 |
|
} |
268 |
|
} |
270 |
|
free(rbf); |
271 |
|
prog_show((ix+1.)*(2./sqres)); |
272 |
|
} |
273 |
+ |
prog_done(); |
274 |
|
if (pctcull >= 0) { /* finish output */ |
275 |
|
if (pclose(ofp)) { |
276 |
< |
fprintf(stderr, "%s: error running '%s'\n", |
277 |
< |
progname, cmd); |
276 |
> |
fprintf(stderr, "%s: error running rttree_reduce on Y\n", |
277 |
> |
progname); |
278 |
|
exit(1); |
279 |
|
} |
280 |
+ |
if (rbf_colorimetry == RBCtristimulus && |
281 |
+ |
(pclose(uvfp[0]) || pclose(uvfp[1]))) { |
282 |
+ |
fprintf(stderr, "%s: error running rttree_reduce on uv\n", |
283 |
+ |
progname); |
284 |
+ |
exit(1); |
285 |
+ |
} |
286 |
|
} else { |
287 |
|
for (ix = sqres*sqres*sqres/2; ix--; ) |
288 |
< |
fputs("\t0\n", stdout); |
289 |
< |
fputs("}\n", stdout); |
288 |
> |
fputs("\t0\n", ofp); |
289 |
> |
fputs("}\n", ofp); |
290 |
> |
if (fclose(ofp)) { |
291 |
> |
fprintf(stderr, "%s: error writing Y file\n", |
292 |
> |
progname); |
293 |
> |
exit(1); |
294 |
> |
} |
295 |
> |
if (rbf_colorimetry == RBCtristimulus) { |
296 |
> |
for (ix = sqres*sqres*sqres/2; ix--; ) { |
297 |
> |
fputs("\t0\n", uvfp[0]); |
298 |
> |
fputs("\t0\n", uvfp[1]); |
299 |
> |
} |
300 |
> |
fputs("}\n", uvfp[0]); |
301 |
> |
fputs("}\n", uvfp[1]); |
302 |
> |
if (fclose(uvfp[0]) || fclose(uvfp[1])) { |
303 |
> |
fprintf(stderr, "%s: error writing uv file(s)\n", |
304 |
> |
progname); |
305 |
> |
exit(1); |
306 |
> |
} |
307 |
> |
} |
308 |
|
} |
265 |
– |
data_epilogue(); |
266 |
– |
prog_done(); |
309 |
|
} |
310 |
|
|
311 |
|
/* Interpolate and output anisotropic BSDF data */ |
313 |
|
eval_anisotropic(char *funame) |
314 |
|
{ |
315 |
|
const int sqres = 1<<samp_order; |
316 |
< |
FILE *ofp = NULL; |
316 |
> |
FILE *ofp, *uvfp[2]; |
317 |
|
int assignD = 0; |
318 |
|
char cmd[128]; |
319 |
|
int ix, iy, ox, oy; |
320 |
|
double iovec[6]; |
321 |
< |
float bsdf; |
321 |
> |
float bsdf, uv[2]; |
322 |
|
|
281 |
– |
data_prologue(); /* begin output */ |
323 |
|
if (pctcull >= 0) { |
324 |
< |
sprintf(cmd, "rttree_reduce%s -h -ff -r 4 -t %f -g %d", |
325 |
< |
(input_orient>0 ^ output_orient>0) ? "" : " -a", |
326 |
< |
pctcull, samp_order); |
327 |
< |
fflush(stdout); |
324 |
> |
const char *avgopt = (input_orient>0 ^ output_orient>0) |
325 |
> |
? "" : " -a"; |
326 |
> |
sprintf(cmd, "rttree_reduce%s -h -ff -r 4 -t %f -g %d > %s", |
327 |
> |
avgopt, pctcull, samp_order, |
328 |
> |
create_component_file(0)); |
329 |
|
ofp = popen(cmd, "w"); |
330 |
|
if (ofp == NULL) { |
331 |
|
fprintf(stderr, "%s: cannot create pipe to rttree_reduce\n", |
336 |
|
#ifdef getc_unlocked /* avoid lock/unlock overhead */ |
337 |
|
flockfile(ofp); |
338 |
|
#endif |
339 |
< |
} else |
340 |
< |
fputs("{\n", stdout); |
341 |
< |
/* need to assign Dx, Dy, Dz? */ |
342 |
< |
if (funame != NULL) |
339 |
> |
if (rbf_colorimetry == RBCtristimulus) { |
340 |
> |
double uvcull = 100. - (100.-pctcull)*.25; |
341 |
> |
sprintf(cmd, "rttree_reduce%s -h -ff -r 4 -t %f -g %d > %s", |
342 |
> |
avgopt, uvcull, samp_order, |
343 |
> |
create_component_file(1)); |
344 |
> |
uvfp[0] = popen(cmd, "w"); |
345 |
> |
sprintf(cmd, "rttree_reduce%s -h -ff -r 4 -t %f -g %d > %s", |
346 |
> |
avgopt, uvcull, samp_order, |
347 |
> |
create_component_file(2)); |
348 |
> |
uvfp[1] = popen(cmd, "w"); |
349 |
> |
if ((uvfp[0] == NULL) | (uvfp[1] == NULL)) { |
350 |
> |
fprintf(stderr, "%s: cannot open pipes to uv output\n", |
351 |
> |
progname); |
352 |
> |
exit(1); |
353 |
> |
} |
354 |
> |
SET_FILE_BINARY(uvfp[0]); SET_FILE_BINARY(uvfp[1]); |
355 |
> |
#ifdef getc_unlocked |
356 |
> |
flockfile(uvfp[0]); flockfile(uvfp[1]); |
357 |
> |
#endif |
358 |
> |
} |
359 |
> |
} else { |
360 |
> |
ofp = fopen(create_component_file(0), "w"); |
361 |
> |
if (ofp == NULL) { |
362 |
> |
fprintf(stderr, "%s: cannot create Y output file\n", |
363 |
> |
progname); |
364 |
> |
exit(1); |
365 |
> |
} |
366 |
> |
fputs("{\n", ofp); |
367 |
> |
if (rbf_colorimetry == RBCtristimulus) { |
368 |
> |
uvfp[0] = fopen(create_component_file(1), "w"); |
369 |
> |
uvfp[1] = fopen(create_component_file(2), "w"); |
370 |
> |
if ((uvfp[0] == NULL) | (uvfp[1] == NULL)) { |
371 |
> |
fprintf(stderr, "%s: cannot create uv output file(s)\n", |
372 |
> |
progname); |
373 |
> |
exit(1); |
374 |
> |
} |
375 |
> |
fputs("{\n", uvfp[0]); |
376 |
> |
fputs("{\n", uvfp[1]); |
377 |
> |
} |
378 |
> |
} |
379 |
> |
if (funame != NULL) /* need to assign Dx, Dy, Dz? */ |
380 |
|
assignD = (fundefined(funame) < 6); |
381 |
|
/* run through directions */ |
382 |
|
for (ix = 0; ix < sqres; ix++) |
393 |
|
SDsquare2disk(iovec+3, (ox+.5)/sqres, (oy+.5)/sqres); |
394 |
|
iovec[5] = output_orient * |
395 |
|
sqrt(1. - iovec[3]*iovec[3] - iovec[4]*iovec[4]); |
396 |
< |
if (funame == NULL) |
397 |
< |
bsdf = eval_rbfrep(rbf, iovec+3); |
398 |
< |
else { |
396 |
> |
if (funame == NULL) { |
397 |
> |
SDValue sdv; |
398 |
> |
eval_rbfcol(&sdv, rbf, iovec+3); |
399 |
> |
bsdf = sdv.cieY; |
400 |
> |
if (rbf_colorimetry == RBCtristimulus) { |
401 |
> |
c_ccvt(&sdv.spec, C_CSXY); |
402 |
> |
uv[0] = uv[1] = 1. / |
403 |
> |
(-2.*sdv.spec.cx + 12.*sdv.spec.cy + 3.); |
404 |
> |
uv[0] *= 4.*sdv.spec.cx; |
405 |
> |
uv[1] *= 9.*sdv.spec.cy; |
406 |
> |
} |
407 |
> |
} else { |
408 |
|
if (assignD) { |
409 |
|
varset("Dx", '=', -iovec[3]); |
410 |
|
varset("Dy", '=', -iovec[4]); |
445 |
|
if (pctcull >= 0) |
446 |
|
fwrite(&bsdf, sizeof(bsdf), 1, ofp); |
447 |
|
else |
448 |
< |
printf("\t%.3e\n", bsdf); |
448 |
> |
fprintf(ofp, "\t%.3e\n", bsdf); |
449 |
> |
|
450 |
> |
if (rbf_colorimetry == RBCtristimulus) { |
451 |
> |
if (pctcull >= 0) { |
452 |
> |
fwrite(&uv[0], sizeof(*uv), 1, uvfp[0]); |
453 |
> |
fwrite(&uv[1], sizeof(*uv), 1, uvfp[1]); |
454 |
> |
} else { |
455 |
> |
fprintf(uvfp[0], "\t%.3e\n", uv[0]); |
456 |
> |
fprintf(uvfp[1], "\t%.3e\n", uv[1]); |
457 |
> |
} |
458 |
> |
} |
459 |
|
last_bsdf = bsdf; |
460 |
|
} |
461 |
|
} |
463 |
|
free(rbf); |
464 |
|
prog_show((ix*sqres+iy+1.)/(sqres*sqres)); |
465 |
|
} |
466 |
+ |
prog_done(); |
467 |
|
if (pctcull >= 0) { /* finish output */ |
468 |
|
if (pclose(ofp)) { |
469 |
< |
fprintf(stderr, "%s: error running '%s'\n", |
470 |
< |
progname, cmd); |
469 |
> |
fprintf(stderr, "%s: error running rttree_reduce on Y\n", |
470 |
> |
progname); |
471 |
|
exit(1); |
472 |
|
} |
473 |
< |
} else |
474 |
< |
fputs("}\n", stdout); |
475 |
< |
data_epilogue(); |
476 |
< |
prog_done(); |
473 |
> |
if (rbf_colorimetry == RBCtristimulus && |
474 |
> |
(pclose(uvfp[0]) || pclose(uvfp[1]))) { |
475 |
> |
fprintf(stderr, "%s: error running rttree_reduce on uv\n", |
476 |
> |
progname); |
477 |
> |
exit(1); |
478 |
> |
} |
479 |
> |
} else { |
480 |
> |
fputs("}\n", ofp); |
481 |
> |
if (fclose(ofp)) { |
482 |
> |
fprintf(stderr, "%s: error writing Y file\n", |
483 |
> |
progname); |
484 |
> |
exit(1); |
485 |
> |
} |
486 |
> |
if (rbf_colorimetry == RBCtristimulus) { |
487 |
> |
fputs("}\n", uvfp[0]); |
488 |
> |
fputs("}\n", uvfp[1]); |
489 |
> |
if (fclose(uvfp[0]) || fclose(uvfp[1])) { |
490 |
> |
fprintf(stderr, "%s: error writing uv file(s)\n", |
491 |
> |
progname); |
492 |
> |
exit(1); |
493 |
> |
} |
494 |
> |
} |
495 |
> |
} |
496 |
|
} |
497 |
|
|
498 |
+ |
#if defined(_WIN32) || defined(_WIN64) |
499 |
+ |
/* Execute wrapBSDF command (may never return) */ |
500 |
+ |
static int |
501 |
+ |
wrap_up(void) |
502 |
+ |
{ |
503 |
+ |
char cmd[8192]; |
504 |
+ |
|
505 |
+ |
if (bsdf_manuf[0]) { |
506 |
+ |
add_wbsdf("-f", 1); |
507 |
+ |
strcpy(cmd, "m="); |
508 |
+ |
strcpy(cmd+2, bsdf_manuf); |
509 |
+ |
add_wbsdf(cmd, 0); |
510 |
+ |
} |
511 |
+ |
if (bsdf_name[0]) { |
512 |
+ |
add_wbsdf("-f", 1); |
513 |
+ |
strcpy(cmd, "n="); |
514 |
+ |
strcpy(cmd+2, bsdf_name); |
515 |
+ |
add_wbsdf(cmd, 0); |
516 |
+ |
} |
517 |
+ |
if (!convert_commandline(cmd, sizeof(cmd), wrapBSDF)) { |
518 |
+ |
fputs(progname, stderr); |
519 |
+ |
fputs(": command line too long in wrap_up()\n", stderr); |
520 |
+ |
return(1); |
521 |
+ |
} |
522 |
+ |
return(system(cmd)); |
523 |
+ |
} |
524 |
+ |
#else |
525 |
+ |
/* Execute wrapBSDF command (may never return) */ |
526 |
+ |
static int |
527 |
+ |
wrap_up(void) |
528 |
+ |
{ |
529 |
+ |
char buf[256]; |
530 |
+ |
char *compath = getpath((char *)wrapBSDF[0], getenv("PATH"), X_OK); |
531 |
+ |
|
532 |
+ |
if (compath == NULL) { |
533 |
+ |
fprintf(stderr, "%s: cannot locate %s\n", progname, wrapBSDF[0]); |
534 |
+ |
return(1); |
535 |
+ |
} |
536 |
+ |
if (bsdf_manuf[0]) { |
537 |
+ |
add_wbsdf("-f", 1); |
538 |
+ |
strcpy(buf, "m="); |
539 |
+ |
strcpy(buf+2, bsdf_manuf); |
540 |
+ |
add_wbsdf(buf, 0); |
541 |
+ |
} |
542 |
+ |
if (bsdf_name[0]) { |
543 |
+ |
add_wbsdf("-f", 1); |
544 |
+ |
strcpy(buf, "n="); |
545 |
+ |
strcpy(buf+2, bsdf_name); |
546 |
+ |
add_wbsdf(buf, 0); |
547 |
+ |
} |
548 |
+ |
execv(compath, wrapBSDF); /* successful call never returns */ |
549 |
+ |
perror(compath); |
550 |
+ |
return(1); |
551 |
+ |
} |
552 |
+ |
#endif |
553 |
+ |
|
554 |
|
/* Read in BSDF and interpolate as tensor tree representation */ |
555 |
|
int |
556 |
|
main(int argc, char *argv[]) |
557 |
|
{ |
558 |
+ |
static char tfmt[2][4] = {"t4", "t3"}; |
559 |
|
int dofwd = 0, dobwd = 1; |
560 |
+ |
char buf[2048]; |
561 |
|
int i, na; |
562 |
|
|
563 |
|
progname = argv[0]; |
571 |
|
scompile(argv[++i], NULL, 0); |
572 |
|
break; |
573 |
|
case 'f': |
574 |
< |
if (!argv[i][2]) |
575 |
< |
fcompile(argv[++i]); |
576 |
< |
else |
574 |
> |
if (!argv[i][2]) { |
575 |
> |
if (strchr(argv[++i], '=') != NULL) { |
576 |
> |
add_wbsdf("-f", 1); |
577 |
> |
add_wbsdf(argv[i], 1); |
578 |
> |
} else |
579 |
> |
fcompile(argv[i]); |
580 |
> |
} else |
581 |
|
dofwd = (argv[i][0] == '+'); |
582 |
|
break; |
583 |
|
case 'b': |
607 |
|
case 'p': |
608 |
|
do_prog = atoi(argv[i]+2); |
609 |
|
break; |
610 |
+ |
case 'W': |
611 |
+ |
add_wbsdf(argv[i], 1); |
612 |
+ |
break; |
613 |
+ |
case 'u': |
614 |
+ |
case 'C': |
615 |
+ |
add_wbsdf(argv[i], 1); |
616 |
+ |
add_wbsdf(argv[++i], 1); |
617 |
+ |
break; |
618 |
|
default: |
619 |
|
goto userr; |
620 |
|
} |
621 |
+ |
strcpy(buf, "File produced by: "); |
622 |
+ |
if (convert_commandline(buf+18, sizeof(buf)-18, argv) != NULL) { |
623 |
+ |
add_wbsdf("-C", 1); add_wbsdf(buf, 0); |
624 |
+ |
} |
625 |
|
if (single_plane_incident >= 0) { /* function-based BSDF? */ |
626 |
|
void (*evf)(char *s) = single_plane_incident ? |
627 |
< |
&eval_isotropic : &eval_anisotropic; |
627 |
> |
eval_isotropic : eval_anisotropic; |
628 |
|
if (i != argc-1 || fundefined(argv[i]) < 3) { |
629 |
|
fprintf(stderr, |
630 |
|
"%s: need single function with 6 arguments: bsdf(ix,iy,iz,ox,oy,oz)\n", |
633 |
|
goto userr; |
634 |
|
} |
635 |
|
++eclock; |
636 |
< |
xml_prologue(argc, argv); /* start XML output */ |
636 |
> |
add_wbsdf("-a", 1); |
637 |
> |
add_wbsdf(tfmt[single_plane_incident], 1); |
638 |
|
if (dofwd) { |
639 |
|
input_orient = -1; |
640 |
|
output_orient = -1; |
653 |
|
prog_start("Evaluating inside->outside transmission"); |
654 |
|
(*evf)(argv[i]); |
655 |
|
} |
656 |
< |
xml_epilogue(); /* finish XML output & exit */ |
464 |
< |
return(0); |
656 |
> |
return(wrap_up()); |
657 |
|
} |
658 |
|
if (i < argc) { /* open input files if given */ |
659 |
|
int nbsdf = 0; |
668 |
|
if (!load_bsdf_rep(fpin)) |
669 |
|
return(1); |
670 |
|
fclose(fpin); |
479 |
– |
if (!nbsdf++) /* start XML on first dist. */ |
480 |
– |
xml_prologue(argc, argv); |
671 |
|
sprintf(pbuf, "Interpolating component '%s'", argv[i]); |
672 |
|
prog_start(pbuf); |
673 |
+ |
if (!nbsdf++) { |
674 |
+ |
add_wbsdf("-a", 1); |
675 |
+ |
add_wbsdf(tfmt[single_plane_incident], 1); |
676 |
+ |
} |
677 |
|
if (single_plane_incident) |
678 |
|
eval_isotropic(NULL); |
679 |
|
else |
680 |
|
eval_anisotropic(NULL); |
681 |
|
} |
682 |
< |
xml_epilogue(); /* finish XML output & exit */ |
489 |
< |
return(0); |
682 |
> |
return(wrap_up()); |
683 |
|
} |
684 |
|
SET_FILE_BINARY(stdin); /* load from stdin */ |
685 |
|
if (!load_bsdf_rep(stdin)) |
686 |
|
return(1); |
494 |
– |
xml_prologue(argc, argv); /* start XML output */ |
687 |
|
prog_start("Interpolating from standard input"); |
688 |
+ |
add_wbsdf("-a", 1); |
689 |
+ |
add_wbsdf(tfmt[single_plane_incident], 1); |
690 |
|
if (single_plane_incident) /* resample dist. */ |
691 |
|
eval_isotropic(NULL); |
692 |
|
else |
693 |
|
eval_anisotropic(NULL); |
694 |
< |
xml_epilogue(); /* finish XML output & exit */ |
695 |
< |
return(0); |
694 |
> |
|
695 |
> |
return(wrap_up()); |
696 |
|
userr: |
697 |
|
fprintf(stderr, |
698 |
|
"Usage: %s [-g Nlog2][-t pctcull][-l maxlobes] [bsdf.sir ..] > bsdf.xml\n", |