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

Comparing ray/src/cv/mgflib/parser.c (file contents):
Revision 1.10 by greg, Wed Jun 29 16:15:20 1994 UTC vs.
Revision 1.15 by greg, Thu Apr 13 12:11:30 1995 UTC

# Line 59 | Line 59 | static int     e_any_toss(),           /* discard unneeded entity *
59                  e_ies(),                /* IES luminaire file */
60                  e_include(),            /* include file */
61                  e_sph(),                /* sphere */
62 +                e_cct(),                /* color temperature */
63                  e_cmix(),               /* color mixtures */
64                  e_cspec(),              /* color spectra */
65                  e_cyl(),                /* cylinder */
# Line 119 | Line 120 | mg_init()                      /* initialize alternate entity handlers */
120          if (mg_ehand[MG_E_COLOR] != NULL) {
121                  if (mg_ehand[MG_E_CMIX] == NULL) {
122                          mg_ehand[MG_E_CMIX] = e_cmix;
123 <                        ineed |= 1<<MG_E_COLOR|1<<MG_E_CXY|1<<MG_E_CSPEC|1<<MG_E_CMIX;
123 >                        ineed |= 1<<MG_E_COLOR|1<<MG_E_CXY|1<<MG_E_CSPEC|1<<MG_E_CMIX|1<<MG_E_CCT;
124                  }
125                  if (mg_ehand[MG_E_CSPEC] == NULL) {
126                          mg_ehand[MG_E_CSPEC] = e_cspec;
127 <                        ineed |= 1<<MG_E_COLOR|1<<MG_E_CXY|1<<MG_E_CSPEC|1<<MG_E_CMIX;
127 >                        ineed |= 1<<MG_E_COLOR|1<<MG_E_CXY|1<<MG_E_CSPEC|1<<MG_E_CMIX|1<<MG_E_CCT;
128                  }
129 +                if (mg_ehand[MG_E_CCT] == NULL) {
130 +                        mg_ehand[MG_E_CCT] = e_cct;
131 +                        ineed |= 1<<MG_E_COLOR|1<<MG_E_CXY|1<<MG_E_CSPEC|1<<MG_E_CMIX|1<<MG_E_CCT;
132 +                }
133          }
134                                          /* check for consistency */
135          if (mg_ehand[MG_E_FACE] != NULL)
# Line 133 | Line 138 | mg_init()                      /* initialize alternate entity handlers */
138                          mg_ehand[MG_E_CMIX] != NULL)
139                  uneed |= 1<<MG_E_COLOR;
140          if (mg_ehand[MG_E_RD] != NULL || mg_ehand[MG_E_TD] != NULL ||
141 +                        mg_ehand[MG_E_IR] != NULL ||
142                          mg_ehand[MG_E_ED] != NULL ||
143                          mg_ehand[MG_E_RS] != NULL ||
144 <                        mg_ehand[MG_E_TS] != NULL)
144 >                        mg_ehand[MG_E_TS] != NULL ||
145 >                        mg_ehand[MG_E_SIDES] != NULL)
146                  uneed |= 1<<MG_E_MATERIAL;
147          for (i = 0; i < MG_NENTITIES; i++)
148                  if (uneed & 1<<i && mg_ehand[i] == NULL) {
# Line 158 | Line 165 | mg_init()                      /* initialize alternate entity handlers */
165                  e_supp[MG_E_CSPEC] = c_hcolor;
166          if (ineed & 1<<MG_E_CMIX && mg_ehand[MG_E_CMIX] != c_hcolor)
167                  e_supp[MG_E_CMIX] = c_hcolor;
168 +        if (ineed & 1<<MG_E_CCT && mg_ehand[MG_E_CCT] != c_hcolor)
169 +                e_supp[MG_E_CCT] = c_hcolor;
170                                          /* discard remaining entities */
171          for (i = 0; i < MG_NENTITIES; i++)
172                  if (mg_ehand[i] == NULL)
# Line 165 | Line 174 | mg_init()                      /* initialize alternate entity handlers */
174   }
175  
176  
168
177   int
178   mg_entity(name)                 /* get entity number from its name */
179   char    *name;
# Line 865 | Line 873 | int    ac;
873   char    **av;
874   {
875          static char     p[3][24];
876 <        static char     *vent[4] = {mg_ename[MG_E_VERTEX],NULL,"="};
876 >        static char     *vent[5] = {mg_ename[MG_E_VERTEX],NULL,"="};
877          static char     *pent[5] = {mg_ename[MG_E_POINT],p[0],p[1],p[2]};
878 +        static char     *znorm[5] = {mg_ename[MG_E_NORMAL],"0","0","0"};
879          char    *newav[MG_MAXARGC], nvn[MG_MAXARGC-1][8];
880          double  length;
881 +        int     hasnorm;
882          FVECT   v1, v2, v3, norm;
883          register C_VERTEX       *cv;
884          C_VERTEX        *cv0;
885          int     rv;
886          register int    i, j;
887 <
887 >                                                /* check arguments */
888          if (ac < 5)
889                  return(MG_EARGC);
890          if (!isflt(av[ac-1]))
# Line 882 | Line 892 | char   **av;
892          length = atof(av[ac-1]);
893          if (length <= FTINY && length >= -FTINY)
894                  return(MG_EILL);
895 <                                        /* do bottom face */
886 <        newav[0] = mg_ename[MG_E_FACE];
887 <        for (i = 1; i < ac-1; i++)
888 <                newav[i] = av[i];
889 <        newav[i] = NULL;
890 <        if ((rv = mg_handle(MG_E_FACE, i, newav)) != MG_OK)
891 <                return(rv);
892 <                                        /* compute face normal */
895 >                                                /* compute face normal */
896          if ((cv0 = c_getvert(av[1])) == NULL)
897                  return(MG_EUNDEF);
898 +        hasnorm = 0;
899          norm[0] = norm[1] = norm[2] = 0.;
900          v1[0] = v1[1] = v1[2] = 0.;
901          for (i = 2; i < ac-1; i++) {
902                  if ((cv = c_getvert(av[i])) == NULL)
903                          return(MG_EUNDEF);
904 +                hasnorm += !is0vect(cv->n);
905                  v2[0] = cv->p[0] - cv0->p[0];
906                  v2[1] = cv->p[1] - cv0->p[1];
907                  v2[2] = cv->p[2] - cv0->p[2];
# Line 908 | Line 913 | char   **av;
913          }
914          if (normalize(norm) == 0.)
915                  return(MG_EILL);
916 <                                        /* create moved vertices */
916 >                                                /* create moved vertices */
917          for (i = 1; i < ac-1; i++) {
918                  sprintf(nvn[i-1], "_pv%d", i);
919                  vent[1] = nvn[i-1];
920 <                if ((rv = mg_handle(MG_E_VERTEX, 3, vent)) != MG_OK)
920 >                vent[3] = av[i];
921 >                if ((rv = mg_handle(MG_E_VERTEX, 4, vent)) != MG_OK)
922                          return(rv);
923                  cv = c_getvert(av[i]);          /* checked above */
924                  for (j = 0; j < 3; j++)
925                          sprintf(p[j], FLTFMT, cv->p[j] - length*norm[j]);
926                  if ((rv = mg_handle(MG_E_POINT, 4, pent)) != MG_OK)
927                          return(rv);
922                newav[ac-1-i] = nvn[i-1];       /* reverse */
928          }
929 <                                                /* do top face */
930 <        if ((rv = mg_handle(MG_E_FACE, ac-1, newav)) != MG_OK)
926 <                return(rv);
929 >                                                /* make faces */
930 >        newav[0] = mg_ename[MG_E_FACE];
931                                                  /* do the side faces */
932          newav[5] = NULL;
933          newav[3] = av[ac-2];
# Line 936 | Line 940 | char   **av;
940                  newav[3] = newav[2];
941                  newav[4] = newav[1];
942          }
943 +                                                /* do top face */
944 +        for (i = 1; i < ac-1; i++) {
945 +                if (hasnorm) {                  /* zero normals */
946 +                        vent[1] = nvn[i-1];
947 +                        if ((rv = mg_handle(MG_E_VERTEX, 2, vent)) != MG_OK)
948 +                                return(rv);
949 +                        if ((rv = mg_handle(MG_E_NORMAL, 4, znorm)) != MG_OK)
950 +                                return(rv);
951 +                }
952 +                newav[ac-1-i] = nvn[i-1];       /* reverse */
953 +        }
954 +        if ((rv = mg_handle(MG_E_FACE, ac-1, newav)) != MG_OK)
955 +                return(rv);
956 +                                                /* do bottom face */
957 +        if (hasnorm)
958 +                for (i = 1; i < ac-1; i++) {
959 +                        vent[1] = nvn[i-1];
960 +                        vent[3] = av[i];
961 +                        if ((rv = mg_handle(MG_E_VERTEX, 4, vent)) != MG_OK)
962 +                                return(rv);
963 +                        if ((rv = mg_handle(MG_E_NORMAL, 4, znorm)) != MG_OK)
964 +                                return(rv);
965 +                        newav[i] = nvn[i-1];
966 +                }
967 +        else
968 +                for (i = 1; i < ac-1; i++)
969 +                        newav[i] = av[i];
970 +        newav[i] = NULL;
971 +        if ((rv = mg_handle(MG_E_FACE, i, newav)) != MG_OK)
972 +                return(rv);
973          return(MG_OK);
974   }
975  
976  
977   static int
978 < e_cspec(ac, av)                 /* handle spectral color */
945 < int     ac;
946 < char    **av;
978 > put_cxy()                       /* put out current xy chromaticities */
979   {
980          static char     xbuf[24], ybuf[24];
981          static char     *ccom[4] = {mg_ename[MG_E_CXY], xbuf, ybuf};
982          int     rv;
983  
984 +        sprintf(xbuf, "%.4f", c_ccolor->cx);
985 +        sprintf(ybuf, "%.4f", c_ccolor->cy);
986 +        if ((rv = mg_handle(MG_E_CXY, 3, ccom)) != MG_OK)
987 +                return(rv);
988 +        return(MG_OK);
989 + }
990 +
991 +
992 + static int
993 + put_cspec()                     /* put out current color spectrum */
994 + {
995 +        char    wl[2][6], vbuf[C_CNSS][24];
996 +        char    *newav[C_CNSS+4];
997 +        double  sf;
998 +        register int    i;
999 +
1000 +        if (mg_ehand[MG_E_CSPEC] != c_hcolor) {
1001 +                sprintf(wl[0], "%d", C_CMINWL);
1002 +                sprintf(wl[1], "%d", C_CMAXWL);
1003 +                newav[0] = mg_ename[MG_E_CSPEC];
1004 +                newav[1] = wl[0];
1005 +                newav[2] = wl[1];
1006 +                sf = (double)C_CNSS / c_ccolor->ssum;
1007 +                for (i = 0; i < C_CNSS; i++) {
1008 +                        sprintf(vbuf[i], "%.4f", sf*c_ccolor->ssamp[i]);
1009 +                        newav[i+3] = vbuf[i];
1010 +                }
1011 +                newav[C_CNSS+3] = NULL;
1012 +                if ((i = mg_handle(MG_E_CSPEC, C_CNSS+3, newav)) != MG_OK)
1013 +                        return(i);
1014 +        }
1015 +        return(MG_OK);
1016 + }
1017 +
1018 +
1019 + static int
1020 + e_cspec(ac, av)                 /* handle spectral color */
1021 + int     ac;
1022 + char    **av;
1023 + {
1024 +                                /* convert to xy chromaticity */
1025          c_ccvt(c_ccolor, C_CSXY);
1026                                  /* if it's really their handler, use it */
1027 <        if (mg_ehand[MG_E_CXY] != c_hcolor) {
1028 <                sprintf(xbuf, "%.4f", c_ccolor->cx);
956 <                sprintf(ybuf, "%.4f", c_ccolor->cy);
957 <                if ((rv = mg_handle(MG_E_CXY, 3, ccom)) != MG_OK)
958 <                        return(rv);
959 <        }
1027 >        if (mg_ehand[MG_E_CXY] != c_hcolor)
1028 >                return(put_cxy());
1029          return(MG_OK);
1030   }
1031  
# Line 966 | Line 1035 | e_cmix(ac, av)                 /* handle mixing of colors */
1035   int     ac;
1036   char    **av;
1037   {
969        char    wl[2][6], vbuf[C_CNSS][24];
970        char    *newav[C_CNSS+4];
971        int     rv;
972        register int    i;
1038          /*
1039           * Contorted logic works as follows:
1040           *      1. the colors are already mixed in c_hcolor() support function
# Line 980 | Line 1045 | char   **av;
1045           */
1046          if (mg_ehand[MG_E_CSPEC] == e_cspec)
1047                  c_ccvt(c_ccolor, C_CSXY);
1048 <        else if (c_ccolor->flags & C_CDSPEC) {
1049 <                if (mg_ehand[MG_E_CSPEC] != c_hcolor) {
1050 <                        sprintf(wl[0], "%d", C_CMINWL);
1051 <                        sprintf(wl[1], "%d", C_CMAXWL);
1052 <                        newav[0] = mg_ename[MG_E_CSPEC];
1053 <                        newav[1] = wl[0];
1054 <                        newav[2] = wl[1];
1055 <                        for (i = 0; i < C_CNSS; i++) {
1056 <                                sprintf(vbuf[i], "%.6f",
1057 <                                                (double)c_ccolor->ssamp[i] /
1058 <                                                c_ccolor->ssum);
1059 <                                newav[i+3] = vbuf[i];
1060 <                        }
1061 <                        newav[C_CNSS+3] = NULL;
1062 <                        if ((rv = mg_handle(MG_E_CSPEC, C_CNSS+3, newav)) != MG_OK)
1063 <                                return(rv);
1064 <                }
1065 <                return(MG_OK);
1066 <        }
1067 <        if (mg_ehand[MG_E_CXY] != c_hcolor) {
1068 <                sprintf(vbuf[0], "%.4f", c_ccolor->cx);
1069 <                sprintf(vbuf[1], "%.4f", c_ccolor->cy);
1070 <                newav[0] = mg_ename[MG_E_CXY];
1071 <                newav[1] = vbuf[0];
1007 <                newav[2] = vbuf[1];
1008 <                newav[3] = NULL;
1009 <                if ((rv = mg_handle(MG_E_CXY, 3, newav)) != MG_OK)
1010 <                        return(rv);
1011 <        }
1048 >        else if (c_ccolor->flags & C_CDSPEC)
1049 >                return(put_cspec());
1050 >        if (mg_ehand[MG_E_CXY] != c_hcolor)
1051 >                return(put_cxy());
1052 >        return(MG_OK);
1053 > }
1054 >
1055 >
1056 > static int
1057 > e_cct(ac, av)                   /* handle color temperature */
1058 > int     ac;
1059 > char    **av;
1060 > {
1061 >        /*
1062 >         * Logic is similar to e_cmix here.  Support handler has already
1063 >         * converted temperature to spectral color.  Put it out as such
1064 >         * if they support it, otherwise convert to xy chromaticity and
1065 >         * put it out if they handle it.
1066 >         */
1067 >        if (mg_ehand[MG_E_CSPEC] != e_cspec)
1068 >                return(put_cspec());
1069 >        c_ccvt(c_ccolor, C_CSXY);
1070 >        if (mg_ehand[MG_E_CXY] != c_hcolor)
1071 >                return(put_cxy());
1072          return(MG_OK);
1073   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines