| 191 |
|
} |
| 192 |
|
|
| 193 |
|
|
| 194 |
+ |
#define bitop(f,i,op) (f[((i)>>3)] op (1<<((i)&7))) |
| 195 |
+ |
#define tstbit(f,i) bitop(f,i,&) |
| 196 |
+ |
#define setbit(f,i) bitop(f,i,|=) |
| 197 |
+ |
#define clrbit(f,i) bitop(f,i,&=~) |
| 198 |
+ |
#define tglbit(f,i) bitop(f,i,^=) |
| 199 |
+ |
|
| 200 |
+ |
|
| 201 |
|
addobject(cu, obj) /* add an object to a cube */ |
| 202 |
|
register CUBE *cu; |
| 203 |
|
OBJECT obj; |
| 204 |
|
{ |
| 198 |
– |
#define nexti(n) ((ndx += cnt*cnt++)%(n)) |
| 199 |
– |
static unsigned long ndx; |
| 200 |
– |
static unsigned int cnt; |
| 205 |
|
CUBE cukid; |
| 206 |
|
OCTREE ot; |
| 207 |
|
OBJECT oset[MAXSET+1]; |
| 208 |
< |
int in, k; |
| 208 |
> |
unsigned char inflg[MAXSET/8], volflg[MAXSET/8]; |
| 209 |
> |
int in; |
| 210 |
|
register int i, j; |
| 211 |
|
|
| 212 |
|
in = (*ofun[objptr(obj)->otype].funp)(objptr(obj), cu); |
| 227 |
|
addobject(&cukid, obj); |
| 228 |
|
octkid(cu->cutree, i) = cukid.cutree; |
| 229 |
|
} |
| 230 |
< |
|
| 231 |
< |
} else if (isempty(cu->cutree)) { |
| 230 |
> |
return; |
| 231 |
> |
} |
| 232 |
> |
if (isempty(cu->cutree)) { |
| 233 |
|
/* singular set */ |
| 234 |
|
oset[0] = 1; oset[1] = obj; |
| 235 |
|
cu->cutree = fullnode(oset); |
| 236 |
< |
|
| 237 |
< |
} else { |
| 238 |
< |
/* add to full node */ |
| 239 |
< |
objset(oset, cu->cutree); |
| 240 |
< |
cukid.cusize = cu->cusize * 0.5; |
| 241 |
< |
|
| 242 |
< |
if (in==O_IN || oset[0] < objlim || cukid.cusize < mincusize) { |
| 243 |
< |
/* add to set */ |
| 244 |
< |
if (oset[0] >= MAXSET) { |
| 245 |
< |
sprintf(errmsg, |
| 246 |
< |
"set overflow in addobject (%s)", |
| 247 |
< |
objptr(obj)->oname); |
| 248 |
< |
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; |
| 236 |
> |
return; |
| 237 |
> |
} |
| 238 |
> |
/* add to full node */ |
| 239 |
> |
objset(oset, cu->cutree); |
| 240 |
> |
cukid.cusize = cu->cusize * 0.5; |
| 241 |
> |
|
| 242 |
> |
if (in==O_IN || oset[0] < objlim || cukid.cusize < mincusize) { |
| 243 |
> |
/* add to set */ |
| 244 |
> |
if (oset[0] >= MAXSET) { |
| 245 |
> |
sprintf(errmsg, |
| 246 |
> |
"set overflow in addobject (%s)", |
| 247 |
> |
objptr(obj)->oname); |
| 248 |
> |
error(INTERNAL, errmsg); |
| 249 |
|
} |
| 250 |
+ |
insertelem(oset, obj); |
| 251 |
+ |
cu->cutree = fullnode(oset); |
| 252 |
+ |
return; |
| 253 |
|
} |
| 254 |
< |
#undef nexti |
| 254 |
> |
/* subdivide cube */ |
| 255 |
> |
if ((ot = octalloc()) == EMPTY) |
| 256 |
> |
error(SYSTEM, "out of octree space"); |
| 257 |
> |
/* mark volumes */ |
| 258 |
> |
j = (oset[0]+7)>>3; |
| 259 |
> |
while (j--) |
| 260 |
> |
volflg[j] = inflg[j] = 0; |
| 261 |
> |
for (j = 1; j <= oset[0]; j++) |
| 262 |
> |
if (isvolume(objptr(oset[j])->otype)) { |
| 263 |
> |
setbit(volflg,j-1); |
| 264 |
> |
if ((*ofun[objptr(oset[j])->otype].funp) |
| 265 |
> |
(objptr(oset[j]),cu) == O_IN) |
| 266 |
> |
setbit(inflg,j-1); |
| 267 |
> |
} |
| 268 |
> |
/* assign subcubes */ |
| 269 |
> |
for (i = 0; i < 8; i++) { |
| 270 |
> |
cukid.cutree = EMPTY; |
| 271 |
> |
for (j = 0; j < 3; j++) { |
| 272 |
> |
cukid.cuorg[j] = cu->cuorg[j]; |
| 273 |
> |
if ((1<<j) & i) |
| 274 |
> |
cukid.cuorg[j] += cukid.cusize; |
| 275 |
> |
} |
| 276 |
> |
/* surfaces first */ |
| 277 |
> |
for (j = 1; j <= oset[0]; j++) |
| 278 |
> |
if (!tstbit(volflg,j-1)) |
| 279 |
> |
addobject(&cukid, oset[j]); |
| 280 |
> |
/* then this object */ |
| 281 |
> |
addobject(&cukid, obj); |
| 282 |
> |
/* partial volumes */ |
| 283 |
> |
for (j = 1; j <= oset[0]; j++) |
| 284 |
> |
if (tstbit(volflg,j-1) && |
| 285 |
> |
!tstbit(inflg,j-1)) |
| 286 |
> |
addobject(&cukid, oset[j]); |
| 287 |
> |
/* full volumes */ |
| 288 |
> |
for (j = 1; j <= oset[0]; j++) |
| 289 |
> |
if (tstbit(inflg,j-1)) |
| 290 |
> |
addobject(&cukid, oset[j]); |
| 291 |
> |
/* returned node */ |
| 292 |
> |
octkid(ot, i) = cukid.cutree; |
| 293 |
> |
} |
| 294 |
> |
cu->cutree = ot; |
| 295 |
|
} |