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 */ |
29 |
|
#ifndef NSSAMP |
30 |
< |
#define NSSAMP 100 |
30 |
> |
#define NSSAMP 64 |
31 |
|
#endif |
32 |
|
/* limit on number of RBF lobes */ |
33 |
|
static int lobe_lim = 15000; |
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 |
|
|
78 |
|
static void |
79 |
|
prog_show(double frac) |
80 |
|
{ |
81 |
< |
char pbar[256]; |
82 |
< |
int nchars; |
81 |
> |
static unsigned call_cnt = 0; |
82 |
> |
static char lastc[] = "-\\|/"; |
83 |
> |
char pbar[256]; |
84 |
> |
int nchars; |
85 |
|
|
86 |
< |
if (do_prog <= 0) return; |
86 |
> |
if (do_prog <= 1) return; |
87 |
|
if (do_prog > sizeof(pbar)-2) |
88 |
|
do_prog = sizeof(pbar)-2; |
89 |
|
if (frac < 0) frac = 0; |
90 |
< |
else if (frac > 1) frac = 1; |
91 |
< |
nchars = do_prog*frac + .5; |
90 |
> |
else if (frac >= 1) frac = .9999; |
91 |
> |
nchars = do_prog*frac; |
92 |
|
pbar[0] = '\r'; |
93 |
|
memset(pbar+1, '*', nchars); |
94 |
< |
memset(pbar+1+nchars, '-', do_prog-nchars); |
94 |
> |
pbar[nchars+1] = lastc[call_cnt++ & 3]; |
95 |
> |
memset(pbar+2+nchars, '-', do_prog-nchars-1); |
96 |
|
pbar[do_prog+1] = '\0'; |
97 |
|
fputs(pbar, stderr); |
98 |
|
} |
110 |
|
fputc('\r', stderr); |
111 |
|
} |
112 |
|
|
73 |
– |
/* Output XML prologue to stdout */ |
74 |
– |
static void |
75 |
– |
xml_prologue(int ac, char *av[]) |
76 |
– |
{ |
77 |
– |
puts("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); |
78 |
– |
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\">"); |
79 |
– |
fputs("<!-- File produced by:", stdout); |
80 |
– |
while (ac-- > 0) { |
81 |
– |
fputc(' ', stdout); |
82 |
– |
fputs(*av++, stdout); |
83 |
– |
} |
84 |
– |
puts(" -->"); |
85 |
– |
puts("<WindowElementType>System</WindowElementType>"); |
86 |
– |
puts("<FileType>BSDF</FileType>"); |
87 |
– |
puts("<Optical>"); |
88 |
– |
puts("<Layer>"); |
89 |
– |
puts("\t<Material>"); |
90 |
– |
printf("\t\t<Name>%s</Name>\n", bsdf_name[0] ? bsdf_name : "Unknown"); |
91 |
– |
printf("\t\t<Manufacturer>%s</Manufacturer>\n", |
92 |
– |
bsdf_manuf[0] ? bsdf_manuf : "Unknown"); |
93 |
– |
puts("\t\t<DeviceType>Other</DeviceType>"); |
94 |
– |
puts("\t</Material>"); |
95 |
– |
puts("\t<DataDefinition>"); |
96 |
– |
printf("\t\t<IncidentDataStructure>TensorTree%c</IncidentDataStructure>\n", |
97 |
– |
single_plane_incident ? '3' : '4'); |
98 |
– |
puts("\t</DataDefinition>"); |
99 |
– |
} |
100 |
– |
|
101 |
– |
/* Output XML data prologue to stdout */ |
102 |
– |
static void |
103 |
– |
data_prologue() |
104 |
– |
{ |
105 |
– |
static const char *bsdf_type[4] = { |
106 |
– |
"Reflection Front", |
107 |
– |
"Transmission Front", |
108 |
– |
"Transmission Back", |
109 |
– |
"Reflection Back" |
110 |
– |
}; |
111 |
– |
|
112 |
– |
puts("\t<WavelengthData>"); |
113 |
– |
puts("\t\t<LayerNumber>System</LayerNumber>"); |
114 |
– |
puts("\t\t<Wavelength unit=\"Integral\">Visible</Wavelength>"); |
115 |
– |
puts("\t\t<SourceSpectrum>CIE Illuminant D65 1nm.ssp</SourceSpectrum>"); |
116 |
– |
puts("\t\t<DetectorSpectrum>ASTM E308 1931 Y.dsp</DetectorSpectrum>"); |
117 |
– |
puts("\t\t<WavelengthDataBlock>"); |
118 |
– |
printf("\t\t\t<WavelengthDataDirection>%s</WavelengthDataDirection>\n", |
119 |
– |
bsdf_type[(input_orient>0)<<1 | (output_orient>0)]); |
120 |
– |
puts("\t\t\t<AngleBasis>LBNL/Shirley-Chiu</AngleBasis>"); |
121 |
– |
puts("\t\t\t<ScatteringDataType>BTDF</ScatteringDataType>"); |
122 |
– |
puts("\t\t\t<ScatteringData>"); |
123 |
– |
} |
124 |
– |
|
125 |
– |
/* Output XML data epilogue to stdout */ |
126 |
– |
static void |
127 |
– |
data_epilogue(void) |
128 |
– |
{ |
129 |
– |
puts("\t\t\t</ScatteringData>"); |
130 |
– |
puts("\t\t</WavelengthDataBlock>"); |
131 |
– |
puts("\t</WavelengthData>"); |
132 |
– |
} |
133 |
– |
|
134 |
– |
/* Output XML epilogue to stdout */ |
135 |
– |
static void |
136 |
– |
xml_epilogue(void) |
137 |
– |
{ |
138 |
– |
puts("</Layer>"); |
139 |
– |
puts("</Optical>"); |
140 |
– |
puts("</WindowElement>"); |
141 |
– |
} |
142 |
– |
|
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 |
|
|
167 |
– |
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); |
171 |
< |
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 |
< |
output_orient/iovec[5]; |
207 |
< |
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 |
> |
uv[0] = uv[1] = 1. / |
210 |
> |
(-2.*sdv.spec.cx + 12.*sdv.spec.cy + 3.); |
211 |
> |
uv[0] *= 4.*sdv.spec.cx; |
212 |
> |
uv[1] *= 9.*sdv.spec.cy; |
213 |
> |
} |
214 |
> |
} else { |
215 |
|
if (assignD) { |
216 |
|
varset("Dx", '=', -iovec[3]); |
217 |
|
varset("Dy", '=', -iovec[4]); |
249 |
|
#endif |
250 |
|
} |
251 |
|
if (pctcull >= 0) |
252 |
< |
fwrite(&bsdf, sizeof(bsdf), 1, ofp); |
252 |
> |
putbinary(&bsdf, sizeof(bsdf), 1, ofp); |
253 |
|
else |
254 |
< |
printf("\t%.3e\n", bsdf); |
254 |
> |
fprintf(ofp, "\t%.3e\n", bsdf); |
255 |
> |
|
256 |
> |
if (rbf_colorimetry == RBCtristimulus) { |
257 |
> |
if (pctcull >= 0) { |
258 |
> |
putbinary(&uv[0], sizeof(*uv), 1, uvfp[0]); |
259 |
> |
putbinary(&uv[1], sizeof(*uv), 1, uvfp[1]); |
260 |
> |
} else { |
261 |
> |
fprintf(uvfp[0], "\t%.3e\n", uv[0]); |
262 |
> |
fprintf(uvfp[1], "\t%.3e\n", uv[1]); |
263 |
> |
} |
264 |
> |
} |
265 |
|
last_bsdf = bsdf; |
266 |
|
} |
267 |
|
} |
269 |
|
free(rbf); |
270 |
|
prog_show((ix+1.)*(2./sqres)); |
271 |
|
} |
272 |
+ |
prog_done(); |
273 |
|
if (pctcull >= 0) { /* finish output */ |
274 |
|
if (pclose(ofp)) { |
275 |
< |
fprintf(stderr, "%s: error running '%s'\n", |
276 |
< |
progname, cmd); |
275 |
> |
fprintf(stderr, "%s: error running rttree_reduce on Y\n", |
276 |
> |
progname); |
277 |
|
exit(1); |
278 |
|
} |
279 |
+ |
if (rbf_colorimetry == RBCtristimulus && |
280 |
+ |
(pclose(uvfp[0]) || pclose(uvfp[1]))) { |
281 |
+ |
fprintf(stderr, "%s: error running rttree_reduce on uv\n", |
282 |
+ |
progname); |
283 |
+ |
exit(1); |
284 |
+ |
} |
285 |
|
} else { |
286 |
|
for (ix = sqres*sqres*sqres/2; ix--; ) |
287 |
< |
fputs("\t0\n", stdout); |
288 |
< |
fputs("}\n", stdout); |
287 |
> |
fputs("\t0\n", ofp); |
288 |
> |
fputs("}\n", ofp); |
289 |
> |
if (fclose(ofp)) { |
290 |
> |
fprintf(stderr, "%s: error writing Y file\n", |
291 |
> |
progname); |
292 |
> |
exit(1); |
293 |
> |
} |
294 |
> |
if (rbf_colorimetry == RBCtristimulus) { |
295 |
> |
for (ix = sqres*sqres*sqres/2; ix--; ) { |
296 |
> |
fputs("\t0\n", uvfp[0]); |
297 |
> |
fputs("\t0\n", uvfp[1]); |
298 |
> |
} |
299 |
> |
fputs("}\n", uvfp[0]); |
300 |
> |
fputs("}\n", uvfp[1]); |
301 |
> |
if (fclose(uvfp[0]) || fclose(uvfp[1])) { |
302 |
> |
fprintf(stderr, "%s: error writing uv file(s)\n", |
303 |
> |
progname); |
304 |
> |
exit(1); |
305 |
> |
} |
306 |
> |
} |
307 |
|
} |
263 |
– |
data_epilogue(); |
264 |
– |
prog_done(); |
308 |
|
} |
309 |
|
|
310 |
|
/* Interpolate and output anisotropic BSDF data */ |
312 |
|
eval_anisotropic(char *funame) |
313 |
|
{ |
314 |
|
const int sqres = 1<<samp_order; |
315 |
< |
FILE *ofp = NULL; |
315 |
> |
FILE *ofp, *uvfp[2]; |
316 |
|
int assignD = 0; |
317 |
|
char cmd[128]; |
318 |
|
int ix, iy, ox, oy; |
319 |
|
double iovec[6]; |
320 |
< |
float bsdf; |
320 |
> |
float bsdf, uv[2]; |
321 |
|
|
279 |
– |
data_prologue(); /* begin output */ |
322 |
|
if (pctcull >= 0) { |
323 |
< |
sprintf(cmd, "rttree_reduce%s -h -ff -r 4 -t %f -g %d", |
324 |
< |
(input_orient>0 ^ output_orient>0) ? "" : " -a", |
325 |
< |
pctcull, samp_order); |
326 |
< |
fflush(stdout); |
323 |
> |
const char *avgopt = (input_orient>0 ^ output_orient>0) |
324 |
> |
? "" : " -a"; |
325 |
> |
sprintf(cmd, "rttree_reduce%s -h -ff -r 4 -t %f -g %d > %s", |
326 |
> |
avgopt, pctcull, samp_order, |
327 |
> |
create_component_file(0)); |
328 |
|
ofp = popen(cmd, "w"); |
329 |
|
if (ofp == NULL) { |
330 |
|
fprintf(stderr, "%s: cannot create pipe to rttree_reduce\n", |
335 |
|
#ifdef getc_unlocked /* avoid lock/unlock overhead */ |
336 |
|
flockfile(ofp); |
337 |
|
#endif |
338 |
< |
} else |
339 |
< |
fputs("{\n", stdout); |
340 |
< |
/* need to assign Dx, Dy, Dz? */ |
341 |
< |
if (funame != NULL) |
338 |
> |
if (rbf_colorimetry == RBCtristimulus) { |
339 |
> |
double uvcull = 100. - (100.-pctcull)*.25; |
340 |
> |
sprintf(cmd, "rttree_reduce%s -h -ff -r 4 -t %f -g %d > %s", |
341 |
> |
avgopt, uvcull, samp_order, |
342 |
> |
create_component_file(1)); |
343 |
> |
uvfp[0] = popen(cmd, "w"); |
344 |
> |
sprintf(cmd, "rttree_reduce%s -h -ff -r 4 -t %f -g %d > %s", |
345 |
> |
avgopt, uvcull, samp_order, |
346 |
> |
create_component_file(2)); |
347 |
> |
uvfp[1] = popen(cmd, "w"); |
348 |
> |
if ((uvfp[0] == NULL) | (uvfp[1] == NULL)) { |
349 |
> |
fprintf(stderr, "%s: cannot open pipes to uv output\n", |
350 |
> |
progname); |
351 |
> |
exit(1); |
352 |
> |
} |
353 |
> |
SET_FILE_BINARY(uvfp[0]); SET_FILE_BINARY(uvfp[1]); |
354 |
> |
#ifdef getc_unlocked |
355 |
> |
flockfile(uvfp[0]); flockfile(uvfp[1]); |
356 |
> |
#endif |
357 |
> |
} |
358 |
> |
} else { |
359 |
> |
ofp = fopen(create_component_file(0), "w"); |
360 |
> |
if (ofp == NULL) { |
361 |
> |
fprintf(stderr, "%s: cannot create Y output file\n", |
362 |
> |
progname); |
363 |
> |
exit(1); |
364 |
> |
} |
365 |
> |
fputs("{\n", ofp); |
366 |
> |
if (rbf_colorimetry == RBCtristimulus) { |
367 |
> |
uvfp[0] = fopen(create_component_file(1), "w"); |
368 |
> |
uvfp[1] = fopen(create_component_file(2), "w"); |
369 |
> |
if ((uvfp[0] == NULL) | (uvfp[1] == NULL)) { |
370 |
> |
fprintf(stderr, "%s: cannot create uv output file(s)\n", |
371 |
> |
progname); |
372 |
> |
exit(1); |
373 |
> |
} |
374 |
> |
fputs("{\n", uvfp[0]); |
375 |
> |
fputs("{\n", uvfp[1]); |
376 |
> |
} |
377 |
> |
} |
378 |
> |
if (funame != NULL) /* need to assign Dx, Dy, Dz? */ |
379 |
|
assignD = (fundefined(funame) < 6); |
380 |
|
/* run through directions */ |
381 |
|
for (ix = 0; ix < sqres; ix++) |
392 |
|
SDsquare2disk(iovec+3, (ox+.5)/sqres, (oy+.5)/sqres); |
393 |
|
iovec[5] = output_orient * |
394 |
|
sqrt(1. - iovec[3]*iovec[3] - iovec[4]*iovec[4]); |
395 |
< |
if (funame == NULL) |
396 |
< |
bsdf = eval_rbfrep(rbf, iovec+3) * |
397 |
< |
output_orient/iovec[5]; |
398 |
< |
else { |
395 |
> |
if (funame == NULL) { |
396 |
> |
SDValue sdv; |
397 |
> |
eval_rbfcol(&sdv, rbf, iovec+3); |
398 |
> |
bsdf = sdv.cieY; |
399 |
> |
if (rbf_colorimetry == RBCtristimulus) { |
400 |
> |
uv[0] = uv[1] = 1. / |
401 |
> |
(-2.*sdv.spec.cx + 12.*sdv.spec.cy + 3.); |
402 |
> |
uv[0] *= 4.*sdv.spec.cx; |
403 |
> |
uv[1] *= 9.*sdv.spec.cy; |
404 |
> |
} |
405 |
> |
} else { |
406 |
|
if (assignD) { |
407 |
|
varset("Dx", '=', -iovec[3]); |
408 |
|
varset("Dy", '=', -iovec[4]); |
441 |
|
#endif |
442 |
|
} |
443 |
|
if (pctcull >= 0) |
444 |
< |
fwrite(&bsdf, sizeof(bsdf), 1, ofp); |
444 |
> |
putbinary(&bsdf, sizeof(bsdf), 1, ofp); |
445 |
|
else |
446 |
< |
printf("\t%.3e\n", bsdf); |
446 |
> |
fprintf(ofp, "\t%.3e\n", bsdf); |
447 |
> |
|
448 |
> |
if (rbf_colorimetry == RBCtristimulus) { |
449 |
> |
if (pctcull >= 0) { |
450 |
> |
putbinary(&uv[0], sizeof(*uv), 1, uvfp[0]); |
451 |
> |
putbinary(&uv[1], sizeof(*uv), 1, uvfp[1]); |
452 |
> |
} else { |
453 |
> |
fprintf(uvfp[0], "\t%.3e\n", uv[0]); |
454 |
> |
fprintf(uvfp[1], "\t%.3e\n", uv[1]); |
455 |
> |
} |
456 |
> |
} |
457 |
|
last_bsdf = bsdf; |
458 |
|
} |
459 |
|
} |
461 |
|
free(rbf); |
462 |
|
prog_show((ix*sqres+iy+1.)/(sqres*sqres)); |
463 |
|
} |
464 |
+ |
prog_done(); |
465 |
|
if (pctcull >= 0) { /* finish output */ |
466 |
|
if (pclose(ofp)) { |
467 |
< |
fprintf(stderr, "%s: error running '%s'\n", |
468 |
< |
progname, cmd); |
467 |
> |
fprintf(stderr, "%s: error running rttree_reduce on Y\n", |
468 |
> |
progname); |
469 |
|
exit(1); |
470 |
|
} |
471 |
< |
} else |
472 |
< |
fputs("}\n", stdout); |
473 |
< |
data_epilogue(); |
474 |
< |
prog_done(); |
471 |
> |
if (rbf_colorimetry == RBCtristimulus && |
472 |
> |
(pclose(uvfp[0]) || pclose(uvfp[1]))) { |
473 |
> |
fprintf(stderr, "%s: error running rttree_reduce on uv\n", |
474 |
> |
progname); |
475 |
> |
exit(1); |
476 |
> |
} |
477 |
> |
} else { |
478 |
> |
fputs("}\n", ofp); |
479 |
> |
if (fclose(ofp)) { |
480 |
> |
fprintf(stderr, "%s: error writing Y file\n", |
481 |
> |
progname); |
482 |
> |
exit(1); |
483 |
> |
} |
484 |
> |
if (rbf_colorimetry == RBCtristimulus) { |
485 |
> |
fputs("}\n", uvfp[0]); |
486 |
> |
fputs("}\n", uvfp[1]); |
487 |
> |
if (fclose(uvfp[0]) || fclose(uvfp[1])) { |
488 |
> |
fprintf(stderr, "%s: error writing uv file(s)\n", |
489 |
> |
progname); |
490 |
> |
exit(1); |
491 |
> |
} |
492 |
> |
} |
493 |
> |
} |
494 |
|
} |
495 |
|
|
496 |
+ |
#if defined(_WIN32) || defined(_WIN64) |
497 |
+ |
/* Execute wrapBSDF command (may never return) */ |
498 |
+ |
static int |
499 |
+ |
wrap_up(void) |
500 |
+ |
{ |
501 |
+ |
char cmd[8192]; |
502 |
+ |
|
503 |
+ |
if (bsdf_manuf[0]) { |
504 |
+ |
add_wbsdf("-f", 1); |
505 |
+ |
strcpy(cmd, "m="); |
506 |
+ |
strcpy(cmd+2, bsdf_manuf); |
507 |
+ |
add_wbsdf(cmd, 0); |
508 |
+ |
} |
509 |
+ |
if (bsdf_name[0]) { |
510 |
+ |
add_wbsdf("-f", 1); |
511 |
+ |
strcpy(cmd, "n="); |
512 |
+ |
strcpy(cmd+2, bsdf_name); |
513 |
+ |
add_wbsdf(cmd, 0); |
514 |
+ |
} |
515 |
+ |
if (!convert_commandline(cmd, sizeof(cmd), wrapBSDF)) { |
516 |
+ |
fputs(progname, stderr); |
517 |
+ |
fputs(": command line too long in wrap_up()\n", stderr); |
518 |
+ |
return(1); |
519 |
+ |
} |
520 |
+ |
return(system(cmd)); |
521 |
+ |
} |
522 |
+ |
#else |
523 |
+ |
/* Execute wrapBSDF command (may never return) */ |
524 |
+ |
static int |
525 |
+ |
wrap_up(void) |
526 |
+ |
{ |
527 |
+ |
char buf[256]; |
528 |
+ |
char *compath = getpath((char *)wrapBSDF[0], getenv("PATH"), X_OK); |
529 |
+ |
|
530 |
+ |
if (compath == NULL) { |
531 |
+ |
fprintf(stderr, "%s: cannot locate %s\n", progname, wrapBSDF[0]); |
532 |
+ |
return(1); |
533 |
+ |
} |
534 |
+ |
if (bsdf_manuf[0]) { |
535 |
+ |
add_wbsdf("-f", 1); |
536 |
+ |
strcpy(buf, "m="); |
537 |
+ |
strcpy(buf+2, bsdf_manuf); |
538 |
+ |
add_wbsdf(buf, 0); |
539 |
+ |
} |
540 |
+ |
if (bsdf_name[0]) { |
541 |
+ |
add_wbsdf("-f", 1); |
542 |
+ |
strcpy(buf, "n="); |
543 |
+ |
strcpy(buf+2, bsdf_name); |
544 |
+ |
add_wbsdf(buf, 0); |
545 |
+ |
} |
546 |
+ |
execv(compath, wrapBSDF); /* successful call never returns */ |
547 |
+ |
perror(compath); |
548 |
+ |
return(1); |
549 |
+ |
} |
550 |
+ |
#endif |
551 |
+ |
|
552 |
|
/* Read in BSDF and interpolate as tensor tree representation */ |
553 |
|
int |
554 |
|
main(int argc, char *argv[]) |
555 |
|
{ |
556 |
+ |
static char tfmt[2][4] = {"t4", "t3"}; |
557 |
|
int dofwd = 0, dobwd = 1; |
558 |
+ |
char buf[2048]; |
559 |
|
int i, na; |
560 |
|
|
561 |
|
progname = argv[0]; |
569 |
|
scompile(argv[++i], NULL, 0); |
570 |
|
break; |
571 |
|
case 'f': |
572 |
< |
if (!argv[i][2]) |
573 |
< |
fcompile(argv[++i]); |
574 |
< |
else |
572 |
> |
if (!argv[i][2]) { |
573 |
> |
if (strchr(argv[++i], '=') != NULL) { |
574 |
> |
add_wbsdf("-f", 1); |
575 |
> |
add_wbsdf(argv[i], 1); |
576 |
> |
} else |
577 |
> |
fcompile(argv[i]); |
578 |
> |
} else |
579 |
|
dofwd = (argv[i][0] == '+'); |
580 |
|
break; |
581 |
|
case 'b': |
605 |
|
case 'p': |
606 |
|
do_prog = atoi(argv[i]+2); |
607 |
|
break; |
608 |
+ |
case 'W': |
609 |
+ |
add_wbsdf(argv[i], 1); |
610 |
+ |
break; |
611 |
+ |
case 'u': |
612 |
+ |
case 'C': |
613 |
+ |
add_wbsdf(argv[i], 1); |
614 |
+ |
add_wbsdf(argv[++i], 1); |
615 |
+ |
break; |
616 |
|
default: |
617 |
|
goto userr; |
618 |
|
} |
619 |
+ |
strcpy(buf, "File produced by: "); |
620 |
+ |
if (convert_commandline(buf+18, sizeof(buf)-18, argv) != NULL) { |
621 |
+ |
add_wbsdf("-C", 1); add_wbsdf(buf, 0); |
622 |
+ |
} |
623 |
|
if (single_plane_incident >= 0) { /* function-based BSDF? */ |
624 |
|
void (*evf)(char *s) = single_plane_incident ? |
625 |
< |
&eval_isotropic : &eval_anisotropic; |
625 |
> |
eval_isotropic : eval_anisotropic; |
626 |
|
if (i != argc-1 || fundefined(argv[i]) < 3) { |
627 |
|
fprintf(stderr, |
628 |
|
"%s: need single function with 6 arguments: bsdf(ix,iy,iz,ox,oy,oz)\n", |
631 |
|
goto userr; |
632 |
|
} |
633 |
|
++eclock; |
634 |
< |
xml_prologue(argc, argv); /* start XML output */ |
634 |
> |
add_wbsdf("-a", 1); |
635 |
> |
add_wbsdf(tfmt[single_plane_incident], 1); |
636 |
|
if (dofwd) { |
637 |
|
input_orient = -1; |
638 |
|
output_orient = -1; |
651 |
|
prog_start("Evaluating inside->outside transmission"); |
652 |
|
(*evf)(argv[i]); |
653 |
|
} |
654 |
< |
xml_epilogue(); /* finish XML output & exit */ |
463 |
< |
return(0); |
654 |
> |
return(wrap_up()); |
655 |
|
} |
656 |
|
if (i < argc) { /* open input files if given */ |
657 |
|
int nbsdf = 0; |
666 |
|
if (!load_bsdf_rep(fpin)) |
667 |
|
return(1); |
668 |
|
fclose(fpin); |
478 |
– |
if (!nbsdf++) /* start XML on first dist. */ |
479 |
– |
xml_prologue(argc, argv); |
669 |
|
sprintf(pbuf, "Interpolating component '%s'", argv[i]); |
670 |
|
prog_start(pbuf); |
671 |
+ |
if (!nbsdf++) { |
672 |
+ |
add_wbsdf("-a", 1); |
673 |
+ |
add_wbsdf(tfmt[single_plane_incident], 1); |
674 |
+ |
} |
675 |
|
if (single_plane_incident) |
676 |
|
eval_isotropic(NULL); |
677 |
|
else |
678 |
|
eval_anisotropic(NULL); |
679 |
|
} |
680 |
< |
xml_epilogue(); /* finish XML output & exit */ |
488 |
< |
return(0); |
680 |
> |
return(wrap_up()); |
681 |
|
} |
682 |
|
SET_FILE_BINARY(stdin); /* load from stdin */ |
683 |
|
if (!load_bsdf_rep(stdin)) |
684 |
|
return(1); |
493 |
– |
xml_prologue(argc, argv); /* start XML output */ |
685 |
|
prog_start("Interpolating from standard input"); |
686 |
+ |
add_wbsdf("-a", 1); |
687 |
+ |
add_wbsdf(tfmt[single_plane_incident], 1); |
688 |
|
if (single_plane_incident) /* resample dist. */ |
689 |
|
eval_isotropic(NULL); |
690 |
|
else |
691 |
|
eval_anisotropic(NULL); |
692 |
< |
xml_epilogue(); /* finish XML output & exit */ |
693 |
< |
return(0); |
692 |
> |
|
693 |
> |
return(wrap_up()); |
694 |
|
userr: |
695 |
|
fprintf(stderr, |
696 |
|
"Usage: %s [-g Nlog2][-t pctcull][-l maxlobes] [bsdf.sir ..] > bsdf.xml\n", |