| 18 |
|
|
| 19 |
|
#include "otypes.h" |
| 20 |
|
|
| 21 |
+ |
#ifndef DEFPATH |
| 22 |
+ |
#define DEFPATH ":/usr/local/lib/ray" |
| 23 |
+ |
#endif |
| 24 |
+ |
|
| 25 |
|
#define OMARGIN (10*FTINY) /* margin around global cube */ |
| 26 |
|
|
| 27 |
|
#define MAXOBJFIL 63 /* maximum number of scene files */ |
| 50 |
|
int argc; |
| 51 |
|
char **argv; |
| 52 |
|
{ |
| 53 |
< |
char *getenv(); |
| 50 |
< |
double atof(); |
| 53 |
> |
extern char *getenv(); |
| 54 |
|
FVECT bbmin, bbmax; |
| 55 |
|
char *infile = NULL; |
| 56 |
|
int outflags = IO_ALL; |
| 60 |
|
progname = argv[0]; |
| 61 |
|
|
| 62 |
|
if ((libpath = getenv("RAYPATH")) == NULL) |
| 63 |
< |
libpath = ":/usr/local/lib/ray"; |
| 63 |
> |
libpath = DEFPATH; |
| 64 |
|
|
| 65 |
+ |
initotypes(); |
| 66 |
+ |
|
| 67 |
|
for (i = 1; i < argc && argv[i][0] == '-'; i++) |
| 68 |
|
switch (argv[i][1]) { |
| 69 |
|
case '\0': /* scene from stdin */ |
| 106 |
|
} |
| 107 |
|
|
| 108 |
|
printargs(argc, argv, stdout); /* info. header */ |
| 109 |
+ |
fputformat(OCTFMT, stdout); |
| 110 |
|
printf("\n"); |
| 111 |
|
|
| 112 |
|
startobj = nobjects; /* previous objects already converted */ |
| 197 |
|
} |
| 198 |
|
|
| 199 |
|
|
| 200 |
+ |
#define bitop(f,i,op) (f[((i)>>3)] op (1<<((i)&7))) |
| 201 |
+ |
#define tstbit(f,i) bitop(f,i,&) |
| 202 |
+ |
#define setbit(f,i) bitop(f,i,|=) |
| 203 |
+ |
#define clrbit(f,i) bitop(f,i,&=~) |
| 204 |
+ |
#define tglbit(f,i) bitop(f,i,^=) |
| 205 |
+ |
|
| 206 |
+ |
|
| 207 |
|
addobject(cu, obj) /* add an object to a cube */ |
| 208 |
|
register CUBE *cu; |
| 209 |
|
OBJECT obj; |
| 210 |
|
{ |
| 198 |
– |
#define nexti(n) ((ndx += cnt*cnt++)%(n)) |
| 199 |
– |
static unsigned long ndx; |
| 200 |
– |
static unsigned int cnt; |
| 211 |
|
CUBE cukid; |
| 212 |
|
OCTREE ot; |
| 213 |
|
OBJECT oset[MAXSET+1]; |
| 214 |
< |
int in, k; |
| 214 |
> |
unsigned char inflg[(MAXSET+7)/8], volflg[(MAXSET+7)/8]; |
| 215 |
> |
int in; |
| 216 |
|
register int i, j; |
| 217 |
|
|
| 218 |
|
in = (*ofun[objptr(obj)->otype].funp)(objptr(obj), cu); |
| 233 |
|
addobject(&cukid, obj); |
| 234 |
|
octkid(cu->cutree, i) = cukid.cutree; |
| 235 |
|
} |
| 236 |
< |
|
| 237 |
< |
} else if (isempty(cu->cutree)) { |
| 236 |
> |
return; |
| 237 |
> |
} |
| 238 |
> |
if (isempty(cu->cutree)) { |
| 239 |
|
/* singular set */ |
| 240 |
|
oset[0] = 1; oset[1] = obj; |
| 241 |
|
cu->cutree = fullnode(oset); |
| 242 |
< |
|
| 243 |
< |
} else { |
| 244 |
< |
/* add to full node */ |
| 245 |
< |
objset(oset, cu->cutree); |
| 246 |
< |
cukid.cusize = cu->cusize * 0.5; |
| 247 |
< |
|
| 248 |
< |
if (in==O_IN || oset[0] < objlim || cukid.cusize < mincusize) { |
| 249 |
< |
/* add to set */ |
| 250 |
< |
if (oset[0] >= MAXSET) { |
| 251 |
< |
sprintf(errmsg, |
| 252 |
< |
"set overflow in addobject (%s)", |
| 253 |
< |
objptr(obj)->oname); |
| 242 |
< |
error(INTERNAL, errmsg); |
| 243 |
< |
} |
| 244 |
< |
insertelem(oset, obj); |
| 245 |
< |
cu->cutree = fullnode(oset); |
| 246 |
< |
|
| 247 |
< |
} else { |
| 248 |
< |
/* subdivide cube */ |
| 249 |
< |
if ((ot = octalloc()) == EMPTY) |
| 250 |
< |
error(SYSTEM, "out of octree space"); |
| 251 |
< |
for (i = 0; i < 8; i++) { |
| 252 |
< |
cukid.cutree = EMPTY; |
| 253 |
< |
for (j = 0; j < 3; j++) { |
| 254 |
< |
cukid.cuorg[j] = cu->cuorg[j]; |
| 255 |
< |
if ((1<<j) & i) |
| 256 |
< |
cukid.cuorg[j] += cukid.cusize; |
| 257 |
< |
} |
| 258 |
< |
/* surfaces first */ |
| 259 |
< |
for (j = 1; j <= oset[0]; j++) |
| 260 |
< |
if (!isvolume(objptr(oset[j])->otype)) |
| 261 |
< |
addobject(&cukid, oset[j]); |
| 262 |
< |
/* then this object */ |
| 263 |
< |
addobject(&cukid, obj); |
| 264 |
< |
/* volumes last */ |
| 265 |
< |
k = nexti(oset[0]); /* random start */ |
| 266 |
< |
for (j = k+1; j <= oset[0]; j++) |
| 267 |
< |
if (isvolume(objptr(oset[j])->otype)) |
| 268 |
< |
addobject(&cukid, oset[j]); |
| 269 |
< |
for (j = 1; j <= k; j++) |
| 270 |
< |
if (isvolume(objptr(oset[j])->otype)) |
| 271 |
< |
addobject(&cukid, oset[j]); |
| 272 |
< |
octkid(ot, i) = cukid.cutree; |
| 273 |
< |
} |
| 274 |
< |
cu->cutree = ot; |
| 242 |
> |
return; |
| 243 |
> |
} |
| 244 |
> |
/* add to full node */ |
| 245 |
> |
objset(oset, cu->cutree); |
| 246 |
> |
cukid.cusize = cu->cusize * 0.5; |
| 247 |
> |
|
| 248 |
> |
if (in==O_IN || oset[0] < objlim || cukid.cusize < mincusize) { |
| 249 |
> |
/* add to set */ |
| 250 |
> |
if (oset[0] >= MAXSET) { |
| 251 |
> |
sprintf(errmsg, "set overflow in addobject (%s)", |
| 252 |
> |
objptr(obj)->oname); |
| 253 |
> |
error(INTERNAL, errmsg); |
| 254 |
|
} |
| 255 |
+ |
insertelem(oset, obj); |
| 256 |
+ |
cu->cutree = fullnode(oset); |
| 257 |
+ |
return; |
| 258 |
|
} |
| 259 |
< |
#undef nexti |
| 259 |
> |
/* subdivide cube */ |
| 260 |
> |
if ((ot = octalloc()) == EMPTY) |
| 261 |
> |
error(SYSTEM, "out of octree space"); |
| 262 |
> |
/* mark volumes */ |
| 263 |
> |
j = (oset[0]+7)>>3; |
| 264 |
> |
while (j--) |
| 265 |
> |
volflg[j] = inflg[j] = 0; |
| 266 |
> |
for (j = 1; j <= oset[0]; j++) |
| 267 |
> |
if (isvolume(objptr(oset[j])->otype)) { |
| 268 |
> |
setbit(volflg,j-1); |
| 269 |
> |
if ((*ofun[objptr(oset[j])->otype].funp) |
| 270 |
> |
(objptr(oset[j]), cu) == O_IN) |
| 271 |
> |
setbit(inflg,j-1); |
| 272 |
> |
} |
| 273 |
> |
/* assign subcubes */ |
| 274 |
> |
for (i = 0; i < 8; i++) { |
| 275 |
> |
cukid.cutree = EMPTY; |
| 276 |
> |
for (j = 0; j < 3; j++) { |
| 277 |
> |
cukid.cuorg[j] = cu->cuorg[j]; |
| 278 |
> |
if ((1<<j) & i) |
| 279 |
> |
cukid.cuorg[j] += cukid.cusize; |
| 280 |
> |
} |
| 281 |
> |
/* surfaces first */ |
| 282 |
> |
for (j = 1; j <= oset[0]; j++) |
| 283 |
> |
if (!tstbit(volflg,j-1)) |
| 284 |
> |
addobject(&cukid, oset[j]); |
| 285 |
> |
/* then this object */ |
| 286 |
> |
addobject(&cukid, obj); |
| 287 |
> |
/* then partial volumes */ |
| 288 |
> |
for (j = 1; j <= oset[0]; j++) |
| 289 |
> |
if (tstbit(volflg,j-1) && |
| 290 |
> |
!tstbit(inflg,j-1)) |
| 291 |
> |
addobject(&cukid, oset[j]); |
| 292 |
> |
/* full volumes last */ |
| 293 |
> |
for (j = 1; j <= oset[0]; j++) |
| 294 |
> |
if (tstbit(inflg,j-1)) |
| 295 |
> |
addobject(&cukid, oset[j]); |
| 296 |
> |
/* returned node */ |
| 297 |
> |
octkid(ot, i) = cukid.cutree; |
| 298 |
> |
} |
| 299 |
> |
cu->cutree = ot; |
| 300 |
|
} |