| 1 |
– |
/* Copyright (c) 1997 Silicon Graphics, Inc. */ |
| 2 |
– |
|
| 1 |
|
#ifndef lint |
| 2 |
< |
static char SCCSid[] = "$SunId$ SGI"; |
| 2 |
> |
static const char RCSid[] = "$Id$"; |
| 3 |
|
#endif |
| 6 |
– |
|
| 4 |
|
/* |
| 5 |
|
* Copy data into a holodeck file |
| 6 |
|
*/ |
| 7 |
|
|
| 8 |
+ |
#include "platform.h" |
| 9 |
|
#include "holo.h" |
| 10 |
|
#include "view.h" |
| 13 |
– |
#include "resolu.h" |
| 11 |
|
|
| 12 |
< |
#ifndef BLOADSIZE |
| 13 |
< |
#define BLOADSIZE 1024 /* number of input beams to load at a time */ |
| 12 |
> |
#ifndef BKBSIZE |
| 13 |
> |
#define BKBSIZE 256 /* beam clump size (kilobytes) */ |
| 14 |
|
#endif |
| 15 |
|
|
| 16 |
< |
int checkdepth = 1; /* check depth (!-f option)? */ |
| 17 |
< |
int checkrepeats = 0; /* check for repeats (-c option)? */ |
| 16 |
> |
int checkdepth = 1; /* check depth (!-d option)? */ |
| 17 |
> |
int checkrepeats = 0; /* check for repeats (-u option)? */ |
| 18 |
|
int frompicz; /* input from pictures & depth-buffers? */ |
| 19 |
|
int noutsects; /* number of output sections */ |
| 20 |
|
char obstr, unobstr; /* flag pointer values */ |
| 52 |
|
if (frompicz && (argc-i)%2) |
| 53 |
|
goto userr; |
| 54 |
|
noutsects = openholo(argv[1], 1); |
| 55 |
< |
if (frompicz) |
| 55 |
> |
if (frompicz) { |
| 56 |
|
for ( ; i < argc; i += 2) |
| 57 |
|
addpicz(argv[i], argv[i+1]); |
| 58 |
< |
else |
| 58 |
> |
} else { |
| 59 |
> |
if (BKBSIZE*1024*1.5 > hdcachesize) |
| 60 |
> |
hdcachesize = BKBSIZE*1024*1.5; |
| 61 |
|
for ( ; i < argc; i++) |
| 62 |
|
addholo(argv[i]); |
| 63 |
+ |
} |
| 64 |
|
quit(0); |
| 65 |
|
userr: |
| 66 |
|
fprintf(stderr, "Usage: %s output.hdk [-u][-d] -h inp1.hdk ..\n", |
| 67 |
|
progname); |
| 68 |
< |
fprintf(stderr, " Or: %s output.hdk [-u][-d] -pz inp1.pic inp1.zbf ..\n", |
| 68 |
> |
fprintf(stderr, " Or: %s output.hdk [-u][-d] -p inp1.pic inp1.zbf ..\n", |
| 69 |
|
progname); |
| 70 |
|
exit(1); |
| 71 |
|
} |
| 92 |
|
if (!strncmp(s, "OBSTRUCTIONS=", 13)) { |
| 93 |
|
s += 13; |
| 94 |
|
while (*s == ' ') s++; |
| 95 |
< |
if (*s == 't' | *s == 'T') |
| 95 |
> |
if ((*s == 't') | (*s == 'T')) |
| 96 |
|
*hf |= H_OBST; |
| 97 |
< |
else if (*s == 'f' | *s == 'F') |
| 97 |
> |
else if ((*s == 'f') | (*s == 'F')) |
| 98 |
|
*hf |= H_OBSF; |
| 99 |
|
else |
| 100 |
|
error(WARNING, "bad OBSTRUCTIONS value in holodeck"); |
| 108 |
|
char *fname; |
| 109 |
|
int append; |
| 110 |
|
{ |
| 111 |
– |
extern long ftell(); |
| 111 |
|
FILE *fp; |
| 112 |
|
int fd; |
| 113 |
|
int hflags = 0; |
| 120 |
|
error(SYSTEM, errmsg); |
| 121 |
|
} |
| 122 |
|
/* check header and magic number */ |
| 123 |
< |
if (getheader(fp, holheadline, &hflags) < 0 || |
| 123 |
> |
if (getheader(fp, holheadline, (char *)&hflags) < 0 || |
| 124 |
|
hflags&H_BADF || getw(fp) != HOLOMAGIC) { |
| 125 |
|
sprintf(errmsg, "file \"%s\" not in holodeck format", fname); |
| 126 |
|
error(USER, errmsg); |
| 129 |
|
nextloc = ftell(fp); /* get stdio position */ |
| 130 |
|
fclose(fp); /* done with stdio */ |
| 131 |
|
for (n = 0; nextloc > 0L; n++) { /* initialize each section */ |
| 132 |
< |
lseek(fd, nextloc, 0); |
| 132 |
> |
lseek(fd, (off_t)nextloc, SEEK_SET); |
| 133 |
|
read(fd, (char *)&nextloc, sizeof(nextloc)); |
| 134 |
|
hdinit(fd, NULL)->priv = hflags&H_OBST ? &obstr : |
| 135 |
|
hflags&H_OBSF ? &unobstr : (char *)NULL; |
| 171 |
|
bi = hdbindex(hp, gc); /* check for duplicates */ |
| 172 |
|
if (checkrepeats && (bp = hdgetbeam(hp, bi)) != NULL) { |
| 173 |
|
for (n = bp->nrm, rv = hdbray(bp); n--; rv++) |
| 174 |
< |
if (rv->d == dc && |
| 174 |
> |
if ((hp->priv != NULL || rv->d == dc) && |
| 175 |
|
rv->r[0][0] == rr[0][0] && |
| 176 |
|
rv->r[0][1] == rr[0][1] && |
| 177 |
|
rv->r[1][0] == rr[1][0] && |
| 189 |
|
} |
| 190 |
|
|
| 191 |
|
|
| 192 |
< |
addholo(hdf) /* add a holodeck file */ |
| 193 |
< |
char *hdf; |
| 192 |
> |
static BEAMI *beamdir; |
| 193 |
> |
|
| 194 |
> |
static int |
| 195 |
> |
bpcmp(b1p, b2p) /* compare beam positions on disk */ |
| 196 |
> |
int *b1p, *b2p; |
| 197 |
|
{ |
| 198 |
< |
HDBEAMI hbl[BLOADSIZE]; |
| 199 |
< |
int fd; |
| 200 |
< |
register HOLO *hp; |
| 201 |
< |
register BEAM *bp; |
| 198 |
> |
register off_t pdif = beamdir[*b1p].fo - beamdir[*b2p].fo; |
| 199 |
> |
|
| 200 |
> |
if (pdif > 0L) return(1); |
| 201 |
> |
if (pdif < 0L) return(-1); |
| 202 |
> |
return(0); |
| 203 |
> |
} |
| 204 |
> |
|
| 205 |
> |
static int |
| 206 |
> |
addclump(hp, bq, nb) /* transfer the given clump and free */ |
| 207 |
> |
HOLO *hp; |
| 208 |
> |
int *bq, nb; |
| 209 |
> |
{ |
| 210 |
|
GCOORD gc[2]; |
| 211 |
|
FVECT ro, rd; |
| 212 |
|
double d; |
| 213 |
< |
int i, j, n, li; |
| 213 |
> |
int i; |
| 214 |
|
register int k; |
| 215 |
+ |
register BEAM *bp; |
| 216 |
+ |
/* sort based on file position */ |
| 217 |
+ |
beamdir = hp->bi; |
| 218 |
+ |
qsort((char *)bq, nb, sizeof(*bq), bpcmp); |
| 219 |
+ |
/* transfer each beam */ |
| 220 |
+ |
for (i = 0; i < nb; i++) { |
| 221 |
+ |
bp = hdgetbeam(hp, bq[i]); |
| 222 |
+ |
hdbcoord(gc, hp, bq[i]); |
| 223 |
+ |
/* add each ray to output */ |
| 224 |
+ |
for (k = bp->nrm; k--; ) { |
| 225 |
+ |
d = hdray(ro, rd, hp, gc, hdbray(bp)[k].r); |
| 226 |
+ |
if (hp->priv == &unobstr) |
| 227 |
+ |
VSUM(ro, ro, rd, d); |
| 228 |
+ |
else |
| 229 |
+ |
d = 0.; |
| 230 |
+ |
d = hddepth(hp, hdbray(bp)[k].d) - d; |
| 231 |
+ |
addray(ro, rd, d, hdbray(bp)[k].v); |
| 232 |
+ |
} |
| 233 |
+ |
hdfreebeam(hp, bq[i]); /* free the beam */ |
| 234 |
+ |
} |
| 235 |
+ |
return(0); |
| 236 |
+ |
} |
| 237 |
+ |
|
| 238 |
+ |
addholo(hdf) /* add a holodeck file */ |
| 239 |
+ |
char *hdf; |
| 240 |
+ |
{ |
| 241 |
+ |
int fd; |
| 242 |
|
/* open the holodeck for reading */ |
| 243 |
|
openholo(hdf, 0); |
| 244 |
|
fd = hdlist[noutsects]->fd; /* remember the file handle */ |
| 245 |
< |
while ((hp = hdlist[noutsects]) != NULL) { /* load each section */ |
| 246 |
< |
for (j = 0; j < nbeams(hp); j++) { /* load each beam */ |
| 247 |
< |
if (!(li = j % BLOADSIZE)) { /* optimize order */ |
| 248 |
< |
if (j+BLOADSIZE > nbeams(hp)) |
| 212 |
< |
k = n = nbeams(hp) - j; |
| 213 |
< |
else |
| 214 |
< |
k = n = BLOADSIZE; |
| 215 |
< |
while (k--) { |
| 216 |
< |
hbl[k].h = hp; |
| 217 |
< |
hbl[k].b = j+k+1; |
| 218 |
< |
} |
| 219 |
< |
qsort((char *)hbl, n, |
| 220 |
< |
sizeof(HDBEAMI), hdfilord); |
| 221 |
< |
} |
| 222 |
< |
if ((bp = hdgetbeam(hp, hbl[li].b)) != NULL) { |
| 223 |
< |
hdbcoord(gc, hp, hbl[li].b); |
| 224 |
< |
for (k = bp->nrm; k--; ) { |
| 225 |
< |
d = hdray(ro, rd, |
| 226 |
< |
hp, gc, hdbray(bp)[k].r); |
| 227 |
< |
if (hp->priv == &unobstr) |
| 228 |
< |
VSUM(ro, ro, rd, d); |
| 229 |
< |
else |
| 230 |
< |
d = 0.; |
| 231 |
< |
d = hddepth(hp, hdbray(bp)[k].d) - d; |
| 232 |
< |
addray(ro, rd, d, hdbray(bp)[k].v); |
| 233 |
< |
} |
| 234 |
< |
hdfreebeam(hp, hbl[li].b); /* free beam */ |
| 235 |
< |
} |
| 236 |
< |
} |
| 237 |
< |
hddone(hp); /* free the section */ |
| 245 |
> |
while (hdlist[noutsects] != NULL) { /* load each section */ |
| 246 |
> |
/* clump the beams */ |
| 247 |
> |
clumpbeams(hdlist[noutsects], 0, BKBSIZE*1024, addclump); |
| 248 |
> |
hddone(hdlist[noutsects]); /* free the section */ |
| 249 |
|
} |
| 250 |
< |
close(fd); /* close the file */ |
| 250 |
> |
close(fd); /* close input file */ |
| 251 |
> |
hdflush(NULL); /* flush output */ |
| 252 |
|
} |
| 253 |
|
|
| 254 |
|
|
| 299 |
|
int eshft; |
| 300 |
|
double emult; |
| 301 |
|
RESOLU prs; |
| 302 |
< |
FLOAT vl[2]; |
| 302 |
> |
RREAL vl[2]; |
| 303 |
|
FVECT ro, rd; |
| 304 |
|
double aftd; |
| 305 |
|
COLOR ctmp; |
| 315 |
|
error(SYSTEM, pcf); |
| 316 |
|
} |
| 317 |
|
/* load picture header */ |
| 318 |
< |
copystruct(&phd.vw, &stdview); |
| 318 |
> |
phd.vw = stdview; |
| 319 |
|
phd.expos = 1.0; |
| 320 |
|
phd.badfmt = phd.gotview = phd.altprims = 0; |
| 321 |
< |
if (getheader(pfp, picheadline, &phd) < 0 || |
| 321 |
> |
if (getheader(pfp, picheadline, (char *)&phd) < 0 || |
| 322 |
|
phd.badfmt || !fgetsresolu(&prs, pfp)) { |
| 323 |
|
sprintf(errmsg, "bad format for picture file \"%s\"", pcf); |
| 324 |
|
error(USER, errmsg); |
| 334 |
|
error(WARNING, errmsg); |
| 335 |
|
} |
| 336 |
|
/* figure out what to do about exposure */ |
| 337 |
< |
if (phd.expos < 0.99 | phd.expos > 1.01) { |
| 337 |
> |
if ((phd.expos < 0.99) | (phd.expos > 1.01)) { |
| 338 |
|
emult = -log(phd.expos)/log(2.); |
| 339 |
|
eshft = emult >= 0. ? emult+.5 : emult-.5; |
| 340 |
|
emult -= (double)eshft; |
| 341 |
< |
if (emult <= 0.01 & emult >= -0.01) |
| 341 |
> |
if ((emult <= 0.01) & (emult >= -0.01)) |
| 342 |
|
emult = -1.; |
| 343 |
|
else { |
| 344 |
|
emult = 1./phd.expos; |
| 351 |
|
/* allocate buffers */ |
| 352 |
|
cscn = (COLR *)malloc(scanlen(&prs)*sizeof(COLR)); |
| 353 |
|
zscn = (float *)malloc(scanlen(&prs)*sizeof(float)); |
| 354 |
< |
if (cscn == NULL | zscn == NULL) |
| 354 |
> |
if ((cscn == NULL) | (zscn == NULL)) |
| 355 |
|
error(SYSTEM, "out of memory in addpicz"); |
| 356 |
|
/* read and process each scanline */ |
| 357 |
|
for (j = 0; j < numscans(&prs); j++) { |
| 383 |
|
addray(ro, rd, (double)zscn[i], cscn[i]); |
| 384 |
|
} |
| 385 |
|
} |
| 386 |
+ |
/* write output and free beams */ |
| 387 |
+ |
hdflush(NULL); |
| 388 |
|
/* clean up */ |
| 389 |
< |
free((char *)cscn); |
| 390 |
< |
free((char *)zscn); |
| 389 |
> |
free((void *)cscn); |
| 390 |
> |
free((void *)zscn); |
| 391 |
|
fclose(pfp); |
| 392 |
|
close(zfd); |
| 393 |
|
} |
| 394 |
|
|
| 395 |
|
|
| 396 |
+ |
void |
| 397 |
|
eputs(s) /* put error message to stderr */ |
| 398 |
|
register char *s; |
| 399 |
|
{ |
| 413 |
|
} |
| 414 |
|
|
| 415 |
|
|
| 416 |
+ |
void |
| 417 |
|
quit(code) /* exit the program gracefully */ |
| 418 |
|
int code; |
| 419 |
|
{ |