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 |
|
|
19 |
|
|
20 |
|
static MAT4 m4tmp; /* for efficiency */ |
21 |
|
|
22 |
< |
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 XF_SPEC *new_xf(); |
29 |
– |
static long comp_xfid(); |
30 |
– |
static int put_oname(); |
26 |
|
|
32 |
– |
|
27 |
|
int |
28 |
|
xf_handler(ac, av) /* handle xf entity */ |
29 |
|
int ac; |
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) |
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 |
63 |
< |
free((MEM_PTR)ap); |
55 |
> |
(void)xf_aname(ap); |
56 |
> |
} |
57 |
|
} |
58 |
|
if (n < 0) { /* pop transform */ |
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 |
|
n = xf_ac(spec); |
73 |
< |
if (spec->prev != NULL) /* incremental comp. is more eff. */ |
79 |
< |
n -= xf_ac(spec->prev); |
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 */ |
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; |
145 |
|
xf_av(spec)[i] = strcpy(cp, av[i]); |
146 |
|
cp += strlen(av[i]) + 1; |
147 |
|
} |
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]; |
182 |
|
} |
183 |
|
|
184 |
|
|
185 |
< |
static long |
185 |
> |
long |
186 |
|
comp_xfid(xfm) /* compute unique ID from matrix */ |
187 |
|
register MAT4 xfm; |
188 |
|
{ |
214 |
|
} |
215 |
|
while ((spec = xf_context) != NULL) { |
216 |
|
xf_context = spec->prev; |
217 |
< |
if (spec->xarr != NULL) |
216 |
< |
free((MEM_PTR)spec->xarr); |
217 |
< |
free((MEM_PTR)spec); |
217 |
> |
free_xf(spec); |
218 |
|
} |
219 |
|
} |
220 |
|
|
224 |
|
FVECT v1, v2; |
225 |
|
{ |
226 |
|
if (xf_context == NULL) { |
227 |
< |
v1[0] = v2[0]; |
228 |
< |
v1[1] = v2[1]; |
229 |
< |
v1[2] = v2[2]; |
227 |
> |
VCOPY(v1, v2); |
228 |
|
return; |
229 |
|
} |
230 |
|
multp3(v1, v2, xf_context->xf.xfm); |
236 |
|
FVECT v1, v2; |
237 |
|
{ |
238 |
|
if (xf_context == NULL) { |
239 |
< |
v1[0] = v2[0]; |
242 |
< |
v1[1] = v2[1]; |
243 |
< |
v1[2] = v2[2]; |
239 |
> |
VCOPY(v1, v2); |
240 |
|
return; |
241 |
|
} |
242 |
|
multv3(v1, v2, xf_context->xf.xfm); |