--- ray/src/ot/oconv.c 1989/04/10 17:00:27 1.3 +++ ray/src/ot/oconv.c 1990/08/29 13:01:16 1.10 @@ -39,7 +39,9 @@ int nfiles = 0; /* number of object files */ double mincusize; /* minimum cube size from resolu */ +int (*addobjnotify[])() = {NULL}; /* new object notifier functions */ + main(argc, argv) /* convert object files to an octree */ int argc; char **argv; @@ -59,6 +61,8 @@ char **argv; 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; @@ -85,7 +89,7 @@ char **argv; error(USER, errmsg); break; } - +breakopt: if (infile != NULL) { /* get old octree & objects */ if (thescene.cusize > FTINY) error(USER, "only one of '-b' or '-i'"); @@ -101,11 +105,16 @@ char **argv; startobj = nobjects; /* previous objects already converted */ - for ( ; i < argc; i++) { /* read new files */ - if (nfiles >= MAXOBJFIL) - error(INTERNAL, "too many scene files"); - readobj(ofname[nfiles++] = argv[i]); - } + 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; /* find bounding box */ bbmin[0] = bbmin[1] = bbmin[2] = FHUGE; @@ -170,15 +179,15 @@ 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; } @@ -186,15 +195,18 @@ addobject(cu, obj) /* add an object to a cube */ register CUBE *cu; OBJECT obj; { +#define nexti(n) ((ndx += cnt*cnt++)%(n)) + static unsigned long ndx; + static unsigned int cnt; CUBE cukid; OCTREE ot; OBJECT oset[MAXSET+1]; - int in; + int in, k; register int i, j; in = (*ofun[objptr(obj)->otype].funp)(objptr(obj), cu); - if (!in) + if (in == O_MISS) return; /* no intersection */ if (istree(cu->cutree)) { @@ -221,7 +233,7 @@ OBJECT obj; objset(oset, cu->cutree); cukid.cusize = cu->cusize * 0.5; - if (in == 2 || oset[0] < objlim || cukid.cusize < mincusize) { + if (in==O_IN || oset[0] < objlim || cukid.cusize < mincusize) { /* add to set */ if (oset[0] >= MAXSET) { sprintf(errmsg, @@ -243,12 +255,24 @@ OBJECT obj; if ((1<otype)) + addobject(&cukid, oset[j]); + /* then this object */ addobject(&cukid, obj); + /* volumes last */ + k = nexti(oset[0]); /* random start */ + for (j = k+1; j <= oset[0]; j++) + if (isvolume(objptr(oset[j])->otype)) + addobject(&cukid, oset[j]); + for (j = 1; j <= k; j++) + if (isvolume(objptr(oset[j])->otype)) + addobject(&cukid, oset[j]); octkid(ot, i) = cukid.cutree; } cu->cutree = ot; } } +#undef nexti }