Back to index

radiance  4R0+20100331
Classes | Defines | Typedefs | Functions | Variables
parser.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  mg_fctxt
struct  MG_FPOS
struct  C_COLOR
struct  C_MATERIAL
struct  C_VERTEX
struct  XF
struct  xf_array
struct  xf_spec
struct  xf_array.aarg

Defines

#define MG_VMAJOR   2 /* major version number */
#define MG_VMINOR   0 /* minor version number */
#define MG_E_COMMENT   0 /* # */
#define MG_E_COLOR   1 /* c */
#define MG_E_CCT   2 /* cct */
#define MG_E_CONE   3 /* cone */
#define MG_E_CMIX   4 /* cmix */
#define MG_E_CSPEC   5 /* cspec */
#define MG_E_CXY   6 /* cxy */
#define MG_E_CYL   7 /* cyl */
#define MG_E_ED   8 /* ed */
#define MG_E_FACE   9 /* f */
#define MG_E_INCLUDE   10 /* i */
#define MG_E_IES   11 /* ies */
#define MG_E_IR   12 /* ir */
#define MG_E_MATERIAL   13 /* m */
#define MG_E_NORMAL   14 /* n */
#define MG_E_OBJECT   15 /* o */
#define MG_E_POINT   16 /* p */
#define MG_E_PRISM   17 /* prism */
#define MG_E_RD   18 /* rd */
#define MG_E_RING   19 /* ring */
#define MG_E_RS   20 /* rs */
#define MG_E_SIDES   21 /* sides */
#define MG_E_SPH   22 /* sph */
#define MG_E_TD   23 /* td */
#define MG_E_TORUS   24 /* torus */
#define MG_E_TS   25 /* ts */
#define MG_E_VERTEX   26 /* v */
#define MG_E_XF   27 /* xf */
#define MG_E_FACEH   28 /* fh */
#define MG_NENTITIES   29 /* total # entities */
#define MG_NELIST   {28,29} /* entity count for version 1 and up */
#define MG_NAMELIST
#define MG_MAXELEN   6
#define MG_OK   0 /* normal return value */
#define MG_EUNK   1 /* unknown entity */
#define MG_EARGC   2 /* wrong number of arguments */
#define MG_ETYPE   3 /* argument type error */
#define MG_EILL   4 /* illegal argument value */
#define MG_EUNDEF   5 /* undefined reference */
#define MG_ENOFILE   6 /* cannot open input file */
#define MG_EINCL   7 /* error in included file */
#define MG_EMEM   8 /* out of memory */
#define MG_ESEEK   9 /* file seek error */
#define MG_EBADMAT   10 /* bad material specification */
#define MG_ELINE   11 /* input line too long */
#define MG_ECNTXT   12 /* unmatched context close */
#define MG_NERRS   13
#define MG_MAXLINE   4096 /* maximum input line length */
#define MG_MAXARGC   (MG_MAXLINE/4) /* maximum argument count */
#define MG_NQCD   5 /* default number of divisions */
#define RREAL   double
#define FTINY   (1e-6)
#define FHUGE   (1e10)
#define VCOPY(v1, v2)   ((v1)[0]=(v2)[0],(v1)[1]=(v2)[1],(v1)[2]=(v2)[2])
#define DOT(v1, v2)   ((v1)[0]*(v2)[0]+(v1)[1]*(v2)[1]+(v1)[2]*(v2)[2])
#define VSUM(vr, v1, v2, f)
#define is0vect(v)   (DOT(v,v) <= FTINY*FTINY)
#define round0(x)   if (x <= FTINY && x >= -FTINY) x = 0
#define C_CMINWL   380 /* minimum wavelength */
#define C_CMAXWL   780 /* maximum wavelength */
#define C_CNSS   41 /* number of spectral samples */
#define C_CWLI   ((C_CMAXWL-C_CMINWL)/(C_CNSS-1))
#define C_CMAXV   10000 /* nominal maximum sample value */
#define C_CLPWM   (683./C_CMAXV) /* peak lumens/watt multiplier */
#define C_CSSPEC   01 /* flag if spectrum is set */
#define C_CDSPEC   02 /* flag if defined w/ spectrum */
#define C_CSXY   04 /* flag if xy is set */
#define C_CDXY   010 /* flag if defined w/ xy */
#define C_CSEFF   020 /* flag if efficacy set */
#define C_DEFCOLOR
#define c_cval(c, l)   ((double)(c)->ssamp[((l)-C_MINWL)/C_CWLI] / (c)->ssum)
#define C_1SIDEDTHICK   0.005 /* assumed thickness of 1-sided mat. */
#define C_DEFMATERIAL
#define C_DEFVERTEX   {1,NULL,{0.,0.,0.},{0.,0.,0.}}
#define copymat4(m4a, m4b)   (void)memcpy((char *)m4a,(char *)m4b,sizeof(MAT4))
#define MAT4IDENT
#define setident4(m4)   copymat4(m4, m4ident)
#define identxf(xp)   (void)(setident4((xp)->xfm),(xp)->sca=1.0)
#define XF_MAXDIM   8 /* maximum array dimensions */
#define xf_ac(xf)   ((xf)==NULL ? 0 : (xf)->xac)
#define xf_av(xf)   (xf_argend - (xf)->xac)
#define xf_argc   xf_ac(xf_context)
#define xf_argv   xf_av(xf_context)
#define PI   3.14159265358979323846
#define MEM_PTR   void *

Typedefs

typedef struct mg_fctxt MG_FCTXT
typedef RREAL FVECT [3]
typedef RREAL MAT4 [4][4]
typedef struct xf_spec XF_SPEC

Functions

int mg_defuhand (int, char **)
void mg_init (void)
int mg_load (char *)
int mg_open (MG_FCTXT *, char *)
int mg_read (void)
int mg_parse (void)
void mg_fgetpos (MG_FPOS *)
int mg_fgoto (MG_FPOS *)
void mg_close (void)
void mg_clear (void)
int mg_handle (int, int, char **)
int mg_entity (char *)
int isint (char *)
int isintd (char *, char *)
int isflt (char *)
int isfltd (char *, char *)
int isname (char *)
int badarg (int, char **, char *)
int e_include (int, char **)
int e_pipe (int, char **)
int e_sph (int, char **)
int e_torus (int, char **)
int e_cyl (int, char **)
int e_ring (int, char **)
int e_cone (int, char **)
int e_prism (int, char **)
int e_faceh (int, char **)
double normalize (FVECT)
void fcross (FVECT, FVECT, FVECT)
int c_hcolor (int, char **)
int c_hmaterial (int, char **)
int c_hvertex (int, char **)
void c_clearall (void)
C_MATERIALc_getmaterial (char *)
C_VERTEXc_getvert (char *)
C_COLORc_getcolor (char *)
void c_ccvt (C_COLOR *, int)
int c_isgrey (C_COLOR *)
int obj_handler (int, char **)
void obj_clear (void)
int xf_handler (int, char **)
void xf_xfmpoint (FVECT, FVECT)
void xf_xfmvect (FVECT, FVECT)
void xf_rotvect (FVECT, FVECT)
double xf_scale (double)
void xf_clear (void)
XF_SPECnew_xf (int, char **)
void free_xf (XF_SPEC *)
int xf_aname (struct xf_array *)
long comp_xfid (MAT4)
void multmat4 (MAT4, MAT4, MAT4)
void multv3 (FVECT, FVECT, MAT4)
void multp3 (FVECT, FVECT, MAT4)
int xf (XF *, int, char **)
void mgf2rgb (C_COLOR *cin, double intensity, float cout[3])

Variables

char mg_ename [MG_NENTITIES][MG_MAXELEN]
int(* mg_ehand [MG_NENTITIES])(int argc, char **argv)
int(* mg_uhand )(int argc, char **argv)
unsigned mg_nunknown
char * mg_err [MG_NERRS]
MG_FCTXTmg_file
int mg_nqcdivs
C_COLORc_ccolor
char * c_ccname
C_MATERIALc_cmaterial
char * c_cmname
C_VERTEXc_cvertex
char * c_cvname
int obj_nnames
char ** obj_name
MAT4 m4ident
XF_SPECxf_context
char ** xf_argend

Class Documentation

struct mg_fctxt

Definition at line 113 of file parser.h.

Collaboration diagram for mg_fctxt:
Class Members
int fid
char fname
FILE * fp
char inpline
int lineno
struct mg_fctxt * prev
struct MG_FPOS

Definition at line 122 of file parser.h.

Class Members
int fid
int lineno
long offset
struct C_COLOR

Definition at line 214 of file parser.h.

Class Members
char * client_data
int clock
float cx
float cy
float eff
short flags
short ssamp
long ssum
struct C_MATERIAL

Definition at line 238 of file parser.h.

Collaboration diagram for C_MATERIAL:
Class Members
char * client_data
int clock
float ed
C_COLOR ed_c
float ni
float nr
float rd
C_COLOR rd_c
float rs
float rs_a
C_COLOR rs_c
int sided
float td
C_COLOR td_c
float ts
float ts_a
C_COLOR ts_c
struct C_VERTEX

Definition at line 257 of file parser.h.

Class Members
char * client_data
int clock
FVECT n
FVECT p
struct XF

Definition at line 19 of file rtmath.h.

Class Members
RREAL sca
MAT4 xfm
struct xf_array

Definition at line 319 of file parser.h.

Collaboration diagram for xf_array:
Class Members
struct xf_array aarg
int ndim
MG_FPOS spos
struct xf_spec

Definition at line 328 of file parser.h.

Collaboration diagram for xf_spec:
Class Members
struct xf_spec * prev
short rev
short xac
struct xf_array * xarr
XF xf
long xid
struct xf_array.aarg

Definition at line 322 of file parser.h.

Class Members
char arg
short i
short n

Define Documentation

#define C_1SIDEDTHICK   0.005 /* assumed thickness of 1-sided mat. */

Definition at line 236 of file parser.h.

#define C_CDSPEC   02 /* flag if defined w/ spectrum */

Definition at line 209 of file parser.h.

#define C_CDXY   010 /* flag if defined w/ xy */

Definition at line 211 of file parser.h.

#define C_CLPWM   (683./C_CMAXV) /* peak lumens/watt multiplier */

Definition at line 206 of file parser.h.

#define C_CMAXV   10000 /* nominal maximum sample value */

Definition at line 205 of file parser.h.

#define C_CMAXWL   780 /* maximum wavelength */

Definition at line 202 of file parser.h.

#define C_CMINWL   380 /* minimum wavelength */

Definition at line 201 of file parser.h.

#define C_CNSS   41 /* number of spectral samples */

Definition at line 203 of file parser.h.

#define C_CSEFF   020 /* flag if efficacy set */

Definition at line 212 of file parser.h.

#define C_CSSPEC   01 /* flag if spectrum is set */

Definition at line 208 of file parser.h.

#define C_CSXY   04 /* flag if xy is set */

Definition at line 210 of file parser.h.

#define c_cval (   c,
 
)    ((double)(c)->ssamp[((l)-C_MINWL)/C_CWLI] / (c)->ssum)

Definition at line 234 of file parser.h.

#define C_CWLI   ((C_CMAXWL-C_CMINWL)/(C_CNSS-1))

Definition at line 204 of file parser.h.

#define C_DEFCOLOR
Value:

Definition at line 224 of file parser.h.

#define C_DEFMATERIAL
Value:
{1,NULL,0,1.,0.,0.,C_DEFCOLOR,0.,C_DEFCOLOR,0.,\
                            C_DEFCOLOR,0.,C_DEFCOLOR,0.,0.,C_DEFCOLOR,0.}

Definition at line 263 of file parser.h.

#define C_DEFVERTEX   {1,NULL,{0.,0.,0.},{0.,0.,0.}}

Definition at line 265 of file parser.h.

#define copymat4 (   m4a,
  m4b 
)    (void)memcpy((char *)m4a,(char *)m4b,sizeof(MAT4))

Definition at line 300 of file parser.h.

#define DOT (   v1,
  v2 
)    ((v1)[0]*(v2)[0]+(v1)[1]*(v2)[1]+(v1)[2]*(v2)[2])

Definition at line 184 of file parser.h.

#define FHUGE   (1e10)

Definition at line 179 of file parser.h.

#define FTINY   (1e-6)

Definition at line 177 of file parser.h.

#define identxf (   xp)    (void)(setident4((xp)->xfm),(xp)->sca=1.0)

Definition at line 315 of file parser.h.

#define is0vect (   v)    (DOT(v,v) <= FTINY*FTINY)

Definition at line 189 of file parser.h.

#define MAT4IDENT
Value:
{ {1.,0.,0.,0.}, {0.,1.,0.,0.}, \
                            {0.,0.,1.,0.}, {0.,0.,0.,1.} }

Definition at line 302 of file parser.h.

#define MEM_PTR   void *

Definition at line 394 of file parser.h.

#define MG_E_CCT   2 /* cct */

Definition at line 22 of file parser.h.

#define MG_E_CMIX   4 /* cmix */

Definition at line 24 of file parser.h.

#define MG_E_COLOR   1 /* c */

Definition at line 21 of file parser.h.

#define MG_E_COMMENT   0 /* # */

Definition at line 20 of file parser.h.

#define MG_E_CONE   3 /* cone */

Definition at line 23 of file parser.h.

#define MG_E_CSPEC   5 /* cspec */

Definition at line 25 of file parser.h.

#define MG_E_CXY   6 /* cxy */

Definition at line 26 of file parser.h.

#define MG_E_CYL   7 /* cyl */

Definition at line 27 of file parser.h.

#define MG_E_ED   8 /* ed */

Definition at line 28 of file parser.h.

#define MG_E_FACE   9 /* f */

Definition at line 29 of file parser.h.

#define MG_E_FACEH   28 /* fh */

Definition at line 49 of file parser.h.

#define MG_E_IES   11 /* ies */

Definition at line 31 of file parser.h.

#define MG_E_INCLUDE   10 /* i */

Definition at line 30 of file parser.h.

#define MG_E_IR   12 /* ir */

Definition at line 32 of file parser.h.

#define MG_E_MATERIAL   13 /* m */

Definition at line 33 of file parser.h.

#define MG_E_NORMAL   14 /* n */

Definition at line 34 of file parser.h.

#define MG_E_OBJECT   15 /* o */

Definition at line 35 of file parser.h.

#define MG_E_POINT   16 /* p */

Definition at line 36 of file parser.h.

#define MG_E_PRISM   17 /* prism */

Definition at line 37 of file parser.h.

#define MG_E_RD   18 /* rd */

Definition at line 38 of file parser.h.

#define MG_E_RING   19 /* ring */

Definition at line 39 of file parser.h.

#define MG_E_RS   20 /* rs */

Definition at line 40 of file parser.h.

#define MG_E_SIDES   21 /* sides */

Definition at line 41 of file parser.h.

#define MG_E_SPH   22 /* sph */

Definition at line 42 of file parser.h.

#define MG_E_TD   23 /* td */

Definition at line 43 of file parser.h.

#define MG_E_TORUS   24 /* torus */

Definition at line 44 of file parser.h.

#define MG_E_TS   25 /* ts */

Definition at line 45 of file parser.h.

#define MG_E_VERTEX   26 /* v */

Definition at line 46 of file parser.h.

#define MG_E_XF   27 /* xf */

Definition at line 47 of file parser.h.

#define MG_EARGC   2 /* wrong number of arguments */

Definition at line 75 of file parser.h.

#define MG_EBADMAT   10 /* bad material specification */

Definition at line 83 of file parser.h.

#define MG_ECNTXT   12 /* unmatched context close */

Definition at line 85 of file parser.h.

#define MG_EILL   4 /* illegal argument value */

Definition at line 77 of file parser.h.

#define MG_EINCL   7 /* error in included file */

Definition at line 80 of file parser.h.

#define MG_ELINE   11 /* input line too long */

Definition at line 84 of file parser.h.

#define MG_EMEM   8 /* out of memory */

Definition at line 81 of file parser.h.

#define MG_ENOFILE   6 /* cannot open input file */

Definition at line 79 of file parser.h.

#define MG_ESEEK   9 /* file seek error */

Definition at line 82 of file parser.h.

#define MG_ETYPE   3 /* argument type error */

Definition at line 76 of file parser.h.

#define MG_EUNDEF   5 /* undefined reference */

Definition at line 78 of file parser.h.

#define MG_EUNK   1 /* unknown entity */

Definition at line 74 of file parser.h.

#define MG_MAXARGC   (MG_MAXLINE/4) /* maximum argument count */

Definition at line 111 of file parser.h.

#define MG_MAXELEN   6

Definition at line 61 of file parser.h.

#define MG_MAXLINE   4096 /* maximum input line length */

Definition at line 110 of file parser.h.

#define MG_NAMELIST
Value:
{"#","c","cct","cone","cmix","cspec","cxy","cyl","ed",\
                     "f","i","ies","ir","m","n","o","p","prism","rd",\
                     "ring","rs","sides","sph","td","torus","ts","v","xf",\
                     "fh"}

Definition at line 56 of file parser.h.

#define MG_NELIST   {28,29} /* entity count for version 1 and up */

Definition at line 54 of file parser.h.

#define MG_NENTITIES   29 /* total # entities */

Definition at line 52 of file parser.h.

#define MG_NERRS   13

Definition at line 87 of file parser.h.

#define MG_NQCD   5 /* default number of divisions */

Definition at line 142 of file parser.h.

#define MG_OK   0 /* normal return value */

Definition at line 73 of file parser.h.

#define MG_VMAJOR   2 /* major version number */

Definition at line 16 of file parser.h.

#define MG_VMINOR   0 /* minor version number */

Definition at line 17 of file parser.h.

#define PI   3.14159265358979323846

Definition at line 389 of file parser.h.

#define round0 (   x)    if (x <= FTINY && x >= -FTINY) x = 0

Definition at line 191 of file parser.h.

#define RREAL   double

Definition at line 176 of file parser.h.

#define setident4 (   m4)    copymat4(m4, m4ident)

Definition at line 307 of file parser.h.

#define VCOPY (   v1,
  v2 
)    ((v1)[0]=(v2)[0],(v1)[1]=(v2)[1],(v1)[2]=(v2)[2])

Definition at line 183 of file parser.h.

#define VSUM (   vr,
  v1,
  v2,
 
)
Value:
((vr)[0]=(v1)[0]+(f)*(v2)[0], \
                            (vr)[1]=(v1)[1]+(f)*(v2)[1], \
                            (vr)[2]=(v1)[2]+(f)*(v2)[2])

Definition at line 185 of file parser.h.

#define xf_ac (   xf)    ((xf)==NULL ? 0 : (xf)->xac)

Definition at line 340 of file parser.h.

#define xf_argc   xf_ac(xf_context)

Definition at line 343 of file parser.h.

#define xf_argv   xf_av(xf_context)

Definition at line 344 of file parser.h.

#define xf_av (   xf)    (xf_argend - (xf)->xac)

Definition at line 341 of file parser.h.

#define XF_MAXDIM   8 /* maximum array dimensions */

Definition at line 317 of file parser.h.


Typedef Documentation

typedef RREAL FVECT[3]

Definition at line 181 of file parser.h.

typedef RREAL MAT4[4][4]

Definition at line 298 of file parser.h.

typedef struct mg_fctxt MG_FCTXT
typedef struct xf_spec XF_SPEC

Function Documentation

int badarg ( int  ,
char **  ,
char *   
)

Definition at line 15 of file badarg.c.

{
       register int  i;

       if (fl == NULL)
              fl = "";             /* no arguments? */
       for (i = 1; *fl; i++,av++,fl++) {
              if (i > ac || *av == NULL)
                     return(-1);
              switch (*fl) {
              case 's':            /* string */
                     if (**av == '\0' || isspace(**av))
                            return(i);
                     break;
              case 'i':            /* integer */
                     if (!isintd(*av, " \t\r\n"))
                            return(i);
                     break;
              case 'f':            /* float */
                     if (!isfltd(*av, " \t\r\n"))
                            return(i);
                     break;
              default:             /* bad call! */
                     return(-1);
              }
       }
       return(0);           /* all's well */
}

Here is the call graph for this function:

void c_ccvt ( C_COLOR ,
int   
)

Definition at line 505 of file context.c.

{
       double x, y, z;
       register int  i;

       fl &= ~clr->flags;                 /* ignore what's done */
       if (!fl)                           /* everything's done! */
              return;
       if (!(clr->flags & (C_CSXY|C_CSSPEC)))    /* nothing set! */
              *clr = c_dfcolor;
       if (fl & C_CSXY) {          /* cspec -> cxy */
              x = y = z = 0.;
              for (i = 0; i < C_CNSS; i++) {
                     x += cie_xf.ssamp[i] * clr->ssamp[i];
                     y += cie_yf.ssamp[i] * clr->ssamp[i];
                     z += cie_zf.ssamp[i] * clr->ssamp[i];
              }
              x /= (double)cie_xf.ssum;
              y /= (double)cie_yf.ssum;
              z /= (double)cie_zf.ssum;
              z += x + y;
              clr->cx = x / z;
              clr->cy = y / z;
              clr->flags |= C_CSXY;
       } else if (fl & C_CSSPEC) { /* cxy -> cspec */
              x = clr->cx;
              y = clr->cy;
              z = 1. - x - y;
              clr->ssum = 0;
              for (i = 0; i < C_CNSS; i++) {
                     clr->ssamp[i] = x*cie_xp.ssamp[i] + y*cie_yp.ssamp[i]
                                   + z*cie_zp.ssamp[i] + .5;
                     if (clr->ssamp[i] < 0)             /* out of gamut! */
                            clr->ssamp[i] = 0;
                     else
                            clr->ssum += clr->ssamp[i];
              }
              clr->flags |= C_CSSPEC;
       }
       if (fl & C_CSEFF) {         /* compute efficacy */
              if (clr->flags & C_CSSPEC) {              /* from spectrum */
                     y = 0.;
                     for (i = 0; i < C_CNSS; i++)
                            y += cie_yf.ssamp[i] * clr->ssamp[i];
                     clr->eff = C_CLPWM * y / clr->ssum;
              } else /* clr->flags & C_CSXY */ { /* from (x,y) */
                     clr->eff = clr->cx*cie_xf.eff + clr->cy*cie_yf.eff +
                                   (1. - clr->cx - clr->cy)*cie_zf.eff;
              }
              clr->flags |= C_CSEFF;
       }
}

Here is the caller graph for this function:

void c_clearall ( void  )

Definition at line 439 of file context.c.

Here is the call graph for this function:

Here is the caller graph for this function:

C_COLOR* c_getcolor ( char *  )

Definition at line 481 of file context.c.

{
       register LUENT       *lp;

       if ((lp = lu_find(&clr_tab, name)) == NULL)
              return(NULL);
       return((C_COLOR *)lp->data);
}

Here is the call graph for this function:

C_MATERIAL* c_getmaterial ( char *  )

Definition at line 457 of file context.c.

{
       register LUENT       *lp;

       if ((lp = lu_find(&mat_tab, name)) == NULL)
              return(NULL);
       return((C_MATERIAL *)lp->data);
}

Here is the call graph for this function:

C_VERTEX* c_getvert ( char *  )

Definition at line 469 of file context.c.

{
       register LUENT       *lp;

       if ((lp = lu_find(&vtx_tab, name)) == NULL)
              return(NULL);
       return((C_VERTEX *)lp->data);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int c_hcolor ( int  ,
char **   
)

Definition at line 88 of file context.c.

{
       double w, wsum;
       register int  i;
       register LUENT       *lp;

       switch (mg_entity(av[0])) {
       case MG_E_COLOR:     /* get/set color context */
              if (ac > 4)
                     return(MG_EARGC);
              if (ac == 1) {              /* set unnamed color context */
                     c_uncolor = c_dfcolor;
                     c_ccolor = &c_uncolor;
                     c_ccname = NULL;
                     return(MG_OK);
              }
              if (!isname(av[1]))
                     return(MG_EILL);
              lp = lu_find(&clr_tab, av[1]);     /* lookup context */
              if (lp == NULL)
                     return(MG_EMEM);
              c_ccname = lp->key;
              c_ccolor = (C_COLOR *)lp->data;
              if (ac == 2) {              /* reestablish previous context */
                     if (c_ccolor == NULL)
                            return(MG_EUNDEF);
                     return(MG_OK);
              }
              if (av[2][0] != '=' || av[2][1])
                     return(MG_ETYPE);
              if (c_ccolor == NULL) {     /* create new color context */
                     lp->key = (char *)malloc(strlen(av[1])+1);
                     if (lp->key == NULL)
                            return(MG_EMEM);
                     strcpy(lp->key, av[1]);
                     lp->data = (char *)malloc(sizeof(C_COLOR));
                     if (lp->data == NULL)
                            return(MG_EMEM);
                     c_ccname = lp->key;
                     c_ccolor = (C_COLOR *)lp->data;
                     c_ccolor->clock = 0;
                     c_ccolor->client_data = NULL;
              }
              i = c_ccolor->clock;
              if (ac == 3) {              /* use default template */
                     *c_ccolor = c_dfcolor;
                     c_ccolor->clock = i + 1;
                     return(MG_OK);
              }
              lp = lu_find(&clr_tab, av[3]);     /* lookup template */
              if (lp == NULL)
                     return(MG_EMEM);
              if (lp->data == NULL)
                     return(MG_EUNDEF);
              *c_ccolor = *(C_COLOR *)lp->data;
              c_ccolor->clock = i + 1;
              return(MG_OK);
       case MG_E_CXY:              /* assign CIE XY value */
              if (ac != 3)
                     return(MG_EARGC);
              if (!isflt(av[1]) | !isflt(av[2]))
                     return(MG_ETYPE);
              c_ccolor->cx = atof(av[1]);
              c_ccolor->cy = atof(av[2]);
              c_ccolor->flags = C_CDXY|C_CSXY;
              if ((c_ccolor->cx < 0.) | (c_ccolor->cy < 0.) |
                            (c_ccolor->cx + c_ccolor->cy > 1.))
                     return(MG_EILL);
              c_ccolor->clock++;
              return(MG_OK);
       case MG_E_CSPEC:     /* assign spectral values */
              if (ac < 5)
                     return(MG_EARGC);
              if (!isflt(av[1]) | !isflt(av[2]))
                     return(MG_ETYPE);
              return(setspectrum(c_ccolor, atof(av[1]), atof(av[2]),
                            ac-3, av+3));
       case MG_E_CCT:              /* assign black body spectrum */
              if (ac != 2)
                     return(MG_EARGC);
              if (!isflt(av[1]))
                     return(MG_ETYPE);
              return(setbbtemp(c_ccolor, atof(av[1])));
       case MG_E_CMIX:             /* mix colors */
              if (ac < 5 || (ac-1)%2)
                     return(MG_EARGC);
              if (!isflt(av[1]))
                     return(MG_ETYPE);
              wsum = atof(av[1]);
              if ((lp = lu_find(&clr_tab, av[2])) == NULL)
                     return(MG_EMEM);
              if (lp->data == NULL)
                     return(MG_EUNDEF);
              *c_ccolor = *(C_COLOR *)lp->data;
              for (i = 3; i < ac; i += 2) {
                     if (!isflt(av[i]))
                            return(MG_ETYPE);
                     w = atof(av[i]);
                     if ((lp = lu_find(&clr_tab, av[i+1])) == NULL)
                            return(MG_EMEM);
                     if (lp->data == NULL)
                            return(MG_EUNDEF);
                     mixcolors(c_ccolor, wsum, c_ccolor,
                                   w, (C_COLOR *)lp->data);
                     wsum += w;
              }
              if (wsum <= 0.)
                     return(MG_EILL);
              c_ccolor->clock++;
              return(MG_OK);
       }
       return(MG_EUNK);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int c_hmaterial ( int  ,
char **   
)

Definition at line 206 of file context.c.

{
       int    i;
       register LUENT       *lp;

       switch (mg_entity(av[0])) {
       case MG_E_MATERIAL:  /* get/set material context */
              if (ac > 4)
                     return(MG_EARGC);
              if (ac == 1) {              /* set unnamed material context */
                     c_unmaterial = c_dfmaterial;
                     c_cmaterial = &c_unmaterial;
                     c_cmname = NULL;
                     return(MG_OK);
              }
              if (!isname(av[1]))
                     return(MG_EILL);
              lp = lu_find(&mat_tab, av[1]);     /* lookup context */
              if (lp == NULL)
                     return(MG_EMEM);
              c_cmname = lp->key;
              c_cmaterial = (C_MATERIAL *)lp->data;
              if (ac == 2) {              /* reestablish previous context */
                     if (c_cmaterial == NULL)
                            return(MG_EUNDEF);
                     return(MG_OK);
              }
              if (av[2][0] != '=' || av[2][1])
                     return(MG_ETYPE);
              if (c_cmaterial == NULL) {  /* create new material */
                     lp->key = (char *)malloc(strlen(av[1])+1);
                     if (lp->key == NULL)
                            return(MG_EMEM);
                     strcpy(lp->key, av[1]);
                     lp->data = (char *)malloc(sizeof(C_MATERIAL));
                     if (lp->data == NULL)
                            return(MG_EMEM);
                     c_cmname = lp->key;
                     c_cmaterial = (C_MATERIAL *)lp->data;
                     c_cmaterial->clock = 0;
                     c_cmaterial->client_data = NULL;
              }
              i = c_cmaterial->clock;
              if (ac == 3) {              /* use default template */
                     *c_cmaterial = c_dfmaterial;
                     c_cmaterial->clock = i + 1;
                     return(MG_OK);
              }
              lp = lu_find(&mat_tab, av[3]);     /* lookup template */
              if (lp == NULL)
                     return(MG_EMEM);
              if (lp->data == NULL)
                     return(MG_EUNDEF);
              *c_cmaterial = *(C_MATERIAL *)lp->data;
              c_cmaterial->clock = i + 1;
              return(MG_OK);
       case MG_E_IR:        /* set index of refraction */
              if (ac != 3)
                     return(MG_EARGC);
              if (!isflt(av[1]) | !isflt(av[2]))
                     return(MG_ETYPE);
              c_cmaterial->nr = atof(av[1]);
              c_cmaterial->ni = atof(av[2]);
              if (c_cmaterial->nr <= FTINY)
                     return(MG_EILL);
              c_cmaterial->clock++;
              return(MG_OK);
       case MG_E_RD:        /* set diffuse reflectance */
              if (ac != 2)
                     return(MG_EARGC);
              if (!isflt(av[1]))
                     return(MG_ETYPE);
              c_cmaterial->rd = atof(av[1]);
              if ((c_cmaterial->rd < 0.) | (c_cmaterial->rd > 1.))
                     return(MG_EILL);
              c_cmaterial->rd_c = *c_ccolor;
              c_cmaterial->clock++;
              return(MG_OK);
       case MG_E_ED:        /* set diffuse emittance */
              if (ac != 2)
                     return(MG_EARGC);
              if (!isflt(av[1]))
                     return(MG_ETYPE);
              c_cmaterial->ed = atof(av[1]);
              if (c_cmaterial->ed < 0.)
                     return(MG_EILL);
              c_cmaterial->ed_c = *c_ccolor;
              c_cmaterial->clock++;
              return(MG_OK);
       case MG_E_TD:        /* set diffuse transmittance */
              if (ac != 2)
                     return(MG_EARGC);
              if (!isflt(av[1]))
                     return(MG_ETYPE);
              c_cmaterial->td = atof(av[1]);
              if ((c_cmaterial->td < 0.) | (c_cmaterial->td > 1.))
                     return(MG_EILL);
              c_cmaterial->td_c = *c_ccolor;
              c_cmaterial->clock++;
              return(MG_OK);
       case MG_E_RS:        /* set specular reflectance */
              if (ac != 3)
                     return(MG_EARGC);
              if (!isflt(av[1]) | !isflt(av[2]))
                     return(MG_ETYPE);
              c_cmaterial->rs = atof(av[1]);
              c_cmaterial->rs_a = atof(av[2]);
              if ((c_cmaterial->rs < 0.) | (c_cmaterial->rs > 1.) |
                            (c_cmaterial->rs_a < 0.))
                     return(MG_EILL);
              c_cmaterial->rs_c = *c_ccolor;
              c_cmaterial->clock++;
              return(MG_OK);
       case MG_E_TS:        /* set specular transmittance */
              if (ac != 3)
                     return(MG_EARGC);
              if (!isflt(av[1]) | !isflt(av[2]))
                     return(MG_ETYPE);
              c_cmaterial->ts = atof(av[1]);
              c_cmaterial->ts_a = atof(av[2]);
              if ((c_cmaterial->ts < 0.) | (c_cmaterial->ts > 1.) |
                            (c_cmaterial->ts_a < 0.))
                     return(MG_EILL);
              c_cmaterial->ts_c = *c_ccolor;
              c_cmaterial->clock++;
              return(MG_OK);
       case MG_E_SIDES:     /* set number of sides */
              if (ac != 2)
                     return(MG_EARGC);
              if (!isint(av[1]))
                     return(MG_ETYPE);
              i = atoi(av[1]);
              if (i == 1)
                     c_cmaterial->sided = 1;
              else if (i == 2)
                     c_cmaterial->sided = 0;
              else
                     return(MG_EILL);
              c_cmaterial->clock++;
              return(MG_OK);
       }
       return(MG_EUNK);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int c_hvertex ( int  ,
char **   
)

Definition at line 354 of file context.c.

{
       int    i;
       register LUENT       *lp;

       switch (mg_entity(av[0])) {
       case MG_E_VERTEX:    /* get/set vertex context */
              if (ac > 4)
                     return(MG_EARGC);
              if (ac == 1) {              /* set unnamed vertex context */
                     c_unvertex = c_dfvertex;
                     c_cvertex = &c_unvertex;
                     c_cvname = NULL;
                     return(MG_OK);
              }
              if (!isname(av[1]))
                     return(MG_EILL);
              lp = lu_find(&vtx_tab, av[1]);     /* lookup context */
              if (lp == NULL)
                     return(MG_EMEM);
              c_cvname = lp->key;
              c_cvertex = (C_VERTEX *)lp->data;
              if (ac == 2) {              /* reestablish previous context */
                     if (c_cvertex == NULL)
                            return(MG_EUNDEF);
                     return(MG_OK);
              }
              if (av[2][0] != '=' || av[2][1])
                     return(MG_ETYPE);
              if (c_cvertex == NULL) {    /* create new vertex context */
                     lp->key = (char *)malloc(strlen(av[1])+1);
                     if (lp->key == NULL)
                            return(MG_EMEM);
                     strcpy(lp->key, av[1]);
                     lp->data = (char *)malloc(sizeof(C_VERTEX));
                     if (lp->data == NULL)
                            return(MG_EMEM);
                     c_cvname = lp->key;
                     c_cvertex = (C_VERTEX *)lp->data;
                     c_cvertex->clock = 0;
                     c_cvertex->client_data = NULL;
              }
              i = c_cvertex->clock;
              if (ac == 3) {              /* use default template */
                     *c_cvertex = c_dfvertex;
                     c_cvertex->clock = i + 1;
                     return(MG_OK);
              }
              lp = lu_find(&vtx_tab, av[3]);     /* lookup template */
              if (lp == NULL)
                     return(MG_EMEM);
              if (lp->data == NULL)
                     return(MG_EUNDEF);
              *c_cvertex = *(C_VERTEX *)lp->data;
              c_cvertex->clock = i + 1;
              return(MG_OK);
       case MG_E_POINT:     /* set point */
              if (ac != 4)
                     return(MG_EARGC);
              if (!isflt(av[1]) | !isflt(av[2]) | !isflt(av[3]))
                     return(MG_ETYPE);
              c_cvertex->p[0] = atof(av[1]);
              c_cvertex->p[1] = atof(av[2]);
              c_cvertex->p[2] = atof(av[3]);
              c_cvertex->clock++;
              return(MG_OK);
       case MG_E_NORMAL:    /* set normal */
              if (ac != 4)
                     return(MG_EARGC);
              if (!isflt(av[1]) | !isflt(av[2]) | !isflt(av[3]))
                     return(MG_ETYPE);
              c_cvertex->n[0] = atof(av[1]);
              c_cvertex->n[1] = atof(av[2]);
              c_cvertex->n[2] = atof(av[3]);
              (void)normalize(c_cvertex->n);
              c_cvertex->clock++;
              return(MG_OK);
       }
       return(MG_EUNK);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int c_isgrey ( C_COLOR )

Definition at line 493 of file context.c.

{
       if (!(clr->flags & (C_CSXY|C_CSSPEC)))
              return(1);           /* no settings == grey */
       c_ccvt(clr, C_CSXY);
       return(clr->cx >= .323 && clr->cx <= .343 &&
                     clr->cy >= .323 && clr->cy <= .343);
}

Here is the call graph for this function:

long comp_xfid ( MAT4  )

Definition at line 186 of file xf.c.

{
       static char   shifttab[64] = { 15, 5, 11, 5, 6, 3,
                            9, 15, 13, 2, 13, 5, 2, 12, 14, 11,
                            11, 12, 12, 3, 2, 11, 8, 12, 1, 12,
                            5, 4, 15, 9, 14, 5, 13, 14, 2, 10,
                            10, 14, 12, 3, 5, 5, 14, 6, 12, 11,
                            13, 9, 12, 8, 1, 6, 5, 12, 7, 13,
                            15, 8, 9, 2, 6, 11, 9, 11 };
       register int  i;
       register long xid;

       xid = 0;                    /* compute unique transform id */
       for (i = 0; i < sizeof(MAT4)/sizeof(unsigned short); i++)
              xid ^= (long)(((unsigned short *)xfm)[i]) << shifttab[i&63];
       return(xid);
}

Here is the caller graph for this function:

int e_cone ( int  ,
char **   
)

Definition at line 789 of file parser.c.

{
       static char   p3[3][24], p4[3][24], n3[3][24], n4[3][24];
       static char   *v1ent[5] = {mg_ename[MG_E_VERTEX],"_cv1","="};
       static char   *v2ent[5] = {mg_ename[MG_E_VERTEX],"_cv2","=","_cv3"};
       static char   *v3ent[4] = {mg_ename[MG_E_VERTEX],"_cv3","="};
       static char   *p3ent[5] = {mg_ename[MG_E_POINT],p3[0],p3[1],p3[2]};
       static char   *n3ent[5] = {mg_ename[MG_E_NORMAL],n3[0],n3[1],n3[2]};
       static char   *v4ent[4] = {mg_ename[MG_E_VERTEX],"_cv4","="};
       static char   *p4ent[5] = {mg_ename[MG_E_POINT],p4[0],p4[1],p4[2]};
       static char   *n4ent[5] = {mg_ename[MG_E_NORMAL],n4[0],n4[1],n4[2]};
       static char   *fent[6] = {mg_ename[MG_E_FACE],"_cv1","_cv2","_cv3","_cv4"};
       char   *v1n;
       register C_VERTEX    *cv1, *cv2;
       register int  i, j;
       FVECT  u, v, w;
       double rad1, rad2;
       int    sgn;
       double n1off, n2off;
       double d;
       int    rv;
       double theta;

       if (ac != 5)
              return(MG_EARGC);
       if ((cv1 = c_getvert(av[1])) == NULL ||
                     (cv2 = c_getvert(av[3])) == NULL)
              return(MG_EUNDEF);
       v1n = av[1];
       if (!isflt(av[2]) || !isflt(av[4]))
              return(MG_ETYPE);
       rad1 = atof(av[2]);
       round0(rad1);
       rad2 = atof(av[4]);
       round0(rad2);
       if (rad1 == 0.) {
              if (rad2 == 0.)
                     return(MG_EILL);
       } else if (rad2 != 0.) {
              if ((rad1 < 0.) ^ (rad2 < 0.))
                     return(MG_EILL);
       } else {                    /* swap */
              C_VERTEX      *cv;

              cv = cv1;
              cv1 = cv2;
              cv2 = cv;
              v1n = av[3];
              d = rad1;
              rad1 = rad2;
              rad2 = d;
       }
       sgn = rad2 < 0. ? -1 : 1;
                                   /* initialize */
       for (j = 0; j < 3; j++)
              w[j] = cv1->p[j] - cv2->p[j];
       if ((d = normalize(w)) == 0.)
              return(MG_EILL);
       n1off = n2off = (rad2 - rad1)/d;
       if (warpconends) {          /* hack for e_sph and e_torus */
              d = atan(n2off) - (PI/4)/mg_nqcdivs;
              if (d <= -PI/2+FTINY)
                     n2off = -FHUGE;
              else
                     n2off = tan(d);
       }
       make_axes(u, v, w);
       for (j = 0; j < 3; j++) {
              sprintf(p3[j], FLTFMT, cv2->p[j] + rad2*u[j]);
              if (n2off <= -FHUGE)
                     sprintf(n3[j], FLTFMT, -w[j]);
              else
                     sprintf(n3[j], FLTFMT, u[j] + w[j]*n2off);
       }
       if ((rv = mg_handle(MG_E_VERTEX, 3, v3ent)) != MG_OK)
              return(rv);
       if ((rv = mg_handle(MG_E_POINT, 4, p3ent)) != MG_OK)
              return(rv);
       if ((rv = mg_handle(MG_E_NORMAL, 4, n3ent)) != MG_OK)
              return(rv);
       if (rad1 == 0.) {           /* triangles */
              v1ent[3] = v1n;
              if ((rv = mg_handle(MG_E_VERTEX, 4, v1ent)) != MG_OK)
                     return(rv);
              for (j = 0; j < 3; j++)
                     sprintf(n4[j], FLTFMT, w[j]);
              if ((rv = mg_handle(MG_E_NORMAL, 4, n4ent)) != MG_OK)
                     return(rv);
              for (i = 1; i <= 4*mg_nqcdivs; i++) {
                     theta = sgn*i*(PI/2)/mg_nqcdivs;
                     if ((rv = mg_handle(MG_E_VERTEX, 4, v2ent)) != MG_OK)
                            return(rv);
                     for (j = 0; j < 3; j++) {
                            d = u[j]*cos(theta) + v[j]*sin(theta);
                            sprintf(p3[j], FLTFMT, cv2->p[j] + rad2*d);
                            if (n2off > -FHUGE)
                                   sprintf(n3[j], FLTFMT, d + w[j]*n2off);
                     }
                     if ((rv = mg_handle(MG_E_VERTEX, 2, v3ent)) != MG_OK)
                            return(rv);
                     if ((rv = mg_handle(MG_E_POINT, 4, p3ent)) != MG_OK)
                            return(rv);
                     if (n2off > -FHUGE &&
                     (rv = mg_handle(MG_E_NORMAL, 4, n3ent)) != MG_OK)
                            return(rv);
                     if ((rv = mg_handle(MG_E_FACE, 4, fent)) != MG_OK)
                            return(rv);
              }
       } else {                    /* quads */
              v1ent[3] = "_cv4";
              if (warpconends) {          /* hack for e_sph and e_torus */
                     d = atan(n1off) + (PI/4)/mg_nqcdivs;
                     if (d >= PI/2-FTINY)
                            n1off = FHUGE;
                     else
                            n1off = tan(atan(n1off)+(PI/4)/mg_nqcdivs);
              }
              for (j = 0; j < 3; j++) {
                     sprintf(p4[j], FLTFMT, cv1->p[j] + rad1*u[j]);
                     if (n1off >= FHUGE)
                            sprintf(n4[j], FLTFMT, w[j]);
                     else
                            sprintf(n4[j], FLTFMT, u[j] + w[j]*n1off);
              }
              if ((rv = mg_handle(MG_E_VERTEX, 3, v4ent)) != MG_OK)
                     return(rv);
              if ((rv = mg_handle(MG_E_POINT, 4, p4ent)) != MG_OK)
                     return(rv);
              if ((rv = mg_handle(MG_E_NORMAL, 4, n4ent)) != MG_OK)
                     return(rv);
              for (i = 1; i <= 4*mg_nqcdivs; i++) {
                     theta = sgn*i*(PI/2)/mg_nqcdivs;
                     if ((rv = mg_handle(MG_E_VERTEX, 4, v1ent)) != MG_OK)
                            return(rv);
                     if ((rv = mg_handle(MG_E_VERTEX, 4, v2ent)) != MG_OK)
                            return(rv);
                     for (j = 0; j < 3; j++) {
                            d = u[j]*cos(theta) + v[j]*sin(theta);
                            sprintf(p3[j], FLTFMT, cv2->p[j] + rad2*d);
                            if (n2off > -FHUGE)
                                   sprintf(n3[j], FLTFMT, d + w[j]*n2off);
                            sprintf(p4[j], FLTFMT, cv1->p[j] + rad1*d);
                            if (n1off < FHUGE)
                                   sprintf(n4[j], FLTFMT, d + w[j]*n1off);
                     }
                     if ((rv = mg_handle(MG_E_VERTEX, 2, v3ent)) != MG_OK)
                            return(rv);
                     if ((rv = mg_handle(MG_E_POINT, 4, p3ent)) != MG_OK)
                            return(rv);
                     if (n2off > -FHUGE &&
                     (rv = mg_handle(MG_E_NORMAL, 4, n3ent)) != MG_OK)
                            return(rv);
                     if ((rv = mg_handle(MG_E_VERTEX, 2, v4ent)) != MG_OK)
                            return(rv);
                     if ((rv = mg_handle(MG_E_POINT, 4, p4ent)) != MG_OK)
                            return(rv);
                     if (n1off < FHUGE &&
                     (rv = mg_handle(MG_E_NORMAL, 4, n4ent)) != MG_OK)
                            return(rv);
                     if ((rv = mg_handle(MG_E_FACE, 5, fent)) != MG_OK)
                            return(rv);
              }
       }
       return(MG_OK);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int e_cyl ( int  ,
char **   
)

Definition at line 672 of file parser.c.

{
       static char   *avnew[6] = {mg_ename[MG_E_CONE]};

       if (ac != 4)
              return(MG_EARGC);
       avnew[1] = av[1];
       avnew[2] = av[2];
       avnew[3] = av[3];
       avnew[4] = av[2];
       return(mg_handle(MG_E_CONE, 5, avnew));
}

Here is the call graph for this function:

Here is the caller graph for this function:

int e_faceh ( int  ,
char **   
)

Definition at line 473 of file parser.c.

{
       char   *newav[MG_MAXARGC];
       int    lastp = 0;
       register int  i, j;

       newav[0] = mg_ename[MG_E_FACE];
       for (i = 1; i < ac; i++)
              if (av[i][0] == '-') {
                     if (i < 4)
                            return(MG_EARGC);
                     if (i >= ac-1)
                            break;
                     if (!lastp)
                            lastp = i-1;
                     for (j = i+1; j < ac-1 && av[j+1][0] != '-'; j++)
                            ;
                     if (j - i < 3)
                            return(MG_EARGC);
                     newav[i] = av[j];    /* connect hole loop */
              } else
                     newav[i] = av[i];    /* hole or perimeter vertex */
       if (lastp)
              newav[i++] = av[lastp];            /* finish seam to outside */
       newav[i] = NULL;
       return(mg_handle(MG_E_FACE, i, newav));
}

Here is the call graph for this function:

Here is the caller graph for this function:

int e_include ( int  ,
char **   
)

Definition at line 419 of file parser.c.

{
       char   *xfarg[MG_MAXARGC];
       MG_FCTXT      ictx;
       XF_SPEC       *xf_orig = xf_context;
       register int  rv;

       if (ac < 2)
              return(MG_EARGC);
       if ((rv = mg_open(&ictx, av[1])) != MG_OK)
              return(rv);
       if (ac > 2) {
              register int  i;

              xfarg[0] = mg_ename[MG_E_XF];
              for (i = 1; i < ac-1; i++)
                     xfarg[i] = av[i+1];
              xfarg[ac-1] = NULL;
              if ((rv = mg_handle(MG_E_XF, ac-1, xfarg)) != MG_OK) {
                     mg_close();
                     return(rv);
              }
       }
       do {
              while ((rv = mg_read()) > 0) {
                     if (rv >= MG_MAXLINE-1) {
                            fprintf(stderr, "%s: %d: %s\n", ictx.fname,
                                          ictx.lineno, mg_err[MG_ELINE]);
                            mg_close();
                            return(MG_EINCL);
                     }
                     if ((rv = mg_parse()) != MG_OK) {
                            fprintf(stderr, "%s: %d: %s:\n%s", ictx.fname,
                                          ictx.lineno, mg_err[rv],
                                          ictx.inpline);
                            mg_close();
                            return(MG_EINCL);
                     }
              }
              if (ac > 2)
                     if ((rv = mg_handle(MG_E_XF, 1, xfarg)) != MG_OK) {
                            mg_close();
                            return(rv);
                     }
       } while (xf_context != xf_orig);
       mg_close();
       return(MG_OK);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int e_pipe ( int  ,
char **   
)
int e_prism ( int  ,
char **   
)

Definition at line 960 of file parser.c.

{
       static char   p[3][24];
       static char   *vent[5] = {mg_ename[MG_E_VERTEX],NULL,"="};
       static char   *pent[5] = {mg_ename[MG_E_POINT],p[0],p[1],p[2]};
       static char   *znorm[5] = {mg_ename[MG_E_NORMAL],"0","0","0"};
       char   *newav[MG_MAXARGC], nvn[MG_MAXARGC-1][8];
       double length;
       int    hasnorm;
       FVECT  v1, v2, v3, norm;
       register C_VERTEX    *cv;
       C_VERTEX      *cv0;
       int    rv;
       register int  i, j;
                                          /* check arguments */
       if (ac < 5)
              return(MG_EARGC);
       if (!isflt(av[ac-1]))
              return(MG_ETYPE);
       length = atof(av[ac-1]);
       if (length <= FTINY && length >= -FTINY)
              return(MG_EILL);
                                          /* compute face normal */
       if ((cv0 = c_getvert(av[1])) == NULL)
              return(MG_EUNDEF);
       hasnorm = 0;
       norm[0] = norm[1] = norm[2] = 0.;
       v1[0] = v1[1] = v1[2] = 0.;
       for (i = 2; i < ac-1; i++) {
              if ((cv = c_getvert(av[i])) == NULL)
                     return(MG_EUNDEF);
              hasnorm += !is0vect(cv->n);
              v2[0] = cv->p[0] - cv0->p[0];
              v2[1] = cv->p[1] - cv0->p[1];
              v2[2] = cv->p[2] - cv0->p[2];
              fcross(v3, v1, v2);
              norm[0] += v3[0];
              norm[1] += v3[1];
              norm[2] += v3[2];
              VCOPY(v1, v2);
       }
       if (normalize(norm) == 0.)
              return(MG_EILL);
                                          /* create moved vertices */
       for (i = 1; i < ac-1; i++) {
              sprintf(nvn[i-1], "_pv%d", i);
              vent[1] = nvn[i-1];
              vent[3] = av[i];
              if ((rv = mg_handle(MG_E_VERTEX, 4, vent)) != MG_OK)
                     return(rv);
              cv = c_getvert(av[i]);             /* checked above */
              for (j = 0; j < 3; j++)
                     sprintf(p[j], FLTFMT, cv->p[j] - length*norm[j]);
              if ((rv = mg_handle(MG_E_POINT, 4, pent)) != MG_OK)
                     return(rv);
       }
                                          /* make faces */
       newav[0] = mg_ename[MG_E_FACE];
                                          /* do the side faces */
       newav[5] = NULL;
       newav[3] = av[ac-2];
       newav[4] = nvn[ac-3];
       for (i = 1; i < ac-1; i++) {
              newav[1] = nvn[i-1];
              newav[2] = av[i];
              if ((rv = mg_handle(MG_E_FACE, 5, newav)) != MG_OK)
                     return(rv);
              newav[3] = newav[2];
              newav[4] = newav[1];
       }
                                          /* do top face */
       for (i = 1; i < ac-1; i++) {
              if (hasnorm) {                     /* zero normals */
                     vent[1] = nvn[i-1];
                     if ((rv = mg_handle(MG_E_VERTEX, 2, vent)) != MG_OK)
                            return(rv);
                     if ((rv = mg_handle(MG_E_NORMAL, 4, znorm)) != MG_OK)
                            return(rv);
              }
              newav[ac-1-i] = nvn[i-1];   /* reverse */
       }
       if ((rv = mg_handle(MG_E_FACE, ac-1, newav)) != MG_OK)
              return(rv);
                                          /* do bottom face */
       if (hasnorm)
              for (i = 1; i < ac-1; i++) {
                     vent[1] = nvn[i-1];
                     vent[3] = av[i];
                     if ((rv = mg_handle(MG_E_VERTEX, 4, vent)) != MG_OK)
                            return(rv);
                     if ((rv = mg_handle(MG_E_NORMAL, 4, znorm)) != MG_OK)
                            return(rv);
                     newav[i] = nvn[i-1];
              }
       else
              for (i = 1; i < ac-1; i++)
                     newav[i] = av[i];
       newav[i] = NULL;
       if ((rv = mg_handle(MG_E_FACE, i, newav)) != MG_OK)
              return(rv);
       return(MG_OK);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int e_ring ( int  ,
char **   
)

Definition at line 690 of file parser.c.

{
       static char   p3[3][24], p4[3][24];
       static char   *nzent[5] = {mg_ename[MG_E_NORMAL],"0","0","0"};
       static char   *v1ent[5] = {mg_ename[MG_E_VERTEX],"_rv1","="};
       static char   *v2ent[5] = {mg_ename[MG_E_VERTEX],"_rv2","=","_rv3"};
       static char   *v3ent[4] = {mg_ename[MG_E_VERTEX],"_rv3","="};
       static char   *p3ent[5] = {mg_ename[MG_E_POINT],p3[0],p3[1],p3[2]};
       static char   *v4ent[4] = {mg_ename[MG_E_VERTEX],"_rv4","="};
       static char   *p4ent[5] = {mg_ename[MG_E_POINT],p4[0],p4[1],p4[2]};
       static char   *fent[6] = {mg_ename[MG_E_FACE],"_rv1","_rv2","_rv3","_rv4"};
       register C_VERTEX    *cv;
       register int  i, j;
       FVECT  u, v;
       double minrad, maxrad;
       int    rv;
       double theta, d;

       if (ac != 4)
              return(MG_EARGC);
       if ((cv = c_getvert(av[1])) == NULL)
              return(MG_EUNDEF);
       if (is0vect(cv->n))
              return(MG_EILL);
       if (!isflt(av[2]) || !isflt(av[3]))
              return(MG_ETYPE);
       minrad = atof(av[2]);
       round0(minrad);
       maxrad = atof(av[3]);
       if (minrad < 0. || maxrad <= minrad)
              return(MG_EILL);
                                   /* initialize */
       make_axes(u, v, cv->n);
       for (j = 0; j < 3; j++)
              sprintf(p3[j], FLTFMT, cv->p[j] + maxrad*u[j]);
       if ((rv = mg_handle(MG_E_VERTEX, 3, v3ent)) != MG_OK)
              return(rv);
       if ((rv = mg_handle(MG_E_POINT, 4, p3ent)) != MG_OK)
              return(rv);
       if (minrad == 0.) {         /* closed */
              v1ent[3] = av[1];
              if ((rv = mg_handle(MG_E_VERTEX, 4, v1ent)) != MG_OK)
                     return(rv);
              if ((rv = mg_handle(MG_E_NORMAL, 4, nzent)) != MG_OK)
                     return(rv);
              for (i = 1; i <= 4*mg_nqcdivs; i++) {
                     theta = i*(PI/2)/mg_nqcdivs;
                     if ((rv = mg_handle(MG_E_VERTEX, 4, v2ent)) != MG_OK)
                            return(rv);
                     for (j = 0; j < 3; j++)
                            sprintf(p3[j], FLTFMT, cv->p[j] +
                                          maxrad*u[j]*cos(theta) +
                                          maxrad*v[j]*sin(theta));
                     if ((rv = mg_handle(MG_E_VERTEX, 2, v3ent)) != MG_OK)
                            return(rv);
                     if ((rv = mg_handle(MG_E_POINT, 4, p3ent)) != MG_OK)
                            return(rv);
                     if ((rv = mg_handle(MG_E_FACE, 4, fent)) != MG_OK)
                            return(rv);
              }
       } else {                    /* open */
              if ((rv = mg_handle(MG_E_VERTEX, 3, v4ent)) != MG_OK)
                     return(rv);
              for (j = 0; j < 3; j++)
                     sprintf(p4[j], FLTFMT, cv->p[j] + minrad*u[j]);
              if ((rv = mg_handle(MG_E_POINT, 4, p4ent)) != MG_OK)
                     return(rv);
              v1ent[3] = "_rv4";
              for (i = 1; i <= 4*mg_nqcdivs; i++) {
                     theta = i*(PI/2)/mg_nqcdivs;
                     if ((rv = mg_handle(MG_E_VERTEX, 4, v1ent)) != MG_OK)
                            return(rv);
                     if ((rv = mg_handle(MG_E_VERTEX, 4, v2ent)) != MG_OK)
                            return(rv);
                     for (j = 0; j < 3; j++) {
                            d = u[j]*cos(theta) + v[j]*sin(theta);
                            sprintf(p3[j], FLTFMT, cv->p[j] + maxrad*d);
                            sprintf(p4[j], FLTFMT, cv->p[j] + minrad*d);
                     }
                     if ((rv = mg_handle(MG_E_VERTEX, 2, v3ent)) != MG_OK)
                            return(rv);
                     if ((rv = mg_handle(MG_E_POINT, 4, p3ent)) != MG_OK)
                            return(rv);
                     if ((rv = mg_handle(MG_E_VERTEX, 2, v4ent)) != MG_OK)
                            return(rv);
                     if ((rv = mg_handle(MG_E_POINT, 4, p4ent)) != MG_OK)
                            return(rv);
                     if ((rv = mg_handle(MG_E_FACE, 5, fent)) != MG_OK)
                            return(rv);
              }
       }
       return(MG_OK);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int e_sph ( int  ,
char **   
)

Definition at line 526 of file parser.c.

{
       static char   p2x[24], p2y[24], p2z[24], r1[24], r2[24];
       static char   *v1ent[5] = {mg_ename[MG_E_VERTEX],"_sv1","=","_sv2"};
       static char   *v2ent[4] = {mg_ename[MG_E_VERTEX],"_sv2","="};
       static char   *p2ent[5] = {mg_ename[MG_E_POINT],p2x,p2y,p2z};
       static char   *conent[6] = {mg_ename[MG_E_CONE],"_sv1",r1,"_sv2",r2};
       register C_VERTEX    *cv;
       register int  i;
       int    rval;
       double rad;
       double theta;

       if (ac != 3)
              return(MG_EARGC);
       if ((cv = c_getvert(av[1])) == NULL)
              return(MG_EUNDEF);
       if (!isflt(av[2]))
              return(MG_ETYPE);
       rad = atof(av[2]);
                                   /* initialize */
       warpconends = 1;
       if ((rval = mg_handle(MG_E_VERTEX, 3, v2ent)) != MG_OK)
              return(rval);
       sprintf(p2x, FLTFMT, cv->p[0]);
       sprintf(p2y, FLTFMT, cv->p[1]);
       sprintf(p2z, FLTFMT, cv->p[2]+rad);
       if ((rval = mg_handle(MG_E_POINT, 4, p2ent)) != MG_OK)
              return(rval);
       r2[0] = '0'; r2[1] = '\0';
       for (i = 1; i <= 2*mg_nqcdivs; i++) {
              theta = i*(PI/2)/mg_nqcdivs;
              if ((rval = mg_handle(MG_E_VERTEX, 4, v1ent)) != MG_OK)
                     return(rval);
              sprintf(p2z, FLTFMT, cv->p[2]+rad*cos(theta));
              if ((rval = mg_handle(MG_E_VERTEX, 2, v2ent)) != MG_OK)
                     return(rval);
              if ((rval = mg_handle(MG_E_POINT, 4, p2ent)) != MG_OK)
                     return(rval);
              strcpy(r1, r2);
              sprintf(r2, FLTFMT, rad*sin(theta));
              if ((rval = mg_handle(MG_E_CONE, 5, conent)) != MG_OK)
                     return(rval);
       }
       warpconends = 0;
       return(MG_OK);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int e_torus ( int  ,
char **   
)

Definition at line 579 of file parser.c.

{
       static char   p2[3][24], r1[24], r2[24];
       static char   *v1ent[5] = {mg_ename[MG_E_VERTEX],"_tv1","=","_tv2"};
       static char   *v2ent[5] = {mg_ename[MG_E_VERTEX],"_tv2","="};
       static char   *p2ent[5] = {mg_ename[MG_E_POINT],p2[0],p2[1],p2[2]};
       static char   *conent[6] = {mg_ename[MG_E_CONE],"_tv1",r1,"_tv2",r2};
       register C_VERTEX    *cv;
       register int  i, j;
       int    rval;
       int    sgn;
       double minrad, maxrad, avgrad;
       double theta;

       if (ac != 4)
              return(MG_EARGC);
       if ((cv = c_getvert(av[1])) == NULL)
              return(MG_EUNDEF);
       if (is0vect(cv->n))
              return(MG_EILL);
       if (!isflt(av[2]) || !isflt(av[3]))
              return(MG_ETYPE);
       minrad = atof(av[2]);
       round0(minrad);
       maxrad = atof(av[3]);
                                   /* check orientation */
       if (minrad > 0.)
              sgn = 1;
       else if (minrad < 0.)
              sgn = -1;
       else if (maxrad > 0.)
              sgn = 1;
       else if (maxrad < 0.)
              sgn = -1;
       else
              return(MG_EILL);
       if (sgn*(maxrad-minrad) <= 0.)
              return(MG_EILL);
                                   /* initialize */
       warpconends = 1;
       v2ent[3] = av[1];
       for (j = 0; j < 3; j++)
              sprintf(p2[j], FLTFMT, cv->p[j] +
                            .5*sgn*(maxrad-minrad)*cv->n[j]);
       if ((rval = mg_handle(MG_E_VERTEX, 4, v2ent)) != MG_OK)
              return(rval);
       if ((rval = mg_handle(MG_E_POINT, 4, p2ent)) != MG_OK)
              return(rval);
       sprintf(r2, FLTFMT, avgrad=.5*(minrad+maxrad));
                                   /* run outer section */
       for (i = 1; i <= 2*mg_nqcdivs; i++) {
              theta = i*(PI/2)/mg_nqcdivs;
              if ((rval = mg_handle(MG_E_VERTEX, 4, v1ent)) != MG_OK)
                     return(rval);
              for (j = 0; j < 3; j++)
                     sprintf(p2[j], FLTFMT, cv->p[j] +
                            .5*sgn*(maxrad-minrad)*cos(theta)*cv->n[j]);
              if ((rval = mg_handle(MG_E_VERTEX, 2, v2ent)) != MG_OK)
                     return(rval);
              if ((rval = mg_handle(MG_E_POINT, 4, p2ent)) != MG_OK)
                     return(rval);
              strcpy(r1, r2);
              sprintf(r2, FLTFMT, avgrad + .5*(maxrad-minrad)*sin(theta));
              if ((rval = mg_handle(MG_E_CONE, 5, conent)) != MG_OK)
                     return(rval);
       }
                                   /* run inner section */
       sprintf(r2, FLTFMT, -.5*(minrad+maxrad));
       for ( ; i <= 4*mg_nqcdivs; i++) {
              theta = i*(PI/2)/mg_nqcdivs;
              for (j = 0; j < 3; j++)
                     sprintf(p2[j], FLTFMT, cv->p[j] +
                            .5*sgn*(maxrad-minrad)*cos(theta)*cv->n[j]);
              if ((rval = mg_handle(MG_E_VERTEX, 4, v1ent)) != MG_OK)
                     return(rval);
              if ((rval = mg_handle(MG_E_VERTEX, 2, v2ent)) != MG_OK)
                     return(rval);
              if ((rval = mg_handle(MG_E_POINT, 4, p2ent)) != MG_OK)
                     return(rval);
              strcpy(r1, r2);
              sprintf(r2, FLTFMT, -avgrad - .5*(maxrad-minrad)*sin(theta));
              if ((rval = mg_handle(MG_E_CONE, 5, conent)) != MG_OK)
                     return(rval);
       }
       warpconends = 0;
       return(MG_OK);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void fcross ( FVECT  ,
FVECT  ,
FVECT   
)

Definition at line 84 of file fvect.c.

{
       vres[0] = v1[1]*v2[2] - v1[2]*v2[1];
       vres[1] = v1[2]*v2[0] - v1[0]*v2[2];
       vres[2] = v1[0]*v2[1] - v1[1]*v2[0];
}

Here is the caller graph for this function:

void free_xf ( XF_SPEC )

Definition at line 153 of file xf.c.

{
       if (spec->xarr != NULL)
              free((MEM_PTR)spec->xarr);
       free((MEM_PTR)spec);
}

Here is the caller graph for this function:

int isflt ( char *  )

Definition at line 156 of file words.c.

{
       register char  *cp;

       cp = fskip(s);
       return(cp != NULL && *cp == '\0');
}

Here is the call graph for this function:

int isfltd ( char *  ,
char *   
)

Definition at line 167 of file words.c.

{
       register char  *cp;

       cp = fskip(s);
       return(cp != NULL && strchr(ds, *cp) != NULL);
}

Here is the call graph for this function:

int isint ( char *  )

Definition at line 134 of file words.c.

{
       register char  *cp;

       cp = iskip(s);
       return(cp != NULL && *cp == '\0');
}

Here is the call graph for this function:

int isintd ( char *  ,
char *   
)

Definition at line 145 of file words.c.

{
       register char  *cp;

       cp = iskip(s);
       return(cp != NULL && strchr(ds, *cp) != NULL);
}

Here is the call graph for this function:

int isname ( char *  )

Definition at line 100 of file words.c.

{
       while (*s == '_')                  /* skip leading underscores */
              s++;
       if (!isascii(*s) || !isalpha(*s))  /* start with a letter */
              return(0);
       while (isascii(*++s) && isgraph(*s))      /* all visible characters */
              ;
       return(*s == '\0');                /* ending in nul */
}

Here is the caller graph for this function:

void mg_clear ( void  )

Definition at line 395 of file parser.c.

{
       c_clearall();               /* clear context tables */
       while (mg_file != NULL)            /* reset our file context */
              mg_close();
}

Here is the call graph for this function:

void mg_close ( void  )

Definition at line 261 of file parser.c.

{
       register MG_FCTXT    *ctx = mg_file;

       mg_file = ctx->prev;        /* restore enclosing context */
       if (ctx->fp != stdin)              /* close file if it's a file */
              fclose(ctx->fp);
}

Here is the caller graph for this function:

int mg_defuhand ( int  ,
char **   
)

Definition at line 382 of file parser.c.

{
       if (mg_nunknown++ == 0)            /* report first incident */
              fprintf(stderr, "%s: %d: %s: %s\n", mg_file->fname,
                            mg_file->lineno, mg_err[MG_EUNK], av[0]);
       return(MG_OK);
}
int mg_entity ( char *  )

Definition at line 183 of file parser.c.

{
       static LUTAB  ent_tab = LU_SINIT(NULL,NULL);     /* lookup table */
       register char *cp;

       if (!ent_tab.tsiz) {        /* initialize hash table */
              if (!lu_init(&ent_tab, MG_NENTITIES))
                     return(-1);          /* what to do? */
              for (cp = mg_ename[MG_NENTITIES-1]; cp >= mg_ename[0];
                            cp -= sizeof(mg_ename[0]))
                     lu_find(&ent_tab, cp)->key = cp;
       }
       cp = lu_find(&ent_tab, name)->key;
       if (cp == NULL)
              return(-1);
       return((cp - mg_ename[0])/sizeof(mg_ename[0]));
}

Here is the call graph for this function:

Here is the caller graph for this function:

void mg_fgetpos ( MG_FPOS )
int mg_fgoto ( MG_FPOS )
int mg_handle ( int  ,
int  ,
char **   
)
void mg_init ( void  )

Definition at line 82 of file parser.c.

{
       unsigned long ineed = 0, uneed = 0;
       register int  i;
                                   /* pick up slack */
       if (mg_ehand[MG_E_IES] == NULL)
              mg_ehand[MG_E_IES] = e_ies;
       if (mg_ehand[MG_E_INCLUDE] == NULL)
              mg_ehand[MG_E_INCLUDE] = e_include;
       if (mg_ehand[MG_E_SPH] == NULL) {
              mg_ehand[MG_E_SPH] = e_sph;
              ineed |= 1L<<MG_E_POINT|1L<<MG_E_VERTEX;
       } else
              uneed |= 1L<<MG_E_POINT|1L<<MG_E_VERTEX|1L<<MG_E_XF;
       if (mg_ehand[MG_E_CYL] == NULL) {
              mg_ehand[MG_E_CYL] = e_cyl;
              ineed |= 1L<<MG_E_POINT|1L<<MG_E_VERTEX;
       } else
              uneed |= 1L<<MG_E_POINT|1L<<MG_E_VERTEX|1L<<MG_E_XF;
       if (mg_ehand[MG_E_CONE] == NULL) {
              mg_ehand[MG_E_CONE] = e_cone;
              ineed |= 1L<<MG_E_POINT|1L<<MG_E_VERTEX;
       } else
              uneed |= 1L<<MG_E_POINT|1L<<MG_E_VERTEX|1L<<MG_E_XF;
       if (mg_ehand[MG_E_RING] == NULL) {
              mg_ehand[MG_E_RING] = e_ring;
              ineed |= 1L<<MG_E_POINT|1L<<MG_E_NORMAL|1L<<MG_E_VERTEX;
       } else
              uneed |= 1L<<MG_E_POINT|1L<<MG_E_NORMAL|1L<<MG_E_VERTEX|1L<<MG_E_XF;
       if (mg_ehand[MG_E_PRISM] == NULL) {
              mg_ehand[MG_E_PRISM] = e_prism;
              ineed |= 1L<<MG_E_POINT|1L<<MG_E_VERTEX;
       } else
              uneed |= 1L<<MG_E_POINT|1L<<MG_E_VERTEX|1L<<MG_E_XF;
       if (mg_ehand[MG_E_TORUS] == NULL) {
              mg_ehand[MG_E_TORUS] = e_torus;
              ineed |= 1L<<MG_E_POINT|1L<<MG_E_NORMAL|1L<<MG_E_VERTEX;
       } else
              uneed |= 1L<<MG_E_POINT|1L<<MG_E_NORMAL|1L<<MG_E_VERTEX|1L<<MG_E_XF;
       if (mg_ehand[MG_E_FACE] == NULL)
              mg_ehand[MG_E_FACE] = mg_ehand[MG_E_FACEH];
       else if (mg_ehand[MG_E_FACEH] == NULL)
              mg_ehand[MG_E_FACEH] = e_faceh;
       if (mg_ehand[MG_E_COLOR] != NULL) {
              if (mg_ehand[MG_E_CMIX] == NULL) {
                     mg_ehand[MG_E_CMIX] = e_cmix;
                     ineed |= 1L<<MG_E_COLOR|1L<<MG_E_CXY|1L<<MG_E_CSPEC|1L<<MG_E_CMIX|1L<<MG_E_CCT;
              }
              if (mg_ehand[MG_E_CSPEC] == NULL) {
                     mg_ehand[MG_E_CSPEC] = e_cspec;
                     ineed |= 1L<<MG_E_COLOR|1L<<MG_E_CXY|1L<<MG_E_CSPEC|1L<<MG_E_CMIX|1L<<MG_E_CCT;
              }
              if (mg_ehand[MG_E_CCT] == NULL) {
                     mg_ehand[MG_E_CCT] = e_cct;
                     ineed |= 1L<<MG_E_COLOR|1L<<MG_E_CXY|1L<<MG_E_CSPEC|1L<<MG_E_CMIX|1L<<MG_E_CCT;
              }
       }
                                   /* check for consistency */
       if (mg_ehand[MG_E_FACE] != NULL)
              uneed |= 1L<<MG_E_POINT|1L<<MG_E_VERTEX|1L<<MG_E_XF;
       if (mg_ehand[MG_E_CXY] != NULL || mg_ehand[MG_E_CSPEC] != NULL ||
                     mg_ehand[MG_E_CMIX] != NULL)
              uneed |= 1L<<MG_E_COLOR;
       if (mg_ehand[MG_E_RD] != NULL || mg_ehand[MG_E_TD] != NULL ||
                     mg_ehand[MG_E_IR] != NULL ||
                     mg_ehand[MG_E_ED] != NULL || 
                     mg_ehand[MG_E_RS] != NULL ||
                     mg_ehand[MG_E_TS] != NULL ||
                     mg_ehand[MG_E_SIDES] != NULL)
              uneed |= 1L<<MG_E_MATERIAL;
       for (i = 0; i < MG_NENTITIES; i++)
              if (uneed & 1L<<i && mg_ehand[i] == NULL) {
                     fprintf(stderr, "Missing support for \"%s\" entity\n",
                                   mg_ename[i]);
                     exit(1);
              }
                                   /* add support as needed */
       if (ineed & 1L<<MG_E_VERTEX && mg_ehand[MG_E_VERTEX] != c_hvertex)
              e_supp[MG_E_VERTEX] = c_hvertex;
       if (ineed & 1L<<MG_E_POINT && mg_ehand[MG_E_POINT] != c_hvertex)
              e_supp[MG_E_POINT] = c_hvertex;
       if (ineed & 1L<<MG_E_NORMAL && mg_ehand[MG_E_NORMAL] != c_hvertex)
              e_supp[MG_E_NORMAL] = c_hvertex;
       if (ineed & 1L<<MG_E_COLOR && mg_ehand[MG_E_COLOR] != c_hcolor)
              e_supp[MG_E_COLOR] = c_hcolor;
       if (ineed & 1L<<MG_E_CXY && mg_ehand[MG_E_CXY] != c_hcolor)
              e_supp[MG_E_CXY] = c_hcolor;
       if (ineed & 1L<<MG_E_CSPEC && mg_ehand[MG_E_CSPEC] != c_hcolor)
              e_supp[MG_E_CSPEC] = c_hcolor;
       if (ineed & 1L<<MG_E_CMIX && mg_ehand[MG_E_CMIX] != c_hcolor)
              e_supp[MG_E_CMIX] = c_hcolor;
       if (ineed & 1L<<MG_E_CCT && mg_ehand[MG_E_CCT] != c_hcolor)
              e_supp[MG_E_CCT] = c_hcolor;
                                   /* discard remaining entities */
       for (i = 0; i < MG_NENTITIES; i++)
              if (mg_ehand[i] == NULL)
                     mg_ehand[i] = e_any_toss;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int mg_load ( char *  )

Definition at line 351 of file parser.c.

{
       MG_FCTXT      cntxt;
       int    rval;
       register int  nbr;

       if ((rval = mg_open(&cntxt, fn)) != MG_OK) {
              fprintf(stderr, "%s: %s\n", fn, mg_err[rval]);
              return(rval);
       }
       while ((nbr = mg_read()) > 0) {    /* parse each line */
              if (nbr >= MG_MAXLINE-1) {
                     fprintf(stderr, "%s: %d: %s\n", cntxt.fname,
                                   cntxt.lineno, mg_err[rval=MG_ELINE]);
                     break;
              }
              if ((rval = mg_parse()) != MG_OK) {
                     fprintf(stderr, "%s: %d: %s:\n%s", cntxt.fname,
                                   cntxt.lineno, mg_err[rval],
                                   cntxt.inpline);
                     break;
              }
       }
       mg_close();
       return(rval);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int mg_open ( MG_FCTXT ,
char *   
)
int mg_parse ( void  )

Definition at line 320 of file parser.c.

{
       char   abuf[MG_MAXLINE];
       char   *argv[MG_MAXARGC];
       register char *cp, *cp2, **ap;
                                   /* copy line, removing escape chars */
       cp = abuf; cp2 = mg_file->inpline;
       while ((*cp++ = *cp2++))
              if (cp2[0] == '\n' && cp2[-1] == '\\')
                     cp--;
       cp = abuf; ap = argv;              /* break into words */
       for ( ; ; ) {
              while (isspace(*cp))
                     *cp++ = '\0';
              if (!*cp)
                     break;
              if (ap - argv >= MG_MAXARGC-1)
                     return(MG_EARGC);
              *ap++ = cp;
              while (*++cp && !isspace(*cp))
                     ;
       }
       if (ap == argv)
              return(MG_OK);              /* no words in line */
       *ap = NULL;
                                   /* else handle it */
       return(mg_handle(-1, ap-argv, argv));
}

Here is the call graph for this function:

Here is the caller graph for this function:

int mg_read ( void  )

Definition at line 301 of file parser.c.

{
       register int  len = 0;

       do {
              if (fgets(mg_file->inpline+len,
                            MG_MAXLINE-len, mg_file->fp) == NULL)
                     return(len);
              len += strlen(mg_file->inpline+len);
              if (len >= MG_MAXLINE-1)
                     return(len);
              mg_file->lineno++;
       } while (len > 1 && mg_file->inpline[len-2] == '\\');

       return(len);
}

Here is the caller graph for this function:

void mgf2rgb ( C_COLOR cin,
double  intensity,
float  cout[3] 
)
void multmat4 ( MAT4  ,
MAT4  ,
MAT4   
)

Definition at line 18 of file mat4.c.

{
       register int  i, j;
       
       for (i = 4; i--; )
              for (j = 4; j--; )
                     m4tmp[i][j] = m4b[i][0]*m4c[0][j] +
                                  m4b[i][1]*m4c[1][j] +
                                  m4b[i][2]*m4c[2][j] +
                                  m4b[i][3]*m4c[3][j];
       
       copymat4(m4a, m4tmp);
}

Here is the caller graph for this function:

void multp3 ( FVECT  ,
FVECT  ,
MAT4   
)

Definition at line 52 of file mat4.c.

{
       multv3(p3a, p3b, m4);       /* transform as vector */
       p3a[0] += m4[3][0];  /* translate */
       p3a[1] += m4[3][1];
       p3a[2] += m4[3][2];
}

Here is the call graph for this function:

Here is the caller graph for this function:

void multv3 ( FVECT  ,
FVECT  ,
MAT4   
)

Definition at line 36 of file mat4.c.

{
       m4tmp[0][0] = v3b[0]*m4[0][0] + v3b[1]*m4[1][0] + v3b[2]*m4[2][0];
       m4tmp[0][1] = v3b[0]*m4[0][1] + v3b[1]*m4[1][1] + v3b[2]*m4[2][1];
       m4tmp[0][2] = v3b[0]*m4[0][2] + v3b[1]*m4[1][2] + v3b[2]*m4[2][2];
       
       v3a[0] = m4tmp[0][0];
       v3a[1] = m4tmp[0][1];
       v3a[2] = m4tmp[0][2];
}

Here is the caller graph for this function:

XF_SPEC* new_xf ( int  ,
char **   
)

Definition at line 91 of file xf.c.

{
       register XF_SPEC     *spec;
       register int  i;
       char   *cp;
       int    n, ndim;

       ndim = 0;
       n = 0;                      /* compute space req'd by arguments */
       for (i = 0; i < ac; i++)
              if (!strcmp(av[i], "-a")) {
                     ndim++;
                     i++;
              } else
                     n += strlen(av[i]) + 1;
       if (ndim > XF_MAXDIM)
              return(NULL);
       spec = (XF_SPEC *)malloc(sizeof(XF_SPEC) + n);
       if (spec == NULL)
              return(NULL);
       if (ndim) {
              spec->xarr = (struct xf_array *)malloc(sizeof(struct xf_array));
              if (spec->xarr == NULL)
                     return(NULL);
              mg_fgetpos(&spec->xarr->spos);
              spec->xarr->ndim = 0;              /* incremented below */
       } else
              spec->xarr = NULL;
       spec->xac = ac + xf_argc;
                                   /* and store new xf arguments */
       if (xf_argbeg == NULL || xf_av(spec) < xf_argbeg) {
              register char **newav =
                            (char **)malloc((spec->xac+1)*sizeof(char *));
              if (newav == NULL)
                     return(NULL);
              for (i = xf_argc; i-- > 0; )
                     newav[ac+i] = xf_argend[i-xf_context->xac];
              *(xf_argend = newav + spec->xac) = NULL;
              if (xf_argbeg != NULL)
                     free((MEM_PTR)xf_argbeg);
              xf_argbeg = newav;
       }
       cp = (char *)(spec + 1);    /* use memory allocated above */
       for (i = 0; i < ac; i++)
              if (!strcmp(av[i], "-a")) {
                     xf_av(spec)[i++] = "-i";
                     xf_av(spec)[i] = strcpy(
                                   spec->xarr->aarg[spec->xarr->ndim].arg,
                                   "0");
                     spec->xarr->aarg[spec->xarr->ndim].i = 0;
                     spec->xarr->aarg[spec->xarr->ndim++].n = atoi(av[i]);
              } else {
                     xf_av(spec)[i] = strcpy(cp, av[i]);
                     cp += strlen(av[i]) + 1;
              }
       return(spec);
}

Here is the call graph for this function:

Here is the caller graph for this function:

double normalize ( FVECT  )

Definition at line 111 of file fvect.c.

{
       double  len, d;
       
       d = DOT(v, v);
       
       if (d == 0.0)
              return(0.0);
       
       if (d <= 1.0+FTINY && d >= 1.0-FTINY)
              len = 0.5 + 0.5*d;   /* first order approximation */
       else
              len = sqrt(d);

       v[0] *= d = 1.0/len;
       v[1] *= d;
       v[2] *= d;

       return(len);
}
void obj_clear ( void  )

Definition at line 59 of file object.c.

{
       while (obj_nnames)
              free((MEM_PTR)obj_name[--obj_nnames]);
       if (obj_maxname) {
              free((MEM_PTR)obj_name);
              obj_maxname = 0;
       }
}
int obj_handler ( int  ,
char **   
)

Definition at line 23 of file object.c.

{
       if (ac == 1) {                            /* just pop top object */
              if (obj_nnames < 1)
                     return(MG_ECNTXT);
              free((MEM_PTR)obj_name[--obj_nnames]);
              obj_name[obj_nnames] = NULL;
              return(MG_OK);
       }
       if (ac != 2)
              return(MG_EARGC);
       if (!isname(av[1]))
              return(MG_EILL);
       if (obj_nnames >= obj_maxname-1) { /* enlarge array */
              if (!obj_maxname)
                     obj_name = (char **)malloc(
                            (obj_maxname=ALLOC_INC)*sizeof(char *));
              else
                     obj_name = (char **)realloc((MEM_PTR)obj_name,
                            (obj_maxname+=ALLOC_INC)*sizeof(char *));
              if (obj_name == NULL)
                     return(MG_EMEM);
       }
                                          /* allocate new entry */
       obj_name[obj_nnames] = (char *)malloc(strlen(av[1])+1);
       if (obj_name[obj_nnames] == NULL)
              return(MG_EMEM);
       strcpy(obj_name[obj_nnames++], av[1]);
       obj_name[obj_nnames] = NULL;
       return(MG_OK);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int xf ( XF ,
int  ,
char **   
)

Definition at line 317 of file xf.c.

{
       MAT4  xfmat, m4;
       double  xfsca, dtmp;
       int  i, icnt;

       setident4(ret->xfm);
       ret->sca = 1.0;

       icnt = 1;
       setident4(xfmat);
       xfsca = 1.0;

       for (i = 0; i < ac && av[i][0] == '-'; i++) {
       
              setident4(m4);
              
              switch (av[i][1]) {
       
              case 't':                   /* translate */
                     checkarg(2,"fff");
                     m4[3][0] = atof(av[++i]);
                     m4[3][1] = atof(av[++i]);
                     m4[3][2] = atof(av[++i]);
                     break;

              case 'r':                   /* rotate */
                     switch (av[i][2]) {
                     case 'x':
                            checkarg(3,"f");
                            dtmp = d2r(atof(av[++i]));
                            m4[1][1] = m4[2][2] = cos(dtmp);
                            m4[2][1] = -(m4[1][2] = sin(dtmp));
                            break;
                     case 'y':
                            checkarg(3,"f");
                            dtmp = d2r(atof(av[++i]));
                            m4[0][0] = m4[2][2] = cos(dtmp);
                            m4[0][2] = -(m4[2][0] = sin(dtmp));
                            break;
                     case 'z':
                            checkarg(3,"f");
                            dtmp = d2r(atof(av[++i]));
                            m4[0][0] = m4[1][1] = cos(dtmp);
                            m4[1][0] = -(m4[0][1] = sin(dtmp));
                            break;
                     default:
                            goto done;
                     }
                     break;

              case 's':                   /* scale */
                     checkarg(2,"f");
                     dtmp = atof(av[i+1]);
                     if (dtmp == 0.0) goto done;
                     i++;
                     xfsca *=
                     m4[0][0] = 
                     m4[1][1] = 
                     m4[2][2] = dtmp;
                     break;

              case 'm':                   /* mirror */
                     switch (av[i][2]) {
                     case 'x':
                            checkarg(3,"");
                            xfsca *=
                            m4[0][0] = -1.0;
                            break;
                     case 'y':
                            checkarg(3,"");
                            xfsca *=
                            m4[1][1] = -1.0;
                            break;
                     case 'z':
                            checkarg(3,"");
                            xfsca *=
                            m4[2][2] = -1.0;
                            break;
                     default:
                            goto done;
                     }
                     break;

              case 'i':                   /* iterate */
                     checkarg(2,"i");
                     while (icnt-- > 0) {
                            multmat4(ret->xfm, ret->xfm, xfmat);
                            ret->sca *= xfsca;
                     }
                     icnt = atoi(av[++i]);
                     setident4(xfmat);
                     xfsca = 1.0;
                     continue;

              default:
                     goto done;

              }
              multmat4(xfmat, xfmat, m4);
       }
done:
       while (icnt-- > 0) {
              multmat4(ret->xfm, ret->xfm, xfmat);
              ret->sca *= xfsca;
       }
       return(i);
}

Here is the call graph for this function:

int xf_aname ( struct xf_array )

Definition at line 163 of file xf.c.

{
       static char   oname[10*XF_MAXDIM];
       static char   *oav[3] = {mg_ename[MG_E_OBJECT], oname};
       register int  i;
       register char *cp1, *cp2;

       if (ap == NULL)
              return(mg_handle(MG_E_OBJECT, 1, oav));
       cp1 = oname;
       *cp1 = 'a';
       for (i = 0; i < ap->ndim; i++) {
              for (cp2 = ap->aarg[i].arg; *cp2; )
                     *++cp1 = *cp2++;
              *++cp1 = '.';
       }
       *cp1 = '\0';
       return(mg_handle(MG_E_OBJECT, 2, oav));
}

Here is the call graph for this function:

Here is the caller graph for this function:

void xf_clear ( void  )

Definition at line 207 of file xf.c.

{
       register XF_SPEC     *spec;

       if (xf_argbeg != NULL) {
              free((MEM_PTR)xf_argbeg);
              xf_argbeg = xf_argend = NULL;
       }
       while ((spec = xf_context) != NULL) {
              xf_context = spec->prev;
              free_xf(spec);
       }
}

Here is the call graph for this function:

int xf_handler ( int  ,
char **   
)

Definition at line 28 of file xf.c.

{
       register XF_SPEC     *spec;
       register int  n;
       int    rv;

       if (ac == 1) {                     /* something with existing transform */
              if ((spec = xf_context) == NULL)
                     return(MG_ECNTXT);
              n = -1;
              if (spec->xarr != NULL) {   /* check for iteration */
                     register struct xf_array    *ap = spec->xarr;

                     (void)xf_aname((struct xf_array *)NULL);
                     n = ap->ndim;
                     while (n--) {
                            if (++ap->aarg[n].i < ap->aarg[n].n)
                                   break;
                            (void)strcpy(ap->aarg[n].arg, "0");
                            ap->aarg[n].i = 0;
                     }
                     if (n >= 0) {
                            if ((rv = mg_fgoto(&ap->spos)) != MG_OK)
                                   return(rv);
                            sprintf(ap->aarg[n].arg, "%d", ap->aarg[n].i);
                            (void)xf_aname(ap);
                     }
              }
              if (n < 0) {                /* pop transform */
                     xf_context = spec->prev;
                     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);
       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 */
       if ((spec->rev = (spec->xf.sca < 0.)))
              spec->xf.sca = -spec->xf.sca;
                                   /* compute total transformation */
       if (spec->prev != NULL) {
              multmat4(spec->xf.xfm, spec->xf.xfm, spec->prev->xf.xfm);
              spec->xf.sca *= spec->prev->xf.sca;
              spec->rev ^= spec->prev->rev;
       }
       spec->xid = comp_xfid(spec->xf.xfm);      /* compute unique ID */
       return(MG_OK);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void xf_rotvect ( FVECT  ,
FVECT   
)

Definition at line 247 of file xf.c.

{
       xf_xfmvect(v1, v2);
       if (xf_context == NULL)
              return;
       v1[0] /= xf_context->xf.sca;
       v1[1] /= xf_context->xf.sca;
       v1[2] /= xf_context->xf.sca;
}

Here is the call graph for this function:

Here is the caller graph for this function:

double xf_scale ( double  )

Definition at line 260 of file xf.c.

{
       if (xf_context == NULL)
              return(d);
       return(d*xf_context->xf.sca);
}

Here is the caller graph for this function:

void xf_xfmpoint ( FVECT  ,
FVECT   
)

Definition at line 223 of file xf.c.

{
       if (xf_context == NULL) {
              VCOPY(v1, v2);
              return;
       }
       multp3(v1, v2, xf_context->xf.xfm);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void xf_xfmvect ( FVECT  ,
FVECT   
)

Definition at line 235 of file xf.c.

{
       if (xf_context == NULL) {
              VCOPY(v1, v2);
              return;
       }
       multv3(v1, v2, xf_context->xf.xfm);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

char* c_ccname

Definition at line 27 of file context.c.

Definition at line 26 of file context.c.

Definition at line 28 of file context.c.

char* c_cmname

Definition at line 29 of file context.c.

Definition at line 30 of file context.c.

char* c_cvname

Definition at line 31 of file context.c.

Definition at line 12 of file mat4.c.

int(* mg_ehand[MG_NENTITIES])(int argc, char **argv)

Definition at line 26 of file parser.c.

Definition at line 22 of file parser.c.

char* mg_err[MG_NERRS]

Definition at line 36 of file parser.c.

Definition at line 38 of file parser.c.

Definition at line 40 of file parser.c.

unsigned mg_nunknown

Definition at line 32 of file parser.c.

int(* mg_uhand)(int argc, char **argv)

Definition at line 30 of file parser.c.

char** obj_name

Definition at line 250 of file 3ds2mgf.c.

Definition at line 14 of file object.c.

char** xf_argend

Definition at line 23 of file xf.c.

Definition at line 22 of file xf.c.