--- ray/src/hd/rhcopy.c 1998/11/09 17:11:40 3.10 +++ ray/src/hd/rhcopy.c 1999/03/08 17:32:26 3.14 @@ -1,4 +1,4 @@ -/* Copyright (c) 1998 Silicon Graphics, Inc. */ +/* Copyright (c) 1999 Silicon Graphics, Inc. */ #ifndef lint static char SCCSid[] = "$SunId$ SGI"; @@ -16,8 +16,8 @@ static char SCCSid[] = "$SunId$ SGI"; #define BKBSIZE 256 /* beam clump size (kilobytes) */ #endif -int checkdepth = 1; /* check depth (!-f option)? */ -int checkrepeats = 0; /* check for repeats (-c option)? */ +int checkdepth = 1; /* check depth (!-d option)? */ +int checkrepeats = 0; /* check for repeats (-u option)? */ int frompicz; /* input from pictures & depth-buffers? */ int noutsects; /* number of output sections */ char obstr, unobstr; /* flag pointer values */ @@ -175,7 +175,7 @@ COLR cv; bi = hdbindex(hp, gc); /* check for duplicates */ if (checkrepeats && (bp = hdgetbeam(hp, bi)) != NULL) { for (n = bp->nrm, rv = hdbray(bp); n--; rv++) - if (rv->d == dc && + if ((hp->priv != NULL || rv->d == dc) && rv->r[0][0] == rr[0][0] && rv->r[0][1] == rr[0][1] && rv->r[1][0] == rr[1][0] && @@ -193,30 +193,52 @@ COLR cv; } -addbeam(bp, hb) /* add a beam to our output holodeck */ -register BEAM *bp; -register HDBEAMI *hb; +static BEAMI *beamdir; + +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); +} + +static int +addclump(hp, bq, nb) /* transfer the given clump and free */ +HOLO *hp; +int *bq, nb; +{ GCOORD gc[2]; FVECT ro, rd; double d; + int i; register int k; - /* get beam coordinates */ - hdbcoord(gc, hb->h, hb->b); - /* add each ray to output */ - for (k = bp->nrm; k--; ) { - d = hdray(ro, rd, hb->h, gc, hdbray(bp)[k].r); - if (hb->h->priv == &unobstr) - VSUM(ro, ro, rd, d); - else - d = 0.; - d = hddepth(hb->h, hdbray(bp)[k].d) - d; - addray(ro, rd, d, hdbray(bp)[k].v); + register BEAM *bp; + /* sort based on file position */ + beamdir = hp->bi; + qsort((char *)bq, nb, sizeof(*bq), bpcmp); + /* transfer each beam */ + for (i = 0; i < nb; i++) { + bp = hdgetbeam(hp, bq[i]); + hdbcoord(gc, hp, bq[i]); + /* add each ray to output */ + for (k = bp->nrm; k--; ) { + d = hdray(ro, rd, hp, gc, hdbray(bp)[k].r); + if (hp->priv == &unobstr) + VSUM(ro, ro, rd, d); + else + d = 0.; + d = hddepth(hp, hdbray(bp)[k].d) - d; + addray(ro, rd, d, hdbray(bp)[k].v); + } + hdfreebeam(hp, bq[i]); /* free the beam */ } - hdfreebeam(hb->h, hb->b); /* free the beam */ + return(0); } - addholo(hdf) /* add a holodeck file */ char *hdf; { @@ -226,10 +248,11 @@ char *hdf; fd = hdlist[noutsects]->fd; /* remember the file handle */ while (hdlist[noutsects] != NULL) { /* load each section */ /* clump the beams */ - clumpbeams(hdlist[noutsects], 0, BKBSIZE*1024, addbeam); + clumpbeams(hdlist[noutsects], 0, BKBSIZE*1024, addclump); hddone(hdlist[noutsects]); /* free the section */ } close(fd); /* close input file */ + hdflush(NULL); /* flush output */ } @@ -364,8 +387,8 @@ char *pcf, *zbf; addray(ro, rd, (double)zscn[i], cscn[i]); } } - /* write output */ - hdsync(NULL, 1); + /* write output and free beams */ + hdflush(NULL); /* clean up */ free((char *)cscn); free((char *)zscn);