--- ray/src/cv/mgflib/xf.c 1995/05/10 22:20:57 1.9 +++ ray/src/cv/mgflib/xf.c 2003/02/28 20:11:30 1.14 @@ -1,15 +1,13 @@ -/* Copyright (c) 1994 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: xf.c,v 1.14 2003/02/28 20:11:30 greg Exp $"; #endif - /* * Routines for 4x4 homogeneous, rigid-body transformations */ #include #include +#include #include #include "parser.h" @@ -21,15 +19,11 @@ MAT4 m4ident = MAT4IDENT; static MAT4 m4tmp; /* for efficiency */ -XF_SPEC *xf_context; /* current context */ +XF_SPEC *xf_context = NULL; /* current context */ char **xf_argend; /* end of transform argument list */ static char **xf_argbeg; /* beginning of transform argument list */ -static XF_SPEC *new_xf(); -static long comp_xfid(); -static int put_oname(); - int xf_handler(ac, av) /* handle xf entity */ int ac; @@ -41,12 +35,12 @@ char **av; if (ac == 1) { /* something with existing transform */ if ((spec = xf_context) == NULL) - return(MG_OK); /* should be error? */ + return(MG_ECNTXT); n = -1; if (spec->xarr != NULL) { /* check for iteration */ register struct xf_array *ap = spec->xarr; - (void)put_oname((struct xf_array *)NULL); + (void)xf_aname((struct xf_array *)NULL); n = ap->ndim; while (n--) { if (++ap->aarg[n].i < ap->aarg[n].n) @@ -58,25 +52,25 @@ char **av; if ((rv = mg_fgoto(&ap->spos)) != MG_OK) return(rv); sprintf(ap->aarg[n].arg, "%d", ap->aarg[n].i); - (void)put_oname(ap); - } else - free((MEM_PTR)ap); + (void)xf_aname(ap); + } } if (n < 0) { /* pop transform */ xf_context = spec->prev; - free((MEM_PTR)spec); + free_xf(spec); return(MG_OK); } } else { /* else allocate transform */ if ((spec = new_xf(ac-1, av+1)) == NULL) return(MG_EMEM); + if (spec->xarr != NULL) + (void)xf_aname(spec->xarr); spec->prev = xf_context; /* push onto stack */ xf_context = spec; } /* translate new specification */ n = xf_ac(spec); - if (spec->prev != NULL) /* incremental comp. is more eff. */ - n -= xf_ac(spec->prev); + n -= xf_ac(spec->prev); /* incremental comp. is more eff. */ if (xf(&spec->xf, n, xf_av(spec)) != n) return(MG_ETYPE); /* check for vertex reversal */ @@ -93,7 +87,7 @@ char **av; } -static XF_SPEC * +XF_SPEC * new_xf(ac, av) /* allocate new transform structure */ int ac; char **av; @@ -151,14 +145,22 @@ char **av; xf_av(spec)[i] = strcpy(cp, av[i]); cp += strlen(av[i]) + 1; } - if (spec->xarr != NULL) - (void)put_oname(spec->xarr); return(spec); } -static int -put_oname(ap) /* put out name for this instance */ +void +free_xf(spec) /* free a transform */ +register XF_SPEC *spec; +{ + if (spec->xarr != NULL) + free((MEM_PTR)spec->xarr); + free((MEM_PTR)spec); +} + + +int +xf_aname(ap) /* put out name for this instance */ register struct xf_array *ap; { static char oname[10*XF_MAXDIM]; @@ -180,7 +182,7 @@ register struct xf_array *ap; } -static long +long comp_xfid(xfm) /* compute unique ID from matrix */ register MAT4 xfm; { @@ -212,9 +214,7 @@ xf_clear() /* clear transform stack */ } while ((spec = xf_context) != NULL) { xf_context = spec->prev; - if (spec->xarr != NULL) - free((MEM_PTR)spec->xarr); - free((MEM_PTR)spec); + free_xf(spec); } } @@ -224,9 +224,7 @@ xf_xfmpoint(v1, v2) /* transform a point by the curre FVECT v1, v2; { if (xf_context == NULL) { - v1[0] = v2[0]; - v1[1] = v2[1]; - v1[2] = v2[2]; + VCOPY(v1, v2); return; } multp3(v1, v2, xf_context->xf.xfm); @@ -238,9 +236,7 @@ xf_xfmvect(v1, v2) /* transform a vector using curren FVECT v1, v2; { if (xf_context == NULL) { - v1[0] = v2[0]; - v1[1] = v2[1]; - v1[2] = v2[2]; + VCOPY(v1, v2); return; } multv3(v1, v2, xf_context->xf.xfm);