| 1 |
< |
/* Copyright (c) 1986 Regents of the University of California */ |
| 1 |
> |
/* Copyright (c) 1992 Regents of the University of California */ |
| 2 |
|
|
| 3 |
|
#ifndef lint |
| 4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
| 18 |
|
|
| 19 |
|
#include "otypes.h" |
| 20 |
|
|
| 21 |
< |
#ifndef DEFPATH |
| 22 |
< |
#define DEFPATH ":/usr/local/lib/ray" |
| 23 |
< |
#endif |
| 21 |
> |
#include "paths.h" |
| 22 |
|
|
| 23 |
< |
#define OMARGIN (10*FTINY) /* margin around global cube */ |
| 23 |
> |
#define OMARGIN (10*FTINY) /* margin around global cube */ |
| 24 |
|
|
| 25 |
< |
#define MAXOBJFIL 63 /* maximum number of scene files */ |
| 25 |
> |
#define MAXOBJFIL 63 /* maximum number of scene files */ |
| 26 |
|
|
| 27 |
|
char *progname; /* argv[0] */ |
| 28 |
|
|
| 31 |
– |
char *libpath; /* library search path */ |
| 32 |
– |
|
| 29 |
|
int nowarn = 0; /* supress warnings? */ |
| 30 |
|
|
| 31 |
|
int objlim = 5; /* # of objects before split */ |
| 37 |
|
char *ofname[MAXOBJFIL+1]; /* object file names */ |
| 38 |
|
int nfiles = 0; /* number of object files */ |
| 39 |
|
|
| 40 |
< |
double mincusize; /* minimum cube size from resolu */ |
| 40 |
> |
double mincusize; /* minimum cube size from resolu */ |
| 41 |
|
|
| 42 |
|
int (*addobjnotify[])() = {NULL}; /* new object notifier functions */ |
| 43 |
|
|
| 44 |
|
|
| 45 |
|
main(argc, argv) /* convert object files to an octree */ |
| 46 |
|
int argc; |
| 47 |
< |
char **argv; |
| 47 |
> |
char *argv[]; |
| 48 |
|
{ |
| 53 |
– |
extern char *getenv(); |
| 49 |
|
FVECT bbmin, bbmax; |
| 50 |
|
char *infile = NULL; |
| 51 |
+ |
int inpfrozen = 0; |
| 52 |
|
int outflags = IO_ALL; |
| 53 |
< |
OBJECT startobj; |
| 53 |
> |
OBJECT startobj; |
| 54 |
|
int i; |
| 55 |
|
|
| 56 |
< |
progname = argv[0]; |
| 56 |
> |
progname = argv[0] = fixargv0(argv[0]); |
| 57 |
|
|
| 62 |
– |
if ((libpath = getenv("RAYPATH")) == NULL) |
| 63 |
– |
libpath = DEFPATH; |
| 64 |
– |
|
| 58 |
|
initotypes(); |
| 59 |
|
|
| 60 |
|
for (i = 1; i < argc && argv[i][0] == '-'; i++) |
| 88 |
|
break; |
| 89 |
|
} |
| 90 |
|
breakopt: |
| 91 |
+ |
#ifdef MSDOS |
| 92 |
+ |
setmode(fileno(stdout), O_BINARY); |
| 93 |
+ |
#endif |
| 94 |
|
if (infile != NULL) { /* get old octree & objects */ |
| 95 |
|
if (thescene.cusize > FTINY) |
| 96 |
|
error(USER, "only one of '-b' or '-i'"); |
| 97 |
|
nfiles = readoct(infile, IO_ALL, &thescene, ofname); |
| 98 |
< |
if (nfiles == 0 && outflags & IO_FILES) { |
| 99 |
< |
error(WARNING, "frozen octree"); |
| 100 |
< |
outflags &= ~IO_FILES; |
| 101 |
< |
} |
| 102 |
< |
} |
| 107 |
< |
|
| 108 |
< |
printargs(argc, argv, stdout); /* info. header */ |
| 98 |
> |
if (nfiles == 0) |
| 99 |
> |
inpfrozen++; |
| 100 |
> |
} else |
| 101 |
> |
newheader("RADIANCE", stdout); /* new binary file header */ |
| 102 |
> |
printargs(argc, argv, stdout); |
| 103 |
|
fputformat(OCTFMT, stdout); |
| 104 |
|
printf("\n"); |
| 105 |
|
|
| 106 |
|
startobj = nobjects; /* previous objects already converted */ |
| 107 |
< |
|
| 107 |
> |
|
| 108 |
|
for ( ; i < argc; i++) /* read new scene descriptions */ |
| 109 |
|
if (!strcmp(argv[i], "-")) { /* from stdin */ |
| 110 |
|
readobj(NULL); |
| 116 |
|
} |
| 117 |
|
|
| 118 |
|
ofname[nfiles] = NULL; |
| 119 |
+ |
|
| 120 |
+ |
if (inpfrozen && outflags & IO_FILES) { |
| 121 |
+ |
error(WARNING, "frozen octree"); |
| 122 |
+ |
outflags &= ~IO_FILES; |
| 123 |
+ |
} |
| 124 |
|
/* find bounding box */ |
| 125 |
|
bbmin[0] = bbmin[1] = bbmin[2] = FHUGE; |
| 126 |
|
bbmax[0] = bbmax[1] = bbmax[2] = -FHUGE; |
| 148 |
|
} |
| 149 |
|
|
| 150 |
|
mincusize = thescene.cusize / resolu - FTINY; |
| 151 |
< |
|
| 151 |
> |
|
| 152 |
|
for (i = startobj; i < nobjects; i++) /* add new objects */ |
| 153 |
|
addobject(&thescene, i); |
| 154 |
< |
|
| 154 |
> |
|
| 155 |
|
thescene.cutree = combine(thescene.cutree); /* optimize */ |
| 156 |
|
|
| 157 |
|
writeoct(outflags, &thescene, ofname); /* write structures to stdout */ |
| 196 |
|
} |
| 197 |
|
|
| 198 |
|
|
| 199 |
< |
#define bitop(f,i,op) (f[((i)>>3)] op (1<<((i)&7))) |
| 200 |
< |
#define tstbit(f,i) bitop(f,i,&) |
| 201 |
< |
#define setbit(f,i) bitop(f,i,|=) |
| 202 |
< |
#define clrbit(f,i) bitop(f,i,&=~) |
| 203 |
< |
#define tglbit(f,i) bitop(f,i,^=) |
| 199 |
> |
#define bitop(f,i,op) (f[((i)>>3)] op (1<<((i)&7))) |
| 200 |
> |
#define tstbit(f,i) bitop(f,i,&) |
| 201 |
> |
#define setbit(f,i) bitop(f,i,|=) |
| 202 |
> |
#define clrbit(f,i) bitop(f,i,&=~) |
| 203 |
> |
#define tglbit(f,i) bitop(f,i,^=) |
| 204 |
|
|
| 205 |
|
|
| 206 |
|
addobject(cu, obj) /* add an object to a cube */ |
| 207 |
|
register CUBE *cu; |
| 208 |
< |
OBJECT obj; |
| 208 |
> |
OBJECT obj; |
| 209 |
|
{ |
| 210 |
|
CUBE cukid; |
| 211 |
< |
OCTREE ot; |
| 212 |
< |
OBJECT oset[MAXSET+1]; |
| 211 |
> |
OCTREE ot; |
| 212 |
> |
OBJECT oset[MAXSET+1]; |
| 213 |
|
unsigned char inflg[(MAXSET+7)/8], volflg[(MAXSET+7)/8]; |
| 214 |
|
int in; |
| 215 |
|
register int i, j; |
| 218 |
|
|
| 219 |
|
if (in == O_MISS) |
| 220 |
|
return; /* no intersection */ |
| 221 |
< |
|
| 221 |
> |
|
| 222 |
|
if (istree(cu->cutree)) { |
| 223 |
|
/* do children */ |
| 224 |
|
cukid.cusize = cu->cusize * 0.5; |
| 243 |
|
/* add to full node */ |
| 244 |
|
objset(oset, cu->cutree); |
| 245 |
|
cukid.cusize = cu->cusize * 0.5; |
| 246 |
< |
|
| 246 |
> |
|
| 247 |
|
if (in==O_IN || oset[0] < objlim || cukid.cusize < mincusize) { |
| 248 |
|
/* add to set */ |
| 249 |
|
if (oset[0] >= MAXSET) { |