--- ray/src/ot/oconv.c 1990/01/12 10:50:59 1.7 +++ ray/src/ot/oconv.c 1992/08/24 15:19:12 2.3 @@ -18,6 +18,10 @@ static char SCCSid[] = "$SunId$ LBL"; #include "otypes.h" +#ifndef DEFPATH +#define DEFPATH ":/usr/local/lib/ray" +#endif + #define OMARGIN (10*FTINY) /* margin around global cube */ #define MAXOBJFIL 63 /* maximum number of scene files */ @@ -46,8 +50,7 @@ main(argc, argv) /* convert object files to an octree int argc; char **argv; { - char *getenv(); - double atof(); + extern char *getenv(); FVECT bbmin, bbmax; char *infile = NULL; int outflags = IO_ALL; @@ -57,8 +60,10 @@ char **argv; progname = argv[0]; if ((libpath = getenv("RAYPATH")) == NULL) - libpath = ":/usr/local/lib/ray"; + libpath = DEFPATH; + initotypes(); + for (i = 1; i < argc && argv[i][0] == '-'; i++) switch (argv[i][1]) { case '\0': /* scene from stdin */ @@ -101,6 +106,7 @@ breakopt: } printargs(argc, argv, stdout); /* info. header */ + fputformat(OCTFMT, stdout); printf("\n"); startobj = nobjects; /* previous objects already converted */ @@ -179,18 +185,25 @@ char *s; eputs(s) /* put string to stderr */ register char *s; { - static int inline = 0; + static int inln = 0; - if (!inline++) { + if (!inln++) { fputs(progname, stderr); fputs(": ", stderr); } fputs(s, stderr); if (*s && s[strlen(s)-1] == '\n') - inline = 0; + inln = 0; } +#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,^=) + + addobject(cu, obj) /* add an object to a cube */ register CUBE *cu; OBJECT obj; @@ -198,6 +211,7 @@ OBJECT obj; CUBE cukid; OCTREE ot; OBJECT oset[MAXSET+1]; + unsigned char inflg[(MAXSET+7)/8], volflg[(MAXSET+7)/8]; int in; register int i, j; @@ -219,45 +233,68 @@ OBJECT obj; addobject(&cukid, obj); octkid(cu->cutree, i) = cukid.cutree; } - - } else if (isempty(cu->cutree)) { + return; + } + if (isempty(cu->cutree)) { /* singular set */ oset[0] = 1; oset[1] = obj; cu->cutree = fullnode(oset); - - } else { - /* add to full node */ - objset(oset, cu->cutree); - cukid.cusize = cu->cusize * 0.5; - - if (in==O_IN || oset[0] < objlim || cukid.cusize < mincusize) { - /* 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); - - } else { - /* subdivide cube */ - if ((ot = octalloc()) == EMPTY) - error(SYSTEM, "out of octree space"); - for (i = 0; i < 8; i++) { - cukid.cutree = EMPTY; - for (j = 0; j < 3; j++) { - cukid.cuorg[j] = cu->cuorg[j]; - if ((1<cutree = ot; + return; + } + /* add to full node */ + objset(oset, cu->cutree); + cukid.cusize = cu->cusize * 0.5; + + if (in==O_IN || oset[0] < objlim || cukid.cusize < mincusize) { + /* 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<cutree = ot; }