Back to index

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

Go to the source code of this file.

Classes

struct  scene
struct  INSTANCE

Typedefs

typedef struct scene SCENE

Functions

SCENEgetscene (char *sname, int flags)
INSTANCEgetinstance (OBJREC *o, int flags)
void freescene (SCENE *sc)
void freeinstance (OBJREC *o)

Class Documentation

struct scene

Definition at line 13 of file instance.h.

Collaboration diagram for scene:
Class Members
OBJECT firstobj
int ldflags
char * name
struct scene * next
OBJECT nobjs
int nref
CUBE scube
struct INSTANCE

Definition at line 22 of file instance.h.

Collaboration diagram for INSTANCE:
Class Members
SCENE * obj
FULLXF x

Typedef Documentation

typedef struct scene SCENE

Function Documentation

void freeinstance ( OBJREC o)

Definition at line 139 of file instance.c.

{
       if (o->os == NULL)
              return;
       freescene((*(INSTANCE *)o->os).obj);
       free((void *)o->os);
       o->os = NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void freescene ( SCENE sc)

Definition at line 108 of file instance.c.

{
       SCENE  shead;
       register SCENE  *scp;

       if (sc == NULL)
              return;
       if (sc->nref <= 0)
              error(CONSISTENCY, "unreferenced scene in freescene");
       sc->nref--;
       if (sc->nref)               /* still in use? */
              return;
       shead.next = slist;         /* else remove from our list */
       for (scp = &shead; scp->next != NULL; scp = scp->next)
              if (scp->next == sc) {
                     scp->next = sc->next;
                     sc->next = NULL;
                     break;
              }
       if (sc->next != NULL)              /* can't be in list anymore */
              error(CONSISTENCY, "unlisted scene in freescene");
       slist = shead.next;
       freestr(sc->name);          /* free memory */
       octfree(sc->scube.cutree);
       freeobjects(sc->firstobj, sc->nobjs);
       free((void *)sc);
}

Here is the call graph for this function:

Here is the caller graph for this function:

INSTANCE* getinstance ( OBJREC o,
int  flags 
)

Definition at line 69 of file instance.c.

{
       register INSTANCE  *ins;

       flags &= ~IO_ILLEGAL;              /* not allowed */
       if ((ins = (INSTANCE *)o->os) == NULL) {
              if ((ins = (INSTANCE *)malloc(sizeof(INSTANCE))) == NULL)
                     error(SYSTEM, "out of memory in getinstance");
              if (o->oargs.nsargs < 1)
                     objerror(o, USER, "bad # of arguments");
              if (fullxf(&ins->x, o->oargs.nsargs-1,
                            o->oargs.sarg+1) != o->oargs.nsargs-1)
                     objerror(o, USER, "bad transform");
              if (ins->x.f.sca < 0.0) {
                     ins->x.f.sca = -ins->x.f.sca;
                     ins->x.b.sca = -ins->x.b.sca;
              }
              ins->obj = NULL;
              o->os = (char *)ins;
       }
       if (ins->obj == NULL)
              ins->obj = getscene(o->oargs.sarg[0], flags);
       else if ((flags &= ~ins->obj->ldflags)) {
              if (flags & IO_SCENE)
                     ins->obj->firstobj = nobjects;
              if (flags)
                     readoct(getpath(o->oargs.sarg[0], getrlibpath(), R_OK),
                                   flags, &ins->obj->scube, NULL);
              if (flags & IO_SCENE)
                     ins->obj->nobjs = nobjects - ins->obj->firstobj;
              ins->obj->ldflags |= flags;
       }
       return(ins);
}

Here is the call graph for this function:

Here is the caller graph for this function:

SCENE* getscene ( char *  sname,
int  flags 
)

Definition at line 25 of file instance.c.

{
       char  *pathname;
       register SCENE  *sc;

       flags &= ~IO_ILLEGAL;              /* not allowed */
       for (sc = slist; sc != NULL; sc = sc->next)
              if (!strcmp(sname, sc->name))
                     break;
       if (sc == NULL) {
              sc = (SCENE *)malloc(sizeof(SCENE));
              if (sc == NULL)
                     error(SYSTEM, "out of memory in getscene");
              sc->name = savestr(sname);
              sc->nref = 0;
              sc->ldflags = 0;
              sc->scube.cutree = EMPTY;
              sc->scube.cuorg[0] = sc->scube.cuorg[1] =
                            sc->scube.cuorg[2] = 0.;
              sc->scube.cusize = 0.;
              sc->firstobj = sc->nobjs = 0;
              sc->next = slist;
              slist = sc;
       }
       if ((pathname = getpath(sname, getrlibpath(), R_OK)) == NULL) {
              sprintf(errmsg, "cannot find octree file \"%s\"", sname);
              error(USER, errmsg);
       }
       flags &= ~sc->ldflags;             /* skip what's already loaded */
       if (flags & IO_SCENE)
              sc->firstobj = nobjects;
       if (flags)
              readoct(pathname, flags, &sc->scube, NULL);
       if (flags & IO_SCENE)
              sc->nobjs = nobjects - sc->firstobj;
       sc->ldflags |= flags;
       sc->nref++;                 /* increase reference count */
       return(sc);
}

Here is the call graph for this function:

Here is the caller graph for this function: