--- ray/src/hd/rhcopy.c 1998/01/23 09:05:14 3.8 +++ ray/src/hd/rhcopy.c 1999/02/01 10:22:46 3.13 @@ -1,4 +1,4 @@ -/* Copyright (c) 1997 Silicon Graphics, Inc. */ +/* Copyright (c) 1999 Silicon Graphics, Inc. */ #ifndef lint static char SCCSid[] = "$SunId$ SGI"; @@ -12,8 +12,8 @@ static char SCCSid[] = "$SunId$ SGI"; #include "view.h" #include "resolu.h" -#ifndef BLOADSIZE -#define BLOADSIZE 1024 /* number of input beams to load at a time */ +#ifndef BKBSIZE +#define BKBSIZE 256 /* beam clump size (kilobytes) */ #endif int checkdepth = 1; /* check depth (!-f option)? */ @@ -55,17 +55,20 @@ char *argv[]; if (frompicz && (argc-i)%2) goto userr; noutsects = openholo(argv[1], 1); - if (frompicz) + if (frompicz) { for ( ; i < argc; i += 2) addpicz(argv[i], argv[i+1]); - else + } else { + if (BKBSIZE*1024*1.5 > hdcachesize) + hdcachesize = BKBSIZE*1024*1.5; for ( ; i < argc; i++) addholo(argv[i]); + } quit(0); userr: fprintf(stderr, "Usage: %s output.hdk [-u][-d] -h inp1.hdk ..\n", progname); - fprintf(stderr, " Or: %s output.hdk [-u][-d] -pz inp1.pic inp1.zbf ..\n", + fprintf(stderr, " Or: %s output.hdk [-u][-d] -p inp1.pic inp1.zbf ..\n", progname); exit(1); } @@ -75,6 +78,7 @@ userr: #define H_OBST 02 #define H_OBSF 04 +int holheadline(s, hf) /* check holodeck header line */ register char *s; int *hf; @@ -86,7 +90,7 @@ int *hf; *hf |= H_BADF; else *hf &= ~H_BADF; - return; + return(0); } if (!strncmp(s, "OBSTRUCTIONS=", 13)) { s += 13; @@ -97,8 +101,9 @@ int *hf; *hf |= H_OBSF; else error(WARNING, "bad OBSTRUCTIONS value in holodeck"); - return; + return(0); } + return(0); } int @@ -170,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] && @@ -188,53 +193,67 @@ COLR cv; } -addholo(hdf) /* add a holodeck file */ -char *hdf; +static BEAMI *beamdir; + +static int +bpcmp(b1p, b2p) /* compare beam positions on disk */ +int *b1p, *b2p; { - HDBEAMI hbl[BLOADSIZE]; - int fd; - register HOLO *hp; - register BEAM *bp; + 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, j, n, li; + int i; register int k; + 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(NULL, 0); /* write & free clump */ + return(0); +} + +addholo(hdf) /* add a holodeck file */ +char *hdf; +{ + int fd; /* open the holodeck for reading */ openholo(hdf, 0); fd = hdlist[noutsects]->fd; /* remember the file handle */ - while ((hp = hdlist[noutsects]) != NULL) { /* load each section */ - for (j = 0; j < nbeams(hp); j++) { /* load each beam */ - if (!(li = j % BLOADSIZE)) { /* optimize order */ - if (j+BLOADSIZE > nbeams(hp)) - k = n = nbeams(hp) - j; - else - k = n = BLOADSIZE; - while (k--) { - hbl[k].h = hp; - hbl[k].b = j+k+1; - } - qsort((char *)hbl, n, - sizeof(HDBEAMI), hdfilord); - } - if ((bp = hdgetbeam(hp, hbl[li].b)) != NULL) { - hdbcoord(gc, hp, hbl[li].b); - 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, hbl[li].b); /* free beam */ - } - } - hddone(hp); /* free the section */ + while (hdlist[noutsects] != NULL) { /* load each section */ + /* clump the beams */ + clumpbeams(hdlist[noutsects], 0, BKBSIZE*1024, addclump); + hddone(hdlist[noutsects]); /* free the section */ } - close(fd); /* close the file */ + close(fd); /* close input file */ + hdflush(NULL); /* flush output */ } @@ -247,6 +266,7 @@ struct phead { }; +int picheadline(s, ph) /* process picture header line */ char *s; struct phead *ph; @@ -255,20 +275,21 @@ struct phead *ph; if (formatval(fmt, s)) { ph->badfmt = strcmp(fmt, COLRFMT); - return; + return(0); } if (isprims(s)) { ph->altprims++; /* don't want to deal with this */ - return; + return(0); } if (isexpos(s)) { ph->expos *= exposval(s); - return; + return(0); } if (isview(s)) { ph->gotview += sscanview(&ph->vw, s); - return; + return(0); } + return(0); } @@ -367,6 +388,8 @@ char *pcf, *zbf; addray(ro, rd, (double)zscn[i], cscn[i]); } } + /* write output and free beams */ + hdflush(NULL); /* clean up */ free((char *)cscn); free((char *)zscn);