Back to index

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

Go to the source code of this file.

Classes

struct  FUNARGS
struct  OBJREC

Defines

#define OCTREE   int
#define MAXSTR   128 /* maximum string length */
#define OBJECT   int32 /* index to object array */
#define MAXOBJBLK   65535 /* maximum number of object blocks */
#define OBJBLKSHFT   9
#define OBJBLKSIZ   (1<<OBJBLKSHFT) /* object block size */
#define objptr(obj)   (objblock[(obj)>>OBJBLKSHFT]+((obj)&(OBJBLKSIZ-1)))
#define OVOID   (-1) /* void object */
#define VOIDID   "void" /* void identifier */
#define MAXSET   511 /* maximum object set size */
#define setfree(os)   free((void *)(os))

Functions

OBJECT objndx (OBJREC *op)
OBJECT lastmod (OBJECT obj, char *mname)
OBJECT modifier (char *name)
OBJECT object (char *oname)
void insertobject (OBJECT obj)
void clearobjndx (void)
void insertelem (OBJECT *os, OBJECT obj)
void deletelem (OBJECT *os, OBJECT obj)
int inset (OBJECT *os, OBJECT obj)
int setequal (OBJECT *os1, OBJECT *os2)
void setcopy (OBJECT *os1, OBJECT *os2)
OBJECTsetsave (OBJECT *os)
void setunion (OBJECT *osr, OBJECT *os1, OBJECT *os2)
void setintersect (OBJECT *osr, OBJECT *os1, OBJECT *os2)
OCTREE fullnode (OBJECT *oset)
void objset (OBJECT *oset, OCTREE ot)
int dosets (int(*f)())
void donesets (void)
int otype (char *ofname)
void objerror (OBJREC *o, int etyp, char *msg)
int readfargs (FUNARGS *fa, FILE *fp)
void freefargs (FUNARGS *fa)
void readobj (char *inpspec)
void getobject (char *name, FILE *fp)
OBJECT newobject (void)
void freeobjects (int firstobj, int nobjs)
int free_os (OBJREC *op)

Variables

OBJRECobjblock [MAXOBJBLK]
OBJECT nobjects
void(* addobjnotify [])()

Class Documentation

struct FUNARGS

Definition at line 24 of file object.h.

Class Members
RREAL * farg
short nfargs
short nsargs
char ** sarg
struct OBJREC

Definition at line 51 of file object.h.

Collaboration diagram for OBJREC:
Class Members
FUNARGS oargs
OBJECT omod
char * oname
char * os
short otype

Define Documentation

#define MAXOBJBLK   65535 /* maximum number of object blocks */

Definition at line 63 of file object.h.

#define MAXSET   511 /* maximum object set size */

Definition at line 82 of file object.h.

#define MAXSTR   128 /* maximum string length */

Definition at line 35 of file object.h.

#define OBJBLKSHFT   9

Definition at line 70 of file object.h.

#define OBJBLKSIZ   (1<<OBJBLKSHFT) /* object block size */

Definition at line 71 of file object.h.

#define OBJECT   int32 /* index to object array */

Definition at line 47 of file object.h.

#define objptr (   obj)    (objblock[(obj)>>OBJBLKSHFT]+((obj)&(OBJBLKSIZ-1)))

Definition at line 72 of file object.h.

#define OCTREE   int

Definition at line 14 of file object.h.

#define OVOID   (-1) /* void object */

Definition at line 74 of file object.h.

#define setfree (   os)    free((void *)(os))

Definition at line 84 of file object.h.

#define VOIDID   "void" /* void identifier */

Definition at line 75 of file object.h.


Function Documentation

void clearobjndx ( void  )

Definition at line 108 of file modobject.c.

{
       if (modtab.htab != NULL) {
              free((void *)modtab.htab);
              modtab.htab = NULL;
              modtab.hsiz = 100;
       }
       if (objtab.htab != NULL) {
              free((void *)objtab.htab);
              objtab.htab = NULL;
              objtab.hsiz = 100;
       }
}

Here is the caller graph for this function:

void deletelem ( OBJECT os,
OBJECT  obj 
)

Definition at line 46 of file objset.c.

{
       register int  i;

       i = (*os)--;
       os++;
       while (i > 0 && *os < obj) {
              i--;
              os++;
       }
       while (--i > 0) {
              os[0] = os[1];
              os++;
       }
}

Here is the caller graph for this function:

void donesets ( void  )

Definition at line 262 of file objset.c.

{
       register int  n;

       for (n = 0; n < OSTSIZ; n++) 
              if (ostable[n] != NULL) {
                     free((void *)ostable[n]);
                     ostable[n] = NULL;
              }
}

Here is the caller graph for this function:

int dosets ( int(*)()  f)
int free_os ( OBJREC op)

Definition at line 23 of file free_os.c.

{
       if (op->os == NULL)
              return(0);
       switch (op->otype) {
       case OBJ_FACE:              /* polygon */
              freeface(op);
              return(1);
       case OBJ_CONE:              /* cone */
       case OBJ_RING:              /* disk */
       case OBJ_CYLINDER:   /* cylinder */
       case OBJ_CUP:        /* inverted cone */
       case OBJ_TUBE:              /* inverted cylinder */
              freecone(op);
              return(1);
       case OBJ_INSTANCE:   /* octree instance */
              freeinstance(op);
              return(1);
       case OBJ_MESH:              /* mesh instance */
              freemeshinst(op);
              return(1);
       }
                            /* don't really know */
       free((void *)op->os);
       op->os = NULL;
       return(1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void freefargs ( FUNARGS fa)

Definition at line 79 of file readfargs.c.

{
       register int  i;

       if (fa->nsargs) {
              for (i = 0; i < fa->nsargs; i++)
                     freestr(fa->sarg[i]);
              free((void *)fa->sarg);
              fa->sarg = NULL;
              fa->nsargs = 0;
       }
#ifdef  IARGS
       if (fa->niargs) {
              free((void *)fa->iarg);
              fa->iarg = NULL;
              fa->niargs = 0;
       }
#endif
       if (fa->nfargs) {
              free((void *)fa->farg);
              fa->farg = NULL;
              fa->nfargs = 0;
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void freeobjects ( int  firstobj,
int  nobjs 
)

Definition at line 178 of file readobj.c.

{
       register int  obj;
                                   /* check bounds */
       if (firstobj < 0)
              return;
       if (nobjs <= 0)
              return;
       if (firstobj + nobjs > nobjects)
              return;
                                   /* clear objects */
       for (obj = firstobj+nobjs; obj-- > firstobj; ) {
              register OBJREC  *o = objptr(obj);
              free_os(o);          /* free client memory */
              freeqstr(o->oname);
              freefargs(&o->oargs);
              memset((void *)o, '\0', sizeof(OBJREC));
       }
       clearobjndx();
                                   /* free objects off end */
       for (obj = nobjects; obj-- > 0; )
              if (objptr(obj)->oname != NULL)
                     break;
       ++obj;
       while (nobjects > obj)             /* free empty end blocks */
              if ((--nobjects & (OBJBLKSIZ-1)) == 0) {
                     int    i = nobjects >> OBJBLKSHFT;
                     free((void *)objblock[i]);
                     objblock[i] = NULL;
              }
}

Here is the call graph for this function:

Here is the caller graph for this function:

OCTREE fullnode ( OBJECT oset)

Definition at line 180 of file objset.c.

{
       int  osentry, ntries;
       long  hval;
       OCTREE  ot;
       register int  i;
       register OBJECT  *os;
                                   /* hash on set */
       hval = 0;
       os = oset;
       i = *os++;
       while (i-- > 0)
              hval += *os++;
       ntries = 0;
tryagain:
       osentry = (hval + (long)ntries*ntries) % OSTSIZ;
       os = ostable[osentry];
       if (os == NULL) {
              os = ostable[osentry] = (OBJECT *)malloc(
                            (unsigned)(oset[0]+2)*sizeof(OBJECT));
              if (os == NULL)
                     goto memerr;
              ot = oseti(osentry);
       } else {
                                          /* look for set */
              for (i = 0; *os > 0; i++, os += *os + 1)
                     if (setequal(os, oset))
                            break;
              ot = oseti(i*OSTSIZ + osentry);
              if (*os > 0)                /* found it */
                     return(ot);
              if (!isfull(ot)) {          /* entry overflow */
                     if (++ntries < OSTSIZ)
                            goto tryagain;
                     else
                            error(INTERNAL, "hash table overflow in fullnode");
              }
                                          /* remember position */
              i = os - ostable[osentry];
              os = ostable[osentry] = (OBJECT *)realloc(
                            (void *)ostable[osentry],
                            (unsigned)(i+oset[0]+2)*sizeof(OBJECT));
              if (os == NULL)
                     goto memerr;
              os += i;                    /* last entry */
       }
       setcopy(os, oset);          /* add new set */
       os += *os + 1;
       *os = 0;                    /* terminator */
       return(ot);
memerr:
       error(SYSTEM, "out of memory in fullnode");
       return 0; /* pro forma return */
}

Here is the call graph for this function:

Here is the caller graph for this function:

void getobject ( char *  name,
FILE *  fp 
)

Definition at line 75 of file readobj.c.

{
#define       OALIAS -2
       OBJECT  obj;
       char  sbuf[MAXSTR];
       int  rval;
       register OBJREC  *objp;

       if ((obj = newobject()) == OVOID)
              error(SYSTEM, "out of object space");
       objp = objptr(obj);
                                   /* get modifier */
       strcpy(sbuf, "EOF");
       fgetword(sbuf, MAXSTR, fp);
       if (strchr(sbuf, '\t')) {
              sprintf(errmsg, "(%s): illegal tab in modifier \"%s\"",
                                   name, sbuf);
              error(USER, errmsg);
       }
       if (!strcmp(sbuf, VOIDID))
              objp->omod = OVOID;
       else if (!strcmp(sbuf, ALIASMOD))
              objp->omod = OALIAS;
       else if ((objp->omod = modifier(sbuf)) == OVOID) {
              sprintf(errmsg, "(%s): undefined modifier \"%s\"", name, sbuf);
              error(USER, errmsg);
       }
                                   /* get type */
       strcpy(sbuf, "EOF");
       fgetword(sbuf, MAXSTR, fp);
       if ((objp->otype = otype(sbuf)) < 0) {
              sprintf(errmsg, "(%s): unknown type \"%s\"", name, sbuf);
              error(USER, errmsg);
       }
                                   /* get identifier */
       sbuf[0] = '\0';
       fgetword(sbuf, MAXSTR, fp);
       if (strchr(sbuf, '\t')) {
              sprintf(errmsg, "(%s): illegal tab in identifier \"%s\"",
                                   name, sbuf);
              error(USER, errmsg);
       }
       objp->oname = savqstr(sbuf);
                                   /* get arguments */
       if (objp->otype == MOD_ALIAS) {
              register OBJECT  alias;
              strcpy(sbuf, "EOF");
              fgetword(sbuf, MAXSTR, fp);
              if ((alias = modifier(sbuf)) == OVOID) {
                     sprintf(errmsg, "(%s): bad reference \"%s\"",
                                   name, sbuf);
                     objerror(objp, USER, errmsg);
              }
              if (objp->omod == OALIAS || 
                            objp->omod == objptr(alias)->omod) {
                     objp->omod = alias;
              } else {
                     objp->oargs.sarg = (char **)malloc(sizeof(char *));
                     if (objp->oargs.sarg == NULL)
                            error(SYSTEM, "out of memory in getobject");
                     objp->oargs.nsargs = 1;
                     objp->oargs.sarg[0] = savestr(sbuf);
              }
       } else if ((rval = readfargs(&objp->oargs, fp)) == 0) {
              sprintf(errmsg, "(%s): bad arguments", name);
              objerror(objp, USER, errmsg);
       } else if (rval < 0) {
              sprintf(errmsg, "(%s): error reading scene", name);
              error(SYSTEM, errmsg);
       }
       if (objp->omod == OALIAS) {
              sprintf(errmsg, "(%s): inappropriate use of '%s' modifier",
                            name, ALIASMOD);
              objerror(objp, USER, errmsg);
       }
                                   /* initialize */
       objp->os = NULL;

       insertobject(obj);          /* add to global structure */
#undef OALIAS
}

Here is the call graph for this function:

Here is the caller graph for this function:

void insertelem ( OBJECT os,
OBJECT  obj 
)

Definition at line 30 of file objset.c.

{
       register int  i;
       
       for (i = os[0]++; i > 0; i--)
              if (os[i] > obj)
                     os[i+1] = os[i];
              else
                     break;
       os[i+1] = obj;
}

Here is the caller graph for this function:

void insertobject ( OBJECT  obj)

Definition at line 87 of file modobject.c.

{
       register int  i;

       if (ismodifier(objptr(obj)->otype)) {
              i = otndx(objptr(obj)->oname, &modtab);
              modtab.htab[i] = obj;
       }
#ifdef  GETOBJ
       else {
              i = otndx(objptr(obj)->oname, &objtab);
              objtab.htab[i] = obj;
       }
#endif
       for (i = 0; addobjnotify[i] != NULL; i++)
              (*addobjnotify[i])(obj);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int inset ( OBJECT os,
OBJECT  obj 
)

Definition at line 66 of file objset.c.

{
       int  upper, lower;
       register int  cm, i;

       if ((i = os[0]) <= 12) {    /* linear search algorithm */
              cm = obj;
              while (i-- > 0)
                     if (*++os == cm)
                            return(1);
              return(0);
       }
       lower = 1;
       upper = cm = i + 1;
                                   /* binary search algorithm */
       while ((i = (lower + upper) >> 1) != cm) {
              cm = obj - os[i];
              if (cm > 0)
                     lower = i;
              else if (cm < 0)
                     upper = i;
              else
                     return(1);
              cm = i;
       }
       return(0);
}

Here is the caller graph for this function:

OBJECT lastmod ( OBJECT  obj,
char *  mname 
)

Definition at line 43 of file modobject.c.

{
       register OBJREC  *op;
       register int  i;

       i = modifier(mname);        /* try hash table first */
       if ((obj == OVOID) | (i < obj))
              return(i);
       for (i = obj; i-- > 0; ) {  /* need to search */
              op = objptr(i);
              if (ismodifier(op->otype) && !strcmp(op->oname, mname))
                     return(i);
       }
       return(OVOID);
}

Here is the call graph for this function:

Here is the caller graph for this function:

OBJECT modifier ( char *  name)

Definition at line 63 of file modobject.c.

{
       register int  ndx;

       ndx = otndx(mname, &modtab);
       return(modtab.htab[ndx]);
}

Here is the call graph for this function:

Here is the caller graph for this function:

OBJECT newobject ( void  )

Definition at line 161 of file readobj.c.

{
       register int  i;

       if ((nobjects & (OBJBLKSIZ-1)) == 0) {    /* new block */
              errno = 0;
              i = nobjects >> OBJBLKSHFT;
              if (i >= MAXOBJBLK)
                     return(OVOID);
              objblock[i] = (OBJREC *)calloc(OBJBLKSIZ, sizeof(OBJREC));
              if (objblock[i] == NULL)
                     return(OVOID);
       }
       return(nobjects++);
}

Here is the caller graph for this function:

OBJECT object ( char *  oname)

Here is the caller graph for this function:

void objerror ( OBJREC o,
int  etyp,
char *  msg 
)

Definition at line 34 of file otypes.c.

{
       char  msgbuf[128];

       sprintf(msgbuf, "%s for %s \"%s\"",
                     msg, ofun[o->otype].funame,
                     o->oname!=NULL ? o->oname : "(NULL)");
       error(etyp, msgbuf);
}

Here is the call graph for this function:

OBJECT objndx ( OBJREC op)

Definition at line 28 of file modobject.c.

{
       register int  i, j;

       for (i = nobjects>>OBJBLKSHFT; i >= 0; i--) {
              j = op - objblock[i];
              if ((j >= 0) & (j < OBJBLKSIZ))
                     return((i<<OBJBLKSHFT) + j);
       }
       return(OVOID);
}

Here is the caller graph for this function:

void objset ( OBJECT oset,
OCTREE  ot 
)

Definition at line 238 of file objset.c.

{
       register OBJECT  *os;
       register int  i;

       if (!isfull(ot))
              goto noderr;
       ot = oseti(ot);
       if ((os = ostable[ot%OSTSIZ]) == NULL)
              goto noderr;
       for (i = ot/OSTSIZ; i--; os += *os + 1)
              if (*os <= 0)
                     goto noderr;
       for (i = *os; i-- >= 0; )          /* copy set here */
              *oset++ = *os++;
       return;
noderr:
       error(CONSISTENCY, "bad node in objset");
}

Here is the call graph for this function:

Here is the caller graph for this function:

int otype ( char *  ofname)

Definition at line 20 of file otypes.c.

{
       register int  i;

       for (i = 0; i < NUMOTYPE; i++)
              if (!strcmp(ofun[i].funame, ofname))
                     return(i);

       return(-1);          /* not found */
}

Here is the call graph for this function:

int readfargs ( FUNARGS fa,
FILE *  fp 
)

Definition at line 17 of file readfargs.c.

{
#define getstr(s)    (fgetword(s,sizeof(s),fp)!=NULL)
#define getint(s)    (getstr(s) && isint(s))
#define getflt(s)    (getstr(s) && isflt(s))
       char  sbuf[MAXSTR];
       register int  n, i;

       if (!getint(sbuf) || (n = atoi(sbuf)) < 0)
              return(0);
       if ( (fa->nsargs = n) ) {
              fa->sarg = (char **)malloc(n*sizeof(char *));
              if (fa->sarg == NULL)
                     return(-1);
              for (i = 0; i < fa->nsargs; i++) {
                     if (!getstr(sbuf))
                            return(0);
                     fa->sarg[i] = savestr(sbuf);
              }
       } else
              fa->sarg = NULL;
       if (!getint(sbuf) || (n = atoi(sbuf)) < 0)
              return(0);
#ifdef  IARGS
       if (fa->niargs = n) {
              fa->iarg = (long *)malloc(n*sizeof(long));
              if (fa->iarg == NULL)
                     return(-1);
              for (i = 0; i < n; i++) {
                     if (!getint(sbuf))
                            return(0);
                     fa->iarg[i] = atol(sbuf);
              }
       } else
              fa->iarg = NULL;
#else
       if (n != 0)
              return(0);
#endif
       if (!getint(sbuf) || (n = atoi(sbuf)) < 0)
              return(0);
       if ( (fa->nfargs = n) ) {
              fa->farg = (RREAL *)malloc(n*sizeof(RREAL));
              if (fa->farg == NULL)
                     return(-1);
              for (i = 0; i < n; i++) {
                     if (!getflt(sbuf))
                            return(0);
                     fa->farg[i] = atof(sbuf);
              }
       } else
              fa->farg = NULL;
       return(1);
#undef getflt
#undef getint
#undef getstr
}

Here is the call graph for this function:

Here is the caller graph for this function:

void readobj ( char *  inpspec)

Definition at line 28 of file readobj.c.

{
       OBJECT  lastobj;
       FILE  *infp;
       char  buf[2048];
       register int  c;

       lastobj = nobjects;
       if (inpspec == NULL) {
              infp = stdin;
              inpspec = "standard input";
       } else if (inpspec[0] == '!') {
              if ((infp = popen(inpspec+1, "r")) == NULL) {
                     sprintf(errmsg, "cannot execute \"%s\"", inpspec);
                     error(SYSTEM, errmsg);
              }
       } else if ((infp = fopen(inpspec, "r")) == NULL) {
              sprintf(errmsg, "cannot open scene file \"%s\"", inpspec);
              error(SYSTEM, errmsg);
       }
       while ((c = getc(infp)) != EOF) {
              if (isspace(c))
                     continue;
              if (c == '#') {                           /* comment */
                     fgets(buf, sizeof(buf), infp);
              } else if (c == '!') {                    /* command */
                     ungetc(c, infp);
                     fgetline(buf, sizeof(buf), infp);
                     readobj(buf);
              } else {                           /* object */
                     ungetc(c, infp);
                     getobject(inpspec, infp);
              }
       }
       if (inpspec[0] == '!')
              pclose(infp);
       else
              fclose(infp);
       if (nobjects == lastobj) {
              sprintf(errmsg, "(%s): empty file", inpspec);
              error(WARNING, errmsg);
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void setcopy ( OBJECT os1,
OBJECT os2 
)

Definition at line 111 of file objset.c.

{
       register int  i;

       for (i = *os2; i-- >= 0; )
              *os1++ = *os2++;
}

Here is the caller graph for this function:

int setequal ( OBJECT os1,
OBJECT os2 
)

Definition at line 98 of file objset.c.

{
       register int  i;

       for (i = *os1; i-- >= 0; )
              if (*os1++ != *os2++)
                     return(0);
       return(1);
}

Here is the caller graph for this function:

void setintersect ( OBJECT osr,
OBJECT os1,
OBJECT os2 
)

Definition at line 158 of file objset.c.

{
       register int  i1, i2;

       osr[0] = 0;
       if (os1[0] <= 0)
              return;
       for (i1 = i2 = 1; i2 <= os2[0]; ) {
              while (os1[i1] < os2[i2])
                     if (++i1 > os1[0])
                            return;
              while (os2[i2] < os1[i1])
                     if (++i2 > os2[0])
                            return;
              if (os1[i1] == os2[i2])
                     osr[++osr[0]] = os2[i2++];
       }
}
OBJECT* setsave ( OBJECT os)

Definition at line 122 of file objset.c.

{
       OBJECT  *osnew;
       register OBJECT  *oset;
       register int  i;

       if ((osnew = oset = (OBJECT *)malloc((*os+1)*sizeof(OBJECT))) == NULL)
              error(SYSTEM, "out of memory in setsave\n");
       for (i = *os; i-- >= 0; )   /* inline setcopy */
              *oset++ = *os++;
       return(osnew);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void setunion ( OBJECT osr,
OBJECT os1,
OBJECT os2 
)

Definition at line 138 of file objset.c.

{
       register int  i1, i2;

       osr[0] = 0;
       for (i1 = i2 = 1; i1 <= os1[0] || i2 <= os2[0]; ) {
              while (i1 <= os1[0] && (i2 > os2[0] || os1[i1] <= os2[i2])) {
                     osr[++osr[0]] = os1[i1];
                     if (i2 <= os2[0] && os2[i2] == os1[i1])
                            i2++;
                     i1++;
              }
              while (i2 <= os2[0] && (i1 > os1[0] || os2[i2] < os1[i1]))
                     osr[++osr[0]] = os2[i2++];
       }
}

Here is the caller graph for this function:


Variable Documentation

void(* addobjnotify[])()

Definition at line 10 of file addobjnotify.c.

Definition at line 24 of file readobj.c.

Definition at line 23 of file readobj.c.