| 1 |
– |
/* Copyright (c) 1998 Silicon Graphics, Inc. */ |
| 2 |
– |
|
| 1 |
|
#ifndef lint |
| 2 |
< |
static char SCCSid[] = "$SunId$ SGI"; |
| 2 |
> |
static const char RCSid[] = "$Id$"; |
| 3 |
|
#endif |
| 6 |
– |
|
| 4 |
|
/* |
| 5 |
|
* Bundle holodeck beams together into clumps. |
| 6 |
|
*/ |
| 8 |
|
#include "holo.h" |
| 9 |
|
|
| 10 |
|
#define flgop(p,i,op) ((p)[(i)>>5] op (1L<<((i)&0x1f))) |
| 11 |
< |
#define isset(p,i) flgop(p,i,&) |
| 11 |
> |
#define issetfl(p,i) flgop(p,i,&) |
| 12 |
|
#define setfl(p,i) flgop(p,i,|=) |
| 13 |
|
#define clrfl(p,i) flgop(p,i,&=~) |
| 14 |
|
|
| 17 |
|
|
| 18 |
|
#define nextneigh() (bneighrem<=0 ? 0 : bneighlist[--bneighrem]) |
| 19 |
|
|
| 20 |
+ |
static void gcshifti(GCOORD *gc, int ia, int di, HOLO *hp); |
| 21 |
+ |
static void mkneighgrid(GCOORD ng[3*3], HOLO *hp, GCOORD *gc); |
| 22 |
+ |
static int firstneigh(HOLO *hp, int b); |
| 23 |
|
|
| 24 |
< |
gcshifti(gc, ia, di, hp) /* shift cell row or column */ |
| 25 |
< |
register GCOORD *gc; |
| 26 |
< |
int ia, di; |
| 27 |
< |
register HOLO *hp; |
| 24 |
> |
|
| 25 |
> |
|
| 26 |
> |
static void |
| 27 |
> |
gcshifti( /* shift cell row or column */ |
| 28 |
> |
GCOORD *gc, |
| 29 |
> |
int ia, |
| 30 |
> |
int di, |
| 31 |
> |
HOLO *hp |
| 32 |
> |
) |
| 33 |
|
{ |
| 34 |
|
int nw; |
| 35 |
|
|
| 51 |
|
} |
| 52 |
|
|
| 53 |
|
|
| 54 |
< |
mkneighgrid(ng, hp, gc) /* compute neighborhood for grid cell */ |
| 55 |
< |
GCOORD ng[3*3]; |
| 56 |
< |
HOLO *hp; |
| 57 |
< |
GCOORD *gc; |
| 54 |
> |
static void |
| 55 |
> |
mkneighgrid( /* compute neighborhood for grid cell */ |
| 56 |
> |
GCOORD ng[3*3], |
| 57 |
> |
HOLO *hp, |
| 58 |
> |
GCOORD *gc |
| 59 |
> |
) |
| 60 |
|
{ |
| 61 |
|
GCOORD gci0; |
| 62 |
< |
register int i, j; |
| 62 |
> |
int i, j; |
| 63 |
|
|
| 64 |
|
for (i = 3; i--; ) { |
| 65 |
< |
copystruct(&gci0, gc); |
| 65 |
> |
gci0 = *gc; |
| 66 |
|
gcshifti(&gci0, 0, i-1, hp); |
| 67 |
|
for (j = 3; j--; ) { |
| 68 |
< |
copystruct(ng+(3*i+j), &gci0); |
| 68 |
> |
*(ng+(3*i+j)) = gci0; |
| 69 |
|
gcshifti(ng+(3*i+j), gci0.w==gc->w, j-1, hp); |
| 70 |
|
} |
| 71 |
|
} |
| 73 |
|
|
| 74 |
|
|
| 75 |
|
static int |
| 76 |
< |
firstneigh(hp, b) /* initialize neighbor list and return first */ |
| 77 |
< |
HOLO *hp; |
| 78 |
< |
int b; |
| 76 |
> |
firstneigh( /* initialize neighbor list and return first */ |
| 77 |
> |
HOLO *hp, |
| 78 |
> |
int b |
| 79 |
> |
) |
| 80 |
|
{ |
| 81 |
|
GCOORD wg0[9], wg1[9], bgc[2]; |
| 82 |
|
int i, j; |
| 87 |
|
bneighrem = 0; |
| 88 |
|
for (i = 9; i--; ) |
| 89 |
|
for (j = 9; j--; ) { |
| 90 |
< |
if (i == 4 & j == 4) /* don't copy starting beam */ |
| 90 |
> |
if ((i == 4) & (j == 4)) /* don't copy starting beam */ |
| 91 |
|
continue; |
| 92 |
|
if (wg0[i].w == wg1[j].w) |
| 93 |
|
continue; |
| 94 |
< |
copystruct(bgc, wg0+i); |
| 95 |
< |
copystruct(bgc+1, wg1+j); |
| 94 |
> |
*bgc = *(wg0+i); |
| 95 |
> |
*(bgc+1) = *(wg1+j); |
| 96 |
|
bneighlist[bneighrem++] = hdbindex(hp, bgc); |
| 97 |
|
#ifdef DEBUG |
| 98 |
|
if (bneighlist[bneighrem-1] <= 0) |
| 103 |
|
} |
| 104 |
|
|
| 105 |
|
|
| 106 |
< |
clumpbeams(hp, maxcnt, maxsiz, cf) /* clump beams from hinp */ |
| 107 |
< |
register HOLO *hp; |
| 108 |
< |
int maxcnt, maxsiz; |
| 109 |
< |
int (*cf)(); |
| 106 |
> |
void |
| 107 |
> |
clumpbeams( /* clump beams from hinp */ |
| 108 |
> |
HOLO *hp, |
| 109 |
> |
int maxcnt, |
| 110 |
> |
int maxsiz, |
| 111 |
> |
int (*cf)(HOLO *hp, int *bqueue, int bqlen) |
| 112 |
> |
) |
| 113 |
|
{ |
| 114 |
|
static short primes[] = {9431,6803,4177,2659,1609,887,587,251,47,1}; |
| 115 |
< |
unsigned int4 *bflags; |
| 115 |
> |
uint32 *bflags; |
| 116 |
|
int *bqueue; |
| 117 |
|
int bqlen; |
| 118 |
< |
int4 bqtotal; |
| 118 |
> |
int32 bqtotal; |
| 119 |
|
int bc, bci, bqc, myprime; |
| 120 |
< |
register int i; |
| 120 |
> |
int i; |
| 121 |
|
/* get clump size */ |
| 122 |
|
if (maxcnt <= 1) |
| 123 |
|
maxcnt = nbeams(hp); |
| 124 |
|
maxsiz /= sizeof(RAYVAL); |
| 125 |
|
/* allocate beam queue */ |
| 126 |
|
bqueue = (int *)malloc(maxcnt*sizeof(int)); |
| 127 |
< |
bflags = (unsigned int4 *)calloc((nbeams(hp)>>5)+1, |
| 128 |
< |
sizeof(unsigned int4)); |
| 129 |
< |
if (bqueue == NULL | bflags == NULL) |
| 127 |
> |
bflags = (uint32 *)calloc((nbeams(hp)>>5)+1, |
| 128 |
> |
sizeof(uint32)); |
| 129 |
> |
if ((bqueue == NULL) | (bflags == NULL)) |
| 130 |
|
error(SYSTEM, "out of memory in clumpbeams"); |
| 131 |
|
/* mark empty beams as done */ |
| 132 |
|
for (i = nbeams(hp); i > 0; i--) |
| 141 |
|
/* add each input beam and neighbors */ |
| 142 |
|
for (bc = bci = nbeams(hp); bc > 0; bc--, |
| 143 |
|
bci += bci>myprime ? -myprime : nbeams(hp)-myprime) { |
| 144 |
< |
if (isset(bflags, bci)) |
| 144 |
> |
if (issetfl(bflags, bci)) |
| 145 |
|
continue; |
| 146 |
|
bqueue[0] = bci; /* initialize queue */ |
| 147 |
|
bqlen = 1; |
| 152 |
|
/* add neighbors until full */ |
| 153 |
|
for (i = firstneigh(hp,bqueue[bqc]); i > 0; |
| 154 |
|
i = nextneigh()) { |
| 155 |
< |
if (isset(bflags, i)) /* done already? */ |
| 155 |
> |
if (issetfl(bflags, i)) /* done already? */ |
| 156 |
|
continue; |
| 157 |
|
bqueue[bqlen++] = i; /* add it */ |
| 158 |
|
bqtotal += bnrays(hp, i); |
| 167 |
|
(*cf)(hp, bqueue, bqlen); /* transfer clump */ |
| 168 |
|
} |
| 169 |
|
/* all done; clean up */ |
| 170 |
< |
free((char *)bqueue); |
| 171 |
< |
free((char *)bflags); |
| 170 |
> |
free((void *)bqueue); |
| 171 |
> |
free((void *)bflags); |
| 172 |
|
} |