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 |
< |
#define OMARGIN (10*FTINY) /* margin around global cube */ |
21 |
> |
#include "paths.h" |
22 |
|
|
23 |
< |
#define MAXOBJFIL 63 /* maximum number of scene files */ |
23 |
> |
#define OMARGIN (10*FTINY) /* margin around global cube */ |
24 |
|
|
25 |
+ |
#define MAXOBJFIL 63 /* maximum number of scene files */ |
26 |
+ |
|
27 |
|
char *progname; /* argv[0] */ |
28 |
|
|
27 |
– |
char *libpath; /* library search path */ |
28 |
– |
|
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 |
|
|
46 |
|
int argc; |
47 |
|
char **argv; |
48 |
|
{ |
49 |
< |
char *getenv(); |
50 |
< |
double atof(); |
49 |
> |
extern char *getenv(); |
50 |
|
FVECT bbmin, bbmax; |
51 |
|
char *infile = NULL; |
52 |
+ |
int inpfrozen = 0; |
53 |
|
int outflags = IO_ALL; |
54 |
< |
OBJECT startobj; |
54 |
> |
OBJECT startobj; |
55 |
|
int i; |
56 |
|
|
57 |
< |
progname = argv[0]; |
57 |
> |
progname = argv[0] = fixargv0(argv[0]); |
58 |
|
|
59 |
< |
if ((libpath = getenv("RAYPATH")) == NULL) |
60 |
< |
libpath = ":/usr/local/lib/ray"; |
59 |
> |
initotypes(); |
60 |
|
|
61 |
|
for (i = 1; i < argc && argv[i][0] == '-'; i++) |
62 |
|
switch (argv[i][1]) { |
63 |
|
case '\0': /* scene from stdin */ |
64 |
+ |
outflags &= ~IO_FILES; |
65 |
|
goto breakopt; |
66 |
|
case 'i': /* input octree */ |
67 |
|
infile = argv[++i]; |
90 |
|
break; |
91 |
|
} |
92 |
|
breakopt: |
93 |
+ |
#ifdef MSDOS |
94 |
+ |
setmode(fileno(stdout), O_BINARY); |
95 |
+ |
#endif |
96 |
|
if (infile != NULL) { /* get old octree & objects */ |
97 |
|
if (thescene.cusize > FTINY) |
98 |
|
error(USER, "only one of '-b' or '-i'"); |
99 |
|
nfiles = readoct(infile, IO_ALL, &thescene, ofname); |
100 |
< |
if (nfiles == 0 && outflags & IO_FILES) { |
101 |
< |
error(WARNING, "frozen octree"); |
102 |
< |
outflags &= ~IO_FILES; |
103 |
< |
} |
104 |
< |
} |
105 |
< |
|
103 |
< |
printargs(argc, argv, stdout); /* info. header */ |
100 |
> |
if (nfiles == 0) |
101 |
> |
inpfrozen++; |
102 |
> |
} else |
103 |
> |
newheader("RADIANCE", stdout); /* new binary file header */ |
104 |
> |
printargs(argc, argv, stdout); |
105 |
> |
fputformat(OCTFMT, stdout); |
106 |
|
printf("\n"); |
107 |
|
|
108 |
|
startobj = nobjects; /* previous objects already converted */ |
109 |
< |
|
109 |
> |
|
110 |
|
for ( ; i < argc; i++) /* read new scene descriptions */ |
111 |
|
if (!strcmp(argv[i], "-")) { /* from stdin */ |
112 |
|
readobj(NULL); |
118 |
|
} |
119 |
|
|
120 |
|
ofname[nfiles] = NULL; |
121 |
+ |
|
122 |
+ |
if (inpfrozen && outflags & IO_FILES) { |
123 |
+ |
error(WARNING, "frozen octree"); |
124 |
+ |
outflags &= ~IO_FILES; |
125 |
+ |
} |
126 |
|
/* find bounding box */ |
127 |
|
bbmin[0] = bbmin[1] = bbmin[2] = FHUGE; |
128 |
|
bbmax[0] = bbmax[1] = bbmax[2] = -FHUGE; |
150 |
|
} |
151 |
|
|
152 |
|
mincusize = thescene.cusize / resolu - FTINY; |
153 |
< |
|
153 |
> |
|
154 |
|
for (i = startobj; i < nobjects; i++) /* add new objects */ |
155 |
|
addobject(&thescene, i); |
156 |
< |
|
156 |
> |
|
157 |
|
thescene.cutree = combine(thescene.cutree); /* optimize */ |
158 |
|
|
159 |
|
writeoct(outflags, &thescene, ofname); /* write structures to stdout */ |
198 |
|
} |
199 |
|
|
200 |
|
|
201 |
+ |
#define bitop(f,i,op) (f[((i)>>3)] op (1<<((i)&7))) |
202 |
+ |
#define tstbit(f,i) bitop(f,i,&) |
203 |
+ |
#define setbit(f,i) bitop(f,i,|=) |
204 |
+ |
#define clrbit(f,i) bitop(f,i,&=~) |
205 |
+ |
#define tglbit(f,i) bitop(f,i,^=) |
206 |
+ |
|
207 |
+ |
|
208 |
|
addobject(cu, obj) /* add an object to a cube */ |
209 |
|
register CUBE *cu; |
210 |
< |
OBJECT obj; |
210 |
> |
OBJECT obj; |
211 |
|
{ |
212 |
|
CUBE cukid; |
213 |
< |
OCTREE ot; |
214 |
< |
OBJECT oset[MAXSET+1]; |
213 |
> |
OCTREE ot; |
214 |
> |
OBJECT oset[MAXSET+1]; |
215 |
> |
unsigned char inflg[(MAXSET+7)/8], volflg[(MAXSET+7)/8]; |
216 |
|
int in; |
217 |
|
register int i, j; |
218 |
|
|
220 |
|
|
221 |
|
if (in == O_MISS) |
222 |
|
return; /* no intersection */ |
223 |
< |
|
223 |
> |
|
224 |
|
if (istree(cu->cutree)) { |
225 |
|
/* do children */ |
226 |
|
cukid.cusize = cu->cusize * 0.5; |
234 |
|
addobject(&cukid, obj); |
235 |
|
octkid(cu->cutree, i) = cukid.cutree; |
236 |
|
} |
237 |
< |
|
238 |
< |
} else if (isempty(cu->cutree)) { |
237 |
> |
return; |
238 |
> |
} |
239 |
> |
if (isempty(cu->cutree)) { |
240 |
|
/* singular set */ |
241 |
|
oset[0] = 1; oset[1] = obj; |
242 |
|
cu->cutree = fullnode(oset); |
243 |
< |
|
244 |
< |
} else { |
245 |
< |
/* add to full node */ |
246 |
< |
objset(oset, cu->cutree); |
247 |
< |
cukid.cusize = cu->cusize * 0.5; |
232 |
< |
|
233 |
< |
if (in==O_IN || oset[0] < objlim || cukid.cusize < mincusize) { |
234 |
< |
/* add to set */ |
235 |
< |
if (oset[0] >= MAXSET) { |
236 |
< |
sprintf(errmsg, |
237 |
< |
"set overflow in addobject (%s)", |
238 |
< |
objptr(obj)->oname); |
239 |
< |
error(INTERNAL, errmsg); |
240 |
< |
} |
241 |
< |
insertelem(oset, obj); |
242 |
< |
cu->cutree = fullnode(oset); |
243 |
> |
return; |
244 |
> |
} |
245 |
> |
/* add to full node */ |
246 |
> |
objset(oset, cu->cutree); |
247 |
> |
cukid.cusize = cu->cusize * 0.5; |
248 |
|
|
249 |
< |
} else { |
250 |
< |
/* subdivide cube */ |
251 |
< |
if ((ot = octalloc()) == EMPTY) |
252 |
< |
error(SYSTEM, "out of octree space"); |
253 |
< |
for (i = 0; i < 8; i++) { |
254 |
< |
cukid.cutree = EMPTY; |
250 |
< |
for (j = 0; j < 3; j++) { |
251 |
< |
cukid.cuorg[j] = cu->cuorg[j]; |
252 |
< |
if ((1<<j) & i) |
253 |
< |
cukid.cuorg[j] += cukid.cusize; |
254 |
< |
} |
255 |
< |
/* surfaces first */ |
256 |
< |
for (j = 1; j <= oset[0]; j++) |
257 |
< |
if (!isvolume(objptr(oset[j])->otype)) |
258 |
< |
addobject(&cukid, oset[j]); |
259 |
< |
/* then this object */ |
260 |
< |
addobject(&cukid, obj); |
261 |
< |
/* volumes last */ |
262 |
< |
for (j = 1; j <= oset[0]; j++) |
263 |
< |
if (isvolume(objptr(oset[j])->otype)) |
264 |
< |
addobject(&cukid, oset[j]); |
265 |
< |
octkid(ot, i) = cukid.cutree; |
266 |
< |
} |
267 |
< |
cu->cutree = ot; |
249 |
> |
if (in==O_IN || oset[0] < objlim || cukid.cusize < mincusize) { |
250 |
> |
/* add to set */ |
251 |
> |
if (oset[0] >= MAXSET) { |
252 |
> |
sprintf(errmsg, "set overflow in addobject (%s)", |
253 |
> |
objptr(obj)->oname); |
254 |
> |
error(INTERNAL, errmsg); |
255 |
|
} |
256 |
+ |
insertelem(oset, obj); |
257 |
+ |
cu->cutree = fullnode(oset); |
258 |
+ |
return; |
259 |
|
} |
260 |
+ |
/* subdivide cube */ |
261 |
+ |
if ((ot = octalloc()) == EMPTY) |
262 |
+ |
error(SYSTEM, "out of octree space"); |
263 |
+ |
/* mark volumes */ |
264 |
+ |
j = (oset[0]+7)>>3; |
265 |
+ |
while (j--) |
266 |
+ |
volflg[j] = inflg[j] = 0; |
267 |
+ |
for (j = 1; j <= oset[0]; j++) |
268 |
+ |
if (isvolume(objptr(oset[j])->otype)) { |
269 |
+ |
setbit(volflg,j-1); |
270 |
+ |
if ((*ofun[objptr(oset[j])->otype].funp) |
271 |
+ |
(objptr(oset[j]), cu) == O_IN) |
272 |
+ |
setbit(inflg,j-1); |
273 |
+ |
} |
274 |
+ |
/* assign subcubes */ |
275 |
+ |
for (i = 0; i < 8; i++) { |
276 |
+ |
cukid.cutree = EMPTY; |
277 |
+ |
for (j = 0; j < 3; j++) { |
278 |
+ |
cukid.cuorg[j] = cu->cuorg[j]; |
279 |
+ |
if ((1<<j) & i) |
280 |
+ |
cukid.cuorg[j] += cukid.cusize; |
281 |
+ |
} |
282 |
+ |
/* surfaces first */ |
283 |
+ |
for (j = 1; j <= oset[0]; j++) |
284 |
+ |
if (!tstbit(volflg,j-1)) |
285 |
+ |
addobject(&cukid, oset[j]); |
286 |
+ |
/* then this object */ |
287 |
+ |
addobject(&cukid, obj); |
288 |
+ |
/* then partial volumes */ |
289 |
+ |
for (j = 1; j <= oset[0]; j++) |
290 |
+ |
if (tstbit(volflg,j-1) && |
291 |
+ |
!tstbit(inflg,j-1)) |
292 |
+ |
addobject(&cukid, oset[j]); |
293 |
+ |
/* full volumes last */ |
294 |
+ |
for (j = 1; j <= oset[0]; j++) |
295 |
+ |
if (tstbit(inflg,j-1)) |
296 |
+ |
addobject(&cukid, oset[j]); |
297 |
+ |
/* returned node */ |
298 |
+ |
octkid(ot, i) = cukid.cutree; |
299 |
+ |
} |
300 |
+ |
cu->cutree = ot; |
301 |
|
} |