--- ray/src/ot/oconv.c 1990/08/29 21:56:17 1.11 +++ ray/src/ot/oconv.c 2003/10/22 02:06:34 2.18 @@ -1,63 +1,55 @@ -/* Copyright (c) 1986 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: oconv.c,v 2.18 2003/10/22 02:06:34 greg Exp $"; #endif - /* * oconv.c - main program for object to octree conversion. * * 7/29/85 */ +#include "platform.h" #include "standard.h" - #include "octree.h" - #include "object.h" - #include "otypes.h" +#include "paths.h" -#define OMARGIN (10*FTINY) /* margin around global cube */ +#define OMARGIN (10*FTINY) /* margin around global cube */ -#define MAXOBJFIL 63 /* maximum number of scene files */ +#define MAXOBJFIL 127 /* maximum number of scene files */ char *progname; /* argv[0] */ -char *libpath; /* library search path */ - int nowarn = 0; /* supress warnings? */ -int objlim = 5; /* # of objects before split */ +int objlim = 6; /* # of objects before split */ -int resolu = 1024; /* octree resolution limit */ +int resolu = 16384; /* octree resolution limit */ CUBE thescene = {EMPTY, {0.0, 0.0, 0.0}, 0.0}; /* our scene */ char *ofname[MAXOBJFIL+1]; /* object file names */ int nfiles = 0; /* number of object files */ -double mincusize; /* minimum cube size from resolu */ +double mincusize; /* minimum cube size from resolu */ -int (*addobjnotify[])() = {NULL}; /* new object notifier functions */ +void (*addobjnotify[])() = {NULL}; /* new object notifier functions */ main(argc, argv) /* convert object files to an octree */ int argc; -char **argv; +char *argv[]; { - char *getenv(); - double atof(); FVECT bbmin, bbmax; char *infile = NULL; + int inpfrozen = 0; int outflags = IO_ALL; - OBJECT startobj; + OBJECT startobj; int i; - progname = argv[0]; + progname = argv[0] = fixargv0(argv[0]); - if ((libpath = getenv("RAYPATH")) == NULL) - libpath = ":/usr/local/lib/ray"; + initotypes(); for (i = 1; i < argc && argv[i][0] == '-'; i++) switch (argv[i][1]) { @@ -90,21 +82,21 @@ char **argv; 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 && outflags & IO_FILES) { - error(WARNING, "frozen octree"); - outflags &= ~IO_FILES; - } - } - - printargs(argc, argv, stdout); /* info. header */ + 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); @@ -116,6 +108,11 @@ breakopt: } 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; @@ -143,10 +140,10 @@ breakopt: } 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 */ @@ -155,6 +152,7 @@ breakopt: } +void quit(code) /* exit program */ int code; { @@ -162,12 +160,14 @@ int code; } +void cputs() /* interactive error */ { /* referenced, but not used */ } +void wputs(s) /* warning message */ char *s; { @@ -176,6 +176,7 @@ char *s; } +void eputs(s) /* put string to stderr */ register char *s; { @@ -190,32 +191,33 @@ register char *s; inln = 0; } + /* conflicting def's in param.h */ +#undef tstbit +#undef setbit +#undef clrbit +#undef tglbit -#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,^=) +#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; +OBJECT obj; { - CUBE cukid; - OCTREE ot; - OBJECT oset[MAXSET+1]; - unsigned char inflg[MAXSET/8], volflg[MAXSET/8]; - int in; - register int i, j; + int inc; - in = (*ofun[objptr(obj)->otype].funp)(objptr(obj), cu); + inc = (*ofun[objptr(obj)->otype].funp)(objptr(obj), cu); - if (in == O_MISS) + if (inc == O_MISS) return; /* no intersection */ - + if (istree(cu->cutree)) { - /* do children */ + 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); @@ -230,20 +232,34 @@ OBJECT obj; return; } if (isempty(cu->cutree)) { - /* singular set */ + OBJECT oset[2]; /* singular set */ oset[0] = 1; oset[1] = obj; cu->cutree = fullnode(oset); return; } /* add to full node */ + add2full(cu, obj, inc); +} + + +add2full(cu, obj, inc) /* add object to full node */ +register CUBE *cu; +OBJECT obj; +int inc; +{ + 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 (in==O_IN || oset[0] < objlim || cukid.cusize < mincusize) { + + if (inc==O_IN || oset[0] < objlim || cukid.cusize < mincusize) { /* add to set */ if (oset[0] >= MAXSET) { - sprintf(errmsg, - "set overflow in addobject (%s)", + sprintf(errmsg, "set overflow in addobject (%s)", objptr(obj)->oname); error(INTERNAL, errmsg); } @@ -262,7 +278,7 @@ OBJECT obj; if (isvolume(objptr(oset[j])->otype)) { setbit(volflg,j-1); if ((*ofun[objptr(oset[j])->otype].funp) - (objptr(oset[j]),cu) == O_IN) + (objptr(oset[j]), cu) == O_IN) setbit(inflg,j-1); } /* assign subcubes */ @@ -279,12 +295,12 @@ OBJECT obj; addobject(&cukid, oset[j]); /* then this object */ addobject(&cukid, obj); - /* partial volumes */ + /* 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 */ + /* full volumes last */ for (j = 1; j <= oset[0]; j++) if (tstbit(inflg,j-1)) addobject(&cukid, oset[j]);