--- ray/src/hd/rhcopy.c 1998/11/09 17:11:40 3.10 +++ ray/src/hd/rhcopy.c 2003/05/29 16:26:22 3.16 @@ -1,23 +1,19 @@ -/* Copyright (c) 1998 Silicon Graphics, Inc. */ - #ifndef lint -static char SCCSid[] = "$SunId$ SGI"; +static const char RCSid[] = "$Id: rhcopy.c,v 3.16 2003/05/29 16:26:22 greg Exp $"; #endif - /* * Copy data into a holodeck file */ #include "holo.h" #include "view.h" -#include "resolu.h" #ifndef BKBSIZE #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 */ @@ -111,7 +107,6 @@ openholo(fname, append) /* open existing holodeck fil char *fname; int append; { - extern long ftell(); FILE *fp; int fd; int hflags = 0; @@ -124,7 +119,7 @@ int append; error(SYSTEM, errmsg); } /* check header and magic number */ - if (getheader(fp, holheadline, &hflags) < 0 || + if (getheader(fp, holheadline, (char *)&hflags) < 0 || hflags&H_BADF || getw(fp) != HOLOMAGIC) { sprintf(errmsg, "file \"%s\" not in holodeck format", fname); error(USER, errmsg); @@ -133,7 +128,7 @@ int append; nextloc = ftell(fp); /* get stdio position */ fclose(fp); /* done with stdio */ for (n = 0; nextloc > 0L; n++) { /* initialize each section */ - lseek(fd, nextloc, 0); + lseek(fd, (off_t)nextloc, 0); read(fd, (char *)&nextloc, sizeof(nextloc)); hdinit(fd, NULL)->priv = hflags&H_OBST ? &obstr : hflags&H_OBSF ? &unobstr : (char *)NULL; @@ -175,7 +170,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 +188,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 off_t 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 +243,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 */ } @@ -299,7 +317,7 @@ char *pcf, *zbf; copystruct(&phd.vw, &stdview); phd.expos = 1.0; phd.badfmt = phd.gotview = phd.altprims = 0; - if (getheader(pfp, picheadline, &phd) < 0 || + if (getheader(pfp, picheadline, (char *)&phd) < 0 || phd.badfmt || !fgetsresolu(&prs, pfp)) { sprintf(errmsg, "bad format for picture file \"%s\"", pcf); error(USER, errmsg); @@ -364,16 +382,17 @@ 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); + free((void *)cscn); + free((void *)zscn); fclose(pfp); close(zfd); } +void eputs(s) /* put error message to stderr */ register char *s; { @@ -393,6 +412,7 @@ register char *s; } +void quit(code) /* exit the program gracefully */ int code; {