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.9 by greg, Wed May 10 22:20:57 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 25 | Line 26 | 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 XF_SPEC  *new_xf();
29 static long     comp_xfid();
30 static int      put_oname();
29  
32
30   int
31   xf_handler(ac, av)              /* handle xf entity */
32   int     ac;
# Line 41 | 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 58 | 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
63 <                                free((MEM_PTR)ap);
58 >                                (void)xf_aname(ap);
59 >                        }
60                  }
61                  if (n < 0) {                    /* pop transform */
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          n = xf_ac(spec);
76 <        if (spec->prev != NULL)         /* incremental comp. is more eff. */
79 <                n -= xf_ac(spec->prev);
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 */
# 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 151 | Line 148 | char   **av;
148                          xf_av(spec)[i] = strcpy(cp, av[i]);
149                          cp += strlen(av[i]) + 1;
150                  }
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 212 | Line 217 | xf_clear()                     /* clear transform stack */
217          }
218          while ((spec = xf_context) != NULL) {
219                  xf_context = spec->prev;
220 <                if (spec->xarr != NULL)
216 <                        free((MEM_PTR)spec->xarr);
217 <                free((MEM_PTR)spec);
220 >                free_xf(spec);
221          }
222   }
223  
# Line 224 | 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];
228 <                v1[1] = v2[1];
229 <                v1[2] = v2[2];
230 >                VCOPY(v1, v2);
231                  return;
232          }
233          multp3(v1, v2, xf_context->xf.xfm);
# Line 238 | 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];
242 <                v1[1] = v2[1];
243 <                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