Back to index

radiance  4R0+20100331
Defines | Functions | Variables
oconv.c File Reference
#include "platform.h"
#include "standard.h"
#include "octree.h"
#include "object.h"
#include "otypes.h"
#include "paths.h"
#include "resolu.h"
#include "oconv.h"

Go to the source code of this file.

Defines

#define OMARGIN   (10*FTINY) /* margin around global cube */
#define MAXOBJFIL   127 /* maximum number of scene files */
#define bitop(f, i, op)   (f[((i)>>3)] op (1<<((i)&7)))
#define tstbit(f, i)   bitop(f,i,&)
#define setbit(f, i)   bitop(f,i,|=)
#define clrbit(f, i)   bitop(f,i,&=~)
#define tglbit(f, i)   bitop(f,i,^=)

Functions

static void addobject (CUBE *cu, OBJECT obj)
static void add2full (CUBE *cu, OBJECT obj, int inc)
int main (int argc, char *argv[])
void quit (int code)
void cputs (void)
void wputs (char *s)
void eputs (register char *s)
static void addobject (register CUBE *cu, OBJECT obj)
static void add2full (register CUBE *cu, OBJECT obj, int inc)

Variables

static const char RCSid [] = "$Id: oconv.c,v 2.21 2005/09/23 19:04:52 greg Exp $"
char * progname
int nowarn = 0
int objlim = 6
int resolu = 16384
CUBE thescene = {{0.0, 0.0, 0.0}, 0.0, EMPTY}
char * ofname [MAXOBJFIL+1]
int nfiles = 0
double mincusize
void(* addobjnotify [])() = {NULL}

Define Documentation

#define bitop (   f,
  i,
  op 
)    (f[((i)>>3)] op (1<<((i)&7)))

Definition at line 211 of file oconv.c.

#define clrbit (   f,
  i 
)    bitop(f,i,&=~)

Definition at line 214 of file oconv.c.

#define MAXOBJFIL   127 /* maximum number of scene files */

Definition at line 21 of file oconv.c.

#define OMARGIN   (10*FTINY) /* margin around global cube */

Definition at line 19 of file oconv.c.

#define setbit (   f,
  i 
)    bitop(f,i,|=)

Definition at line 213 of file oconv.c.

#define tglbit (   f,
  i 
)    bitop(f,i,^=)

Definition at line 215 of file oconv.c.

#define tstbit (   f,
  i 
)    bitop(f,i,&)

Definition at line 212 of file oconv.c.


Function Documentation

static void add2full ( CUBE cu,
OBJECT  obj,
int  inc 
) [static]
static void add2full ( register CUBE cu,
OBJECT  obj,
int  inc 
) [static]

Definition at line 259 of file oconv.c.

{
       OCTREE ot;
       OBJECT oset[MAXSET+1];
       CUBE  cukid;
       unsigned char  inflg[(MAXSET+7)/8], volflg[(MAXSET+7)/8];
       register int  i, j;

       objset(oset, cu->cutree);
       cukid.cusize = cu->cusize * 0.5;

       if (inc==O_IN || oset[0] < objlim || cukid.cusize <
                     (oset[0] < MAXSET ? mincusize : mincusize/256.0)) {
                                          /* add to set */
              if (oset[0] >= MAXSET) {
                     sprintf(errmsg, "set overflow in addobject (%s)",
                                   objptr(obj)->oname);
                     error(INTERNAL, errmsg);
              }
              insertelem(oset, obj);
              cu->cutree = fullnode(oset);
              return;
       }
                                   /* subdivide cube */
       if ((ot = octalloc()) == EMPTY)
              error(SYSTEM, "out of octree space");
                                   /* mark volumes */
       j = (oset[0]+7)>>3;
       while (j--)
              volflg[j] = inflg[j] = 0;
       for (j = 1; j <= oset[0]; j++)
              if (isvolume(objptr(oset[j])->otype)) {
                     setbit(volflg,j-1);
                     if ((*ofun[objptr(oset[j])->otype].funp)
                                   (objptr(oset[j]), cu) == O_IN)
                            setbit(inflg,j-1);
              }
                                   /* assign subcubes */
       for (i = 0; i < 8; i++) {
              cukid.cutree = EMPTY;
              for (j = 0; j < 3; j++) {
                     cukid.cuorg[j] = cu->cuorg[j];
                     if ((1<<j) & i)
                            cukid.cuorg[j] += cukid.cusize;
              }
                                   /* surfaces first */
              for (j = 1; j <= oset[0]; j++)
                     if (!tstbit(volflg,j-1))
                            addobject(&cukid, oset[j]);
                                   /* then this object */
              addobject(&cukid, obj);
                                   /* then partial volumes */
              for (j = 1; j <= oset[0]; j++)
                     if (tstbit(volflg,j-1) &&
                                   !tstbit(inflg,j-1))
                            addobject(&cukid, oset[j]);
                                   /* full volumes last */
              for (j = 1; j <= oset[0]; j++)
                     if (tstbit(inflg,j-1))
                            addobject(&cukid, oset[j]);
                                   /* returned node */
              octkid(ot, i) = cukid.cutree;
       }
       cu->cutree = ot;
}

Here is the call graph for this function:

static void addobject ( CUBE cu,
OBJECT  obj 
) [static]
static void addobject ( register CUBE cu,
OBJECT  obj 
) [static]

Definition at line 219 of file oconv.c.

{
       int  inc;

       inc = (*ofun[objptr(obj)->otype].funp)(objptr(obj), cu);

       if (inc == O_MISS)
              return;                            /* no intersection */

       if (istree(cu->cutree)) {
              CUBE  cukid;                /* do children */
              int  i, j;
              cukid.cusize = cu->cusize * 0.5;
              for (i = 0; i < 8; i++) {
                     cukid.cutree = octkid(cu->cutree, i);
                     for (j = 0; j < 3; j++) {
                            cukid.cuorg[j] = cu->cuorg[j];
                            if ((1<<j) & i)
                                   cukid.cuorg[j] += cukid.cusize;
                     }
                     addobject(&cukid, obj);
                     octkid(cu->cutree, i) = cukid.cutree;
              }
              return;
       }
       if (isempty(cu->cutree)) {
              OBJECT  oset[2];            /* singular set */
              oset[0] = 1; oset[1] = obj;
              cu->cutree = fullnode(oset);
              return;
       }
                                   /* add to full node */
       add2full(cu, obj, inc);
}

Here is the call graph for this function:

void cputs ( void  )

Definition at line 173 of file oconv.c.

{
       /* referenced, but not used */
}
void eputs ( register char *  s)

Definition at line 190 of file oconv.c.

{
       static int  inln = 0;

       if (!inln++) {
              fputs(progname, stderr);
              fputs(": ", stderr);
       }
       fputs(s, stderr);
       if (*s && s[strlen(s)-1] == '\n')
              inln = 0;
}
int main ( int  argc,
char *  argv[] 
)

Definition at line 45 of file oconv.c.

{
       FVECT  bbmin, bbmax;
       char  *infile = NULL;
       int  inpfrozen = 0;
       int  outflags = IO_ALL;
       OBJECT startobj;
       int  i;

       progname = argv[0] = fixargv0(argv[0]);

       ot_initotypes();

       for (i = 1; i < argc && argv[i][0] == '-'; i++)
              switch (argv[i][1]) {
              case '\0':                         /* scene from stdin */
                     goto breakopt;
              case 'i':                          /* input octree */
                     infile = argv[++i];
                     break;
              case 'b':                          /* bounding cube */
                     thescene.cuorg[0] = atof(argv[++i]) - OMARGIN;
                     thescene.cuorg[1] = atof(argv[++i]) - OMARGIN;
                     thescene.cuorg[2] = atof(argv[++i]) - OMARGIN;
                     thescene.cusize = atof(argv[++i]) + 2*OMARGIN;
                     break;
              case 'n':                          /* set limit */
                     objlim = atoi(argv[++i]);
                     break;
              case 'r':                          /* resolution limit */
                     resolu = atoi(argv[++i]);
                     break;
              case 'f':                          /* freeze octree */
                     outflags &= ~IO_FILES;
                     break;
              case 'w':                          /* supress warnings */
                     nowarn = 1;
                     break;
              default:
                     sprintf(errmsg, "unknown option: '%s'", argv[i]);
                     error(USER, errmsg);
                     break;
              }
breakopt:
       SET_FILE_BINARY(stdout);
       if (infile != NULL) {              /* get old octree & objects */
              if (thescene.cusize > FTINY)
                     error(USER, "only one of '-b' or '-i'");
              nfiles = readoct(infile, IO_ALL, &thescene, ofname);
              if (nfiles == 0)
                     inpfrozen++;
       } else
              newheader("RADIANCE", stdout);     /* new binary file header */
       printargs(argc, argv, stdout);
       fputformat(OCTFMT, stdout);
       printf("\n");

       startobj = nobjects;        /* previous objects already converted */

       for ( ; i < argc; i++)             /* read new scene descriptions */
              if (!strcmp(argv[i], "-")) {       /* from stdin */
                     readobj(NULL);
                     outflags &= ~IO_FILES;
              } else {                    /* from file */
                     if (nfiles >= MAXOBJFIL)
                            error(INTERNAL, "too many scene files");
                     readobj(ofname[nfiles++] = argv[i]);
              }

       ofname[nfiles] = NULL;

       if (inpfrozen && outflags & IO_FILES) {
              error(WARNING, "frozen octree");
              outflags &= ~IO_FILES;
       }
                                          /* find bounding box */
       bbmin[0] = bbmin[1] = bbmin[2] = FHUGE;
       bbmax[0] = bbmax[1] = bbmax[2] = -FHUGE;
       for (i = startobj; i < nobjects; i++)
              add2bbox(objptr(i), bbmin, bbmax);
                                          /* set/check cube */
       if (thescene.cusize == 0.0) {
              if (bbmin[0] <= bbmax[0]) {
                     for (i = 0; i < 3; i++) {
                            bbmin[i] -= OMARGIN;
                            bbmax[i] += OMARGIN;
                     }
                     for (i = 0; i < 3; i++)
                            if (bbmax[i] - bbmin[i] > thescene.cusize)
                                   thescene.cusize = bbmax[i] - bbmin[i];
                     for (i = 0; i < 3; i++)
                            thescene.cuorg[i] =
                                   (bbmax[i]+bbmin[i]-thescene.cusize)*.5;
              }
       } else {
              for (i = 0; i < 3; i++)
                     if (bbmin[i] < thescene.cuorg[i] ||
                            bbmax[i] > thescene.cuorg[i] + thescene.cusize)
                            error(USER, "boundary does not encompass scene");
       }

       mincusize = thescene.cusize / resolu - FTINY;

       for (i = startobj; i < nobjects; i++)            /* add new objects */
              addobject(&thescene, i);

       thescene.cutree = combine(thescene.cutree);      /* optimize */

       writeoct(outflags, &thescene, ofname);    /* write structures to stdout */

       quit(0);
       return 0; /* pro forma return */
}

Here is the call graph for this function:

void quit ( int  code)

Definition at line 164 of file oconv.c.

{
       exit(code);
}
void wputs ( char *  s)

Definition at line 180 of file oconv.c.

{
       if (!nowarn)
              eputs(s);
}

Here is the call graph for this function:


Variable Documentation

void(* addobjnotify[])() = {NULL}

Definition at line 38 of file oconv.c.

double mincusize

Definition at line 36 of file oconv.c.

int nfiles = 0

Definition at line 34 of file oconv.c.

int nowarn = 0

Definition at line 25 of file oconv.c.

int objlim = 6

Definition at line 27 of file oconv.c.

int ofname

Definition at line 33 of file oconv.c.

char* progname

Definition at line 23 of file oconv.c.

const char RCSid[] = "$Id: oconv.c,v 2.21 2005/09/23 19:04:52 greg Exp $" [static]

Definition at line 2 of file oconv.c.

int resolu = 16384

Definition at line 29 of file oconv.c.

CUBE thescene = {{0.0, 0.0, 0.0}, 0.0, EMPTY}

Definition at line 31 of file oconv.c.