| 1 |
< |
/* Copyright (c) 1997 Silicon Graphics, Inc. */ |
| 1 |
> |
/* Copyright (c) 1999 Silicon Graphics, Inc. */ |
| 2 |
|
|
| 3 |
|
#ifndef lint |
| 4 |
|
static char SCCSid[] = "$SunId$ SGI"; |
| 12 |
|
#include "view.h" |
| 13 |
|
#include "resolu.h" |
| 14 |
|
|
| 15 |
+ |
#ifndef BKBSIZE |
| 16 |
+ |
#define BKBSIZE 256 /* beam clump size (kilobytes) */ |
| 17 |
+ |
#endif |
| 18 |
+ |
|
| 19 |
+ |
int checkdepth = 1; /* check depth (!-f option)? */ |
| 20 |
+ |
int checkrepeats = 0; /* check for repeats (-c option)? */ |
| 21 |
|
int frompicz; /* input from pictures & depth-buffers? */ |
| 22 |
|
int noutsects; /* number of output sections */ |
| 23 |
|
char obstr, unobstr; /* flag pointer values */ |
| 32 |
|
int i; |
| 33 |
|
|
| 34 |
|
progname = argv[0]; |
| 35 |
< |
if (argc < 4) |
| 35 |
> |
frompicz = -1; |
| 36 |
> |
for (i = 2; i < argc && argv[i][0] == '-'; i++) |
| 37 |
> |
switch (argv[i][1]) { |
| 38 |
> |
case 'u': |
| 39 |
> |
checkrepeats = 1; |
| 40 |
> |
break; |
| 41 |
> |
case 'd': |
| 42 |
> |
checkdepth = 0; |
| 43 |
> |
break; |
| 44 |
> |
case 'h': |
| 45 |
> |
frompicz = 0; |
| 46 |
> |
break; |
| 47 |
> |
case 'p': |
| 48 |
> |
frompicz = 1; |
| 49 |
> |
break; |
| 50 |
> |
default: |
| 51 |
> |
goto userr; |
| 52 |
> |
} |
| 53 |
> |
if (i >= argc || frompicz < 0) |
| 54 |
|
goto userr; |
| 55 |
< |
if (!strcmp(argv[2], "-h")) |
| 32 |
< |
frompicz = 0; |
| 33 |
< |
else if (!strcmp(argv[2], "-pz")) |
| 34 |
< |
frompicz = 1; |
| 35 |
< |
else |
| 55 |
> |
if (frompicz && (argc-i)%2) |
| 56 |
|
goto userr; |
| 37 |
– |
if (frompicz && (argc-3)%2) |
| 38 |
– |
goto userr; |
| 57 |
|
noutsects = openholo(argv[1], 1); |
| 58 |
< |
if (frompicz) |
| 59 |
< |
for (i = 3; i < argc; i += 2) |
| 58 |
> |
if (frompicz) { |
| 59 |
> |
for ( ; i < argc; i += 2) |
| 60 |
|
addpicz(argv[i], argv[i+1]); |
| 61 |
< |
else |
| 62 |
< |
for (i = 3; i < argc; i++) |
| 61 |
> |
} else { |
| 62 |
> |
if (BKBSIZE*1024*1.5 > hdcachesize) |
| 63 |
> |
hdcachesize = BKBSIZE*1024*1.5; |
| 64 |
> |
for ( ; i < argc; i++) |
| 65 |
|
addholo(argv[i]); |
| 66 |
+ |
} |
| 67 |
|
quit(0); |
| 68 |
|
userr: |
| 69 |
< |
fprintf(stderr, "Usage: %s output.hdk -h inp1.hdk ..\n", progname); |
| 49 |
< |
fprintf(stderr, " Or: %s output.hdk -pz inp1.pic inp1.zbf ..\n", |
| 69 |
> |
fprintf(stderr, "Usage: %s output.hdk [-u][-d] -h inp1.hdk ..\n", |
| 70 |
|
progname); |
| 71 |
+ |
fprintf(stderr, " Or: %s output.hdk [-u][-d] -p inp1.pic inp1.zbf ..\n", |
| 72 |
+ |
progname); |
| 73 |
|
exit(1); |
| 74 |
|
} |
| 75 |
|
|
| 78 |
|
#define H_OBST 02 |
| 79 |
|
#define H_OBSF 04 |
| 80 |
|
|
| 81 |
+ |
int |
| 82 |
|
holheadline(s, hf) /* check holodeck header line */ |
| 83 |
|
register char *s; |
| 84 |
|
int *hf; |
| 90 |
|
*hf |= H_BADF; |
| 91 |
|
else |
| 92 |
|
*hf &= ~H_BADF; |
| 93 |
< |
return; |
| 93 |
> |
return(0); |
| 94 |
|
} |
| 95 |
|
if (!strncmp(s, "OBSTRUCTIONS=", 13)) { |
| 96 |
|
s += 13; |
| 101 |
|
*hf |= H_OBSF; |
| 102 |
|
else |
| 103 |
|
error(WARNING, "bad OBSTRUCTIONS value in holodeck"); |
| 104 |
< |
return; |
| 104 |
> |
return(0); |
| 105 |
|
} |
| 106 |
+ |
return(0); |
| 107 |
|
} |
| 108 |
|
|
| 109 |
|
int |
| 151 |
|
double d; |
| 152 |
|
COLR cv; |
| 153 |
|
{ |
| 154 |
< |
int sn; |
| 154 |
> |
int sn, bi, n; |
| 155 |
|
register HOLO *hp; |
| 156 |
|
GCOORD gc[2]; |
| 157 |
|
BYTE rr[2][2]; |
| 158 |
+ |
BEAM *bp; |
| 159 |
|
double d0, d1; |
| 160 |
+ |
unsigned dc; |
| 161 |
|
register RAYVAL *rv; |
| 162 |
|
/* check each output section */ |
| 163 |
|
for (sn = noutsects; sn--; ) { |
| 165 |
|
d0 = hdinter(gc, rr, &d1, hp, ro, rd); |
| 166 |
|
if (d <= d0 || d1 < -0.001) |
| 167 |
|
continue; /* missed section */ |
| 168 |
< |
if (hp->priv == &obstr && d0 < -0.001) |
| 169 |
< |
continue; /* ray starts too late */ |
| 170 |
< |
if (hp->priv == &unobstr && d < 0.999*d1) |
| 171 |
< |
continue; /* ray ends too soon */ |
| 172 |
< |
/* should we check for duplicates? */ |
| 173 |
< |
rv = hdnewrays(hp, hdbindex(hp, gc), 1); |
| 168 |
> |
if (checkdepth) { /* check depth */ |
| 169 |
> |
if (hp->priv == &obstr && d0 < -0.001) |
| 170 |
> |
continue; /* ray starts too late */ |
| 171 |
> |
if (hp->priv == &unobstr && d < 0.999*d1) |
| 172 |
> |
continue; /* ray ends too soon */ |
| 173 |
> |
} |
| 174 |
> |
dc = hdcode(hp, d-d0); |
| 175 |
> |
bi = hdbindex(hp, gc); /* check for duplicates */ |
| 176 |
> |
if (checkrepeats && (bp = hdgetbeam(hp, bi)) != NULL) { |
| 177 |
> |
for (n = bp->nrm, rv = hdbray(bp); n--; rv++) |
| 178 |
> |
if ((hp->priv != NULL || rv->d == dc) && |
| 179 |
> |
rv->r[0][0] == rr[0][0] && |
| 180 |
> |
rv->r[0][1] == rr[0][1] && |
| 181 |
> |
rv->r[1][0] == rr[1][0] && |
| 182 |
> |
rv->r[1][1] == rr[1][1]) |
| 183 |
> |
break; |
| 184 |
> |
if (n >= 0) |
| 185 |
> |
continue; /* found a matching ray */ |
| 186 |
> |
} |
| 187 |
> |
rv = hdnewrays(hp, bi, 1); |
| 188 |
> |
rv->d = dc; |
| 189 |
|
rv->r[0][0] = rr[0][0]; rv->r[0][1] = rr[0][1]; |
| 190 |
|
rv->r[1][0] = rr[1][0]; rv->r[1][1] = rr[1][1]; |
| 191 |
|
copycolr(rv->v, cv); |
| 151 |
– |
rv->d = hdcode(hp, d-d0); |
| 192 |
|
} |
| 193 |
|
} |
| 194 |
|
|
| 195 |
|
|
| 196 |
< |
addholo(hdf) /* add a holodeck file */ |
| 197 |
< |
char *hdf; |
| 196 |
> |
static BEAMI *beamdir; |
| 197 |
> |
|
| 198 |
> |
static int |
| 199 |
> |
bpcmp(b1p, b2p) /* compare beam positions on disk */ |
| 200 |
> |
int *b1p, *b2p; |
| 201 |
|
{ |
| 202 |
< |
int fd; |
| 203 |
< |
register HOLO *hp; |
| 204 |
< |
register BEAM *bp; |
| 205 |
< |
register HDBEAMI *hbl; |
| 202 |
> |
register long pdif = beamdir[*b1p].fo - beamdir[*b2p].fo; |
| 203 |
> |
|
| 204 |
> |
if (pdif > 0L) return(1); |
| 205 |
> |
if (pdif < 0L) return(-1); |
| 206 |
> |
return(0); |
| 207 |
> |
} |
| 208 |
> |
|
| 209 |
> |
static int |
| 210 |
> |
addclump(hp, bq, nb) /* transfer the given clump and free */ |
| 211 |
> |
HOLO *hp; |
| 212 |
> |
int *bq, nb; |
| 213 |
> |
{ |
| 214 |
|
GCOORD gc[2]; |
| 215 |
|
FVECT ro, rd; |
| 216 |
|
double d; |
| 217 |
< |
int i, j; |
| 217 |
> |
int i; |
| 218 |
|
register int k; |
| 219 |
+ |
register BEAM *bp; |
| 220 |
+ |
/* sort based on file position */ |
| 221 |
+ |
beamdir = hp->bi; |
| 222 |
+ |
qsort((char *)bq, nb, sizeof(*bq), bpcmp); |
| 223 |
+ |
/* transfer each beam */ |
| 224 |
+ |
for (i = 0; i < nb; i++) { |
| 225 |
+ |
bp = hdgetbeam(hp, bq[i]); |
| 226 |
+ |
hdbcoord(gc, hp, bq[i]); |
| 227 |
+ |
/* add each ray to output */ |
| 228 |
+ |
for (k = bp->nrm; k--; ) { |
| 229 |
+ |
d = hdray(ro, rd, hp, gc, hdbray(bp)[k].r); |
| 230 |
+ |
if (hp->priv == &unobstr) |
| 231 |
+ |
VSUM(ro, ro, rd, d); |
| 232 |
+ |
else |
| 233 |
+ |
d = 0.; |
| 234 |
+ |
d = hddepth(hp, hdbray(bp)[k].d) - d; |
| 235 |
+ |
addray(ro, rd, d, hdbray(bp)[k].v); |
| 236 |
+ |
} |
| 237 |
+ |
hdfreebeam(hp, bq[i]); /* free the beam */ |
| 238 |
+ |
} |
| 239 |
+ |
hdfreebeam(NULL, 0); /* write & free clump */ |
| 240 |
+ |
return(0); |
| 241 |
+ |
} |
| 242 |
+ |
|
| 243 |
+ |
addholo(hdf) /* add a holodeck file */ |
| 244 |
+ |
char *hdf; |
| 245 |
+ |
{ |
| 246 |
+ |
int fd; |
| 247 |
|
/* open the holodeck for reading */ |
| 248 |
|
openholo(hdf, 0); |
| 249 |
|
fd = hdlist[noutsects]->fd; /* remember the file handle */ |
| 250 |
< |
while ((hp = hdlist[noutsects]) != NULL) { /* load each section */ |
| 251 |
< |
hbl = (HDBEAMI *)malloc(nbeams(hp)*sizeof(HDBEAMI)); |
| 252 |
< |
if (hbl == NULL) |
| 253 |
< |
error(SYSTEM, "out of memory in addholo"); |
| 175 |
< |
for (j = nbeams(hp); j > 0; j--) { /* sort the beams */ |
| 176 |
< |
hbl[j].h = hp; |
| 177 |
< |
hbl[j].b = j; |
| 178 |
< |
} |
| 179 |
< |
qsort((char *)hbl, nbeams(hp), sizeof(HDBEAMI), hdfilord); |
| 180 |
< |
for (j = 0; j < nbeams(hp); j++) /* load each beam */ |
| 181 |
< |
if ((bp = hdgetbeam(hp, hbl[j].b)) != NULL) { |
| 182 |
< |
hdbcoord(gc, hp, hbl[j].b); |
| 183 |
< |
for (k = bp->nrm; k--; ) { |
| 184 |
< |
d = hdray(ro, rd, |
| 185 |
< |
hp, gc, hdbray(bp)[k].r); |
| 186 |
< |
if (hp->priv == &unobstr) |
| 187 |
< |
VSUM(ro, ro, rd, d); |
| 188 |
< |
else |
| 189 |
< |
d = 0.; |
| 190 |
< |
d = hddepth(hp, hdbray(bp)[k].d) - d; |
| 191 |
< |
addray(ro, rd, d, hdbray(bp)[k].v); |
| 192 |
< |
} |
| 193 |
< |
hdfreebeam(hp, hbl[j].b); /* free beam */ |
| 194 |
< |
} |
| 195 |
< |
free((char *)hbl); /* free beam list */ |
| 196 |
< |
hddone(hp); /* free the section */ |
| 250 |
> |
while (hdlist[noutsects] != NULL) { /* load each section */ |
| 251 |
> |
/* clump the beams */ |
| 252 |
> |
clumpbeams(hdlist[noutsects], 0, BKBSIZE*1024, addclump); |
| 253 |
> |
hddone(hdlist[noutsects]); /* free the section */ |
| 254 |
|
} |
| 255 |
< |
close(fd); /* close the file */ |
| 255 |
> |
close(fd); /* close input file */ |
| 256 |
> |
hdflush(NULL); /* flush output */ |
| 257 |
|
} |
| 258 |
|
|
| 259 |
|
|
| 266 |
|
}; |
| 267 |
|
|
| 268 |
|
|
| 269 |
+ |
int |
| 270 |
|
picheadline(s, ph) /* process picture header line */ |
| 271 |
|
char *s; |
| 272 |
|
struct phead *ph; |
| 275 |
|
|
| 276 |
|
if (formatval(fmt, s)) { |
| 277 |
|
ph->badfmt = strcmp(fmt, COLRFMT); |
| 278 |
< |
return; |
| 278 |
> |
return(0); |
| 279 |
|
} |
| 280 |
|
if (isprims(s)) { |
| 281 |
|
ph->altprims++; /* don't want to deal with this */ |
| 282 |
< |
return; |
| 282 |
> |
return(0); |
| 283 |
|
} |
| 284 |
|
if (isexpos(s)) { |
| 285 |
|
ph->expos *= exposval(s); |
| 286 |
< |
return; |
| 286 |
> |
return(0); |
| 287 |
|
} |
| 288 |
|
if (isview(s)) { |
| 289 |
|
ph->gotview += sscanview(&ph->vw, s); |
| 290 |
< |
return; |
| 290 |
> |
return(0); |
| 291 |
|
} |
| 292 |
+ |
return(0); |
| 293 |
|
} |
| 294 |
|
|
| 295 |
|
|
| 388 |
|
addray(ro, rd, (double)zscn[i], cscn[i]); |
| 389 |
|
} |
| 390 |
|
} |
| 391 |
+ |
/* write output and free beams */ |
| 392 |
+ |
hdflush(NULL); |
| 393 |
|
/* clean up */ |
| 394 |
|
free((char *)cscn); |
| 395 |
|
free((char *)zscn); |