ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/cv/bsdf2ttree.c
(Generate patch)

Comparing ray/src/cv/bsdf2ttree.c (file contents):
Revision 2.55 by greg, Wed Oct 28 18:54:21 2020 UTC vs.
Revision 2.56 by greg, Fri Nov 13 19:21:11 2020 UTC

# Line 702 | Line 702 | wrap_up(void)
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  
# Line 743 | Line 743 | done_header(void)
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)
# Line 832 | Line 838 | main(int argc, char *argv[])
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) {
# Line 867 | Line 901 | main(int argc, char *argv[])
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 */
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());
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",

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines