59 |
|
if ((libpath = getenv("RAYPATH")) == NULL) |
60 |
|
libpath = ":/usr/local/lib/ray"; |
61 |
|
|
62 |
+ |
initotypes(); |
63 |
+ |
|
64 |
|
for (i = 1; i < argc && argv[i][0] == '-'; i++) |
65 |
|
switch (argv[i][1]) { |
66 |
|
case '\0': /* scene from stdin */ |
181 |
|
eputs(s) /* put string to stderr */ |
182 |
|
register char *s; |
183 |
|
{ |
184 |
< |
static int inline = 0; |
184 |
> |
static int inln = 0; |
185 |
|
|
186 |
< |
if (!inline++) { |
186 |
> |
if (!inln++) { |
187 |
|
fputs(progname, stderr); |
188 |
|
fputs(": ", stderr); |
189 |
|
} |
190 |
|
fputs(s, stderr); |
191 |
|
if (*s && s[strlen(s)-1] == '\n') |
192 |
< |
inline = 0; |
192 |
> |
inln = 0; |
193 |
|
} |
194 |
|
|
195 |
|
|
196 |
+ |
#define bitop(f,i,op) (f[((i)>>3)] op (1<<((i)&7))) |
197 |
+ |
#define tstbit(f,i) bitop(f,i,&) |
198 |
+ |
#define setbit(f,i) bitop(f,i,|=) |
199 |
+ |
#define clrbit(f,i) bitop(f,i,&=~) |
200 |
+ |
#define tglbit(f,i) bitop(f,i,^=) |
201 |
+ |
|
202 |
+ |
|
203 |
|
addobject(cu, obj) /* add an object to a cube */ |
204 |
|
register CUBE *cu; |
205 |
|
OBJECT obj; |
207 |
|
CUBE cukid; |
208 |
|
OCTREE ot; |
209 |
|
OBJECT oset[MAXSET+1]; |
210 |
+ |
unsigned char inflg[MAXSET/8], volflg[MAXSET/8]; |
211 |
|
int in; |
212 |
|
register int i, j; |
213 |
|
|
229 |
|
addobject(&cukid, obj); |
230 |
|
octkid(cu->cutree, i) = cukid.cutree; |
231 |
|
} |
232 |
< |
|
233 |
< |
} else if (isempty(cu->cutree)) { |
232 |
> |
return; |
233 |
> |
} |
234 |
> |
if (isempty(cu->cutree)) { |
235 |
|
/* singular set */ |
236 |
|
oset[0] = 1; oset[1] = obj; |
237 |
|
cu->cutree = fullnode(oset); |
238 |
< |
|
239 |
< |
} else { |
240 |
< |
/* add to full node */ |
241 |
< |
objset(oset, cu->cutree); |
242 |
< |
cukid.cusize = cu->cusize * 0.5; |
243 |
< |
|
244 |
< |
if (in==O_IN || oset[0] < objlim || cukid.cusize < mincusize) { |
245 |
< |
/* add to set */ |
246 |
< |
if (oset[0] >= MAXSET) { |
247 |
< |
sprintf(errmsg, |
248 |
< |
"set overflow in addobject (%s)", |
249 |
< |
objptr(obj)->oname); |
250 |
< |
error(INTERNAL, errmsg); |
240 |
< |
} |
241 |
< |
insertelem(oset, obj); |
242 |
< |
cu->cutree = fullnode(oset); |
243 |
< |
|
244 |
< |
} else { |
245 |
< |
/* subdivide cube */ |
246 |
< |
if ((ot = octalloc()) == EMPTY) |
247 |
< |
error(SYSTEM, "out of octree space"); |
248 |
< |
for (i = 0; i < 8; i++) { |
249 |
< |
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 |
< |
addobject(&cukid, obj); |
256 |
< |
for (j = 1; j <= oset[0]; j++) |
257 |
< |
addobject(&cukid, oset[j]); |
258 |
< |
octkid(ot, i) = cukid.cutree; |
259 |
< |
} |
260 |
< |
cu->cutree = ot; |
238 |
> |
return; |
239 |
> |
} |
240 |
> |
/* add to full node */ |
241 |
> |
objset(oset, cu->cutree); |
242 |
> |
cukid.cusize = cu->cusize * 0.5; |
243 |
> |
|
244 |
> |
if (in==O_IN || oset[0] < objlim || cukid.cusize < mincusize) { |
245 |
> |
/* add to set */ |
246 |
> |
if (oset[0] >= MAXSET) { |
247 |
> |
sprintf(errmsg, |
248 |
> |
"set overflow in addobject (%s)", |
249 |
> |
objptr(obj)->oname); |
250 |
> |
error(INTERNAL, errmsg); |
251 |
|
} |
252 |
+ |
insertelem(oset, obj); |
253 |
+ |
cu->cutree = fullnode(oset); |
254 |
+ |
return; |
255 |
|
} |
256 |
+ |
/* subdivide cube */ |
257 |
+ |
if ((ot = octalloc()) == EMPTY) |
258 |
+ |
error(SYSTEM, "out of octree space"); |
259 |
+ |
/* mark volumes */ |
260 |
+ |
j = (oset[0]+7)>>3; |
261 |
+ |
while (j--) |
262 |
+ |
volflg[j] = inflg[j] = 0; |
263 |
+ |
for (j = 1; j <= oset[0]; j++) |
264 |
+ |
if (isvolume(objptr(oset[j])->otype)) { |
265 |
+ |
setbit(volflg,j-1); |
266 |
+ |
if ((*ofun[objptr(oset[j])->otype].funp) |
267 |
+ |
(objptr(oset[j]),cu) == O_IN) |
268 |
+ |
setbit(inflg,j-1); |
269 |
+ |
} |
270 |
+ |
/* assign subcubes */ |
271 |
+ |
for (i = 0; i < 8; i++) { |
272 |
+ |
cukid.cutree = EMPTY; |
273 |
+ |
for (j = 0; j < 3; j++) { |
274 |
+ |
cukid.cuorg[j] = cu->cuorg[j]; |
275 |
+ |
if ((1<<j) & i) |
276 |
+ |
cukid.cuorg[j] += cukid.cusize; |
277 |
+ |
} |
278 |
+ |
/* surfaces first */ |
279 |
+ |
for (j = 1; j <= oset[0]; j++) |
280 |
+ |
if (!tstbit(volflg,j-1)) |
281 |
+ |
addobject(&cukid, oset[j]); |
282 |
+ |
/* then this object */ |
283 |
+ |
addobject(&cukid, obj); |
284 |
+ |
/* partial volumes */ |
285 |
+ |
for (j = 1; j <= oset[0]; j++) |
286 |
+ |
if (tstbit(volflg,j-1) && |
287 |
+ |
!tstbit(inflg,j-1)) |
288 |
+ |
addobject(&cukid, oset[j]); |
289 |
+ |
/* full volumes */ |
290 |
+ |
for (j = 1; j <= oset[0]; j++) |
291 |
+ |
if (tstbit(inflg,j-1)) |
292 |
+ |
addobject(&cukid, oset[j]); |
293 |
+ |
/* returned node */ |
294 |
+ |
octkid(ot, i) = cukid.cutree; |
295 |
+ |
} |
296 |
+ |
cu->cutree = ot; |
297 |
|
} |