| 1 | 
– | 
/* Copyright (c) 1986 Regents of the University of California */ | 
| 2 | 
– | 
 | 
| 1 | 
  | 
#ifndef lint | 
| 2 | 
< | 
static char SCCSid[] = "$SunId$ LBL"; | 
| 2 | 
> | 
static const char       RCSid[] = "$Id$"; | 
| 3 | 
  | 
#endif | 
| 6 | 
– | 
 | 
| 4 | 
  | 
/* | 
| 5 | 
  | 
 *  octree.c - routines dealing with octrees and cubes. | 
| 9 | 
– | 
 * | 
| 10 | 
– | 
 *     7/28/85 | 
| 6 | 
  | 
 */ | 
| 7 | 
  | 
 | 
| 8 | 
+ | 
#include "copyright.h" | 
| 9 | 
+ | 
 | 
| 10 | 
  | 
#include  "standard.h" | 
| 11 | 
  | 
 | 
| 12 | 
  | 
#include  "octree.h" | 
| 19 | 
  | 
OCTREE | 
| 20 | 
  | 
octalloc()                      /* allocate an octree */ | 
| 21 | 
  | 
{ | 
| 22 | 
< | 
        register OCTREE  freet; | 
| 22 | 
> | 
        OCTREE  freet; | 
| 23 | 
  | 
 | 
| 24 | 
  | 
        if ((freet = ofreelist) != EMPTY) { | 
| 25 | 
  | 
                ofreelist = octkid(freet, 0); | 
| 30 | 
  | 
                errno = 0; | 
| 31 | 
  | 
                if (octbi(freet) >= MAXOBLK) | 
| 32 | 
  | 
                        return(EMPTY); | 
| 33 | 
< | 
                if ((octblock[octbi(freet)] = (OCTREE *)bmalloc( | 
| 34 | 
< | 
                                (unsigned)256*8*sizeof(OCTREE))) == NULL) | 
| 33 | 
> | 
                if ((octblock[octbi(freet)] = (OCTREE *)malloc( | 
| 34 | 
> | 
                                (unsigned)OCTBLKSIZ*8*sizeof(OCTREE))) == NULL) | 
| 35 | 
  | 
                        return(EMPTY); | 
| 36 | 
  | 
        } | 
| 37 | 
< | 
        treetop += 8; | 
| 37 | 
> | 
        treetop++; | 
| 38 | 
  | 
        return(freet); | 
| 39 | 
  | 
} | 
| 40 | 
  | 
 | 
| 41 | 
  | 
 | 
| 42 | 
+ | 
void | 
| 43 | 
  | 
octfree(ot)                     /* free an octree */ | 
| 44 | 
< | 
register OCTREE  ot; | 
| 44 | 
> | 
OCTREE  ot; | 
| 45 | 
  | 
{ | 
| 46 | 
< | 
        register int  i; | 
| 46 | 
> | 
        int  i; | 
| 47 | 
  | 
 | 
| 48 | 
  | 
        if (!istree(ot)) | 
| 49 | 
  | 
                return; | 
| 54 | 
  | 
} | 
| 55 | 
  | 
 | 
| 56 | 
  | 
 | 
| 57 | 
+ | 
void | 
| 58 | 
  | 
octdone()                       /* free EVERYTHING */ | 
| 59 | 
  | 
{ | 
| 60 | 
< | 
        register int    i; | 
| 60 | 
> | 
        int     i; | 
| 61 | 
  | 
 | 
| 62 | 
  | 
        for (i = 0; i < MAXOBLK; i++) { | 
| 63 | 
  | 
                if (octblock[i] == NULL) | 
| 64 | 
  | 
                        break; | 
| 65 | 
< | 
                bfree((char *)octblock[i], (unsigned)256*8*sizeof(OCTREE)); | 
| 65 | 
> | 
                free((void *)octblock[i]); | 
| 66 | 
  | 
                octblock[i] = NULL; | 
| 67 | 
  | 
        } | 
| 68 | 
  | 
        ofreelist = EMPTY; | 
| 72 | 
  | 
 | 
| 73 | 
  | 
OCTREE | 
| 74 | 
  | 
combine(ot)                     /* recursively combine nodes */ | 
| 75 | 
< | 
register OCTREE  ot; | 
| 75 | 
> | 
OCTREE  ot; | 
| 76 | 
  | 
{ | 
| 77 | 
< | 
        register int  i; | 
| 78 | 
< | 
        register OCTREE  ores; | 
| 77 | 
> | 
        int  i; | 
| 78 | 
> | 
        OCTREE  ores; | 
| 79 | 
  | 
 | 
| 80 | 
  | 
        if (!istree(ot))        /* not a tree */ | 
| 81 | 
  | 
                return(ot); | 
| 91 | 
  | 
} | 
| 92 | 
  | 
 | 
| 93 | 
  | 
 | 
| 94 | 
+ | 
void | 
| 95 | 
  | 
culocate(cu, pt)                /* locate point within cube */ | 
| 96 | 
< | 
register CUBE  *cu; | 
| 97 | 
< | 
register FVECT  pt; | 
| 96 | 
> | 
CUBE  *cu; | 
| 97 | 
> | 
FVECT  pt; | 
| 98 | 
  | 
{ | 
| 99 | 
< | 
        register int  i; | 
| 99 | 
> | 
        int  i; | 
| 100 | 
  | 
        int  branch; | 
| 101 | 
  | 
 | 
| 102 | 
  | 
        while (istree(cu->cutree)) { | 
| 112 | 
  | 
} | 
| 113 | 
  | 
 | 
| 114 | 
  | 
 | 
| 115 | 
< | 
cucopy(cu1, cu2)                /* copy cu2 into cu1 */ | 
| 116 | 
< | 
register CUBE  *cu1, *cu2; | 
| 117 | 
< | 
{ | 
| 118 | 
< | 
        cu1->cutree = cu2->cutree; | 
| 119 | 
< | 
        cu1->cusize = cu2->cusize; | 
| 120 | 
< | 
        VCOPY(cu1->cuorg, cu2->cuorg); | 
| 121 | 
< | 
} | 
| 122 | 
< | 
 | 
| 123 | 
< | 
 | 
| 115 | 
> | 
int | 
| 116 | 
  | 
incube(cu, pt)                  /* determine if a point is inside a cube */ | 
| 117 | 
< | 
register CUBE  *cu; | 
| 118 | 
< | 
register FVECT  pt; | 
| 117 | 
> | 
CUBE  *cu; | 
| 118 | 
> | 
FVECT  pt; | 
| 119 | 
  | 
{ | 
| 120 | 
  | 
        if (cu->cuorg[0] > pt[0] || pt[0] >= cu->cuorg[0] + cu->cusize) | 
| 121 | 
  | 
                return(0); |