--- ray/src/common/octree.c 1989/02/02 10:34:37 1.1 +++ ray/src/common/octree.c 2003/02/25 02:47:21 2.6 @@ -1,21 +1,18 @@ -/* 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.6 2003/02/25 02:47:21 greg Exp $"; #endif - /* * octree.c - routines dealing with octrees and cubes. - * - * 7/28/85 */ +#include "copyright.h" + #include "standard.h" #include "octree.h" OCTREE *octblock[MAXOBLK]; /* our octree */ -static OCTREE ofreelist = EMPTY; /* free octree nodes */ +static OCTREE ofreelist = EMPTY; /* freed octree nodes */ static OCTREE treetop = 0; /* next free node */ @@ -34,7 +31,7 @@ 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; @@ -42,6 +39,7 @@ octalloc() /* allocate an octree */ } +void octfree(ot) /* free an octree */ register OCTREE ot; { @@ -56,6 +54,22 @@ register OCTREE ot; } +void +octdone() /* free EVERYTHING */ +{ + register 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; @@ -69,12 +83,15 @@ register OCTREE ot; for (i = 1; i < 8; i++) if ((octkid(ot, i) = combine(octkid(ot, i))) != ores) ores = ot; - if (!istree(ores)) /* all were identical leaves */ - octfree(ot); + if (!istree(ores)) { /* all were identical leaves */ + octkid(ot, 0) = ofreelist; + ofreelist = ot; + } return(ores); } +void culocate(cu, pt) /* locate point within cube */ register CUBE *cu; register FVECT pt; @@ -95,6 +112,7 @@ register FVECT pt; } +void cucopy(cu1, cu2) /* copy cu2 into cu1 */ register CUBE *cu1, *cu2; { @@ -104,6 +122,7 @@ register CUBE *cu1, *cu2; } +int incube(cu, pt) /* determine if a point is inside a cube */ register CUBE *cu; register FVECT pt;