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.11 by greg, Fri Jul 1 18:06:58 1994 UTC vs.
Revision 1.14 by greg, Fri Mar 10 15:16:07 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 159 | Line 164 | mg_init()                      /* initialize alternate entity handlers */
164                  e_supp[MG_E_CSPEC] = c_hcolor;
165          if (ineed & 1<<MG_E_CMIX && mg_ehand[MG_E_CMIX] != c_hcolor)
166                  e_supp[MG_E_CMIX] = c_hcolor;
167 +        if (ineed & 1<<MG_E_CCT && mg_ehand[MG_E_CCT] != c_hcolor)
168 +                e_supp[MG_E_CCT] = c_hcolor;
169                                          /* discard remaining entities */
170          for (i = 0; i < MG_NENTITIES; i++)
171                  if (mg_ehand[i] == NULL)
# Line 166 | Line 173 | mg_init()                      /* initialize alternate entity handlers */
173   }
174  
175  
169
176   int
177   mg_entity(name)                 /* get entity number from its name */
178   char    *name;
# Line 866 | Line 872 | int    ac;
872   char    **av;
873   {
874          static char     p[3][24];
875 <        static char     *vent[4] = {mg_ename[MG_E_VERTEX],NULL,"="};
875 >        static char     *vent[5] = {mg_ename[MG_E_VERTEX],NULL,"="};
876          static char     *pent[5] = {mg_ename[MG_E_POINT],p[0],p[1],p[2]};
877 +        static char     *znorm[5] = {mg_ename[MG_E_NORMAL],"0","0","0"};
878          char    *newav[MG_MAXARGC], nvn[MG_MAXARGC-1][8];
879          double  length;
880 +        int     hasnorm;
881          FVECT   v1, v2, v3, norm;
882          register C_VERTEX       *cv;
883          C_VERTEX        *cv0;
884          int     rv;
885          register int    i, j;
886 <
886 >                                                /* check arguments */
887          if (ac < 5)
888                  return(MG_EARGC);
889          if (!isflt(av[ac-1]))
# Line 883 | Line 891 | char   **av;
891          length = atof(av[ac-1]);
892          if (length <= FTINY && length >= -FTINY)
893                  return(MG_EILL);
894 <                                        /* do bottom face */
887 <        newav[0] = mg_ename[MG_E_FACE];
888 <        for (i = 1; i < ac-1; i++)
889 <                newav[i] = av[i];
890 <        newav[i] = NULL;
891 <        if ((rv = mg_handle(MG_E_FACE, i, newav)) != MG_OK)
892 <                return(rv);
893 <                                        /* compute face normal */
894 >                                                /* compute face normal */
895          if ((cv0 = c_getvert(av[1])) == NULL)
896                  return(MG_EUNDEF);
897 +        hasnorm = 0;
898          norm[0] = norm[1] = norm[2] = 0.;
899          v1[0] = v1[1] = v1[2] = 0.;
900          for (i = 2; i < ac-1; i++) {
901                  if ((cv = c_getvert(av[i])) == NULL)
902                          return(MG_EUNDEF);
903 +                hasnorm += !is0vect(cv->n);
904                  v2[0] = cv->p[0] - cv0->p[0];
905                  v2[1] = cv->p[1] - cv0->p[1];
906                  v2[2] = cv->p[2] - cv0->p[2];
# Line 909 | Line 912 | char   **av;
912          }
913          if (normalize(norm) == 0.)
914                  return(MG_EILL);
915 <                                        /* create moved vertices */
915 >                                                /* create moved vertices */
916          for (i = 1; i < ac-1; i++) {
917                  sprintf(nvn[i-1], "_pv%d", i);
918                  vent[1] = nvn[i-1];
919 <                if ((rv = mg_handle(MG_E_VERTEX, 3, vent)) != MG_OK)
919 >                vent[3] = av[i];
920 >                if ((rv = mg_handle(MG_E_VERTEX, 4, vent)) != MG_OK)
921                          return(rv);
922                  cv = c_getvert(av[i]);          /* checked above */
923                  for (j = 0; j < 3; j++)
924                          sprintf(p[j], FLTFMT, cv->p[j] - length*norm[j]);
925                  if ((rv = mg_handle(MG_E_POINT, 4, pent)) != MG_OK)
926                          return(rv);
923                newav[ac-1-i] = nvn[i-1];       /* reverse */
927          }
928 <                                                /* do top face */
929 <        if ((rv = mg_handle(MG_E_FACE, ac-1, newav)) != MG_OK)
927 <                return(rv);
928 >                                                /* make faces */
929 >        newav[0] = mg_ename[MG_E_FACE];
930                                                  /* do the side faces */
931          newav[5] = NULL;
932          newav[3] = av[ac-2];
# Line 937 | Line 939 | char   **av;
939                  newav[3] = newav[2];
940                  newav[4] = newav[1];
941          }
942 +                                                /* do top face */
943 +        for (i = 1; i < ac-1; i++) {
944 +                if (hasnorm) {                  /* zero normals */
945 +                        vent[1] = nvn[i-1];
946 +                        if ((rv = mg_handle(MG_E_VERTEX, 2, vent)) != MG_OK)
947 +                                return(rv);
948 +                        if ((rv = mg_handle(MG_E_NORMAL, 4, znorm)) != MG_OK)
949 +                                return(rv);
950 +                }
951 +                newav[ac-1-i] = nvn[i-1];       /* reverse */
952 +        }
953 +        if ((rv = mg_handle(MG_E_FACE, ac-1, newav)) != MG_OK)
954 +                return(rv);
955 +                                                /* do bottom face */
956 +        if (hasnorm)
957 +                for (i = 1; i < ac-1; i++) {
958 +                        vent[1] = nvn[i-1];
959 +                        vent[3] = av[i];
960 +                        if ((rv = mg_handle(MG_E_VERTEX, 4, vent)) != MG_OK)
961 +                                return(rv);
962 +                        if ((rv = mg_handle(MG_E_NORMAL, 4, znorm)) != MG_OK)
963 +                                return(rv);
964 +                        newav[i] = nvn[i-1];
965 +                }
966 +        else
967 +                for (i = 1; i < ac-1; i++)
968 +                        newav[i] = av[i];
969 +        newav[i] = NULL;
970 +        if ((rv = mg_handle(MG_E_FACE, i, newav)) != MG_OK)
971 +                return(rv);
972          return(MG_OK);
973   }
974  
975  
976   static int
977 < e_cspec(ac, av)                 /* handle spectral color */
946 < int     ac;
947 < char    **av;
977 > put_cxy()                       /* put out current xy chromaticities */
978   {
979          static char     xbuf[24], ybuf[24];
980          static char     *ccom[4] = {mg_ename[MG_E_CXY], xbuf, ybuf};
981          int     rv;
982  
983 +        sprintf(xbuf, "%.4f", c_ccolor->cx);
984 +        sprintf(ybuf, "%.4f", c_ccolor->cy);
985 +        if ((rv = mg_handle(MG_E_CXY, 3, ccom)) != MG_OK)
986 +                return(rv);
987 +        return(MG_OK);
988 + }
989 +
990 +
991 + static int
992 + put_cspec()                     /* put out current color spectrum */
993 + {
994 +        char    wl[2][6], vbuf[C_CNSS][24];
995 +        char    *newav[C_CNSS+4];
996 +        double  sf;
997 +        register int    i;
998 +
999 +        if (mg_ehand[MG_E_CSPEC] != c_hcolor) {
1000 +                sprintf(wl[0], "%d", C_CMINWL);
1001 +                sprintf(wl[1], "%d", C_CMAXWL);
1002 +                newav[0] = mg_ename[MG_E_CSPEC];
1003 +                newav[1] = wl[0];
1004 +                newav[2] = wl[1];
1005 +                sf = (double)C_CNSS / c_ccolor->ssum;
1006 +                for (i = 0; i < C_CNSS; i++) {
1007 +                        sprintf(vbuf[i], "%.4f", sf*c_ccolor->ssamp[i]);
1008 +                        newav[i+3] = vbuf[i];
1009 +                }
1010 +                newav[C_CNSS+3] = NULL;
1011 +                if ((i = mg_handle(MG_E_CSPEC, C_CNSS+3, newav)) != MG_OK)
1012 +                        return(i);
1013 +        }
1014 +        return(MG_OK);
1015 + }
1016 +
1017 +
1018 + static int
1019 + e_cspec(ac, av)                 /* handle spectral color */
1020 + int     ac;
1021 + char    **av;
1022 + {
1023 +                                /* convert to xy chromaticity */
1024          c_ccvt(c_ccolor, C_CSXY);
1025                                  /* if it's really their handler, use it */
1026 <        if (mg_ehand[MG_E_CXY] != c_hcolor) {
1027 <                sprintf(xbuf, "%.4f", c_ccolor->cx);
957 <                sprintf(ybuf, "%.4f", c_ccolor->cy);
958 <                if ((rv = mg_handle(MG_E_CXY, 3, ccom)) != MG_OK)
959 <                        return(rv);
960 <        }
1026 >        if (mg_ehand[MG_E_CXY] != c_hcolor)
1027 >                return(put_cxy());
1028          return(MG_OK);
1029   }
1030  
# Line 967 | Line 1034 | e_cmix(ac, av)                 /* handle mixing of colors */
1034   int     ac;
1035   char    **av;
1036   {
970        char    wl[2][6], vbuf[C_CNSS][24];
971        char    *newav[C_CNSS+4];
972        int     rv;
973        register int    i;
1037          /*
1038           * Contorted logic works as follows:
1039           *      1. the colors are already mixed in c_hcolor() support function
# Line 981 | Line 1044 | char   **av;
1044           */
1045          if (mg_ehand[MG_E_CSPEC] == e_cspec)
1046                  c_ccvt(c_ccolor, C_CSXY);
1047 <        else if (c_ccolor->flags & C_CDSPEC) {
1048 <                if (mg_ehand[MG_E_CSPEC] != c_hcolor) {
1049 <                        sprintf(wl[0], "%d", C_CMINWL);
1050 <                        sprintf(wl[1], "%d", C_CMAXWL);
1051 <                        newav[0] = mg_ename[MG_E_CSPEC];
1052 <                        newav[1] = wl[0];
1053 <                        newav[2] = wl[1];
1054 <                        for (i = 0; i < C_CNSS; i++) {
1055 <                                sprintf(vbuf[i], "%.6f",
1056 <                                                (double)c_ccolor->ssamp[i] /
1057 <                                                c_ccolor->ssum);
1058 <                                newav[i+3] = vbuf[i];
1059 <                        }
1060 <                        newav[C_CNSS+3] = NULL;
1061 <                        if ((rv = mg_handle(MG_E_CSPEC, C_CNSS+3, newav)) != MG_OK)
1062 <                                return(rv);
1063 <                }
1064 <                return(MG_OK);
1065 <        }
1066 <        if (mg_ehand[MG_E_CXY] != c_hcolor) {
1067 <                sprintf(vbuf[0], "%.4f", c_ccolor->cx);
1068 <                sprintf(vbuf[1], "%.4f", c_ccolor->cy);
1069 <                newav[0] = mg_ename[MG_E_CXY];
1070 <                newav[1] = vbuf[0];
1008 <                newav[2] = vbuf[1];
1009 <                newav[3] = NULL;
1010 <                if ((rv = mg_handle(MG_E_CXY, 3, newav)) != MG_OK)
1011 <                        return(rv);
1012 <        }
1047 >        else if (c_ccolor->flags & C_CDSPEC)
1048 >                return(put_cspec());
1049 >        if (mg_ehand[MG_E_CXY] != c_hcolor)
1050 >                return(put_cxy());
1051 >        return(MG_OK);
1052 > }
1053 >
1054 >
1055 > static int
1056 > e_cct(ac, av)                   /* handle color temperature */
1057 > int     ac;
1058 > char    **av;
1059 > {
1060 >        /*
1061 >         * Logic is similar to e_cmix here.  Support handler has already
1062 >         * converted temperature to spectral color.  Put it out as such
1063 >         * if they support it, otherwise convert to xy chromaticity and
1064 >         * put it out if they handle it.
1065 >         */
1066 >        if (mg_ehand[MG_E_CSPEC] != e_cspec)
1067 >                return(put_cspec());
1068 >        c_ccvt(c_ccolor, C_CSXY);
1069 >        if (mg_ehand[MG_E_CXY] != c_hcolor)
1070 >                return(put_cxy());
1071          return(MG_OK);
1072   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines