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"; |
21 |
|
|
22 |
|
static MAT4 m4tmp; /* for efficiency */ |
23 |
|
|
24 |
< |
int xf_argc; /* total # transform args. */ |
25 |
< |
char **xf_argv; /* transform arguments */ |
26 |
< |
XF_SPEC *xf_context; /* current context */ |
24 |
> |
XF_SPEC *xf_context; /* current context */ |
25 |
> |
char **xf_argend; /* end of transform argument list */ |
26 |
> |
static char **xf_argbeg; /* beginning of transform argument list */ |
27 |
|
|
28 |
– |
static int xf_maxarg; /* # allocated arguments */ |
28 |
|
|
30 |
– |
static XF_SPEC *new_xf(); |
31 |
– |
static long comp_xfid(); |
32 |
– |
static int put_oname(); |
33 |
– |
|
34 |
– |
|
29 |
|
int |
30 |
|
xf_handler(ac, av) /* handle xf entity */ |
31 |
|
int ac; |
34 |
|
register XF_SPEC *spec; |
35 |
|
register int n; |
36 |
|
int rv; |
43 |
– |
XF thisxf; |
37 |
|
|
38 |
|
if (ac == 1) { /* something with existing transform */ |
39 |
|
if ((spec = xf_context) == NULL) |
40 |
< |
return(MG_OK); /* should be error? */ |
40 |
> |
return(MG_ECNTXT); |
41 |
|
n = -1; |
42 |
|
if (spec->xarr != NULL) { /* check for iteration */ |
43 |
|
register struct xf_array *ap = spec->xarr; |
44 |
|
|
45 |
< |
(void)put_oname((struct xf_array *)NULL); |
45 |
> |
(void)xf_aname((struct xf_array *)NULL); |
46 |
|
n = ap->ndim; |
47 |
|
while (n--) { |
48 |
|
if (++ap->aarg[n].i < ap->aarg[n].n) |
54 |
|
if ((rv = mg_fgoto(&ap->spos)) != MG_OK) |
55 |
|
return(rv); |
56 |
|
sprintf(ap->aarg[n].arg, "%d", ap->aarg[n].i); |
57 |
< |
(void)put_oname(ap); |
58 |
< |
} else |
66 |
< |
free((MEM_PTR)ap); |
57 |
> |
(void)xf_aname(ap); |
58 |
> |
} |
59 |
|
} |
60 |
|
if (n < 0) { /* pop transform */ |
69 |
– |
xf_argv[xf_argc=spec->xav0] = NULL; |
61 |
|
xf_context = spec->prev; |
62 |
< |
free((MEM_PTR)spec); |
62 |
> |
free_xf(spec); |
63 |
|
return(MG_OK); |
64 |
|
} |
65 |
|
} else { /* else allocate transform */ |
66 |
|
if ((spec = new_xf(ac-1, av+1)) == NULL) |
67 |
|
return(MG_EMEM); |
68 |
+ |
if (spec->xarr != NULL) |
69 |
+ |
(void)xf_aname(spec->xarr); |
70 |
|
spec->prev = xf_context; /* push onto stack */ |
71 |
|
xf_context = spec; |
72 |
|
} |
73 |
|
/* translate new specification */ |
74 |
< |
if (xf(&thisxf, spec->xac, &xf_argv[spec->xav0]) != spec->xac) |
74 |
> |
n = xf_ac(spec); |
75 |
> |
n -= xf_ac(spec->prev); /* incremental comp. is more eff. */ |
76 |
> |
if (xf(&spec->xf, n, xf_av(spec)) != n) |
77 |
|
return(MG_ETYPE); |
78 |
+ |
/* check for vertex reversal */ |
79 |
+ |
if ((spec->rev = (spec->xf.sca < 0.))) |
80 |
+ |
spec->xf.sca = -spec->xf.sca; |
81 |
|
/* compute total transformation */ |
82 |
|
if (spec->prev != NULL) { |
83 |
< |
multmat4(spec->xf.xfm, spec->prev->xf.xfm, thisxf.xfm); |
84 |
< |
spec->xf.sca = spec->prev->xf.sca * thisxf.sca; |
85 |
< |
} else |
86 |
< |
spec->xf = thisxf; |
83 |
> |
multmat4(spec->xf.xfm, spec->xf.xfm, spec->prev->xf.xfm); |
84 |
> |
spec->xf.sca *= spec->prev->xf.sca; |
85 |
> |
spec->rev ^= spec->prev->rev; |
86 |
> |
} |
87 |
|
spec->xid = comp_xfid(spec->xf.xfm); /* compute unique ID */ |
88 |
|
return(MG_OK); |
89 |
|
} |
90 |
|
|
91 |
|
|
92 |
< |
static XF_SPEC * |
92 |
> |
XF_SPEC * |
93 |
|
new_xf(ac, av) /* allocate new transform structure */ |
94 |
|
int ac; |
95 |
|
char **av; |
120 |
|
spec->xarr->ndim = 0; /* incremented below */ |
121 |
|
} else |
122 |
|
spec->xarr = NULL; |
123 |
< |
spec->xav0 = xf_argc; |
126 |
< |
spec->xac = ac; |
123 |
> |
spec->xac = ac + xf_argc; |
124 |
|
/* and store new xf arguments */ |
125 |
< |
if (xf_argc+ac+1 > xf_maxarg) { |
126 |
< |
if (!xf_maxarg) |
127 |
< |
xf_argv = (char **)malloc( |
128 |
< |
(xf_maxarg=ac+1)*sizeof(char *)); |
132 |
< |
else |
133 |
< |
xf_argv = (char **)realloc((MEM_PTR)xf_argv, |
134 |
< |
(xf_maxarg=xf_argc+ac+1)*sizeof(char *)); |
135 |
< |
if (xf_argv == NULL) |
125 |
> |
if (xf_argbeg == NULL || xf_av(spec) < xf_argbeg) { |
126 |
> |
register char **newav = |
127 |
> |
(char **)malloc((spec->xac+1)*sizeof(char *)); |
128 |
> |
if (newav == NULL) |
129 |
|
return(NULL); |
130 |
+ |
for (i = xf_argc; i-- > 0; ) |
131 |
+ |
newav[ac+i] = xf_argend[i-xf_context->xac]; |
132 |
+ |
*(xf_argend = newav + spec->xac) = NULL; |
133 |
+ |
if (xf_argbeg != NULL) |
134 |
+ |
free((MEM_PTR)xf_argbeg); |
135 |
+ |
xf_argbeg = newav; |
136 |
|
} |
137 |
|
cp = (char *)(spec + 1); /* use memory allocated above */ |
138 |
|
for (i = 0; i < ac; i++) |
139 |
|
if (!strcmp(av[i], "-a")) { |
140 |
< |
xf_argv[xf_argc++] = "-i"; |
141 |
< |
xf_argv[xf_argc++] = strcpy( |
140 |
> |
xf_av(spec)[i++] = "-i"; |
141 |
> |
xf_av(spec)[i] = strcpy( |
142 |
|
spec->xarr->aarg[spec->xarr->ndim].arg, |
143 |
|
"0"); |
144 |
|
spec->xarr->aarg[spec->xarr->ndim].i = 0; |
145 |
< |
spec->xarr->aarg[spec->xarr->ndim++].n = atoi(av[++i]); |
145 |
> |
spec->xarr->aarg[spec->xarr->ndim++].n = atoi(av[i]); |
146 |
|
} else { |
147 |
< |
xf_argv[xf_argc++] = strcpy(cp, av[i]); |
147 |
> |
xf_av(spec)[i] = strcpy(cp, av[i]); |
148 |
|
cp += strlen(av[i]) + 1; |
149 |
|
} |
151 |
– |
xf_argv[xf_argc] = NULL; |
152 |
– |
if (spec->xarr != NULL) |
153 |
– |
(void)put_oname(spec->xarr); |
150 |
|
return(spec); |
151 |
|
} |
152 |
|
|
153 |
|
|
154 |
< |
static int |
155 |
< |
put_oname(ap) /* put out name for this instance */ |
154 |
> |
void |
155 |
> |
free_xf(spec) /* free a transform */ |
156 |
> |
register XF_SPEC *spec; |
157 |
> |
{ |
158 |
> |
if (spec->xarr != NULL) |
159 |
> |
free((MEM_PTR)spec->xarr); |
160 |
> |
free((MEM_PTR)spec); |
161 |
> |
} |
162 |
> |
|
163 |
> |
|
164 |
> |
int |
165 |
> |
xf_aname(ap) /* put out name for this instance */ |
166 |
|
register struct xf_array *ap; |
167 |
|
{ |
168 |
|
static char oname[10*XF_MAXDIM]; |
184 |
|
} |
185 |
|
|
186 |
|
|
187 |
< |
static long |
187 |
> |
long |
188 |
|
comp_xfid(xfm) /* compute unique ID from matrix */ |
189 |
|
register MAT4 xfm; |
190 |
|
{ |
210 |
|
{ |
211 |
|
register XF_SPEC *spec; |
212 |
|
|
213 |
< |
if (xf_maxarg) { |
214 |
< |
free((MEM_PTR)xf_argv); |
215 |
< |
xf_argv = NULL; |
210 |
< |
xf_maxarg = 0; |
213 |
> |
if (xf_argbeg != NULL) { |
214 |
> |
free((MEM_PTR)xf_argbeg); |
215 |
> |
xf_argbeg = xf_argend = NULL; |
216 |
|
} |
212 |
– |
xf_argc = 0; |
217 |
|
while ((spec = xf_context) != NULL) { |
218 |
|
xf_context = spec->prev; |
219 |
< |
if (spec->xarr != NULL) |
216 |
< |
free((MEM_PTR)spec->xarr); |
217 |
< |
free((MEM_PTR)spec); |
219 |
> |
free_xf(spec); |
220 |
|
} |
221 |
|
} |
222 |
|
|
226 |
|
FVECT v1, v2; |
227 |
|
{ |
228 |
|
if (xf_context == NULL) { |
229 |
< |
v1[0] = v2[0]; |
228 |
< |
v1[1] = v2[1]; |
229 |
< |
v1[2] = v2[2]; |
229 |
> |
VCOPY(v1, v2); |
230 |
|
return; |
231 |
|
} |
232 |
|
multp3(v1, v2, xf_context->xf.xfm); |
238 |
|
FVECT v1, v2; |
239 |
|
{ |
240 |
|
if (xf_context == NULL) { |
241 |
< |
v1[0] = v2[0]; |
242 |
< |
v1[1] = v2[1]; |
243 |
< |
v1[2] = v2[2]; |
241 |
> |
VCOPY(v1, v2); |
242 |
|
return; |
243 |
|
} |
244 |
|
multv3(v1, v2, xf_context->xf.xfm); |