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

Comparing ray/src/cv/mgflib/xf.c (file contents):
Revision 1.8 by greg, Tue Apr 18 16:52:28 1995 UTC vs.
Revision 1.13 by gregl, Mon Dec 15 09:41:37 1997 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1994 Regents of the University of California */
1 > /* Copyright (c) 1995 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 10 | Line 10 | static char SCCSid[] = "$SunId$ LBL";
10  
11   #include <stdio.h>
12   #include <math.h>
13 + #include <stdlib.h>
14   #include <string.h>
15   #include "parser.h"
16  
# Line 21 | Line 22 | MAT4  m4ident = MAT4IDENT;
22  
23   static MAT4  m4tmp;             /* for efficiency */
24  
25 < int     xf_argc;                        /* total # transform args. */
26 < char    **xf_argv;                      /* transform arguments */
27 < XF_SPEC *xf_context;                    /* current context */
25 > XF_SPEC *xf_context;            /* current context */
26 > char    **xf_argend;            /* end of transform argument list */
27 > static char     **xf_argbeg;    /* beginning of transform argument list */
28  
28 static int      xf_maxarg;              /* # allocated arguments */
29  
30 static XF_SPEC  *new_xf();
31 static long     comp_xfid();
32 static int      put_oname();
33
34
30   int
31   xf_handler(ac, av)              /* handle xf entity */
32   int     ac;
# Line 43 | Line 38 | char   **av;
38  
39          if (ac == 1) {                  /* something with existing transform */
40                  if ((spec = xf_context) == NULL)
41 <                        return(MG_OK);          /* should be error? */
41 >                        return(MG_ECNTXT);
42                  n = -1;
43                  if (spec->xarr != NULL) {       /* check for iteration */
44                          register struct xf_array        *ap = spec->xarr;
45  
46 <                        (void)put_oname((struct xf_array *)NULL);
46 >                        (void)xf_aname((struct xf_array *)NULL);
47                          n = ap->ndim;
48                          while (n--) {
49                                  if (++ap->aarg[n].i < ap->aarg[n].n)
# Line 60 | Line 55 | char   **av;
55                                  if ((rv = mg_fgoto(&ap->spos)) != MG_OK)
56                                          return(rv);
57                                  sprintf(ap->aarg[n].arg, "%d", ap->aarg[n].i);
58 <                                (void)put_oname(ap);
59 <                        } else
65 <                                free((MEM_PTR)ap);
58 >                                (void)xf_aname(ap);
59 >                        }
60                  }
61                  if (n < 0) {                    /* pop transform */
68                        xf_argv[xf_argc=spec->xav0] = NULL;
62                          xf_context = spec->prev;
63 <                        free((MEM_PTR)spec);
63 >                        free_xf(spec);
64                          return(MG_OK);
65                  }
66          } else {                        /* else allocate transform */
67                  if ((spec = new_xf(ac-1, av+1)) == NULL)
68                          return(MG_EMEM);
69 +                if (spec->xarr != NULL)
70 +                        (void)xf_aname(spec->xarr);
71                  spec->prev = xf_context;        /* push onto stack */
72                  xf_context = spec;
73          }
74                                          /* translate new specification */
75 <        if (xf(&spec->xf, spec->xac, &xf_argv[spec->xav0]) != spec->xac)
75 >        n = xf_ac(spec);
76 >        n -= xf_ac(spec->prev);         /* incremental comp. is more eff. */
77 >        if (xf(&spec->xf, n, xf_av(spec)) != n)
78                  return(MG_ETYPE);
79                                          /* check for vertex reversal */
80          if ((spec->rev = (spec->xf.sca < 0.)))
# Line 93 | Line 90 | char   **av;
90   }
91  
92  
93 < static XF_SPEC *
93 > XF_SPEC *
94   new_xf(ac, av)                  /* allocate new transform structure */
95   int     ac;
96   char    **av;
# Line 124 | Line 121 | char   **av;
121                  spec->xarr->ndim = 0;           /* incremented below */
122          } else
123                  spec->xarr = NULL;
124 <        spec->xav0 = xf_argc;
128 <        spec->xac = ac;
124 >        spec->xac = ac + xf_argc;
125                                          /* and store new xf arguments */
126 <        if (xf_argc+ac+1 > xf_maxarg) {
127 <                if (!xf_maxarg)
128 <                        xf_argv = (char **)malloc(
129 <                                        (xf_maxarg=ac+1)*sizeof(char *));
134 <                else
135 <                        xf_argv = (char **)realloc((MEM_PTR)xf_argv,
136 <                                (xf_maxarg=xf_argc+ac+1)*sizeof(char *));
137 <                if (xf_argv == NULL)
126 >        if (xf_argbeg == NULL || xf_av(spec) < xf_argbeg) {
127 >                register char   **newav =
128 >                                (char **)malloc((spec->xac+1)*sizeof(char *));
129 >                if (newav == NULL)
130                          return(NULL);
131 +                for (i = xf_argc; i-- > 0; )
132 +                        newav[ac+i] = xf_argend[i-xf_context->xac];
133 +                *(xf_argend = newav + spec->xac) = NULL;
134 +                if (xf_argbeg != NULL)
135 +                        free((MEM_PTR)xf_argbeg);
136 +                xf_argbeg = newav;
137          }
138          cp = (char *)(spec + 1);        /* use memory allocated above */
139          for (i = 0; i < ac; i++)
140                  if (!strcmp(av[i], "-a")) {
141 <                        xf_argv[xf_argc++] = "-i";
142 <                        xf_argv[xf_argc++] = strcpy(
141 >                        xf_av(spec)[i++] = "-i";
142 >                        xf_av(spec)[i] = strcpy(
143                                          spec->xarr->aarg[spec->xarr->ndim].arg,
144                                          "0");
145                          spec->xarr->aarg[spec->xarr->ndim].i = 0;
146 <                        spec->xarr->aarg[spec->xarr->ndim++].n = atoi(av[++i]);
146 >                        spec->xarr->aarg[spec->xarr->ndim++].n = atoi(av[i]);
147                  } else {
148 <                        xf_argv[xf_argc++] = strcpy(cp, av[i]);
148 >                        xf_av(spec)[i] = strcpy(cp, av[i]);
149                          cp += strlen(av[i]) + 1;
150                  }
153        xf_argv[xf_argc] = NULL;
154        if (spec->xarr != NULL)
155                (void)put_oname(spec->xarr);
151          return(spec);
152   }
153  
154  
155 < static int
156 < put_oname(ap)                   /* put out name for this instance */
155 > void
156 > free_xf(spec)                   /* free a transform */
157 > register XF_SPEC        *spec;
158 > {
159 >        if (spec->xarr != NULL)
160 >                free((MEM_PTR)spec->xarr);
161 >        free((MEM_PTR)spec);
162 > }
163 >
164 >
165 > int
166 > xf_aname(ap)                    /* put out name for this instance */
167   register struct xf_array        *ap;
168   {
169          static char     oname[10*XF_MAXDIM];
# Line 180 | Line 185 | register struct xf_array       *ap;
185   }
186  
187  
188 < static long
188 > long
189   comp_xfid(xfm)                  /* compute unique ID from matrix */
190   register MAT4   xfm;
191   {
# Line 206 | Line 211 | xf_clear()                     /* clear transform stack */
211   {
212          register XF_SPEC        *spec;
213  
214 <        if (xf_maxarg) {
215 <                free((MEM_PTR)xf_argv);
216 <                xf_argv = NULL;
212 <                xf_maxarg = 0;
214 >        if (xf_argbeg != NULL) {
215 >                free((MEM_PTR)xf_argbeg);
216 >                xf_argbeg = xf_argend = NULL;
217          }
214        xf_argc = 0;
218          while ((spec = xf_context) != NULL) {
219                  xf_context = spec->prev;
220 <                if (spec->xarr != NULL)
218 <                        free((MEM_PTR)spec->xarr);
219 <                free((MEM_PTR)spec);
220 >                free_xf(spec);
221          }
222   }
223  
# Line 226 | Line 227 | xf_xfmpoint(v1, v2)            /* transform a point by the curre
227   FVECT   v1, v2;
228   {
229          if (xf_context == NULL) {
230 <                v1[0] = v2[0];
230 <                v1[1] = v2[1];
231 <                v1[2] = v2[2];
230 >                VCOPY(v1, v2);
231                  return;
232          }
233          multp3(v1, v2, xf_context->xf.xfm);
# Line 240 | Line 239 | xf_xfmvect(v1, v2)             /* transform a vector using curren
239   FVECT   v1, v2;
240   {
241          if (xf_context == NULL) {
242 <                v1[0] = v2[0];
244 <                v1[1] = v2[1];
245 <                v1[2] = v2[2];
242 >                VCOPY(v1, v2);
243                  return;
244          }
245          multv3(v1, v2, xf_context->xf.xfm);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines