Back to index

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

Go to the source code of this file.

Classes

struct  CUBE

Defines

#define OCTREE   int
#define EMPTY   (-1)
#define isempty(ot)   ((ot) == EMPTY)
#define isfull(ot)   ((ot) < EMPTY)
#define istree(ot)   ((ot) > EMPTY)
#define oseti(ot)   (-(ot)-2) /* object set index */
#define OCTBLKSIZ   04000 /* octree block size */
#define octbi(ot)   ((ot)>>11) /* octree block index */
#define octti(ot)   (((ot)&03777)<<3)/* octree index in block */
#define MAXOBLK   32767 /* maximum octree block */
#define octkid(ot, br)   (octblock[octbi(ot)][octti(ot)+br])
#define IO_CHECK   0 /* verify file type */
#define IO_INFO   01 /* information header */
#define IO_SCENE   02 /* objects */
#define IO_TREE   04 /* octree */
#define IO_FILES   010 /* object file names */
#define IO_BOUNDS   020 /* octree boundary */
#define IO_ALL   (~0) /* everything */
#define OCTFMT   "Radiance_octree"
#define MAXOBJSIZ   8 /* maximum sizeof(OBJECT) */
#define OCTMAGIC   ( 4 *MAXOBJSIZ+251) /* increment first value */
#define OT_EMPTY   0
#define OT_FULL   1
#define OT_TREE   2
#define O_MISS   0 /* no intersection */
#define O_HIT   1 /* intersection */
#define O_IN   2 /* cube contained entirely */

Functions

OCTREE octalloc (void)
void octfree (OCTREE ot)
void octdone (void)
OCTREE combine (OCTREE ot)
void culocate (CUBE *cu, FVECT pt)
int incube (CUBE *cu, FVECT pt)
int readoct (char *fname, int load, CUBE *scene, char *ofn[])
void readscene (FILE *fp, int objsiz)
void writescene (int firstobj, int nobjs, FILE *fp)

Variables

OCTREEoctblock [MAXOBLK]
CUBE thescene

Class Documentation

struct CUBE

Definition at line 55 of file octree.h.

Class Members
FVECT cuorg
double cusize
OCTREE cutree

Define Documentation

#define EMPTY   (-1)

Definition at line 27 of file octree.h.

#define IO_ALL   (~0) /* everything */

Definition at line 70 of file octree.h.

#define IO_BOUNDS   020 /* octree boundary */

Definition at line 69 of file octree.h.

#define IO_CHECK   0 /* verify file type */

Definition at line 64 of file octree.h.

#define IO_FILES   010 /* object file names */

Definition at line 68 of file octree.h.

#define IO_INFO   01 /* information header */

Definition at line 65 of file octree.h.

#define IO_SCENE   02 /* objects */

Definition at line 66 of file octree.h.

#define IO_TREE   04 /* octree */

Definition at line 67 of file octree.h.

#define isempty (   ot)    ((ot) == EMPTY)

Definition at line 29 of file octree.h.

#define isfull (   ot)    ((ot) < EMPTY)

Definition at line 30 of file octree.h.

#define istree (   ot)    ((ot) > EMPTY)

Definition at line 31 of file octree.h.

#define MAXOBJSIZ   8 /* maximum sizeof(OBJECT) */

Definition at line 74 of file octree.h.

#define MAXOBLK   32767 /* maximum octree block */

Definition at line 42 of file octree.h.

#define O_HIT   1 /* intersection */

Definition at line 82 of file octree.h.

#define O_IN   2 /* cube contained entirely */

Definition at line 83 of file octree.h.

#define O_MISS   0 /* no intersection */

Definition at line 81 of file octree.h.

#define octbi (   ot)    ((ot)>>11) /* octree block index */

Definition at line 35 of file octree.h.

#define OCTBLKSIZ   04000 /* octree block size */

Definition at line 34 of file octree.h.

#define OCTFMT   "Radiance_octree"

Definition at line 72 of file octree.h.

#define octkid (   ot,
  br 
)    (octblock[octbi(ot)][octti(ot)+br])

Definition at line 48 of file octree.h.

#define OCTMAGIC   ( 4 *MAXOBJSIZ+251) /* increment first value */

Definition at line 75 of file octree.h.

#define OCTREE   int

Definition at line 24 of file octree.h.

#define octti (   ot)    (((ot)&03777)<<3)/* octree index in block */

Definition at line 36 of file octree.h.

#define oseti (   ot)    (-(ot)-2) /* object set index */

Definition at line 33 of file octree.h.

#define OT_EMPTY   0

Definition at line 77 of file octree.h.

#define OT_FULL   1

Definition at line 78 of file octree.h.

#define OT_TREE   2

Definition at line 79 of file octree.h.


Function Documentation

Definition at line 74 of file octree.c.

{
       int  i;
       OCTREE  ores;

       if (!istree(ot))     /* not a tree */
              return(ot);
       ores = octkid(ot, 0) = combine(octkid(ot, 0));
       for (i = 1; i < 8; i++)
              if ((octkid(ot, i) = combine(octkid(ot, i))) != ores)
                     ores = ot;
       if (!istree(ores)) { /* all were identical leaves */
              octkid(ot, 0) = ofreelist;
              ofreelist = ot;
       }
       return(ores);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void culocate ( CUBE cu,
FVECT  pt 
)

Definition at line 95 of file octree.c.

{
       int  i;
       int  branch;

       while (istree(cu->cutree)) {
              cu->cusize *= 0.5;
              branch = 0;
              for (i = 0; i < 3; i++)
                     if (cu->cuorg[i] + cu->cusize <= pt[i]) {
                            cu->cuorg[i] += cu->cusize;
                            branch |= 1 << i;
                     }
              cu->cutree = octkid(cu->cutree, branch);
       }
}

Here is the call graph for this function:

int incube ( CUBE cu,
FVECT  pt 
)

Definition at line 116 of file octree.c.

{
       if (cu->cuorg[0] > pt[0] || pt[0] >= cu->cuorg[0] + cu->cusize)
              return(0);
       if (cu->cuorg[1] > pt[1] || pt[1] >= cu->cuorg[1] + cu->cusize)
              return(0);
       if (cu->cuorg[2] > pt[2] || pt[2] >= cu->cuorg[2] + cu->cusize)
              return(0);
       return(1);
}

Here is the caller graph for this function:

OCTREE octalloc ( void  )

Definition at line 20 of file octree.c.

{
       OCTREE  freet;

       if ((freet = ofreelist) != EMPTY) {
              ofreelist = octkid(freet, 0);
              return(freet);
       }
       freet = treetop;
       if (octti(freet) == 0) {
              errno = 0;
              if (octbi(freet) >= MAXOBLK)
                     return(EMPTY);
              if ((octblock[octbi(freet)] = (OCTREE *)malloc(
                            (unsigned)OCTBLKSIZ*8*sizeof(OCTREE))) == NULL)
                     return(EMPTY);
       }
       treetop++;
       return(freet);
}

Here is the caller graph for this function:

void octdone ( void  )

Definition at line 58 of file octree.c.

{
       int    i;

       for (i = 0; i < MAXOBLK; i++) {
              if (octblock[i] == NULL)
                     break;
              free((void *)octblock[i]);
              octblock[i] = NULL;
       }
       ofreelist = EMPTY;
       treetop = 0;
}

Here is the caller graph for this function:

void octfree ( OCTREE  ot)

Definition at line 43 of file octree.c.

{
       int  i;

       if (!istree(ot))
              return;
       for (i = 0; i < 8; i++)
              octfree(octkid(ot, i));
       octkid(ot, 0) = ofreelist;
       ofreelist = ot;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int readoct ( char *  fname,
int  load,
CUBE scene,
char *  ofn[] 
)

Definition at line 42 of file readoct.c.

{
       char  sbuf[512];
       int  nf;
       int  i;
       long  m;
       
       if (inpspec == NULL) {
              infn = "standard input";
              infp = stdin;
       } else if (inpspec[0] == '!') {
              infn = inpspec;
              if ((infp = popen(inpspec+1, "r")) == NULL) {
                     sprintf(errmsg, "cannot execute \"%s\"", inpspec);
                     error(SYSTEM, errmsg);
              }
       } else {
              infn = inpspec;
              if ((infp = fopen(inpspec, "r")) == NULL) {
                     sprintf(errmsg, "cannot open octree file \"%s\"",
                                   inpspec);
                     error(SYSTEM, errmsg);
              }
       }
       SET_FILE_BINARY(infp);
                                   /* get header */
       if (checkheader(infp, OCTFMT, load&IO_INFO ? stdout : (FILE *)NULL) < 0)
              octerror(USER, "not an octree");
                                   /* check format */
       if ((objsize = ogetint(2)-OCTMAGIC) <= 0 ||
                     objsize > MAXOBJSIZ || objsize > sizeof(long))
              octerror(USER, "incompatible octree format");
                                   /* get boundaries */
       if (load & IO_BOUNDS) {
              for (i = 0; i < 3; i++)
                     scene->cuorg[i] = atof(ogetstr(sbuf));
              scene->cusize = atof(ogetstr(sbuf));
       } else {
              for (i = 0; i < 4; i++)
                     ogetstr(sbuf);
       }
       objorig = nobjects;         /* set object offset */
       nf = 0;                            /* get object files */
       while (*ogetstr(sbuf)) {
              if (load & IO_SCENE)
                     readobj(sbuf);
              if (load & IO_FILES)
                     ofn[nf] = savqstr(sbuf);
              nf++;
       }
       if (load & IO_FILES)
              ofn[nf] = NULL;
                                   /* get number of objects */
       fnobjects = m = ogetint(objsize);
       if (fnobjects != m)
              octerror(USER, "too many objects");

       if (load & IO_TREE)         /* get the octree */
              scene->cutree = gettree();
       else if (load & IO_SCENE && nf == 0)
              skiptree();
              
       if (load & IO_SCENE) {             /* get the scene */
           if (nf == 0) {
                                   /* load binary scene data */
              readscene(infp, objsize);

           } else {                /* consistency checks */
                            /* check object count */
              if (nobjects != objorig+fnobjects)
                     octerror(USER, "bad object count; octree stale?");
                            /* check for non-surfaces */
              if (nonsurfintree(scene->cutree))
                     octerror(USER, "modifier in tree; octree stale?");
           }
       }
                            /* close the input */
       if (infn[0] == '!')
              pclose(infp);
       else
              fclose(infp);
       return(nf);
}

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

Definition at line 14 of file octree.c.

Definition at line 31 of file oconv.c.