8 |
|
*/ |
9 |
|
|
10 |
|
#define _USE_MATH_DEFINES |
11 |
– |
#include <stdio.h> |
11 |
|
#include <stdlib.h> |
12 |
|
#include <math.h> |
13 |
|
#include "random.h" |
18 |
|
#include "bsdfrep.h" |
19 |
|
/* global argv[0] */ |
20 |
|
char *progname; |
21 |
+ |
/* reciprocity averaging option */ |
22 |
+ |
static const char *recip = " -a"; |
23 |
|
/* percentage to cull (<0 to turn off) */ |
24 |
|
static double pctcull = 90.; |
25 |
|
/* sampling order */ |
26 |
|
static int samp_order = 6; |
27 |
|
/* super-sampling threshold */ |
28 |
< |
const double ssamp_thresh = 0.35; |
28 |
> |
const double ssamp_thresh = 0.30; |
29 |
|
/* number of super-samples */ |
30 |
|
#ifndef NSSAMP |
31 |
< |
#define NSSAMP 100 |
31 |
> |
#define NSSAMP 256 |
32 |
|
#endif |
33 |
|
/* limit on number of RBF lobes */ |
34 |
|
static int lobe_lim = 15000; |
39 |
|
static char *wrapBSDF[MAXCARG] = {"wrapBSDF", "-U"}; |
40 |
|
static int wbsdfac = 2; |
41 |
|
|
42 |
< |
/* Add argument to wrapBSDF, allocating space if isstatic */ |
42 |
> |
/* Add argument to wrapBSDF, allocating space if !isstatic */ |
43 |
|
static void |
44 |
|
add_wbsdf(const char *arg, int isstatic) |
45 |
|
{ |
128 |
|
eval_isotropic(char *funame) |
129 |
|
{ |
130 |
|
const int sqres = 1<<samp_order; |
131 |
+ |
const double sqfact = 1./(double)sqres; |
132 |
+ |
float *ryval = NULL; |
133 |
+ |
char *rtrip = NULL; |
134 |
|
FILE *ofp, *uvfp[2]; |
135 |
|
int assignD = 0; |
136 |
|
char cmd[128]; |
139 |
|
float bsdf, uv[2]; |
140 |
|
|
141 |
|
if (pctcull >= 0) { |
142 |
< |
sprintf(cmd, "rttree_reduce -a -h -ff -r 3 -t %f -g %d > %s", |
143 |
< |
pctcull, samp_order, create_component_file(0)); |
142 |
> |
sprintf(cmd, "rttree_reduce%s -h -ff -r 3 -t %f -g %d > %s", |
143 |
> |
recip, pctcull, samp_order, create_component_file(0)); |
144 |
|
ofp = popen(cmd, "w"); |
145 |
|
if (ofp == NULL) { |
146 |
|
fprintf(stderr, "%s: cannot create pipe to rttree_reduce\n", |
153 |
|
#endif |
154 |
|
if (rbf_colorimetry == RBCtristimulus) { |
155 |
|
double uvcull = 100. - (100.-pctcull)*.25; |
156 |
< |
sprintf(cmd, "rttree_reduce -a -h -ff -r 3 -t %f -g %d > %s", |
157 |
< |
uvcull, samp_order, create_component_file(1)); |
156 |
> |
sprintf(cmd, "rttree_reduce%s -h -ff -r 3 -t %f -g %d > %s", |
157 |
> |
recip, uvcull, samp_order, create_component_file(1)); |
158 |
|
uvfp[0] = popen(cmd, "w"); |
159 |
< |
sprintf(cmd, "rttree_reduce -a -h -ff -r 3 -t %f -g %d > %s", |
160 |
< |
uvcull, samp_order, create_component_file(2)); |
159 |
> |
sprintf(cmd, "rttree_reduce%s -h -ff -r 3 -t %f -g %d > %s", |
160 |
> |
recip, uvcull, samp_order, create_component_file(2)); |
161 |
|
uvfp[1] = popen(cmd, "w"); |
162 |
|
if ((uvfp[0] == NULL) | (uvfp[1] == NULL)) { |
163 |
|
fprintf(stderr, "%s: cannot open pipes to uv output\n", |
191 |
|
} |
192 |
|
if (funame != NULL) /* need to assign Dx, Dy, Dz? */ |
193 |
|
assignD = (fundefined(funame) < 6); |
194 |
+ |
#if (NSSAMP > 0) |
195 |
+ |
rtrip = (char *)calloc(sqres, 1); /* track sample triggerings */ |
196 |
+ |
ryval = (float *)calloc(sqres, sizeof(float)); |
197 |
+ |
#endif |
198 |
|
/* run through directions */ |
199 |
|
for (ix = 0; ix < sqres/2; ix++) { |
200 |
< |
RBFNODE *rbf = NULL; |
201 |
< |
iovec[0] = 2.*(ix+.5)/sqres - 1.; |
202 |
< |
iovec[1] = .0; |
203 |
< |
iovec[2] = input_orient * sqrt(1. - iovec[0]*iovec[0]); |
200 |
> |
const int zipsgn = (ix & 1)*2 - 1; |
201 |
> |
RBFNODE *rbf = NULL; |
202 |
> |
iovec[0] = 2.*sqfact*(ix+.5) - 1.; |
203 |
> |
iovec[1] = zipsgn*sqfact*.5; |
204 |
> |
iovec[2] = input_orient * sqrt(1. - iovec[0]*iovec[0] |
205 |
> |
- iovec[1]*iovec[1]); |
206 |
|
if (funame == NULL) |
207 |
|
rbf = advect_rbf(iovec, lobe_lim); |
208 |
|
for (ox = 0; ox < sqres; ox++) { |
209 |
< |
float last_bsdf = -1; |
209 |
> |
SDValue sdv_next; |
210 |
> |
SDsquare2disk(iovec+3, (ox+.5)*sqfact, .5*sqfact); |
211 |
> |
iovec[5] = output_orient * |
212 |
> |
sqrt(1. - iovec[3]*iovec[3] - iovec[4]*iovec[4]); |
213 |
> |
if (funame == NULL) { |
214 |
> |
eval_rbfcol(&sdv_next, rbf, iovec+3); |
215 |
> |
} else { |
216 |
> |
sdv_next.spec = c_dfcolor; |
217 |
> |
if (assignD) { |
218 |
> |
varset("Dx", '=', -iovec[3]); |
219 |
> |
varset("Dy", '=', -iovec[4]); |
220 |
> |
varset("Dz", '=', -iovec[5]); |
221 |
> |
++eclock; |
222 |
> |
} |
223 |
> |
sdv_next.cieY = funvalue(funame, 6, iovec); |
224 |
> |
} |
225 |
|
for (oy = 0; oy < sqres; oy++) { |
226 |
< |
SDsquare2disk(iovec+3, (ox+.5)/sqres, (oy+.5)/sqres); |
227 |
< |
iovec[5] = output_orient * |
226 |
> |
int trip; |
227 |
> |
bsdf = sdv_next.cieY; /* keeping one step ahead... */ |
228 |
> |
if (oy < sqres-1) { |
229 |
> |
SDsquare2disk(iovec+3, (ox+.5)*sqfact, (oy+1.5)*sqfact); |
230 |
> |
iovec[5] = output_orient * |
231 |
|
sqrt(1. - iovec[3]*iovec[3] - iovec[4]*iovec[4]); |
232 |
+ |
} |
233 |
|
if (funame == NULL) { |
234 |
< |
SDValue sdv; |
235 |
< |
eval_rbfcol(&sdv, rbf, iovec+3); |
236 |
< |
bsdf = sdv.cieY; |
234 |
> |
SDValue sdv = sdv_next; |
235 |
> |
if (oy < sqres-1) |
236 |
> |
eval_rbfcol(&sdv_next, rbf, iovec+3); |
237 |
> |
#if (NSSAMP > 0) |
238 |
> |
trip = (abs_diff(bsdf, sdv_next.cieY) > ssamp_thresh || |
239 |
> |
(ox && abs_diff(bsdf, ryval[oy]) > ssamp_thresh) || |
240 |
> |
(oy && abs_diff(bsdf, ryval[oy-1]) > ssamp_thresh)); |
241 |
> |
if (trip | rtrip[oy] || (oy && rtrip[oy-1])) { |
242 |
> |
int ssi; |
243 |
> |
double ssa[2], sum = 0, usum = 0, vsum = 0; |
244 |
> |
/* super-sample voxel */ |
245 |
> |
for (ssi = NSSAMP; ssi--; ) { |
246 |
> |
SDmultiSamp(ssa, 2, (ssi+frandom()) * |
247 |
> |
(1./NSSAMP)); |
248 |
> |
SDsquare2disk(iovec+3, (ox+ssa[0])*sqfact, |
249 |
> |
(oy+ssa[1])*sqfact); |
250 |
> |
iovec[5] = output_orient * |
251 |
> |
sqrt(1. - iovec[3]*iovec[3] - iovec[4]*iovec[4]); |
252 |
> |
eval_rbfcol(&sdv, rbf, iovec+3); |
253 |
> |
sum += sdv.cieY; |
254 |
> |
if (rbf_colorimetry == RBCtristimulus) { |
255 |
> |
sdv.cieY /= |
256 |
> |
-2.*sdv.spec.cx + 12.*sdv.spec.cy + 3.; |
257 |
> |
usum += 4.*sdv.spec.cx * sdv.cieY; |
258 |
> |
vsum += 9.*sdv.spec.cy * sdv.cieY; |
259 |
> |
} |
260 |
> |
} |
261 |
> |
bsdf = sum * (1./NSSAMP); |
262 |
> |
if (rbf_colorimetry == RBCtristimulus) { |
263 |
> |
uv[0] = usum / (sum+FTINY); |
264 |
> |
uv[1] = vsum / (sum+FTINY); |
265 |
> |
} |
266 |
> |
} else |
267 |
> |
#endif |
268 |
|
if (rbf_colorimetry == RBCtristimulus) { |
209 |
– |
c_ccvt(&sdv.spec, C_CSXY); |
269 |
|
uv[0] = uv[1] = 1. / |
270 |
|
(-2.*sdv.spec.cx + 12.*sdv.spec.cy + 3.); |
271 |
|
uv[0] *= 4.*sdv.spec.cx; |
272 |
|
uv[1] *= 9.*sdv.spec.cy; |
273 |
|
} |
274 |
|
} else { |
275 |
< |
if (assignD) { |
276 |
< |
varset("Dx", '=', -iovec[3]); |
277 |
< |
varset("Dy", '=', -iovec[4]); |
278 |
< |
varset("Dz", '=', -iovec[5]); |
279 |
< |
++eclock; |
275 |
> |
if (oy < sqres-1) { |
276 |
> |
if (assignD) { |
277 |
> |
varset("Dx", '=', -iovec[3]); |
278 |
> |
varset("Dy", '=', -iovec[4]); |
279 |
> |
varset("Dz", '=', -iovec[5]); |
280 |
> |
++eclock; |
281 |
> |
} |
282 |
> |
sdv_next.cieY = funvalue(funame, 6, iovec); |
283 |
|
} |
222 |
– |
bsdf = funvalue(funame, 6, iovec); |
284 |
|
#if (NSSAMP > 0) |
285 |
< |
if (abs_diff(bsdf, last_bsdf) > ssamp_thresh) { |
285 |
> |
trip = (abs_diff(bsdf, sdv_next.cieY) > ssamp_thresh || |
286 |
> |
(ox && abs_diff(bsdf, ryval[oy]) > ssamp_thresh) || |
287 |
> |
(oy && abs_diff(bsdf, ryval[oy-1]) > ssamp_thresh)); |
288 |
> |
if (trip | rtrip[oy] || (oy && rtrip[oy-1])) { |
289 |
|
int ssi; |
290 |
< |
double ssa[3], ssvec[6], sum = 0; |
290 |
> |
double ssa[4], ssvec[6], sum = 0; |
291 |
|
/* super-sample voxel */ |
292 |
|
for (ssi = NSSAMP; ssi--; ) { |
293 |
< |
SDmultiSamp(ssa, 3, (ssi+frandom()) * |
293 |
> |
SDmultiSamp(ssa, 4, (ssi+frandom()) * |
294 |
|
(1./NSSAMP)); |
295 |
< |
ssvec[0] = 2.*(ix+ssa[0])/sqres - 1.; |
296 |
< |
ssvec[1] = .0; |
297 |
< |
ssvec[2] = input_orient * |
298 |
< |
sqrt(1. - ssvec[0]*ssvec[0]); |
299 |
< |
SDsquare2disk(ssvec+3, (ox+ssa[1])/sqres, |
300 |
< |
(oy+ssa[2])/sqres); |
295 |
> |
ssvec[0] = 2.*sqfact*(ix+ssa[0]) - 1.; |
296 |
> |
ssvec[1] = zipsgn*sqfact*ssa[1]; |
297 |
> |
ssvec[2] = 1. - ssvec[0]*ssvec[0] |
298 |
> |
- ssvec[1]*ssvec[1]; |
299 |
> |
if (ssvec[2] < .0) { |
300 |
> |
ssvec[1] = 0; |
301 |
> |
ssvec[2] = 1. - ssvec[0]*ssvec[0]; |
302 |
> |
} |
303 |
> |
ssvec[2] = input_orient * sqrt(ssvec[2]); |
304 |
> |
SDsquare2disk(ssvec+3, (ox+ssa[2])*sqfact, |
305 |
> |
(oy+ssa[3])*sqfact); |
306 |
|
ssvec[5] = output_orient * |
307 |
|
sqrt(1. - ssvec[3]*ssvec[3] - |
308 |
|
ssvec[4]*ssvec[4]); |
314 |
|
} |
315 |
|
sum += funvalue(funame, 6, ssvec); |
316 |
|
} |
317 |
< |
bsdf = sum/NSSAMP; |
317 |
> |
bsdf = sum * (1./NSSAMP); |
318 |
|
} |
319 |
|
#endif |
320 |
|
} |
321 |
|
if (pctcull >= 0) |
322 |
< |
fwrite(&bsdf, sizeof(bsdf), 1, ofp); |
322 |
> |
putbinary(&bsdf, sizeof(bsdf), 1, ofp); |
323 |
|
else |
324 |
|
fprintf(ofp, "\t%.3e\n", bsdf); |
325 |
|
|
326 |
|
if (rbf_colorimetry == RBCtristimulus) { |
327 |
|
if (pctcull >= 0) { |
328 |
< |
fwrite(&uv[0], sizeof(*uv), 1, uvfp[0]); |
329 |
< |
fwrite(&uv[1], sizeof(*uv), 1, uvfp[1]); |
328 |
> |
putbinary(&uv[0], sizeof(*uv), 1, uvfp[0]); |
329 |
> |
putbinary(&uv[1], sizeof(*uv), 1, uvfp[1]); |
330 |
|
} else { |
331 |
|
fprintf(uvfp[0], "\t%.3e\n", uv[0]); |
332 |
|
fprintf(uvfp[1], "\t%.3e\n", uv[1]); |
333 |
|
} |
334 |
|
} |
335 |
< |
last_bsdf = bsdf; |
335 |
> |
if (ryval != NULL) { |
336 |
> |
rtrip[oy] = trip; |
337 |
> |
ryval[oy] = bsdf; |
338 |
> |
} |
339 |
|
} |
340 |
|
} |
341 |
|
if (rbf != NULL) |
342 |
|
free(rbf); |
343 |
< |
prog_show((ix+1.)*(2./sqres)); |
343 |
> |
prog_show((ix+1.)*(2.*sqfact)); |
344 |
|
} |
345 |
|
prog_done(); |
346 |
+ |
if (ryval != NULL) { |
347 |
+ |
free(rtrip); |
348 |
+ |
free(ryval); |
349 |
+ |
} |
350 |
|
if (pctcull >= 0) { /* finish output */ |
351 |
|
if (pclose(ofp)) { |
352 |
|
fprintf(stderr, "%s: error running rttree_reduce on Y\n", |
389 |
|
eval_anisotropic(char *funame) |
390 |
|
{ |
391 |
|
const int sqres = 1<<samp_order; |
392 |
+ |
const double sqfact = 1./(double)sqres; |
393 |
+ |
float *ryval = NULL; |
394 |
+ |
char *rtrip = NULL; |
395 |
|
FILE *ofp, *uvfp[2]; |
396 |
|
int assignD = 0; |
397 |
|
char cmd[128]; |
401 |
|
|
402 |
|
if (pctcull >= 0) { |
403 |
|
const char *avgopt = (input_orient>0 ^ output_orient>0) |
404 |
< |
? "" : " -a"; |
404 |
> |
? "" : recip; |
405 |
|
sprintf(cmd, "rttree_reduce%s -h -ff -r 4 -t %f -g %d > %s", |
406 |
|
avgopt, pctcull, samp_order, |
407 |
|
create_component_file(0)); |
457 |
|
} |
458 |
|
if (funame != NULL) /* need to assign Dx, Dy, Dz? */ |
459 |
|
assignD = (fundefined(funame) < 6); |
460 |
+ |
#if (NSSAMP > 0) |
461 |
+ |
rtrip = (char *)calloc(sqres, 1); /* track sample triggerings */ |
462 |
+ |
ryval = (float *)calloc(sqres, sizeof(float)); |
463 |
+ |
#endif |
464 |
|
/* run through directions */ |
465 |
|
for (ix = 0; ix < sqres; ix++) |
466 |
|
for (iy = 0; iy < sqres; iy++) { |
467 |
|
RBFNODE *rbf = NULL; /* Klems reversal */ |
468 |
< |
SDsquare2disk(iovec, 1.-(ix+.5)/sqres, 1.-(iy+.5)/sqres); |
468 |
> |
SDsquare2disk(iovec, 1.-(ix+.5)*sqfact, 1.-(iy+.5)*sqfact); |
469 |
|
iovec[2] = input_orient * |
470 |
|
sqrt(1. - iovec[0]*iovec[0] - iovec[1]*iovec[1]); |
471 |
|
if (funame == NULL) |
472 |
|
rbf = advect_rbf(iovec, lobe_lim); |
473 |
|
for (ox = 0; ox < sqres; ox++) { |
474 |
< |
float last_bsdf = -1; |
474 |
> |
SDValue sdv_next; |
475 |
> |
SDsquare2disk(iovec+3, (ox+.5)*sqfact, .5*sqfact); |
476 |
> |
iovec[5] = output_orient * |
477 |
> |
sqrt(1. - iovec[3]*iovec[3] - iovec[4]*iovec[4]); |
478 |
> |
if (funame == NULL) { |
479 |
> |
eval_rbfcol(&sdv_next, rbf, iovec+3); |
480 |
> |
} else { |
481 |
> |
sdv_next.spec = c_dfcolor; |
482 |
> |
if (assignD) { |
483 |
> |
varset("Dx", '=', -iovec[3]); |
484 |
> |
varset("Dy", '=', -iovec[4]); |
485 |
> |
varset("Dz", '=', -iovec[5]); |
486 |
> |
++eclock; |
487 |
> |
} |
488 |
> |
sdv_next.cieY = funvalue(funame, 6, iovec); |
489 |
> |
} |
490 |
|
for (oy = 0; oy < sqres; oy++) { |
491 |
< |
SDsquare2disk(iovec+3, (ox+.5)/sqres, (oy+.5)/sqres); |
492 |
< |
iovec[5] = output_orient * |
491 |
> |
int trip; |
492 |
> |
bsdf = sdv_next.cieY; /* keeping one step ahead... */ |
493 |
> |
if (oy < sqres-1) { |
494 |
> |
SDsquare2disk(iovec+3, (ox+.5)*sqfact, (oy+1.5)*sqfact); |
495 |
> |
iovec[5] = output_orient * |
496 |
|
sqrt(1. - iovec[3]*iovec[3] - iovec[4]*iovec[4]); |
497 |
+ |
} |
498 |
|
if (funame == NULL) { |
499 |
< |
SDValue sdv; |
500 |
< |
eval_rbfcol(&sdv, rbf, iovec+3); |
501 |
< |
bsdf = sdv.cieY; |
499 |
> |
SDValue sdv = sdv_next; |
500 |
> |
if (oy < sqres-1) |
501 |
> |
eval_rbfcol(&sdv_next, rbf, iovec+3); |
502 |
> |
#if (NSSAMP > 0) |
503 |
> |
trip = (abs_diff(bsdf, sdv_next.cieY) > ssamp_thresh || |
504 |
> |
(ox && abs_diff(bsdf, ryval[oy]) > ssamp_thresh) || |
505 |
> |
(oy && abs_diff(bsdf, ryval[oy-1]) > ssamp_thresh)); |
506 |
> |
if (trip | rtrip[oy] || (oy && rtrip[oy-1])) { |
507 |
> |
int ssi; |
508 |
> |
double ssa[2], sum = 0, usum = 0, vsum = 0; |
509 |
> |
/* super-sample voxel */ |
510 |
> |
for (ssi = NSSAMP; ssi--; ) { |
511 |
> |
SDmultiSamp(ssa, 2, (ssi+frandom()) * |
512 |
> |
(1./NSSAMP)); |
513 |
> |
SDsquare2disk(iovec+3, (ox+ssa[0])*sqfact, |
514 |
> |
(oy+ssa[1])*sqfact); |
515 |
> |
iovec[5] = output_orient * |
516 |
> |
sqrt(1. - iovec[3]*iovec[3] - iovec[4]*iovec[4]); |
517 |
> |
eval_rbfcol(&sdv, rbf, iovec+3); |
518 |
> |
sum += sdv.cieY; |
519 |
> |
if (rbf_colorimetry == RBCtristimulus) { |
520 |
> |
sdv.cieY /= |
521 |
> |
-2.*sdv.spec.cx + 12.*sdv.spec.cy + 3.; |
522 |
> |
usum += 4.*sdv.spec.cx * sdv.cieY; |
523 |
> |
vsum += 9.*sdv.spec.cy * sdv.cieY; |
524 |
> |
} |
525 |
> |
} |
526 |
> |
bsdf = sum * (1./NSSAMP); |
527 |
> |
if (rbf_colorimetry == RBCtristimulus) { |
528 |
> |
uv[0] = usum / (sum+FTINY); |
529 |
> |
uv[1] = vsum / (sum+FTINY); |
530 |
> |
} |
531 |
> |
} else |
532 |
> |
#endif |
533 |
|
if (rbf_colorimetry == RBCtristimulus) { |
401 |
– |
c_ccvt(&sdv.spec, C_CSXY); |
534 |
|
uv[0] = uv[1] = 1. / |
535 |
|
(-2.*sdv.spec.cx + 12.*sdv.spec.cy + 3.); |
536 |
|
uv[0] *= 4.*sdv.spec.cx; |
537 |
|
uv[1] *= 9.*sdv.spec.cy; |
538 |
|
} |
539 |
|
} else { |
540 |
< |
if (assignD) { |
541 |
< |
varset("Dx", '=', -iovec[3]); |
542 |
< |
varset("Dy", '=', -iovec[4]); |
543 |
< |
varset("Dz", '=', -iovec[5]); |
544 |
< |
++eclock; |
540 |
> |
if (oy < sqres-1) { |
541 |
> |
if (assignD) { |
542 |
> |
varset("Dx", '=', -iovec[3]); |
543 |
> |
varset("Dy", '=', -iovec[4]); |
544 |
> |
varset("Dz", '=', -iovec[5]); |
545 |
> |
++eclock; |
546 |
> |
} |
547 |
> |
sdv_next.cieY = funvalue(funame, 6, iovec); |
548 |
|
} |
414 |
– |
bsdf = funvalue(funame, 6, iovec); |
549 |
|
#if (NSSAMP > 0) |
550 |
< |
if (abs_diff(bsdf, last_bsdf) > ssamp_thresh) { |
550 |
> |
trip = (abs_diff(bsdf, sdv_next.cieY) > ssamp_thresh || |
551 |
> |
(ox && abs_diff(bsdf, ryval[oy]) > ssamp_thresh) || |
552 |
> |
(oy && abs_diff(bsdf, ryval[oy-1]) > ssamp_thresh)); |
553 |
> |
if (trip | rtrip[oy] || (oy && rtrip[oy-1])) { |
554 |
|
int ssi; |
555 |
|
double ssa[4], ssvec[6], sum = 0; |
556 |
|
/* super-sample voxel */ |
557 |
|
for (ssi = NSSAMP; ssi--; ) { |
558 |
|
SDmultiSamp(ssa, 4, (ssi+frandom()) * |
559 |
|
(1./NSSAMP)); |
560 |
< |
SDsquare2disk(ssvec, 1.-(ix+ssa[0])/sqres, |
561 |
< |
1.-(iy+ssa[1])/sqres); |
560 |
> |
SDsquare2disk(ssvec, 1.-(ix+ssa[0])*sqfact, |
561 |
> |
1.-(iy+ssa[1])*sqfact); |
562 |
|
ssvec[2] = input_orient * |
563 |
|
sqrt(1. - ssvec[0]*ssvec[0] - |
564 |
|
ssvec[1]*ssvec[1]); |
565 |
< |
SDsquare2disk(ssvec+3, (ox+ssa[2])/sqres, |
566 |
< |
(oy+ssa[3])/sqres); |
565 |
> |
SDsquare2disk(ssvec+3, (ox+ssa[2])*sqfact, |
566 |
> |
(oy+ssa[3])*sqfact); |
567 |
|
ssvec[5] = output_orient * |
568 |
|
sqrt(1. - ssvec[3]*ssvec[3] - |
569 |
|
ssvec[4]*ssvec[4]); |
575 |
|
} |
576 |
|
sum += funvalue(funame, 6, ssvec); |
577 |
|
} |
578 |
< |
bsdf = sum/NSSAMP; |
578 |
> |
bsdf = sum * (1./NSSAMP); |
579 |
|
} |
580 |
|
#endif |
581 |
|
} |
582 |
|
if (pctcull >= 0) |
583 |
< |
fwrite(&bsdf, sizeof(bsdf), 1, ofp); |
583 |
> |
putbinary(&bsdf, sizeof(bsdf), 1, ofp); |
584 |
|
else |
585 |
|
fprintf(ofp, "\t%.3e\n", bsdf); |
586 |
|
|
587 |
|
if (rbf_colorimetry == RBCtristimulus) { |
588 |
|
if (pctcull >= 0) { |
589 |
< |
fwrite(&uv[0], sizeof(*uv), 1, uvfp[0]); |
590 |
< |
fwrite(&uv[1], sizeof(*uv), 1, uvfp[1]); |
589 |
> |
putbinary(&uv[0], sizeof(*uv), 1, uvfp[0]); |
590 |
> |
putbinary(&uv[1], sizeof(*uv), 1, uvfp[1]); |
591 |
|
} else { |
592 |
|
fprintf(uvfp[0], "\t%.3e\n", uv[0]); |
593 |
|
fprintf(uvfp[1], "\t%.3e\n", uv[1]); |
594 |
|
} |
595 |
|
} |
596 |
< |
last_bsdf = bsdf; |
596 |
> |
if (ryval != NULL) { |
597 |
> |
rtrip[oy] = trip; |
598 |
> |
ryval[oy] = bsdf; |
599 |
> |
} |
600 |
|
} |
461 |
– |
} |
601 |
|
if (rbf != NULL) |
602 |
|
free(rbf); |
603 |
|
prog_show((ix*sqres+iy+1.)/(sqres*sqres)); |
604 |
|
} |
605 |
+ |
} |
606 |
|
prog_done(); |
607 |
+ |
if (ryval != NULL) { |
608 |
+ |
free(rtrip); |
609 |
+ |
free(ryval); |
610 |
+ |
} |
611 |
|
if (pctcull >= 0) { /* finish output */ |
612 |
|
if (pclose(ofp)) { |
613 |
|
fprintf(stderr, "%s: error running rttree_reduce on Y\n", |
639 |
|
} |
640 |
|
} |
641 |
|
|
642 |
< |
#ifdef _WIN32 |
642 |
> |
#if defined(_WIN32) || defined(_WIN64) |
643 |
|
/* Execute wrapBSDF command (may never return) */ |
644 |
|
static int |
645 |
|
wrap_up(void) |
709 |
|
esupport &= ~(E_INCHAN|E_OUTCHAN); |
710 |
|
scompile("PI:3.14159265358979323846", NULL, 0); |
711 |
|
biggerlib(); |
712 |
< |
for (i = 1; i < argc-1 && (argv[i][0] == '-') | (argv[i][0] == '+'); i++) |
712 |
> |
for (i = 1; i < argc && (argv[i][0] == '-') | (argv[i][0] == '+'); i++) |
713 |
|
switch (argv[i][1]) { /* get options */ |
714 |
|
case 'e': |
715 |
|
scompile(argv[++i], NULL, 0); |
716 |
+ |
if (single_plane_incident < 0) |
717 |
+ |
single_plane_incident = 0; |
718 |
|
break; |
719 |
|
case 'f': |
720 |
|
if (!argv[i][2]) { |
721 |
|
if (strchr(argv[++i], '=') != NULL) { |
722 |
|
add_wbsdf("-f", 1); |
723 |
|
add_wbsdf(argv[i], 1); |
724 |
< |
} else |
725 |
< |
fcompile(argv[i]); |
724 |
> |
} else { |
725 |
> |
char *fpath = getpath(argv[i], |
726 |
> |
getrlibpath(), 0); |
727 |
> |
if (fpath == NULL) { |
728 |
> |
fprintf(stderr, |
729 |
> |
"%s: cannot find file '%s'\n", |
730 |
> |
argv[0], argv[i]); |
731 |
> |
return(1); |
732 |
> |
} |
733 |
> |
fcompile(fpath); |
734 |
> |
if (single_plane_incident < 0) |
735 |
> |
single_plane_incident = 0; |
736 |
> |
} |
737 |
|
} else |
738 |
|
dofwd = (argv[i][0] == '+'); |
739 |
|
break; |
740 |
+ |
case 'a': |
741 |
+ |
recip = (argv[i][0] == '+') ? " -a" : ""; |
742 |
+ |
break; |
743 |
|
case 'b': |
744 |
|
dobwd = (argv[i][0] == '+'); |
745 |
|
break; |
855 |
|
return(wrap_up()); |
856 |
|
userr: |
857 |
|
fprintf(stderr, |
858 |
< |
"Usage: %s [-g Nlog2][-t pctcull][-l maxlobes] [bsdf.sir ..] > bsdf.xml\n", |
858 |
> |
"Usage: %s [{+|-}a][-g Nlog2][-t pctcull][-l maxlobes] [bsdf.sir ..] > bsdf.xml\n", |
859 |
|
progname); |
860 |
|
fprintf(stderr, |
861 |
< |
" or: %s -t{3|4} [-g Nlog2][-t pctcull][{+|-}for[ward]][{+|-}b[ackward]][-e expr][-f file] bsdf_func > bsdf.xml\n", |
861 |
> |
" or: %s -t{3|4} [{+|-}a][-g Nlog2][-t pctcull][{+|-}for[ward]][{+|-}b[ackward]][-e expr][-f file] bsdf_func > bsdf.xml\n", |
862 |
|
progname); |
863 |
|
return(1); |
864 |
|
} |