Back to index

radiance  4R0+20100331
Functions | Variables
sceneio.c File Reference
#include "copyright.h"
#include "standard.h"
#include "octree.h"
#include "object.h"
#include "otypes.h"

Go to the source code of this file.

Functions

static int getobj (FILE *fp, int objsiz)
void readscene (FILE *fp, int objsiz)
static void putobj (OBJREC *o, FILE *fp)
void writescene (int firstobj, int nobjs, FILE *fp)

Variables

static const char RCSid [] = "$Id: sceneio.c,v 2.4 2003/06/26 00:58:09 schorsch Exp $"
static OBJECT object0
static short otypmap [NUMOTYPE+32]

Function Documentation

static int getobj ( FILE *  fp,
int  objsiz 
) [static]

Definition at line 21 of file sceneio.c.

{
       char  sbuf[MAXSTR];
       int  obj;
       register int  i;
       register long  m;
       register OBJREC       *objp;

       i = getint(1, fp);
       if (i == -1)
              return(OVOID);              /* terminator */
       if ((obj = newobject()) == OVOID)
              error(SYSTEM, "out of object space");
       objp = objptr(obj);
       if ((objp->otype = otypmap[i]) < 0)
              error(USER, "reference to unknown type");
       if ((m = getint(objsiz, fp)) != OVOID) {
              m += object0;
              if ((OBJECT)m != m)
                     error(INTERNAL, "too many objects in getobj");
       }
       objp->omod = m;
       objp->oname = savqstr(getstr(sbuf, fp));
       if ((objp->oargs.nsargs = getint(2, fp)) > 0) {
              objp->oargs.sarg = (char **)malloc
                            (objp->oargs.nsargs*sizeof(char *));
              if (objp->oargs.sarg == NULL)
                     goto memerr;
              for (i = 0; i < objp->oargs.nsargs; i++)
                     objp->oargs.sarg[i] = savestr(getstr(sbuf, fp));
       } else
              objp->oargs.sarg = NULL;
#ifdef IARGS
       if ((objp->oargs.niargs = getint(2, fp)) > 0) {
              objp->oargs.iarg = (long *)malloc
                            (objp->oargs.niargs*sizeof(long));
              if (objp->oargs.iarg == NULL)
                     goto memerr;
              for (i = 0; i < objp->oargs.niargs; i++)
                     objp->oargs.iarg[i] = getint(4, fp);
       } else
              objp->oargs.iarg = NULL;
#endif
       if ((objp->oargs.nfargs = getint(2, fp)) > 0) {
              objp->oargs.farg = (RREAL *)malloc
                            (objp->oargs.nfargs*sizeof(RREAL));
              if (objp->oargs.farg == NULL)
                     goto memerr;
              for (i = 0; i < objp->oargs.nfargs; i++)
                     objp->oargs.farg[i] = getflt(fp);
       } else
              objp->oargs.farg = NULL;
       if (feof(fp))
              error(SYSTEM, "unexpected EOF in getobj");
                                          /* initialize */
       objp->os = NULL;
                                          /* insert */
       insertobject(obj);
       return(obj);
memerr:
       error(SYSTEM, "out of memory in getobj");
       return 0; /* pro forma return */
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void putobj ( OBJREC o,
FILE *  fp 
) [static]

Definition at line 111 of file sceneio.c.

{
       register int  i;

       if (o == NULL) {            /* terminator */
              putint(-1L, 1, fp);
              return;
       }
       putint((long)o->otype, 1, fp);
       putint((long)o->omod, sizeof(OBJECT), fp);
       putstr(o->oname, fp);
       putint((long)o->oargs.nsargs, 2, fp);
       for (i = 0; i < o->oargs.nsargs; i++)
              putstr(o->oargs.sarg[i], fp);
#ifdef  IARGS
       putint((long)o->oargs.niargs, 2, fp);
       for (i = 0; i < o->oargs.niargs; i++)
              putint((long)o->oargs.iarg[i], 4, fp);
#endif
       putint((long)o->oargs.nfargs, 2, fp);
       for (i = 0; i < o->oargs.nfargs; i++)
              putflt(o->oargs.farg[i], fp);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void readscene ( FILE *  fp,
int  objsiz 
)

Definition at line 89 of file sceneio.c.

{
       char  sbuf[32];
       int  i;
                                   /* record starting object */
       object0 = nobjects;
                                   /* read type map */
       for (i = 0; getstr(sbuf, fp) != NULL && sbuf[0]; i++)
              if ((otypmap[i] = otype(sbuf)) < 0) {
                     sprintf(errmsg, "unknown object type \"%s\"",
                                   sbuf);
                     error(WARNING, errmsg);
              }
                                   /* read objects */
       while (getobj(fp, objsiz) != OVOID)
              ;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void writescene ( int  firstobj,
int  nobjs,
FILE *  fp 
)

Definition at line 139 of file sceneio.c.

{
       int    i;
                                   /* write out type list */
       for (i = 0; i < NUMOTYPE; i++)
              putstr(ofun[i].funame, fp);
       putstr("", fp);
                                   /* write objects */
       for (i = firstobj; i < firstobj+nobjs; i++)
              putobj(objptr(i), fp);
       putobj(NULL, fp);           /* terminator */
       if (ferror(fp))
              error(SYSTEM, "write error in writescene");
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

OBJECT object0 [static]

Definition at line 16 of file sceneio.c.

short otypmap[NUMOTYPE+32] [static]

Definition at line 17 of file sceneio.c.

const char RCSid[] = "$Id: sceneio.c,v 2.4 2003/06/26 00:58:09 schorsch Exp $" [static]

Definition at line 2 of file sceneio.c.