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.9 by greg, Sat Jun 25 16:33:09 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 159 | Line 170 | int
170   mg_entity(name)                 /* get entity number from its name */
171   char    *name;
172   {
173 <        static LUTAB    ent_tab;        /* entity lookup table */
173 >        static LUTAB    ent_tab = LU_SINIT(NULL,NULL);  /* lookup table */
174          register char   *cp;
175  
176          if (!ent_tab.tsiz) {            /* initialize hash table */
# Line 204 | Line 215 | char   *fn;
215  
216          ctx->lineno = 0;
217          if (fn == NULL) {
218 <                ctx->fname = "<stdin>";
218 >                strcpy(ctx->fname, "<stdin>");
219                  ctx->fp = stdin;
220                  ctx->prev = mg_file;
221                  mg_file = ctx;
# Line 216 | Line 227 | char   *fn;
227                  olen = cp - mg_file->fname + 1;
228          else
229                  olen = 0;
219        ctx->fname = (char *)malloc(olen+strlen(fn)+1);
220        if (ctx->fname == NULL)
221                return(MG_EMEM);
230          if (olen)
231                  strcpy(ctx->fname, mg_file->fname);
232          strcpy(ctx->fname+olen, fn);
233          ctx->fp = fopen(ctx->fname, "r");
234 <        if (ctx->fp == NULL) {
227 <                free((MEM_PTR)ctx->fname);
234 >        if (ctx->fp == NULL)
235                  return(MG_ENOFILE);
229        }
236          ctx->prev = mg_file;            /* establish new context */
237          mg_file = ctx;
238          return(MG_OK);
# Line 242 | Line 248 | mg_close()                     /* close input file */
248          if (ctx->fp == stdin)
249                  return;                 /* don't close standard input */
250          fclose(ctx->fp);
245        free((MEM_PTR)ctx->fname);
251   }
252  
253  
# Line 904 | Line 909 | char   **av;
909  
910          if (ac < 5)
911                  return(MG_EARGC);
912 <        if (!isflt(av[1]))
912 >        if (!isflt(av[ac-1]))
913                  return(MG_ETYPE);
914 <        length = atof(av[1]);
914 >        length = atof(av[ac-1]);
915          if (length <= FTINY && length >= -FTINY)
916                  return(MG_EILL);
917                                          /* do bottom face */
918          newav[0] = mg_ename[MG_E_FACE];
919          for (i = 1; i < ac-1; i++)
920 <                newav[i] = av[i+1];
920 >                newav[i] = av[i];
921          newav[i] = NULL;
922          if ((rv = handle_it(MG_E_FACE, i, newav)) != MG_OK)
923                  return(rv);
924                                          /* compute face normal */
925 <        if ((cv0 = c_getvert(av[2])) == NULL)
925 >        if ((cv0 = c_getvert(av[1])) == NULL)
926                  return(MG_EUNDEF);
927          norm[0] = norm[1] = norm[2] = 0.;
928          v1[0] = v1[1] = v1[2] = 0.;
929          for (i = 2; i < ac-1; i++) {
930 <                if ((cv = c_getvert(av[i+1])) == NULL)
930 >                if ((cv = c_getvert(av[i])) == NULL)
931                          return(MG_EUNDEF);
932                  v2[0] = cv->p[0] - cv0->p[0];
933                  v2[1] = cv->p[1] - cv0->p[1];
# Line 941 | Line 946 | char   **av;
946                  vent[1] = nvn[i-1];
947                  if ((rv = handle_it(MG_E_VERTEX, 3, vent)) != MG_OK)
948                          return(rv);
949 <                cv = c_getvert(av[i+1]);        /* checked above */
949 >                cv = c_getvert(av[i]);          /* checked above */
950                  for (j = 0; j < 3; j++)
951                          sprintf(p[j], FLTFMT, cv->p[j] - length*norm[j]);
952                  if ((rv = handle_it(MG_E_POINT, 4, pent)) != MG_OK)
# Line 953 | Line 958 | char   **av;
958                  return(rv);
959                                                  /* do the side faces */
960          newav[5] = NULL;
961 <        newav[3] = av[ac-1];
961 >        newav[3] = av[ac-2];
962          newav[4] = nvn[ac-3];
963          for (i = 1; i < ac-1; i++) {
964                  newav[1] = nvn[i-1];
965 <                newav[2] = av[i+1];
965 >                newav[2] = av[i];
966                  if ((rv = handle_it(MG_E_FACE, 5, newav)) != MG_OK)
967                          return(rv);
968                  newav[3] = newav[2];
969                  newav[4] = newav[1];
970 +        }
971 +        return(MG_OK);
972 + }
973 +
974 +
975 + static int
976 + e_cspec(ac, av)                 /* handle spectral color */
977 + int     ac;
978 + char    **av;
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 +        c_ccvt(c_ccolor, C_CSXY);
985 +                                /* if it's really their handler, use it */
986 +        if (mg_ehand[MG_E_CXY] != c_hcolor) {
987 +                sprintf(xbuf, "%.4f", c_ccolor->cx);
988 +                sprintf(ybuf, "%.4f", c_ccolor->cy);
989 +                if ((rv = handle_it(MG_E_CXY, 3, ccom)) != MG_OK)
990 +                        return(rv);
991 +        }
992 +        return(MG_OK);
993 + }
994 +
995 +
996 + static int
997 + e_cmix(ac, av)                  /* handle mixing of colors */
998 + int     ac;
999 + char    **av;
1000 + {
1001 +        char    wl[2][6], vbuf[C_CNSS][24];
1002 +        char    *newav[C_CNSS+4];
1003 +        int     rv;
1004 +        register int    i;
1005 +        /*
1006 +         * Contorted logic works as follows:
1007 +         *      1. the colors are already mixed in c_hcolor() support function
1008 +         *      2. if we would handle a spectral result, make sure it's not
1009 +         *      3. if c_hcolor() would handle a spectral result, don't bother
1010 +         *      4. otherwise, make cspec entity and pass it to their handler
1011 +         *      5. if we have only xy results, handle it as c_spec() would
1012 +         */
1013 +        if (mg_ehand[MG_E_CSPEC] == e_cspec)
1014 +                c_ccvt(c_ccolor, C_CSXY);
1015 +        else if (c_ccolor->flags & C_CDSPEC) {
1016 +                if (mg_ehand[MG_E_CSPEC] != c_hcolor) {
1017 +                        sprintf(wl[0], "%d", C_CMINWL);
1018 +                        sprintf(wl[1], "%d", C_CMAXWL);
1019 +                        newav[0] = mg_ename[MG_E_CSPEC];
1020 +                        newav[1] = wl[0];
1021 +                        newav[2] = wl[1];
1022 +                        for (i = 0; i < C_CNSS; i++) {
1023 +                                sprintf(vbuf[i], "%.6f",
1024 +                                                (double)c_ccolor->ssamp[i] /
1025 +                                                c_ccolor->ssum);
1026 +                                newav[i+3] = vbuf[i];
1027 +                        }
1028 +                        newav[C_CNSS+3] = NULL;
1029 +                        if ((rv = handle_it(MG_E_CSPEC, C_CNSS+3, newav)) != MG_OK)
1030 +                                return(rv);
1031 +                }
1032 +                return(MG_OK);
1033 +        }
1034 +        if (mg_ehand[MG_E_CXY] != c_hcolor) {
1035 +                sprintf(vbuf[0], "%.4f", c_ccolor->cx);
1036 +                sprintf(vbuf[1], "%.4f", c_ccolor->cy);
1037 +                newav[0] = mg_ename[MG_E_CXY];
1038 +                newav[1] = vbuf[0];
1039 +                newav[2] = vbuf[1];
1040 +                newav[3] = NULL;
1041 +                if ((rv = handle_it(MG_E_CXY, 3, newav)) != MG_OK)
1042 +                        return(rv);
1043          }
1044          return(MG_OK);
1045   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines