10 |
|
#define _USE_MATH_DEFINES |
11 |
|
#include <stdlib.h> |
12 |
|
#include <math.h> |
13 |
+ |
#include <ctype.h> |
14 |
|
#include "random.h" |
15 |
|
#include "platform.h" |
16 |
|
#include "paths.h" |
26 |
|
/* sampling order */ |
27 |
|
static int samp_order = 6; |
28 |
|
/* super-sampling threshold */ |
29 |
< |
const double ssamp_thresh = 0.30; |
29 |
> |
static double ssamp_thresh = 0.35; |
30 |
|
/* number of super-samples */ |
31 |
< |
#ifndef NSSAMP |
31 |
< |
#define NSSAMP 256 |
32 |
< |
#endif |
31 |
> |
static int nssamp = 256; |
32 |
|
/* limit on number of RBF lobes */ |
33 |
|
static int lobe_lim = 15000; |
34 |
|
/* progress bar length */ |
128 |
|
{ |
129 |
|
const int sqres = 1<<samp_order; |
130 |
|
const double sqfact = 1./(double)sqres; |
131 |
< |
float *ryval = NULL; |
132 |
< |
char *rtrip = NULL; |
131 |
> |
float *val_last = NULL; |
132 |
> |
float *val_next = NULL; |
133 |
> |
SDValue *sdv_next = NULL; |
134 |
|
FILE *ofp, *uvfp[2]; |
135 |
|
int assignD = 0; |
136 |
|
char cmd[128]; |
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 |
194 |
> |
val_last = (float *)calloc(sqres, sizeof(float)); |
195 |
> |
if (funame == NULL) |
196 |
> |
sdv_next = (SDValue *)malloc(sizeof(SDValue)*sqres); |
197 |
> |
else |
198 |
> |
val_next = (float *)malloc(sizeof(float)*sqres); |
199 |
|
/* run through directions */ |
200 |
|
for (ix = 0; ix < sqres/2; ix++) { |
201 |
|
const int zipsgn = (ix & 1)*2 - 1; |
206 |
|
- iovec[1]*iovec[1]); |
207 |
|
if (funame == NULL) |
208 |
|
rbf = advect_rbf(iovec, lobe_lim); |
209 |
< |
for (ox = 0; ox < sqres; ox++) { |
210 |
< |
SDValue sdv_next; |
211 |
< |
SDsquare2disk(iovec+3, (ox+.5)*sqfact, .5*sqfact); |
209 |
> |
/* presample first row */ |
210 |
> |
for (oy = 0; oy < sqres; oy++) { |
211 |
> |
SDsquare2disk(iovec+3, .5*sqfact, (oy+.5)*sqfact); |
212 |
|
iovec[5] = output_orient * |
213 |
|
sqrt(1. - iovec[3]*iovec[3] - iovec[4]*iovec[4]); |
214 |
|
if (funame == NULL) { |
215 |
< |
eval_rbfcol(&sdv_next, rbf, iovec+3); |
215 |
> |
eval_rbfcol(&sdv_next[oy], rbf, iovec+3); |
216 |
|
} 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); |
223 |
> |
val_next[oy] = funvalue(funame, 6, iovec); |
224 |
|
} |
225 |
+ |
} |
226 |
+ |
for (ox = 0; ox < sqres; ox++) { |
227 |
+ |
/* |
228 |
+ |
* Super-sample when we detect a difference from before |
229 |
+ |
* or after in this row, above or below. |
230 |
+ |
*/ |
231 |
|
for (oy = 0; oy < sqres; oy++) { |
232 |
< |
int trip; |
233 |
< |
bsdf = sdv_next.cieY; /* keeping one step ahead... */ |
228 |
< |
if (oy < sqres-1) { |
229 |
< |
SDsquare2disk(iovec+3, (ox+.5)*sqfact, (oy+1.5)*sqfact); |
232 |
> |
if (ox < sqres-1) { /* keeping one row ahead... */ |
233 |
> |
SDsquare2disk(iovec+3, (ox+1.5)*sqfact, (oy+.5)*sqfact); |
234 |
|
iovec[5] = output_orient * |
235 |
|
sqrt(1. - iovec[3]*iovec[3] - iovec[4]*iovec[4]); |
236 |
|
} |
237 |
|
if (funame == NULL) { |
238 |
< |
SDValue sdv = sdv_next; |
239 |
< |
if (oy < sqres-1) |
240 |
< |
eval_rbfcol(&sdv_next, rbf, iovec+3); |
241 |
< |
#if (NSSAMP > 0) |
242 |
< |
trip = (abs_diff(bsdf, sdv_next.cieY) > ssamp_thresh || |
243 |
< |
(ox && abs_diff(bsdf, ryval[oy]) > ssamp_thresh) || |
244 |
< |
(oy && abs_diff(bsdf, ryval[oy-1]) > ssamp_thresh)); |
245 |
< |
if (trip | rtrip[oy] || (oy && rtrip[oy-1])) { |
238 |
> |
SDValue sdv = sdv_next[oy]; |
239 |
> |
bsdf = sdv.cieY; |
240 |
> |
if (ox < sqres-1) |
241 |
> |
eval_rbfcol(&sdv_next[oy], rbf, iovec+3); |
242 |
> |
if (abs_diff(bsdf, sdv_next[oy].cieY) > ssamp_thresh || |
243 |
> |
(ox && abs_diff(bsdf, val_last[oy]) > ssamp_thresh) || |
244 |
> |
(oy && abs_diff(bsdf, val_last[oy-1]) > ssamp_thresh) || |
245 |
> |
(oy < sqres-1 && |
246 |
> |
abs_diff(bsdf, sdv_next[oy+1].cieY) > ssamp_thresh)) { |
247 |
|
int ssi; |
248 |
|
double ssa[2], sum = 0, usum = 0, vsum = 0; |
249 |
|
/* super-sample voxel */ |
250 |
< |
for (ssi = NSSAMP; ssi--; ) { |
251 |
< |
SDmultiSamp(ssa, 2, (ssi+frandom()) * |
252 |
< |
(1./NSSAMP)); |
250 |
> |
for (ssi = nssamp; ssi--; ) { |
251 |
> |
SDmultiSamp(ssa, 2, (ssi+frandom()) / |
252 |
> |
(double)nssamp); |
253 |
|
SDsquare2disk(iovec+3, (ox+ssa[0])*sqfact, |
254 |
|
(oy+ssa[1])*sqfact); |
255 |
|
iovec[5] = output_orient * |
263 |
|
vsum += 9.*sdv.spec.cy * sdv.cieY; |
264 |
|
} |
265 |
|
} |
266 |
< |
bsdf = sum * (1./NSSAMP); |
266 |
> |
bsdf = sum / (double)nssamp; |
267 |
|
if (rbf_colorimetry == RBCtristimulus) { |
268 |
|
uv[0] = usum / (sum+FTINY); |
269 |
|
uv[1] = vsum / (sum+FTINY); |
270 |
|
} |
271 |
|
} else |
267 |
– |
#endif |
272 |
|
if (rbf_colorimetry == RBCtristimulus) { |
273 |
|
uv[0] = uv[1] = 1. / |
274 |
|
(-2.*sdv.spec.cx + 12.*sdv.spec.cy + 3.); |
276 |
|
uv[1] *= 9.*sdv.spec.cy; |
277 |
|
} |
278 |
|
} else { |
279 |
< |
if (oy < sqres-1) { |
279 |
> |
bsdf = val_next[oy]; |
280 |
> |
if (ox < sqres-1) { |
281 |
|
if (assignD) { |
282 |
|
varset("Dx", '=', -iovec[3]); |
283 |
|
varset("Dy", '=', -iovec[4]); |
284 |
|
varset("Dz", '=', -iovec[5]); |
285 |
|
++eclock; |
286 |
|
} |
287 |
< |
sdv_next.cieY = funvalue(funame, 6, iovec); |
287 |
> |
val_next[oy] = funvalue(funame, 6, iovec); |
288 |
|
} |
289 |
< |
#if (NSSAMP > 0) |
290 |
< |
trip = (abs_diff(bsdf, sdv_next.cieY) > ssamp_thresh || |
291 |
< |
(ox && abs_diff(bsdf, ryval[oy]) > ssamp_thresh) || |
292 |
< |
(oy && abs_diff(bsdf, ryval[oy-1]) > ssamp_thresh)); |
293 |
< |
if (trip | rtrip[oy] || (oy && rtrip[oy-1])) { |
289 |
> |
if (abs_diff(bsdf, val_next[oy]) > ssamp_thresh || |
290 |
> |
(ox && abs_diff(bsdf, val_last[oy]) > ssamp_thresh) || |
291 |
> |
(oy && abs_diff(bsdf, val_last[oy-1]) > ssamp_thresh) || |
292 |
> |
(oy < sqres-1 && |
293 |
> |
abs_diff(bsdf, val_next[oy+1]) > ssamp_thresh)) { |
294 |
|
int ssi; |
295 |
|
double ssa[4], ssvec[6], sum = 0; |
296 |
|
/* super-sample voxel */ |
297 |
< |
for (ssi = NSSAMP; ssi--; ) { |
298 |
< |
SDmultiSamp(ssa, 4, (ssi+frandom()) * |
299 |
< |
(1./NSSAMP)); |
297 |
> |
for (ssi = nssamp; ssi--; ) { |
298 |
> |
SDmultiSamp(ssa, 4, (ssi+frandom()) / |
299 |
> |
(double)nssamp); |
300 |
|
ssvec[0] = 2.*sqfact*(ix+ssa[0]) - 1.; |
301 |
|
ssvec[1] = zipsgn*sqfact*ssa[1]; |
302 |
|
ssvec[2] = 1. - ssvec[0]*ssvec[0] |
319 |
|
} |
320 |
|
sum += funvalue(funame, 6, ssvec); |
321 |
|
} |
322 |
< |
bsdf = sum * (1./NSSAMP); |
322 |
> |
bsdf = sum / (double)nssamp; |
323 |
|
} |
319 |
– |
#endif |
324 |
|
} |
325 |
|
if (pctcull >= 0) |
326 |
|
putbinary(&bsdf, sizeof(bsdf), 1, ofp); |
336 |
|
fprintf(uvfp[1], "\t%.3e\n", uv[1]); |
337 |
|
} |
338 |
|
} |
339 |
< |
if (ryval != NULL) { |
340 |
< |
rtrip[oy] = trip; |
337 |
< |
ryval[oy] = bsdf; |
338 |
< |
} |
339 |
> |
if (val_last != NULL) |
340 |
> |
val_last[oy] = bsdf; |
341 |
|
} |
342 |
|
} |
343 |
|
if (rbf != NULL) |
345 |
|
prog_show((ix+1.)*(2.*sqfact)); |
346 |
|
} |
347 |
|
prog_done(); |
348 |
< |
if (ryval != NULL) { |
349 |
< |
free(rtrip); |
350 |
< |
free(ryval); |
348 |
> |
if (val_last != NULL) { |
349 |
> |
free(val_last); |
350 |
> |
if (val_next != NULL) free(val_next); |
351 |
> |
if (sdv_next != NULL) free(sdv_next); |
352 |
|
} |
353 |
|
if (pctcull >= 0) { /* finish output */ |
354 |
|
if (pclose(ofp)) { |
393 |
|
{ |
394 |
|
const int sqres = 1<<samp_order; |
395 |
|
const double sqfact = 1./(double)sqres; |
396 |
< |
float *ryval = NULL; |
397 |
< |
char *rtrip = NULL; |
396 |
> |
float *val_last = NULL; |
397 |
> |
float *val_next = NULL; |
398 |
> |
SDValue *sdv_next = NULL; |
399 |
|
FILE *ofp, *uvfp[2]; |
400 |
|
int assignD = 0; |
401 |
|
char cmd[128]; |
461 |
|
} |
462 |
|
if (funame != NULL) /* need to assign Dx, Dy, Dz? */ |
463 |
|
assignD = (fundefined(funame) < 6); |
464 |
< |
#if (NSSAMP > 0) |
465 |
< |
rtrip = (char *)calloc(sqres, 1); /* track sample triggerings */ |
466 |
< |
ryval = (float *)calloc(sqres, sizeof(float)); |
467 |
< |
#endif |
464 |
> |
val_last = (float *)calloc(sqres, sizeof(float)); |
465 |
> |
if (funame == NULL) |
466 |
> |
sdv_next = (SDValue *)malloc(sizeof(SDValue)*sqres); |
467 |
> |
else |
468 |
> |
val_next = (float *)malloc(sizeof(float)*sqres); |
469 |
|
/* run through directions */ |
470 |
|
for (ix = 0; ix < sqres; ix++) |
471 |
|
for (iy = 0; iy < sqres; iy++) { |
475 |
|
sqrt(1. - iovec[0]*iovec[0] - iovec[1]*iovec[1]); |
476 |
|
if (funame == NULL) |
477 |
|
rbf = advect_rbf(iovec, lobe_lim); |
478 |
< |
for (ox = 0; ox < sqres; ox++) { |
479 |
< |
SDValue sdv_next; |
480 |
< |
SDsquare2disk(iovec+3, (ox+.5)*sqfact, .5*sqfact); |
478 |
> |
/* presample first row */ |
479 |
> |
for (oy = 0; oy < sqres; oy++) { |
480 |
> |
SDsquare2disk(iovec+3, .5*sqfact, (oy+.5)*sqfact); |
481 |
|
iovec[5] = output_orient * |
482 |
|
sqrt(1. - iovec[3]*iovec[3] - iovec[4]*iovec[4]); |
483 |
|
if (funame == NULL) { |
484 |
< |
eval_rbfcol(&sdv_next, rbf, iovec+3); |
484 |
> |
eval_rbfcol(&sdv_next[oy], rbf, iovec+3); |
485 |
|
} else { |
481 |
– |
sdv_next.spec = c_dfcolor; |
486 |
|
if (assignD) { |
487 |
|
varset("Dx", '=', -iovec[3]); |
488 |
|
varset("Dy", '=', -iovec[4]); |
489 |
|
varset("Dz", '=', -iovec[5]); |
490 |
|
++eclock; |
491 |
|
} |
492 |
< |
sdv_next.cieY = funvalue(funame, 6, iovec); |
492 |
> |
val_next[oy] = funvalue(funame, 6, iovec); |
493 |
|
} |
494 |
+ |
} |
495 |
+ |
for (ox = 0; ox < sqres; ox++) { |
496 |
+ |
/* |
497 |
+ |
* Super-sample when we detect a difference from before |
498 |
+ |
* or after in this row, above or below. |
499 |
+ |
*/ |
500 |
|
for (oy = 0; oy < sqres; oy++) { |
501 |
< |
int trip; |
502 |
< |
bsdf = sdv_next.cieY; /* keeping one step ahead... */ |
493 |
< |
if (oy < sqres-1) { |
494 |
< |
SDsquare2disk(iovec+3, (ox+.5)*sqfact, (oy+1.5)*sqfact); |
501 |
> |
if (ox < sqres-1) { /* keeping one row ahead... */ |
502 |
> |
SDsquare2disk(iovec+3, (ox+1.5)*sqfact, (oy+.5)*sqfact); |
503 |
|
iovec[5] = output_orient * |
504 |
|
sqrt(1. - iovec[3]*iovec[3] - iovec[4]*iovec[4]); |
505 |
|
} |
506 |
|
if (funame == NULL) { |
507 |
< |
SDValue sdv = sdv_next; |
508 |
< |
if (oy < sqres-1) |
509 |
< |
eval_rbfcol(&sdv_next, rbf, iovec+3); |
510 |
< |
#if (NSSAMP > 0) |
511 |
< |
trip = (abs_diff(bsdf, sdv_next.cieY) > ssamp_thresh || |
512 |
< |
(ox && abs_diff(bsdf, ryval[oy]) > ssamp_thresh) || |
513 |
< |
(oy && abs_diff(bsdf, ryval[oy-1]) > ssamp_thresh)); |
514 |
< |
if (trip | rtrip[oy] || (oy && rtrip[oy-1])) { |
507 |
> |
SDValue sdv = sdv_next[oy]; |
508 |
> |
bsdf = sdv.cieY; |
509 |
> |
if (ox < sqres-1) |
510 |
> |
eval_rbfcol(&sdv_next[oy], rbf, iovec+3); |
511 |
> |
if (abs_diff(bsdf, sdv_next[oy].cieY) > ssamp_thresh || |
512 |
> |
(ox && abs_diff(bsdf, val_last[oy]) > ssamp_thresh) || |
513 |
> |
(oy && abs_diff(bsdf, val_last[oy-1]) > ssamp_thresh) || |
514 |
> |
(oy < sqres-1 && |
515 |
> |
abs_diff(bsdf, sdv_next[oy+1].cieY) > ssamp_thresh)) { |
516 |
|
int ssi; |
517 |
|
double ssa[2], sum = 0, usum = 0, vsum = 0; |
518 |
|
/* super-sample voxel */ |
519 |
< |
for (ssi = NSSAMP; ssi--; ) { |
520 |
< |
SDmultiSamp(ssa, 2, (ssi+frandom()) * |
521 |
< |
(1./NSSAMP)); |
519 |
> |
for (ssi = nssamp; ssi--; ) { |
520 |
> |
SDmultiSamp(ssa, 2, (ssi+frandom()) / |
521 |
> |
(double)nssamp); |
522 |
|
SDsquare2disk(iovec+3, (ox+ssa[0])*sqfact, |
523 |
|
(oy+ssa[1])*sqfact); |
524 |
|
iovec[5] = output_orient * |
532 |
|
vsum += 9.*sdv.spec.cy * sdv.cieY; |
533 |
|
} |
534 |
|
} |
535 |
< |
bsdf = sum * (1./NSSAMP); |
535 |
> |
bsdf = sum / (double)nssamp; |
536 |
|
if (rbf_colorimetry == RBCtristimulus) { |
537 |
|
uv[0] = usum / (sum+FTINY); |
538 |
|
uv[1] = vsum / (sum+FTINY); |
539 |
|
} |
540 |
|
} else |
532 |
– |
#endif |
541 |
|
if (rbf_colorimetry == RBCtristimulus) { |
542 |
|
uv[0] = uv[1] = 1. / |
543 |
|
(-2.*sdv.spec.cx + 12.*sdv.spec.cy + 3.); |
545 |
|
uv[1] *= 9.*sdv.spec.cy; |
546 |
|
} |
547 |
|
} else { |
548 |
< |
if (oy < sqres-1) { |
548 |
> |
bsdf = val_next[oy]; |
549 |
> |
if (ox < sqres-1) { |
550 |
|
if (assignD) { |
551 |
|
varset("Dx", '=', -iovec[3]); |
552 |
|
varset("Dy", '=', -iovec[4]); |
553 |
|
varset("Dz", '=', -iovec[5]); |
554 |
|
++eclock; |
555 |
|
} |
556 |
< |
sdv_next.cieY = funvalue(funame, 6, iovec); |
556 |
> |
val_next[oy] = funvalue(funame, 6, iovec); |
557 |
|
} |
558 |
< |
#if (NSSAMP > 0) |
559 |
< |
trip = (abs_diff(bsdf, sdv_next.cieY) > ssamp_thresh || |
560 |
< |
(ox && abs_diff(bsdf, ryval[oy]) > ssamp_thresh) || |
561 |
< |
(oy && abs_diff(bsdf, ryval[oy-1]) > ssamp_thresh)); |
562 |
< |
if (trip | rtrip[oy] || (oy && rtrip[oy-1])) { |
558 |
> |
if (abs_diff(bsdf, val_next[oy]) > ssamp_thresh || |
559 |
> |
(ox && abs_diff(bsdf, val_last[oy]) > ssamp_thresh) || |
560 |
> |
(oy && abs_diff(bsdf, val_last[oy-1]) > ssamp_thresh) || |
561 |
> |
(oy < sqres-1 && |
562 |
> |
abs_diff(bsdf, val_next[oy+1]) > ssamp_thresh)) { |
563 |
|
int ssi; |
564 |
|
double ssa[4], ssvec[6], sum = 0; |
565 |
|
/* super-sample voxel */ |
566 |
< |
for (ssi = NSSAMP; ssi--; ) { |
567 |
< |
SDmultiSamp(ssa, 4, (ssi+frandom()) * |
568 |
< |
(1./NSSAMP)); |
566 |
> |
for (ssi = nssamp; ssi--; ) { |
567 |
> |
SDmultiSamp(ssa, 4, (ssi+frandom()) / |
568 |
> |
(double)nssamp); |
569 |
|
SDsquare2disk(ssvec, 1.-(ix+ssa[0])*sqfact, |
570 |
|
1.-(iy+ssa[1])*sqfact); |
571 |
|
ssvec[2] = input_orient * |
584 |
|
} |
585 |
|
sum += funvalue(funame, 6, ssvec); |
586 |
|
} |
587 |
< |
bsdf = sum * (1./NSSAMP); |
587 |
> |
bsdf = sum / (double)nssamp; |
588 |
|
} |
580 |
– |
#endif |
589 |
|
} |
590 |
|
if (pctcull >= 0) |
591 |
|
putbinary(&bsdf, sizeof(bsdf), 1, ofp); |
601 |
|
fprintf(uvfp[1], "\t%.3e\n", uv[1]); |
602 |
|
} |
603 |
|
} |
604 |
< |
if (ryval != NULL) { |
605 |
< |
rtrip[oy] = trip; |
598 |
< |
ryval[oy] = bsdf; |
599 |
< |
} |
604 |
> |
if (val_last != NULL) |
605 |
> |
val_last[oy] = bsdf; |
606 |
|
} |
607 |
+ |
} |
608 |
|
if (rbf != NULL) |
609 |
|
free(rbf); |
610 |
|
prog_show((ix*sqres+iy+1.)/(sqres*sqres)); |
611 |
|
} |
605 |
– |
} |
612 |
|
prog_done(); |
613 |
< |
if (ryval != NULL) { |
614 |
< |
free(rtrip); |
615 |
< |
free(ryval); |
613 |
> |
if (val_last != NULL) { |
614 |
> |
free(val_last); |
615 |
> |
if (val_next != NULL) free(val_next); |
616 |
> |
if (sdv_next != NULL) free(sdv_next); |
617 |
|
} |
618 |
|
if (pctcull >= 0) { /* finish output */ |
619 |
|
if (pclose(ofp)) { |
651 |
|
static int |
652 |
|
wrap_up(void) |
653 |
|
{ |
654 |
< |
char cmd[8192]; |
654 |
> |
char cmd[32700]; |
655 |
|
|
656 |
|
if (bsdf_manuf[0]) { |
657 |
|
add_wbsdf("-f", 1); |
702 |
|
} |
703 |
|
#endif |
704 |
|
|
705 |
+ |
#define HEAD_BUFLEN 10240 |
706 |
+ |
static char head_buf[HEAD_BUFLEN]; |
707 |
+ |
static int cur_headlen = 0; |
708 |
+ |
|
709 |
+ |
/* Record header line as comment associated with this SIR input */ |
710 |
+ |
static int |
711 |
+ |
record2header(char *s) |
712 |
+ |
{ |
713 |
+ |
int len = strlen(s); |
714 |
+ |
|
715 |
+ |
if (cur_headlen+len >= HEAD_BUFLEN-6) |
716 |
+ |
return(0); |
717 |
+ |
/* includes EOL */ |
718 |
+ |
strcpy(head_buf+cur_headlen, s); |
719 |
+ |
cur_headlen += len; |
720 |
+ |
|
721 |
+ |
#if defined(_WIN32) || defined(_WIN64) |
722 |
+ |
if (head_buf[cur_headlen-1] == '\n') |
723 |
+ |
head_buf[cur_headlen-1] = '\t'; |
724 |
+ |
#endif |
725 |
+ |
return(1); |
726 |
+ |
} |
727 |
+ |
|
728 |
+ |
/* Finish off header for this file */ |
729 |
+ |
static void |
730 |
+ |
done_header(void) |
731 |
+ |
{ |
732 |
+ |
while (cur_headlen > 0 && isspace(head_buf[cur_headlen-1])) |
733 |
+ |
--cur_headlen; |
734 |
+ |
head_buf[cur_headlen] = '\0'; |
735 |
+ |
if (!cur_headlen) |
736 |
+ |
return; |
737 |
+ |
add_wbsdf("-C", 1); |
738 |
+ |
add_wbsdf(head_buf, 0); |
739 |
+ |
head_buf[cur_headlen=0] = '\0'; |
740 |
+ |
} |
741 |
+ |
|
742 |
|
/* Read in BSDF and interpolate as tensor tree representation */ |
743 |
|
int |
744 |
|
main(int argc, char *argv[]) |
745 |
|
{ |
746 |
< |
static char tfmt[2][4] = {"t4", "t3"}; |
747 |
< |
int dofwd = 0, dobwd = 1; |
748 |
< |
char buf[2048]; |
749 |
< |
int i, na; |
746 |
> |
static const char tfmt[2][4] = {"t4", "t3"}; |
747 |
> |
int dofwd = 0, dobwd = 1; |
748 |
> |
int nsirs = 0; |
749 |
> |
char buf[1024]; |
750 |
> |
int i; |
751 |
|
|
752 |
|
progname = argv[0]; |
753 |
|
esupport |= E_VARIABLE|E_FUNCTION|E_RCONST; |
754 |
|
esupport &= ~(E_INCHAN|E_OUTCHAN); |
755 |
|
scompile("PI:3.14159265358979323846", NULL, 0); |
756 |
|
biggerlib(); |
757 |
< |
for (i = 1; i < argc && (argv[i][0] == '-') | (argv[i][0] == '+'); i++) |
758 |
< |
switch (argv[i][1]) { /* get options */ |
757 |
> |
strcpy(buf, "File produced by: "); |
758 |
> |
if (convert_commandline(buf+18, sizeof(buf)-18, argv) != NULL) { |
759 |
> |
add_wbsdf("-C", 1); add_wbsdf(buf, 0); |
760 |
> |
} |
761 |
> |
for (i = 1; i < argc; i++) |
762 |
> |
if ((argv[i][0] == '-') | (argv[i][0] == '+')) { |
763 |
> |
switch (argv[i][1]) { /* get option */ |
764 |
|
case 'e': |
765 |
|
scompile(argv[++i], NULL, 0); |
766 |
|
if (single_plane_incident < 0) |
793 |
|
case 'b': |
794 |
|
dobwd = (argv[i][0] == '+'); |
795 |
|
break; |
796 |
+ |
case 'n': |
797 |
+ |
nssamp = atoi(argv[++i]); |
798 |
+ |
if (nssamp <= 0) |
799 |
+ |
goto userr; |
800 |
+ |
break; |
801 |
+ |
case 's': |
802 |
+ |
ssamp_thresh = atof(argv[++i]); |
803 |
+ |
if (ssamp_thresh <= FTINY) |
804 |
+ |
goto userr; |
805 |
+ |
break; |
806 |
|
case 't': |
807 |
|
switch (argv[i][2]) { |
808 |
|
case '3': |
838 |
|
default: |
839 |
|
goto userr; |
840 |
|
} |
841 |
< |
strcpy(buf, "File produced by: "); |
842 |
< |
if (convert_commandline(buf+18, sizeof(buf)-18, argv) != NULL) { |
843 |
< |
add_wbsdf("-C", 1); add_wbsdf(buf, 0); |
844 |
< |
} |
845 |
< |
if (single_plane_incident >= 0) { /* function-based BSDF? */ |
841 |
> |
} else { /* input SIR or function */ |
842 |
> |
FILE *fpin; |
843 |
> |
if (!nsirs & (single_plane_incident >= 0)) |
844 |
> |
break; /* must be a function */ |
845 |
> |
if (nsirs >= 4) { |
846 |
> |
fprintf(stderr, "At most 4 SIR inputs supported\n"); |
847 |
> |
goto userr; |
848 |
> |
} |
849 |
> |
fpin = fopen(argv[i], "rb"); /* open SIR file */ |
850 |
> |
if (fpin == NULL) { |
851 |
> |
fprintf(stderr, "%s: cannot open BSDF interpolant '%s'\n", |
852 |
> |
progname, argv[i]); |
853 |
> |
return(1); |
854 |
> |
} |
855 |
> |
sprintf(buf, "%s:\n", argv[i]); |
856 |
> |
record2header(buf); |
857 |
> |
sir_headshare = &record2header; |
858 |
> |
if (!load_bsdf_rep(fpin)) |
859 |
> |
return(1); |
860 |
> |
fclose(fpin); |
861 |
> |
done_header(); |
862 |
> |
sprintf(buf, "Interpolating component '%s'", argv[i]); |
863 |
> |
prog_start(buf); |
864 |
> |
if (!nsirs++) { |
865 |
> |
add_wbsdf("-a", 1); |
866 |
> |
add_wbsdf(tfmt[single_plane_incident], 1); |
867 |
> |
} |
868 |
> |
if (single_plane_incident) |
869 |
> |
eval_isotropic(NULL); |
870 |
> |
else |
871 |
> |
eval_anisotropic(NULL); |
872 |
> |
} |
873 |
> |
if (i < argc) { /* function-based BSDF? */ |
874 |
|
void (*evf)(char *s) = single_plane_incident ? |
875 |
|
eval_isotropic : eval_anisotropic; |
876 |
|
if (i != argc-1 || fundefined(argv[i]) < 3) { |
901 |
|
prog_start("Evaluating inside->outside transmission"); |
902 |
|
(*evf)(argv[i]); |
903 |
|
} |
904 |
< |
return(wrap_up()); |
904 |
> |
} else if (!nsirs) { /* else load SIR from stdin? */ |
905 |
> |
record2header("<stdin>:\n"); |
906 |
> |
sir_headshare = &record2header; |
907 |
> |
if (!load_bsdf_rep(stdin)) |
908 |
> |
return(1); |
909 |
> |
done_header(); |
910 |
> |
prog_start("Interpolating from standard input"); |
911 |
> |
add_wbsdf("-a", 1); |
912 |
> |
add_wbsdf(tfmt[single_plane_incident], 1); |
913 |
> |
if (single_plane_incident) /* resample dist. */ |
914 |
> |
eval_isotropic(NULL); |
915 |
> |
else |
916 |
> |
eval_anisotropic(NULL); |
917 |
|
} |
918 |
< |
if (i < argc) { /* open input files if given */ |
819 |
< |
int nbsdf = 0; |
820 |
< |
for ( ; i < argc; i++) { /* interpolate each component */ |
821 |
< |
char pbuf[256]; |
822 |
< |
FILE *fpin = fopen(argv[i], "rb"); |
823 |
< |
if (fpin == NULL) { |
824 |
< |
fprintf(stderr, "%s: cannot open BSDF interpolant '%s'\n", |
825 |
< |
progname, argv[i]); |
826 |
< |
return(1); |
827 |
< |
} |
828 |
< |
if (!load_bsdf_rep(fpin)) |
829 |
< |
return(1); |
830 |
< |
fclose(fpin); |
831 |
< |
sprintf(pbuf, "Interpolating component '%s'", argv[i]); |
832 |
< |
prog_start(pbuf); |
833 |
< |
if (!nbsdf++) { |
834 |
< |
add_wbsdf("-a", 1); |
835 |
< |
add_wbsdf(tfmt[single_plane_incident], 1); |
836 |
< |
} |
837 |
< |
if (single_plane_incident) |
838 |
< |
eval_isotropic(NULL); |
839 |
< |
else |
840 |
< |
eval_anisotropic(NULL); |
841 |
< |
} |
842 |
< |
return(wrap_up()); |
843 |
< |
} |
844 |
< |
SET_FILE_BINARY(stdin); /* load from stdin */ |
845 |
< |
if (!load_bsdf_rep(stdin)) |
846 |
< |
return(1); |
847 |
< |
prog_start("Interpolating from standard input"); |
848 |
< |
add_wbsdf("-a", 1); |
849 |
< |
add_wbsdf(tfmt[single_plane_incident], 1); |
850 |
< |
if (single_plane_incident) /* resample dist. */ |
851 |
< |
eval_isotropic(NULL); |
852 |
< |
else |
853 |
< |
eval_anisotropic(NULL); |
854 |
< |
|
855 |
< |
return(wrap_up()); |
918 |
> |
return(wrap_up()); /* call wrapBSDF */ |
919 |
|
userr: |
920 |
|
fprintf(stderr, |
921 |
< |
"Usage: %s [{+|-}a][-g Nlog2][-t pctcull][-l maxlobes] [bsdf.sir ..] > bsdf.xml\n", |
921 |
> |
"Usage: %s [{+|-}a][-g Nlog2][-t pctcull][-n nss][-s thresh][-l maxlobes][bsdf.sir ..] > bsdf.xml\n", |
922 |
|
progname); |
923 |
|
fprintf(stderr, |
924 |
< |
" or: %s -t{3|4} [{+|-}a][-g Nlog2][-t pctcull][{+|-}for[ward]][{+|-}b[ackward]][-e expr][-f file] bsdf_func > bsdf.xml\n", |
924 |
> |
" or: %s -t{3|4} [{+|-}a][-g Nlog2][-t pctcull][-n nss][-s thresh][{+|-}for[ward]][{+|-}b[ackward]][-e expr][-f file] bsdf_func > bsdf.xml\n", |
925 |
|
progname); |
926 |
|
return(1); |
927 |
|
} |