--- ray/src/common/octree.c 1989/10/14 10:56:32 1.2 +++ ray/src/common/octree.c 2009/11/01 04:41:55 2.8 @@ -1,15 +1,12 @@ -/* Copyright (c) 1986 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: octree.c,v 2.8 2009/11/01 04:41:55 greg Exp $"; #endif - /* * octree.c - routines dealing with octrees and cubes. - * - * 7/28/85 */ +#include "copyright.h" + #include "standard.h" #include "octree.h" @@ -22,7 +19,7 @@ static OCTREE treetop = 0; /* next free node */ OCTREE octalloc() /* allocate an octree */ { - register OCTREE freet; + OCTREE freet; if ((freet = ofreelist) != EMPTY) { ofreelist = octkid(freet, 0); @@ -34,18 +31,19 @@ octalloc() /* allocate an octree */ if (octbi(freet) >= MAXOBLK) return(EMPTY); if ((octblock[octbi(freet)] = (OCTREE *)malloc( - (unsigned)256*8*sizeof(OCTREE))) == NULL) + (unsigned)OCTBLKSIZ*8*sizeof(OCTREE))) == NULL) return(EMPTY); } - treetop += 8; + treetop++; return(freet); } +void octfree(ot) /* free an octree */ -register OCTREE ot; +OCTREE ot; { - register int i; + int i; if (!istree(ot)) return; @@ -56,12 +54,28 @@ register OCTREE ot; } +void +octdone() /* free EVERYTHING */ +{ + int i; + + for (i = 0; i < MAXOBLK; i++) { + if (octblock[i] == NULL) + break; + free((void *)octblock[i]); + octblock[i] = NULL; + } + ofreelist = EMPTY; + treetop = 0; +} + + OCTREE combine(ot) /* recursively combine nodes */ -register OCTREE ot; +OCTREE ot; { - register int i; - register OCTREE ores; + int i; + OCTREE ores; if (!istree(ot)) /* not a tree */ return(ot); @@ -77,11 +91,12 @@ register OCTREE ot; } +void culocate(cu, pt) /* locate point within cube */ -register CUBE *cu; -register FVECT pt; +CUBE *cu; +FVECT pt; { - register int i; + int i; int branch; while (istree(cu->cutree)) { @@ -97,18 +112,10 @@ register FVECT pt; } -cucopy(cu1, cu2) /* copy cu2 into cu1 */ -register CUBE *cu1, *cu2; -{ - cu1->cutree = cu2->cutree; - cu1->cusize = cu2->cusize; - VCOPY(cu1->cuorg, cu2->cuorg); -} - - +int incube(cu, pt) /* determine if a point is inside a cube */ -register CUBE *cu; -register FVECT pt; +CUBE *cu; +FVECT pt; { if (cu->cuorg[0] > pt[0] || pt[0] >= cu->cuorg[0] + cu->cusize) return(0);