Back to index

radiance  4R0+20100331
Functions | Variables
readoct.c File Reference
#include "copyright.h"
#include <stdio.h>
#include <time.h>
#include "platform.h"
#include "rtprocess.h"
#include "standard.h"
#include "octree.h"
#include "object.h"
#include "otypes.h"
#include "resolu.h"

Go to the source code of this file.

Functions

static double ogetflt (void)
static long ogetint (int)
static char * ogetstr (char *)
static int nonsurfintree (OCTREE ot)
static void octerror (int etyp, char *msg)
static void skiptree (void)
static OCTREE getfullnode (void)
static OCTREE gettree (void)
int readoct (char *inpspec, int load, CUBE *scene, char *ofn[])

Variables

static const char RCSid [] = "$Id: readoct.c,v 2.28 2004/12/16 19:31:36 greg Exp $"
static char * infn
static FILE * infp
static int objsize
static OBJECT objorig
static OBJECT fnobjects

Function Documentation

static OCTREE getfullnode ( void  ) [static]

Definition at line 144 of file readoct.c.

{
       OBJECT set[MAXSET+1];
       register int  i;
       register long  m;

       if ((set[0] = ogetint(objsize)) > MAXSET)
              octerror(USER, "bad set in getfullnode");
       for (i = 1; i <= set[0]; i++) {
              m = ogetint(objsize) + objorig;
              if ((set[i] = m) != m)
                     octerror(USER, "too many objects");
       }
       return(fullnode(set));
}      

Here is the call graph for this function:

Here is the caller graph for this function:

static OCTREE gettree ( void  )

Definition at line 188 of file readoct.c.

{
       register OCTREE       ot;
       register int  i;
       
       switch (getc(infp)) {
       case OT_EMPTY:
              return(EMPTY);
       case OT_FULL:
              return(getfullnode());
       case OT_TREE:
              if ((ot = octalloc()) == EMPTY)
                     octerror(SYSTEM, "out of tree space in gettree");
              for (i = 0; i < 8; i++)
                     octkid(ot, i) = gettree();
              return(ot);
       case EOF:
              octerror(USER, "truncated octree");
       default:
              octerror(USER, "damaged octree");
       }
       return EMPTY; /* pro forma return */
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int nonsurfintree ( OCTREE  ot) [static]

Definition at line 214 of file readoct.c.

{
       OBJECT  set[MAXSET+1];
       register int  i;

       if (isempty(ot))
              return(0);
       if (istree(ot)) {
              for (i = 0; i < 8; i++)
                     if (nonsurfintree(octkid(ot, i)))
                            return(1);
              return(0);
       }
       objset(set, ot);
       for (i = set[0]; i > 0; i-- )
              if (ismodifier(objptr(set[i])->otype))
                     return(1);
       return(0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void octerror ( int  etyp,
char *  msg 
) [static]

Definition at line 261 of file readoct.c.

{
       char  msgbuf[128];

       sprintf(msgbuf, "(%s): %s", infn, msg);
       error(etyp, msgbuf);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static double ogetflt ( void  ) [static]

Definition at line 175 of file readoct.c.

{
       extern double  getflt();
       double r;

       r = getflt(infp);
       if (feof(infp))
              octerror(USER, "truncated octree");
       return(r);
}

Here is the call graph for this function:

static long ogetint ( int  siz) [static]

Definition at line 162 of file readoct.c.

{
       extern long  getint();
       register long  r;

       r = getint(siz, infp);
       if (feof(infp))
              octerror(USER, "truncated octree");
       return(r);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static char * ogetstr ( char *  s) [static]

Definition at line 133 of file readoct.c.

{
       extern char  *getstr();

       if (getstr(s, infp) == NULL)
              octerror(USER, "truncated octree");
       return(s);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int readoct ( char *  inpspec,
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:

static void skiptree ( void  ) [static]

Definition at line 236 of file readoct.c.

{
       register int  i;
       
       switch (getc(infp)) {
       case OT_EMPTY:
              return;
       case OT_FULL:
              for (i = ogetint(objsize)*objsize; i-- > 0; )
                     if (getc(infp) == EOF)
                            octerror(USER, "truncated octree");
              return;
       case OT_TREE:
              for (i = 0; i < 8; i++)
                     skiptree();
              return;
       case EOF:
              octerror(USER, "truncated octree");
       default:
              octerror(USER, "damaged octree");
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

OBJECT fnobjects [static]

Definition at line 38 of file readoct.c.

char* infn [static]

Definition at line 34 of file readoct.c.

FILE* infp [static]

Definition at line 35 of file readoct.c.

OBJECT objorig [static]

Definition at line 37 of file readoct.c.

int objsize [static]

Definition at line 36 of file readoct.c.

const char RCSid[] = "$Id: readoct.c,v 2.28 2004/12/16 19:31:36 greg Exp $" [static]

Definition at line 2 of file readoct.c.