--- ray/src/ot/oconv.c 1990/08/29 21:56:17 1.11 +++ ray/src/ot/oconv.c 1992/10/09 10:26:28 2.5 @@ -1,4 +1,4 @@ -/* Copyright (c) 1986 Regents of the University of California */ +/* Copyright (c) 1992 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; @@ -18,10 +18,12 @@ static char SCCSid[] = "$SunId$ LBL"; #include "otypes.h" -#define OMARGIN (10*FTINY) /* margin around global cube */ +#include "paths.h" -#define MAXOBJFIL 63 /* maximum number of scene files */ +#define OMARGIN (10*FTINY) /* margin around global cube */ +#define MAXOBJFIL 63 /* maximum number of scene files */ + char *progname; /* argv[0] */ char *libpath; /* library search path */ @@ -37,7 +39,7 @@ CUBE thescene = {EMPTY, {0.0, 0.0, 0.0}, 0.0}; /* ou 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 */ @@ -46,19 +48,20 @@ 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; - 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"; + if ((libpath = getenv(ULIBVAR)) == NULL) + libpath = DEFPATH; + initotypes(); + for (i = 1; i < argc && argv[i][0] == '-'; i++) switch (argv[i][1]) { case '\0': /* scene from stdin */ @@ -90,6 +93,9 @@ char **argv; break; } breakopt: +#ifdef MSDOS + setmode(fileno(stdout), O_BINARY); +#endif if (infile != NULL) { /* get old octree & objects */ if (thescene.cusize > FTINY) error(USER, "only one of '-b' or '-i'"); @@ -101,10 +107,11 @@ breakopt: } printargs(argc, argv, stdout); /* info. header */ + 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); @@ -143,10 +150,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 */ @@ -191,21 +198,21 @@ register char *s; } -#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]; + OCTREE ot; + OBJECT oset[MAXSET+1]; + unsigned char inflg[(MAXSET+7)/8], volflg[(MAXSET+7)/8]; int in; register int i, j; @@ -213,7 +220,7 @@ OBJECT obj; if (in == O_MISS) return; /* no intersection */ - + if (istree(cu->cutree)) { /* do children */ cukid.cusize = cu->cusize * 0.5; @@ -238,12 +245,11 @@ OBJECT obj; /* 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)", + sprintf(errmsg, "set overflow in addobject (%s)", objptr(obj)->oname); error(INTERNAL, errmsg); } @@ -262,7 +268,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 +285,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]);