--- ray/src/hd/clumpbeams.c 1998/11/09 17:11:04 3.1 +++ ray/src/hd/clumpbeams.c 2003/11/17 02:21:53 3.7 @@ -1,9 +1,6 @@ -/* Copyright (c) 1998 Silicon Graphics, Inc. */ - #ifndef lint -static char SCCSid[] = "$SunId$ SGI"; +static const char RCSid[] = "$Id: clumpbeams.c,v 3.7 2003/11/17 02:21:53 greg Exp $"; #endif - /* * Bundle holodeck beams together into clumps. */ @@ -11,7 +8,7 @@ static char SCCSid[] = "$SunId$ SGI"; #include "holo.h" #define flgop(p,i,op) ((p)[(i)>>5] op (1L<<((i)&0x1f))) -#define isset(p,i) flgop(p,i,&) +#define issetfl(p,i) flgop(p,i,&) #define setfl(p,i) flgop(p,i,|=) #define clrfl(p,i) flgop(p,i,&=~) @@ -20,9 +17,7 @@ static int bneighrem; #define nextneigh() (bneighrem<=0 ? 0 : bneighlist[--bneighrem]) -static BEAMI *beamdir; - gcshifti(gc, ia, di, hp) /* shift cell row or column */ register GCOORD *gc; int ia, di; @@ -57,10 +52,10 @@ GCOORD *gc; register int i, j; for (i = 3; i--; ) { - copystruct(&gci0, gc); + gci0 = *gc; gcshifti(&gci0, 0, i-1, hp); for (j = 3; j--; ) { - copystruct(ng+(3*i+j), &gci0); + *(ng+(3*i+j)) = gci0; gcshifti(ng+(3*i+j), gci0.w==gc->w, j-1, hp); } } @@ -81,12 +76,12 @@ int b; bneighrem = 0; for (i = 9; i--; ) for (j = 9; j--; ) { - if (i == 4 & j == 4) /* don't copy starting beam */ + if ((i == 4) & (j == 4)) /* don't copy starting beam */ continue; if (wg0[i].w == wg1[j].w) continue; - copystruct(bgc, wg0+i); - copystruct(bgc+1, wg1+j); + *bgc = *(wg0+i); + *(bgc+1) = *(wg1+j); bneighlist[bneighrem++] = hdbindex(hp, bgc); #ifdef DEBUG if (bneighlist[bneighrem-1] <= 0) @@ -97,30 +92,16 @@ int b; } -static int -bpcmp(b1p, b2p) /* compare beam positions on disk */ -int *b1p, *b2p; -{ - register long pdif = beamdir[*b1p].fo - beamdir[*b2p].fo; - - if (pdif > 0L) return(1); - if (pdif < 0L) return(-1); - return(0); -} - - -clumpbeams(hp, maxcnt, maxsiz, bf) /* clump beams from hinp */ +clumpbeams(hp, maxcnt, maxsiz, cf) /* clump beams from hinp */ register HOLO *hp; int maxcnt, maxsiz; -int (*bf)(); +int (*cf)(); { static short primes[] = {9431,6803,4177,2659,1609,887,587,251,47,1}; - HDBEAMI bis; - BEAM *bp; - unsigned int4 *bflags; + uint32 *bflags; int *bqueue; int bqlen; - int4 bqtotal; + int32 bqtotal; int bc, bci, bqc, myprime; register int i; /* get clump size */ @@ -129,9 +110,9 @@ int (*bf)(); maxsiz /= sizeof(RAYVAL); /* allocate beam queue */ bqueue = (int *)malloc(maxcnt*sizeof(int)); - bflags = (unsigned int4 *)calloc((nbeams(hp)>>5)+1, - sizeof(unsigned int4)); - if (bqueue == NULL | bflags == NULL) + bflags = (uint32 *)calloc((nbeams(hp)>>5)+1, + sizeof(uint32)); + if ((bqueue == NULL) | (bflags == NULL)) error(SYSTEM, "out of memory in clumpbeams"); /* mark empty beams as done */ for (i = nbeams(hp); i > 0; i--) @@ -146,7 +127,7 @@ int (*bf)(); /* add each input beam and neighbors */ for (bc = bci = nbeams(hp); bc > 0; bc--, bci += bci>myprime ? -myprime : nbeams(hp)-myprime) { - if (isset(bflags, bci)) + if (issetfl(bflags, bci)) continue; bqueue[0] = bci; /* initialize queue */ bqlen = 1; @@ -157,7 +138,7 @@ int (*bf)(); /* add neighbors until full */ for (i = firstneigh(hp,bqueue[bqc]); i > 0; i = nextneigh()) { - if (isset(bflags, i)) /* done already? */ + if (issetfl(bflags, i)) /* done already? */ continue; bqueue[bqlen++] = i; /* add it */ bqtotal += bnrays(hp, i); @@ -169,16 +150,9 @@ int (*bf)(); if (i > 0) break; } - beamdir = hp->bi; /* sort queue */ - qsort((char *)bqueue, bqlen, sizeof(*bqueue), bpcmp); - /* transfer each beam */ - for (i = 0; i < bqlen; i++) { - bp = hdgetbeam(bis.h=hp, bis.b=bqueue[i]); - (*bf)(bp, &bis); - } - hdfreebeam(NULL, 0); /* write & free clump */ + (*cf)(hp, bqueue, bqlen); /* transfer clump */ } - hdsync(NULL, 0); /* we're done -- clean up */ - free((char *)bqueue); - free((char *)bflags); + /* all done; clean up */ + free((void *)bqueue); + free((void *)bflags); }