12 |
|
#include <math.h> |
13 |
|
#include <ctype.h> |
14 |
|
#include "random.h" |
15 |
– |
#include "platform.h" |
16 |
– |
#include "paths.h" |
15 |
|
#include "rtio.h" |
16 |
|
#include "calcomp.h" |
17 |
|
#include "bsdfrep.h" |
20 |
– |
/* global argv[0] */ |
21 |
– |
char *progname; |
18 |
|
/* reciprocity averaging option */ |
19 |
< |
static const char *recip = " -a"; |
19 |
> |
static const char *recip = ""; |
20 |
|
/* percentage to cull (<0 to turn off) */ |
21 |
|
static double pctcull = 90.; |
22 |
|
/* sampling order */ |
24 |
|
/* super-sampling threshold */ |
25 |
|
static double ssamp_thresh = 0.35; |
26 |
|
/* number of super-samples */ |
27 |
< |
static int nssamp = 256; |
27 |
> |
static int nssamp = 64; |
28 |
|
/* limit on number of RBF lobes */ |
29 |
|
static int lobe_lim = 15000; |
30 |
|
/* progress bar length */ |
131 |
|
int assignD = 0; |
132 |
|
char cmd[128]; |
133 |
|
int ix, ox, oy; |
134 |
< |
double iovec[6]; |
134 |
> |
RREAL iovec[6]; |
135 |
|
float bsdf, uv[2]; |
136 |
|
|
137 |
|
if (pctcull >= 0) { |
204 |
|
rbf = advect_rbf(iovec, lobe_lim); |
205 |
|
/* presample first row */ |
206 |
|
for (oy = 0; oy < sqres; oy++) { |
207 |
< |
SDsquare2disk(iovec+3, .5*sqfact, (oy+.5)*sqfact); |
207 |
> |
square2disk(iovec+3, .5*sqfact, (oy+.5)*sqfact); |
208 |
|
iovec[5] = output_orient * |
209 |
|
sqrt(1. - iovec[3]*iovec[3] - iovec[4]*iovec[4]); |
210 |
|
if (funame == NULL) { |
226 |
|
*/ |
227 |
|
for (oy = 0; oy < sqres; oy++) { |
228 |
|
if (ox < sqres-1) { /* keeping one row ahead... */ |
229 |
< |
SDsquare2disk(iovec+3, (ox+1.5)*sqfact, (oy+.5)*sqfact); |
229 |
> |
square2disk(iovec+3, (ox+1.5)*sqfact, (oy+.5)*sqfact); |
230 |
|
iovec[5] = output_orient * |
231 |
|
sqrt(1. - iovec[3]*iovec[3] - iovec[4]*iovec[4]); |
232 |
|
} |
246 |
|
for (ssi = nssamp; ssi--; ) { |
247 |
|
SDmultiSamp(ssa, 2, (ssi+frandom()) / |
248 |
|
(double)nssamp); |
249 |
< |
SDsquare2disk(iovec+3, (ox+ssa[0])*sqfact, |
249 |
> |
square2disk(iovec+3, (ox+ssa[0])*sqfact, |
250 |
|
(oy+ssa[1])*sqfact); |
251 |
|
iovec[5] = output_orient * |
252 |
|
sqrt(1. - iovec[3]*iovec[3] - iovec[4]*iovec[4]); |
264 |
|
uv[0] = usum / (sum+FTINY); |
265 |
|
uv[1] = vsum / (sum+FTINY); |
266 |
|
} |
267 |
< |
} else |
272 |
< |
if (rbf_colorimetry == RBCtristimulus) { |
267 |
> |
} else if (rbf_colorimetry == RBCtristimulus) { |
268 |
|
uv[0] = uv[1] = 1. / |
269 |
|
(-2.*sdv.spec.cx + 12.*sdv.spec.cy + 3.); |
270 |
|
uv[0] *= 4.*sdv.spec.cx; |
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, |
304 |
> |
square2disk(ssvec+3, (ox+ssa[2])*sqfact, |
305 |
|
(oy+ssa[3])*sqfact); |
306 |
|
ssvec[5] = output_orient * |
307 |
|
sqrt(1. - ssvec[3]*ssvec[3] - |
395 |
|
int assignD = 0; |
396 |
|
char cmd[128]; |
397 |
|
int ix, iy, ox, oy; |
398 |
< |
double iovec[6]; |
398 |
> |
RREAL iovec[6]; |
399 |
|
float bsdf, uv[2]; |
400 |
|
|
401 |
|
if (pctcull >= 0) { |
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)*sqfact, 1.-(iy+.5)*sqfact); |
468 |
> |
square2disk(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 |
|
/* presample first row */ |
474 |
|
for (oy = 0; oy < sqres; oy++) { |
475 |
< |
SDsquare2disk(iovec+3, .5*sqfact, (oy+.5)*sqfact); |
475 |
> |
square2disk(iovec+3, .5*sqfact, (oy+.5)*sqfact); |
476 |
|
iovec[5] = output_orient * |
477 |
|
sqrt(1. - iovec[3]*iovec[3] - iovec[4]*iovec[4]); |
478 |
|
if (funame == NULL) { |
494 |
|
*/ |
495 |
|
for (oy = 0; oy < sqres; oy++) { |
496 |
|
if (ox < sqres-1) { /* keeping one row ahead... */ |
497 |
< |
SDsquare2disk(iovec+3, (ox+1.5)*sqfact, (oy+.5)*sqfact); |
497 |
> |
square2disk(iovec+3, (ox+1.5)*sqfact, (oy+.5)*sqfact); |
498 |
|
iovec[5] = output_orient * |
499 |
|
sqrt(1. - iovec[3]*iovec[3] - iovec[4]*iovec[4]); |
500 |
|
} |
514 |
|
for (ssi = nssamp; ssi--; ) { |
515 |
|
SDmultiSamp(ssa, 2, (ssi+frandom()) / |
516 |
|
(double)nssamp); |
517 |
< |
SDsquare2disk(iovec+3, (ox+ssa[0])*sqfact, |
517 |
> |
square2disk(iovec+3, (ox+ssa[0])*sqfact, |
518 |
|
(oy+ssa[1])*sqfact); |
519 |
|
iovec[5] = output_orient * |
520 |
|
sqrt(1. - iovec[3]*iovec[3] - iovec[4]*iovec[4]); |
532 |
|
uv[0] = usum / (sum+FTINY); |
533 |
|
uv[1] = vsum / (sum+FTINY); |
534 |
|
} |
535 |
< |
} else |
541 |
< |
if (rbf_colorimetry == RBCtristimulus) { |
535 |
> |
} else if (rbf_colorimetry == RBCtristimulus) { |
536 |
|
uv[0] = uv[1] = 1. / |
537 |
|
(-2.*sdv.spec.cx + 12.*sdv.spec.cy + 3.); |
538 |
|
uv[0] *= 4.*sdv.spec.cx; |
560 |
|
for (ssi = nssamp; ssi--; ) { |
561 |
|
SDmultiSamp(ssa, 4, (ssi+frandom()) / |
562 |
|
(double)nssamp); |
563 |
< |
SDsquare2disk(ssvec, 1.-(ix+ssa[0])*sqfact, |
563 |
> |
square2disk(ssvec, 1.-(ix+ssa[0])*sqfact, |
564 |
|
1.-(iy+ssa[1])*sqfact); |
565 |
|
ssvec[2] = input_orient * |
566 |
|
sqrt(1. - ssvec[0]*ssvec[0] - |
567 |
|
ssvec[1]*ssvec[1]); |
568 |
< |
SDsquare2disk(ssvec+3, (ox+ssa[2])*sqfact, |
568 |
> |
square2disk(ssvec+3, (ox+ssa[2])*sqfact, |
569 |
|
(oy+ssa[3])*sqfact); |
570 |
|
ssvec[5] = output_orient * |
571 |
|
sqrt(1. - ssvec[3]*ssvec[3] - |
696 |
|
} |
697 |
|
#endif |
698 |
|
|
699 |
< |
#define HEAD_BUFLEN 8192 |
699 |
> |
#define HEAD_BUFLEN 10240 |
700 |
|
static char head_buf[HEAD_BUFLEN]; |
701 |
|
static int cur_headlen = 0; |
702 |
|
|
737 |
|
int |
738 |
|
main(int argc, char *argv[]) |
739 |
|
{ |
740 |
< |
static char tfmt[2][4] = {"t4", "t3"}; |
741 |
< |
int dofwd = 0, dobwd = 1; |
742 |
< |
char buf[2048]; |
743 |
< |
int i, na; |
744 |
< |
|
745 |
< |
progname = argv[0]; |
740 |
> |
static const char tfmt[2][4] = {"t4", "t3"}; |
741 |
> |
int dofwd = 0, dobwd = 1; |
742 |
> |
int nsirs = 0; |
743 |
> |
char buf[1024]; |
744 |
> |
int i; |
745 |
> |
/* set global progname */ |
746 |
> |
fixargv0(argv[0]); |
747 |
|
esupport |= E_VARIABLE|E_FUNCTION|E_RCONST; |
748 |
|
esupport &= ~(E_INCHAN|E_OUTCHAN); |
749 |
|
scompile("PI:3.14159265358979323846", NULL, 0); |
750 |
|
biggerlib(); |
751 |
< |
for (i = 1; i < argc && (argv[i][0] == '-') | (argv[i][0] == '+'); i++) |
752 |
< |
switch (argv[i][1]) { /* get options */ |
751 |
> |
strcpy(buf, "File produced by: "); |
752 |
> |
if (convert_commandline(buf+18, sizeof(buf)-18, argv) != NULL) { |
753 |
> |
add_wbsdf("-C", 1); add_wbsdf(buf, 0); |
754 |
> |
} |
755 |
> |
for (i = 1; i < argc; i++) |
756 |
> |
if ((argv[i][0] == '-') | (argv[i][0] == '+')) { |
757 |
> |
switch (argv[i][1]) { /* get option */ |
758 |
|
case 'e': |
759 |
|
scompile(argv[++i], NULL, 0); |
760 |
|
if (single_plane_incident < 0) |
761 |
|
single_plane_incident = 0; |
762 |
|
break; |
763 |
|
case 'f': |
764 |
< |
if (!argv[i][2]) { |
764 |
> |
if ((argv[i][0] == '-') & !argv[i][2]) { |
765 |
|
if (strchr(argv[++i], '=') != NULL) { |
766 |
|
add_wbsdf("-f", 1); |
767 |
|
add_wbsdf(argv[i], 1); |
832 |
|
default: |
833 |
|
goto userr; |
834 |
|
} |
835 |
< |
strcpy(buf, "File produced by: "); |
836 |
< |
if (convert_commandline(buf+18, sizeof(buf)-18, argv) != NULL) { |
837 |
< |
add_wbsdf("-C", 1); add_wbsdf(buf, 0); |
838 |
< |
} |
839 |
< |
if (single_plane_incident >= 0) { /* function-based BSDF? */ |
835 |
> |
} else { /* input SIR or function */ |
836 |
> |
FILE *fpin; |
837 |
> |
if (!nsirs & (single_plane_incident >= 0)) |
838 |
> |
break; /* must be a function */ |
839 |
> |
if (nsirs >= 4) { |
840 |
> |
fprintf(stderr, "At most 4 SIR inputs supported\n"); |
841 |
> |
goto userr; |
842 |
> |
} |
843 |
> |
fpin = fopen(argv[i], "rb"); /* open SIR file */ |
844 |
> |
if (fpin == NULL) { |
845 |
> |
fprintf(stderr, "%s: cannot open BSDF interpolant '%s'\n", |
846 |
> |
progname, argv[i]); |
847 |
> |
return(1); |
848 |
> |
} |
849 |
> |
sprintf(buf, "%s:\n", argv[i]); |
850 |
> |
record2header(buf); |
851 |
> |
sir_headshare = &record2header; |
852 |
> |
if (!load_bsdf_rep(fpin)) |
853 |
> |
return(1); |
854 |
> |
fclose(fpin); |
855 |
> |
done_header(); |
856 |
> |
sprintf(buf, "Interpolating component '%s'", argv[i]); |
857 |
> |
prog_start(buf); |
858 |
> |
if (!nsirs++) { |
859 |
> |
add_wbsdf("-a", 1); |
860 |
> |
add_wbsdf(tfmt[single_plane_incident], 1); |
861 |
> |
} |
862 |
> |
if (single_plane_incident) |
863 |
> |
eval_isotropic(NULL); |
864 |
> |
else |
865 |
> |
eval_anisotropic(NULL); |
866 |
> |
} |
867 |
> |
if (i < argc) { /* function-based BSDF? */ |
868 |
|
void (*evf)(char *s) = single_plane_incident ? |
869 |
|
eval_isotropic : eval_anisotropic; |
870 |
|
if (i != argc-1 || fundefined(argv[i]) < 3) { |
874 |
|
fprintf(stderr, "\tor 3 arguments using Dx,Dy,Dz: bsdf(ix,iy,iz)\n"); |
875 |
|
goto userr; |
876 |
|
} |
877 |
+ |
doptimize(1); /* optimize definitions */ |
878 |
|
++eclock; |
879 |
|
add_wbsdf("-a", 1); |
880 |
|
add_wbsdf(tfmt[single_plane_incident], 1); |
896 |
|
prog_start("Evaluating inside->outside transmission"); |
897 |
|
(*evf)(argv[i]); |
898 |
|
} |
899 |
< |
return(wrap_up()); |
899 |
> |
} else if (!nsirs) { /* else load SIR from stdin? */ |
900 |
> |
record2header("<stdin>:\n"); |
901 |
> |
sir_headshare = &record2header; |
902 |
> |
if (!load_bsdf_rep(stdin)) |
903 |
> |
return(1); |
904 |
> |
done_header(); |
905 |
> |
prog_start("Interpolating from standard input"); |
906 |
> |
add_wbsdf("-a", 1); |
907 |
> |
add_wbsdf(tfmt[single_plane_incident], 1); |
908 |
> |
if (single_plane_incident) /* resample dist. */ |
909 |
> |
eval_isotropic(NULL); |
910 |
> |
else |
911 |
> |
eval_anisotropic(NULL); |
912 |
|
} |
913 |
< |
if (i < argc) { /* open input files if given */ |
873 |
< |
int nbsdf = 0; |
874 |
< |
for ( ; i < argc; i++) { /* interpolate each component */ |
875 |
< |
char pbuf[256]; |
876 |
< |
FILE *fpin = fopen(argv[i], "rb"); |
877 |
< |
if (fpin == NULL) { |
878 |
< |
fprintf(stderr, "%s: cannot open BSDF interpolant '%s'\n", |
879 |
< |
progname, argv[i]); |
880 |
< |
return(1); |
881 |
< |
} |
882 |
< |
sprintf(pbuf, "%s:\n", argv[i]); |
883 |
< |
record2header(pbuf); |
884 |
< |
sir_headshare = &record2header; |
885 |
< |
if (!load_bsdf_rep(fpin)) |
886 |
< |
return(1); |
887 |
< |
fclose(fpin); |
888 |
< |
done_header(); |
889 |
< |
sprintf(pbuf, "Interpolating component '%s'", argv[i]); |
890 |
< |
prog_start(pbuf); |
891 |
< |
if (!nbsdf++) { |
892 |
< |
add_wbsdf("-a", 1); |
893 |
< |
add_wbsdf(tfmt[single_plane_incident], 1); |
894 |
< |
} |
895 |
< |
if (single_plane_incident) |
896 |
< |
eval_isotropic(NULL); |
897 |
< |
else |
898 |
< |
eval_anisotropic(NULL); |
899 |
< |
} |
900 |
< |
return(wrap_up()); |
901 |
< |
} |
902 |
< |
SET_FILE_BINARY(stdin); /* load from stdin */ |
903 |
< |
if (!load_bsdf_rep(stdin)) |
904 |
< |
return(1); |
905 |
< |
prog_start("Interpolating from standard input"); |
906 |
< |
add_wbsdf("-a", 1); |
907 |
< |
add_wbsdf(tfmt[single_plane_incident], 1); |
908 |
< |
if (single_plane_incident) /* resample dist. */ |
909 |
< |
eval_isotropic(NULL); |
910 |
< |
else |
911 |
< |
eval_anisotropic(NULL); |
912 |
< |
|
913 |
< |
return(wrap_up()); |
913 |
> |
return(wrap_up()); /* call wrapBSDF */ |
914 |
|
userr: |
915 |
|
fprintf(stderr, |
916 |
< |
"Usage: %s [{+|-}a][-g Nlog2][-t pctcull][-n nss][-s thresh][-l maxlobes] [bsdf.sir ..] > bsdf.xml\n", |
916 |
> |
"Usage: %s [{+|-}a][-g Nlog2][-t pctcull][-n nss][-s thresh][-l maxlobes][bsdf.sir ..] > bsdf.xml\n", |
917 |
|
progname); |
918 |
|
fprintf(stderr, |
919 |
|
" 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", |