--- ray/src/ot/oconv.c 1995/06/02 17:47:04 2.11 +++ ray/src/ot/oconv.c 2004/04/12 17:31:27 2.20 @@ -1,24 +1,20 @@ -/* Copyright (c) 1992 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: oconv.c,v 2.20 2004/04/12 17:31:27 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" +#include "resolu.h" +#include "oconv.h" #define OMARGIN (10*FTINY) /* margin around global cube */ @@ -28,9 +24,9 @@ char *progname; /* argv[0] */ 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 */ @@ -39,12 +35,17 @@ int nfiles = 0; /* number of object files */ double mincusize; /* minimum cube size from resolu */ -int (*addobjnotify[])() = {NULL}; /* new object notifier functions */ +void (*addobjnotify[])() = {NULL}; /* new object notifier functions */ +static void addobject(CUBE *cu, OBJECT obj); +static void add2full(CUBE *cu, OBJECT obj, int inc); -main(argc, argv) /* convert object files to an octree */ -int argc; -char *argv[]; + +int +main( /* convert object files to an octree */ + int argc, + char *argv[] +) { FVECT bbmin, bbmax; char *infile = NULL; @@ -55,7 +56,7 @@ char *argv[]; progname = argv[0] = fixargv0(argv[0]); - initotypes(); + ot_initotypes(); for (i = 1; i < argc && argv[i][0] == '-'; i++) switch (argv[i][1]) { @@ -88,9 +89,7 @@ char *argv[]; break; } breakopt: -#ifdef MSDOS - setmode(fileno(stdout), O_BINARY); -#endif + SET_FILE_BINARY(stdout); if (infile != NULL) { /* get old octree & objects */ if (thescene.cusize > FTINY) error(USER, "only one of '-b' or '-i'"); @@ -157,32 +156,40 @@ breakopt: writeoct(outflags, &thescene, ofname); /* write structures to stdout */ quit(0); + return 0; /* pro forma return */ } -quit(code) /* exit program */ -int code; +void +quit( /* exit program */ + int code +) { exit(code); } -cputs() /* interactive error */ +void +cputs(void) /* interactive error */ { /* referenced, but not used */ } -wputs(s) /* warning message */ -char *s; +void +wputs( /* warning message */ + char *s +) { if (!nowarn) eputs(s); } -eputs(s) /* put string to stderr */ -register char *s; +void +eputs( /* put string to stderr */ + register char *s +) { static int inln = 0; @@ -195,6 +202,11 @@ 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,&) @@ -203,24 +215,22 @@ register char *s; #define tglbit(f,i) bitop(f,i,^=) -addobject(cu, obj) /* add an object to a cube */ -register CUBE *cu; -OBJECT obj; +static void +addobject( /* add an object to a cube */ + register CUBE *cu, + 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; + 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); @@ -235,16 +245,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); +} + + +static void +add2full( /* 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 < + (oset[0] < MAXSET ? mincusize : mincusize/256.0)) { /* add to set */ if (oset[0] >= MAXSET) { sprintf(errmsg, "set overflow in addobject (%s)",