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 BLOADSIZE |
16 |
< |
#define BLOADSIZE 1024 /* number of input beams to load at a time */ |
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)? */ |
19 |
> |
int checkdepth = 1; /* check depth (!-d option)? */ |
20 |
> |
int checkrepeats = 0; /* check for repeats (-u option)? */ |
21 |
|
int frompicz; /* input from pictures & depth-buffers? */ |
22 |
|
int noutsects; /* number of output sections */ |
23 |
|
char obstr, unobstr; /* flag pointer values */ |
55 |
|
if (frompicz && (argc-i)%2) |
56 |
|
goto userr; |
57 |
|
noutsects = openholo(argv[1], 1); |
58 |
< |
if (frompicz) |
58 |
> |
if (frompicz) { |
59 |
|
for ( ; i < argc; i += 2) |
60 |
|
addpicz(argv[i], argv[i+1]); |
61 |
< |
else |
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 [-u][-d] -h inp1.hdk ..\n", |
70 |
|
progname); |
71 |
< |
fprintf(stderr, " Or: %s output.hdk [-u][-d] -pz inp1.pic inp1.zbf ..\n", |
71 |
> |
fprintf(stderr, " Or: %s output.hdk [-u][-d] -p inp1.pic inp1.zbf ..\n", |
72 |
|
progname); |
73 |
|
exit(1); |
74 |
|
} |
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 |
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 (rv->d == dc && |
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] && |
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 |
< |
HDBEAMI hbl[BLOADSIZE]; |
203 |
< |
int fd; |
204 |
< |
register HOLO *hp; |
205 |
< |
register BEAM *bp; |
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, n, li; |
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 |
+ |
return(0); |
240 |
+ |
} |
241 |
+ |
|
242 |
+ |
addholo(hdf) /* add a holodeck file */ |
243 |
+ |
char *hdf; |
244 |
+ |
{ |
245 |
+ |
int fd; |
246 |
|
/* open the holodeck for reading */ |
247 |
|
openholo(hdf, 0); |
248 |
|
fd = hdlist[noutsects]->fd; /* remember the file handle */ |
249 |
< |
while ((hp = hdlist[noutsects]) != NULL) { /* load each section */ |
250 |
< |
for (j = 0; j < nbeams(hp); j++) { /* load each beam */ |
251 |
< |
if (!(li = j % BLOADSIZE)) { /* optimize order */ |
252 |
< |
if (j+BLOADSIZE > nbeams(hp)) |
210 |
< |
k = n = nbeams(hp) - j; |
211 |
< |
else |
212 |
< |
k = n = BLOADSIZE; |
213 |
< |
while (k--) { |
214 |
< |
hbl[k].h = hp; |
215 |
< |
hbl[k].b = j+k+1; |
216 |
< |
} |
217 |
< |
qsort((char *)hbl, n, |
218 |
< |
sizeof(HDBEAMI), hdfilord); |
219 |
< |
} |
220 |
< |
if ((bp = hdgetbeam(hp, hbl[li].b)) != NULL) { |
221 |
< |
hdbcoord(gc, hp, hbl[li].b); |
222 |
< |
for (k = bp->nrm; k--; ) { |
223 |
< |
d = hdray(ro, rd, |
224 |
< |
hp, gc, hdbray(bp)[k].r); |
225 |
< |
if (hp->priv == &unobstr) |
226 |
< |
VSUM(ro, ro, rd, d); |
227 |
< |
else |
228 |
< |
d = 0.; |
229 |
< |
d = hddepth(hp, hdbray(bp)[k].d) - d; |
230 |
< |
addray(ro, rd, d, hdbray(bp)[k].v); |
231 |
< |
} |
232 |
< |
hdfreebeam(hp, hbl[li].b); /* free beam */ |
233 |
< |
} |
234 |
< |
} |
235 |
< |
hddone(hp); /* free the section */ |
249 |
> |
while (hdlist[noutsects] != NULL) { /* load each section */ |
250 |
> |
/* clump the beams */ |
251 |
> |
clumpbeams(hdlist[noutsects], 0, BKBSIZE*1024, addclump); |
252 |
> |
hddone(hdlist[noutsects]); /* free the section */ |
253 |
|
} |
254 |
< |
close(fd); /* close the file */ |
254 |
> |
close(fd); /* close input file */ |
255 |
> |
hdflush(NULL); /* flush output */ |
256 |
|
} |
257 |
|
|
258 |
|
|
265 |
|
}; |
266 |
|
|
267 |
|
|
268 |
+ |
int |
269 |
|
picheadline(s, ph) /* process picture header line */ |
270 |
|
char *s; |
271 |
|
struct phead *ph; |
274 |
|
|
275 |
|
if (formatval(fmt, s)) { |
276 |
|
ph->badfmt = strcmp(fmt, COLRFMT); |
277 |
< |
return; |
277 |
> |
return(0); |
278 |
|
} |
279 |
|
if (isprims(s)) { |
280 |
|
ph->altprims++; /* don't want to deal with this */ |
281 |
< |
return; |
281 |
> |
return(0); |
282 |
|
} |
283 |
|
if (isexpos(s)) { |
284 |
|
ph->expos *= exposval(s); |
285 |
< |
return; |
285 |
> |
return(0); |
286 |
|
} |
287 |
|
if (isview(s)) { |
288 |
|
ph->gotview += sscanview(&ph->vw, s); |
289 |
< |
return; |
289 |
> |
return(0); |
290 |
|
} |
291 |
+ |
return(0); |
292 |
|
} |
293 |
|
|
294 |
|
|
387 |
|
addray(ro, rd, (double)zscn[i], cscn[i]); |
388 |
|
} |
389 |
|
} |
390 |
+ |
/* write output and free beams */ |
391 |
+ |
hdflush(NULL); |
392 |
|
/* clean up */ |
393 |
|
free((char *)cscn); |
394 |
|
free((char *)zscn); |