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.14 by greg, Fri Feb 28 20:11:30 2003 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines