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 |
|
|
39 |
|
char *ofname[MAXOBJFIL+1]; /* object file names */ |
40 |
|
int nfiles = 0; /* number of object files */ |
41 |
|
|
42 |
< |
double mincusize; /* minimum cube size from resolu */ |
42 |
> |
double mincusize; /* minimum cube size from resolu */ |
43 |
|
|
44 |
|
int (*addobjnotify[])() = {NULL}; /* new object notifier functions */ |
45 |
|
|
48 |
|
int argc; |
49 |
|
char **argv; |
50 |
|
{ |
51 |
< |
char *getenv(); |
54 |
< |
double atof(); |
51 |
> |
extern char *getenv(); |
52 |
|
FVECT bbmin, bbmax; |
53 |
|
char *infile = NULL; |
54 |
+ |
int inpfrozen = 0; |
55 |
|
int outflags = IO_ALL; |
56 |
< |
OBJECT startobj; |
56 |
> |
OBJECT startobj; |
57 |
|
int i; |
58 |
|
|
59 |
< |
progname = argv[0]; |
59 |
> |
progname = argv[0] = fixargv0(argv[0]); |
60 |
|
|
61 |
< |
if ((libpath = getenv("RAYPATH")) == NULL) |
61 |
> |
if ((libpath = getenv(ULIBVAR)) == NULL) |
62 |
|
libpath = DEFPATH; |
63 |
|
|
64 |
|
initotypes(); |
66 |
|
for (i = 1; i < argc && argv[i][0] == '-'; i++) |
67 |
|
switch (argv[i][1]) { |
68 |
|
case '\0': /* scene from stdin */ |
69 |
+ |
outflags &= ~IO_FILES; |
70 |
|
goto breakopt; |
71 |
|
case 'i': /* input octree */ |
72 |
|
infile = argv[++i]; |
95 |
|
break; |
96 |
|
} |
97 |
|
breakopt: |
98 |
+ |
#ifdef MSDOS |
99 |
+ |
setmode(fileno(stdout), O_BINARY); |
100 |
+ |
#endif |
101 |
|
if (infile != NULL) { /* get old octree & objects */ |
102 |
|
if (thescene.cusize > FTINY) |
103 |
|
error(USER, "only one of '-b' or '-i'"); |
104 |
|
nfiles = readoct(infile, IO_ALL, &thescene, ofname); |
105 |
< |
if (nfiles == 0 && outflags & IO_FILES) { |
106 |
< |
error(WARNING, "frozen octree"); |
105 |
< |
outflags &= ~IO_FILES; |
106 |
< |
} |
105 |
> |
if (nfiles == 0) |
106 |
> |
inpfrozen++; |
107 |
|
} |
108 |
|
|
109 |
< |
printargs(argc, argv, stdout); /* info. header */ |
109 |
> |
newheader("RADIANCE", stdout); /* new binary file header */ |
110 |
> |
printargs(argc, argv, stdout); |
111 |
|
fputformat(OCTFMT, stdout); |
112 |
|
printf("\n"); |
113 |
|
|
114 |
|
startobj = nobjects; /* previous objects already converted */ |
115 |
< |
|
115 |
> |
|
116 |
|
for ( ; i < argc; i++) /* read new scene descriptions */ |
117 |
|
if (!strcmp(argv[i], "-")) { /* from stdin */ |
118 |
|
readobj(NULL); |
124 |
|
} |
125 |
|
|
126 |
|
ofname[nfiles] = NULL; |
127 |
+ |
|
128 |
+ |
if (inpfrozen && outflags & IO_FILES) { |
129 |
+ |
error(WARNING, "frozen octree"); |
130 |
+ |
outflags &= ~IO_FILES; |
131 |
+ |
} |
132 |
|
/* find bounding box */ |
133 |
|
bbmin[0] = bbmin[1] = bbmin[2] = FHUGE; |
134 |
|
bbmax[0] = bbmax[1] = bbmax[2] = -FHUGE; |
156 |
|
} |
157 |
|
|
158 |
|
mincusize = thescene.cusize / resolu - FTINY; |
159 |
< |
|
159 |
> |
|
160 |
|
for (i = startobj; i < nobjects; i++) /* add new objects */ |
161 |
|
addobject(&thescene, i); |
162 |
< |
|
162 |
> |
|
163 |
|
thescene.cutree = combine(thescene.cutree); /* optimize */ |
164 |
|
|
165 |
|
writeoct(outflags, &thescene, ofname); /* write structures to stdout */ |
204 |
|
} |
205 |
|
|
206 |
|
|
207 |
< |
#define bitop(f,i,op) (f[((i)>>3)] op (1<<((i)&7))) |
208 |
< |
#define tstbit(f,i) bitop(f,i,&) |
209 |
< |
#define setbit(f,i) bitop(f,i,|=) |
210 |
< |
#define clrbit(f,i) bitop(f,i,&=~) |
211 |
< |
#define tglbit(f,i) bitop(f,i,^=) |
207 |
> |
#define bitop(f,i,op) (f[((i)>>3)] op (1<<((i)&7))) |
208 |
> |
#define tstbit(f,i) bitop(f,i,&) |
209 |
> |
#define setbit(f,i) bitop(f,i,|=) |
210 |
> |
#define clrbit(f,i) bitop(f,i,&=~) |
211 |
> |
#define tglbit(f,i) bitop(f,i,^=) |
212 |
|
|
213 |
|
|
214 |
|
addobject(cu, obj) /* add an object to a cube */ |
215 |
|
register CUBE *cu; |
216 |
< |
OBJECT obj; |
216 |
> |
OBJECT obj; |
217 |
|
{ |
218 |
|
CUBE cukid; |
219 |
< |
OCTREE ot; |
220 |
< |
OBJECT oset[MAXSET+1]; |
221 |
< |
unsigned char inflg[MAXSET/8], volflg[MAXSET/8]; |
219 |
> |
OCTREE ot; |
220 |
> |
OBJECT oset[MAXSET+1]; |
221 |
> |
unsigned char inflg[(MAXSET+7)/8], volflg[(MAXSET+7)/8]; |
222 |
|
int in; |
223 |
|
register int i, j; |
224 |
|
|
226 |
|
|
227 |
|
if (in == O_MISS) |
228 |
|
return; /* no intersection */ |
229 |
< |
|
229 |
> |
|
230 |
|
if (istree(cu->cutree)) { |
231 |
|
/* do children */ |
232 |
|
cukid.cusize = cu->cusize * 0.5; |
251 |
|
/* add to full node */ |
252 |
|
objset(oset, cu->cutree); |
253 |
|
cukid.cusize = cu->cusize * 0.5; |
254 |
< |
|
254 |
> |
|
255 |
|
if (in==O_IN || oset[0] < objlim || cukid.cusize < mincusize) { |
256 |
|
/* add to set */ |
257 |
|
if (oset[0] >= MAXSET) { |
258 |
< |
sprintf(errmsg, |
253 |
< |
"set overflow in addobject (%s)", |
258 |
> |
sprintf(errmsg, "set overflow in addobject (%s)", |
259 |
|
objptr(obj)->oname); |
260 |
|
error(INTERNAL, errmsg); |
261 |
|
} |
274 |
|
if (isvolume(objptr(oset[j])->otype)) { |
275 |
|
setbit(volflg,j-1); |
276 |
|
if ((*ofun[objptr(oset[j])->otype].funp) |
277 |
< |
(objptr(oset[j]),cu) == O_IN) |
277 |
> |
(objptr(oset[j]), cu) == O_IN) |
278 |
|
setbit(inflg,j-1); |
279 |
|
} |
280 |
|
/* assign subcubes */ |
291 |
|
addobject(&cukid, oset[j]); |
292 |
|
/* then this object */ |
293 |
|
addobject(&cukid, obj); |
294 |
< |
/* partial volumes */ |
294 |
> |
/* then partial volumes */ |
295 |
|
for (j = 1; j <= oset[0]; j++) |
296 |
|
if (tstbit(volflg,j-1) && |
297 |
|
!tstbit(inflg,j-1)) |
298 |
|
addobject(&cukid, oset[j]); |
299 |
< |
/* full volumes */ |
299 |
> |
/* full volumes last */ |
300 |
|
for (j = 1; j <= oset[0]; j++) |
301 |
|
if (tstbit(inflg,j-1)) |
302 |
|
addobject(&cukid, oset[j]); |