| 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 */ |
| 185 |
|
eputs(s) /* put string to stderr */ |
| 186 |
|
register char *s; |
| 187 |
|
{ |
| 188 |
< |
static int inline = 0; |
| 188 |
> |
static int inln = 0; |
| 189 |
|
|
| 190 |
< |
if (!inline++) { |
| 190 |
> |
if (!inln++) { |
| 191 |
|
fputs(progname, stderr); |
| 192 |
|
fputs(": ", stderr); |
| 193 |
|
} |
| 194 |
|
fputs(s, stderr); |
| 195 |
|
if (*s && s[strlen(s)-1] == '\n') |
| 196 |
< |
inline = 0; |
| 196 |
> |
inln = 0; |
| 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; |
| 211 |
|
CUBE cukid; |
| 212 |
|
OCTREE ot; |
| 213 |
|
OBJECT oset[MAXSET+1]; |
| 214 |
+ |
unsigned char inflg[(MAXSET+7)/8], volflg[(MAXSET+7)/8]; |
| 215 |
|
int in; |
| 216 |
|
register int i, j; |
| 217 |
|
|
| 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); |
| 239 |
< |
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; |
| 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 |
+ |
/* 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 |
|
} |