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 8192 |
705 |
> |
#define HEAD_BUFLEN 10240 |
706 |
|
static char head_buf[HEAD_BUFLEN]; |
707 |
|
static int cur_headlen = 0; |
708 |
|
|
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 |
|
|
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) |
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 */ |
869 |
< |
int nbsdf = 0; |
870 |
< |
for ( ; i < argc; i++) { /* interpolate each component */ |
871 |
< |
char pbuf[256]; |
872 |
< |
FILE *fpin = fopen(argv[i], "rb"); |
873 |
< |
if (fpin == NULL) { |
874 |
< |
fprintf(stderr, "%s: cannot open BSDF interpolant '%s'\n", |
875 |
< |
progname, argv[i]); |
876 |
< |
return(1); |
877 |
< |
} |
878 |
< |
sprintf(pbuf, "%s:\n", argv[i]); |
879 |
< |
record2header(pbuf); |
880 |
< |
sir_headshare = &record2header; |
881 |
< |
if (!load_bsdf_rep(fpin)) |
882 |
< |
return(1); |
883 |
< |
fclose(fpin); |
884 |
< |
done_header(); |
885 |
< |
sprintf(pbuf, "Interpolating component '%s'", argv[i]); |
886 |
< |
prog_start(pbuf); |
887 |
< |
if (!nbsdf++) { |
888 |
< |
add_wbsdf("-a", 1); |
889 |
< |
add_wbsdf(tfmt[single_plane_incident], 1); |
890 |
< |
} |
891 |
< |
if (single_plane_incident) |
892 |
< |
eval_isotropic(NULL); |
893 |
< |
else |
894 |
< |
eval_anisotropic(NULL); |
895 |
< |
} |
896 |
< |
return(wrap_up()); |
897 |
< |
} |
898 |
< |
SET_FILE_BINARY(stdin); /* load from stdin */ |
899 |
< |
if (!load_bsdf_rep(stdin)) |
900 |
< |
return(1); |
901 |
< |
prog_start("Interpolating from standard input"); |
902 |
< |
add_wbsdf("-a", 1); |
903 |
< |
add_wbsdf(tfmt[single_plane_incident], 1); |
904 |
< |
if (single_plane_incident) /* resample dist. */ |
905 |
< |
eval_isotropic(NULL); |
906 |
< |
else |
907 |
< |
eval_anisotropic(NULL); |
908 |
< |
|
909 |
< |
return(wrap_up()); |
918 |
> |
return(wrap_up()); /* call wrapBSDF */ |
919 |
|
userr: |
920 |
|
fprintf(stderr, |
921 |
< |
"Usage: %s [{+|-}a][-g Nlog2][-t pctcull][-n nss][-s thresh][-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][-n nss][-s thresh][{+|-}for[ward]][{+|-}b[ackward]][-e expr][-f file] bsdf_func > bsdf.xml\n", |