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.4 by greg, Fri Jun 24 09:32:51 1994 UTC vs.
Revision 1.7 by greg, Fri Jun 24 17:15:49 1994 UTC

# Line 53 | Line 53 | int    mg_nqcdivs = MG_NQCD;   /* number of divisions per q
53  
54   /* temporary settings for testing */
55   #define e_ies e_any_toss
56 #define e_cmix e_any_toss
57 #define e_cspec e_any_toss
56                                  /* alternate handler routines */
57  
58   static int      e_any_toss(),           /* discard unneeded entity */
# Line 62 | Line 60 | static int     e_any_toss(),           /* discard unneeded entity *
60                  e_include(),            /* include file */
61                  e_sph(),                /* sphere */
62                  e_cmix(),               /* color mixtures */
63 <                e_cspec();              /* color spectra */
63 >                e_cspec(),              /* color spectra */
64                  e_cyl(),                /* cylinder */
65                  e_cone(),               /* cone */
66                  e_prism(),              /* prism */
# Line 119 | Line 117 | mg_init()                      /* initialize alternate entity handlers */
117          } else
118                  uneed |= 1<<MG_E_POINT|1<<MG_E_NORMAL|1<<MG_E_VERTEX|1<<MG_E_XF;
119          if (mg_ehand[MG_E_COLOR] != NULL) {
120 <                if (mg_ehand[MG_E_CMIX] == NULL)
120 >                if (mg_ehand[MG_E_CMIX] == NULL) {
121                          mg_ehand[MG_E_CMIX] = e_cmix;
122 <                if (mg_ehand[MG_E_CSPEC] == NULL)
122 >                        ineed |= 1<<MG_E_COLOR|1<<MG_E_CXY|1<<MG_E_CSPEC|1<<MG_E_CMIX;
123 >                }
124 >                if (mg_ehand[MG_E_CSPEC] == NULL) {
125                          mg_ehand[MG_E_CSPEC] = e_cspec;
126 +                        ineed |= 1<<MG_E_COLOR|1<<MG_E_CXY|1<<MG_E_CSPEC|1<<MG_E_CMIX;
127 +                }
128          }
129                                          /* check for consistency */
130          if (mg_ehand[MG_E_FACE] != NULL)
131                  uneed |= 1<<MG_E_POINT|1<<MG_E_VERTEX|1<<MG_E_XF;
132 <        if (mg_ehand[MG_E_CXY] != NULL)
132 >        if (mg_ehand[MG_E_CXY] != NULL || mg_ehand[MG_E_CSPEC] != NULL ||
133 >                        mg_ehand[MG_E_CMIX] != NULL)
134                  uneed |= 1<<MG_E_COLOR;
135          if (mg_ehand[MG_E_RD] != NULL || mg_ehand[MG_E_TD] != NULL ||
136                          mg_ehand[MG_E_ED] != NULL ||
# Line 147 | Line 150 | mg_init()                      /* initialize alternate entity handlers */
150                  e_supp[MG_E_POINT] = c_hvertex;
151          if (ineed & 1<<MG_E_NORMAL && mg_ehand[MG_E_NORMAL] != c_hvertex)
152                  e_supp[MG_E_NORMAL] = c_hvertex;
153 +        if (ineed & 1<<MG_E_COLOR && mg_ehand[MG_E_COLOR] != c_hcolor)
154 +                e_supp[MG_E_COLOR] = c_hcolor;
155 +        if (ineed & 1<<MG_E_CXY && mg_ehand[MG_E_CXY] != c_hcolor)
156 +                e_supp[MG_E_CXY] = c_hcolor;
157 +        if (ineed & 1<<MG_E_CSPEC && mg_ehand[MG_E_CSPEC] != c_hcolor)
158 +                e_supp[MG_E_CSPEC] = c_hcolor;
159 +        if (ineed & 1<<MG_E_CMIX && mg_ehand[MG_E_CMIX] != c_hcolor)
160 +                e_supp[MG_E_CMIX] = c_hcolor;
161                                          /* discard remaining entities */
162          for (i = 0; i < MG_NENTITIES; i++)
163                  if (mg_ehand[i] == NULL)
# Line 904 | Line 915 | char   **av;
915  
916          if (ac < 5)
917                  return(MG_EARGC);
918 <        if (!isflt(av[1]))
918 >        if (!isflt(av[ac-1]))
919                  return(MG_ETYPE);
920 <        length = atof(av[1]);
920 >        length = atof(av[ac-1]);
921          if (length <= FTINY && length >= -FTINY)
922                  return(MG_EILL);
923                                          /* do bottom face */
924          newav[0] = mg_ename[MG_E_FACE];
925          for (i = 1; i < ac-1; i++)
926 <                newav[i] = av[i+1];
926 >                newav[i] = av[i];
927          newav[i] = NULL;
928          if ((rv = handle_it(MG_E_FACE, i, newav)) != MG_OK)
929                  return(rv);
930                                          /* compute face normal */
931 <        if ((cv0 = c_getvert(av[2])) == NULL)
931 >        if ((cv0 = c_getvert(av[1])) == NULL)
932                  return(MG_EUNDEF);
933          norm[0] = norm[1] = norm[2] = 0.;
934          v1[0] = v1[1] = v1[2] = 0.;
935          for (i = 2; i < ac-1; i++) {
936 <                if ((cv = c_getvert(av[i+1])) == NULL)
936 >                if ((cv = c_getvert(av[i])) == NULL)
937                          return(MG_EUNDEF);
938                  v2[0] = cv->p[0] - cv0->p[0];
939                  v2[1] = cv->p[1] - cv0->p[1];
# Line 941 | Line 952 | char   **av;
952                  vent[1] = nvn[i-1];
953                  if ((rv = handle_it(MG_E_VERTEX, 3, vent)) != MG_OK)
954                          return(rv);
955 <                cv = c_getvert(av[i+1]);        /* checked above */
955 >                cv = c_getvert(av[i]);          /* checked above */
956                  for (j = 0; j < 3; j++)
957                          sprintf(p[j], FLTFMT, cv->p[j] - length*norm[j]);
958                  if ((rv = handle_it(MG_E_POINT, 4, pent)) != MG_OK)
# Line 953 | Line 964 | char   **av;
964                  return(rv);
965                                                  /* do the side faces */
966          newav[5] = NULL;
967 <        newav[3] = av[ac-1];
967 >        newav[3] = av[ac-2];
968          newav[4] = nvn[ac-3];
969          for (i = 1; i < ac-1; i++) {
970                  newav[1] = nvn[i-1];
971 <                newav[2] = av[i+1];
971 >                newav[2] = av[i];
972                  if ((rv = handle_it(MG_E_FACE, 5, newav)) != MG_OK)
973                          return(rv);
974                  newav[3] = newav[2];
975                  newav[4] = newav[1];
976 +        }
977 +        return(MG_OK);
978 + }
979 +
980 +
981 + static int
982 + e_cspec(ac, av)                 /* handle spectral color */
983 + int     ac;
984 + char    **av;
985 + {
986 +        static char     xbuf[24], ybuf[24];
987 +        static char     *ccom[4] = {mg_ename[MG_E_CXY], xbuf, ybuf};
988 +        int     rv;
989 +
990 +        c_ccvt(c_ccolor, C_CSXY);
991 +                                /* if it's really their handler, use it */
992 +        if (mg_ehand[MG_E_CXY] != c_hcolor) {
993 +                sprintf(xbuf, "%.4f", c_ccolor->cx);
994 +                sprintf(ybuf, "%.4f", c_ccolor->cy);
995 +                if ((rv = handle_it(MG_E_CXY, 3, ccom)) != MG_OK)
996 +                        return(rv);
997 +        }
998 +        return(MG_OK);
999 + }
1000 +
1001 +
1002 + static int
1003 + e_cmix(ac, av)                  /* handle mixing of colors */
1004 + int     ac;
1005 + char    **av;
1006 + {
1007 +        char    wl[2][6], vbuf[C_CNSS][24];
1008 +        char    *newav[C_CNSS+4];
1009 +        int     rv;
1010 +        register int    i;
1011 +        /*
1012 +         * Contorted logic works as follows:
1013 +         *      1. the colors are already mixed in c_hcolor() support function
1014 +         *      2. if we would handle a spectral result, make sure it's not
1015 +         *      3. if c_hcolor() would handle a spectral result, don't bother
1016 +         *      4. otherwise, make cspec entity and pass it to their handler
1017 +         *      5. if we have only xy results, handle it as c_spec() would
1018 +         */
1019 +        if (mg_ehand[MG_E_CSPEC] == e_cspec)
1020 +                c_ccvt(c_ccolor, C_CSXY);
1021 +        else if (c_ccolor->flags & C_CDSPEC) {
1022 +                if (mg_ehand[MG_E_CSPEC] != c_hcolor) {
1023 +                        sprintf(wl[0], "%d", C_CMINWL);
1024 +                        sprintf(wl[1], "%d", C_CMAXWL);
1025 +                        newav[0] = mg_ename[MG_E_CSPEC];
1026 +                        newav[1] = wl[0];
1027 +                        newav[2] = wl[1];
1028 +                        for (i = 0; i < C_CNSS; i++) {
1029 +                                sprintf(vbuf[i], "%.6f",
1030 +                                                (double)c_ccolor->ssamp[i] /
1031 +                                                c_ccolor->ssum);
1032 +                                newav[i+3] = vbuf[i];
1033 +                        }
1034 +                        newav[C_CNSS+3] = NULL;
1035 +                        if ((rv = handle_it(MG_E_CSPEC, C_CNSS+3, newav)) != MG_OK)
1036 +                                return(rv);
1037 +                }
1038 +                return(MG_OK);
1039 +        }
1040 +        if (mg_ehand[MG_E_CXY] != c_hcolor) {
1041 +                sprintf(vbuf[0], "%.4f", c_ccolor->cx);
1042 +                sprintf(vbuf[1], "%.4f", c_ccolor->cy);
1043 +                newav[0] = mg_ename[MG_E_CXY];
1044 +                newav[1] = vbuf[0];
1045 +                newav[2] = vbuf[1];
1046 +                newav[3] = NULL;
1047 +                if ((rv = handle_it(MG_E_CXY, 3, newav)) != MG_OK)
1048 +                        return(rv);
1049          }
1050          return(MG_OK);
1051   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines