1 |
< |
/* Copyright (c) 1997 Silicon Graphics, Inc. */ |
1 |
> |
/* Copyright (c) 1998 Silicon Graphics, Inc. */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ SGI"; |
27 |
|
} |
28 |
|
|
29 |
|
|
30 |
+ |
int |
31 |
+ |
dispbeam(b, hp, bi) /* display a holodeck beam */ |
32 |
+ |
register BEAM *b; |
33 |
+ |
HOLO *hp; |
34 |
+ |
int bi; |
35 |
+ |
{ |
36 |
+ |
static int n = 0; |
37 |
+ |
static PACKHEAD *p = NULL; |
38 |
+ |
|
39 |
+ |
if (b == NULL) |
40 |
+ |
return; |
41 |
+ |
if (b->nrm > n) { /* (re)allocate packet holder */ |
42 |
+ |
n = b->nrm; |
43 |
+ |
if (p == NULL) p = (PACKHEAD *)malloc(packsiz(n)); |
44 |
+ |
else p = (PACKHEAD *)realloc((char *)p, packsiz(n)); |
45 |
+ |
if (p == NULL) |
46 |
+ |
error(SYSTEM, "out of memory in dispbeam"); |
47 |
+ |
} |
48 |
+ |
/* assign packet fields */ |
49 |
+ |
bcopy((char *)hdbray(b), (char *)packra(p), b->nrm*sizeof(RAYVAL)); |
50 |
+ |
p->nr = p->nc = b->nrm; |
51 |
+ |
for (p->hd = 0; hdlist[p->hd] != hp; p->hd++) |
52 |
+ |
if (hdlist[p->hd] == NULL) |
53 |
+ |
error(CONSISTENCY, "unregistered holodeck in dispbeam"); |
54 |
+ |
p->bi = bi; |
55 |
+ |
disp_packet(p); /* display it */ |
56 |
+ |
} |
57 |
+ |
|
58 |
+ |
|
59 |
|
bundle_set(op, clist, nents) /* bundle set operation */ |
60 |
|
int op; |
61 |
< |
PACKHEAD *clist; |
61 |
> |
register PACKHEAD *clist; |
62 |
|
int nents; |
63 |
|
{ |
64 |
< |
BEAM *b; |
36 |
< |
PACKHEAD *p; |
64 |
> |
int oldnr; |
65 |
|
register int i, n; |
66 |
< |
|
66 |
> |
/* look for common members */ |
67 |
> |
for (n = 0; n < nents; n++) { |
68 |
> |
for (i = 0; i < complen; i++) |
69 |
> |
if (clist[n].bi == complist[i].bi && |
70 |
> |
clist[n].hd == complist[i].hd) { |
71 |
> |
oldnr = complist[i].nr; |
72 |
> |
clist[n].nc = complist[i].nc; |
73 |
> |
switch (op) { |
74 |
> |
case BS_ADD: /* add to count */ |
75 |
> |
complist[i].nr += clist[n].nr; |
76 |
> |
clist[n].nr = 0; |
77 |
> |
break; |
78 |
> |
case BS_ADJ: /* reset count */ |
79 |
> |
complist[i].nr = clist[n].nr; |
80 |
> |
clist[n].nr = 0; |
81 |
> |
break; |
82 |
> |
case BS_DEL: /* delete count */ |
83 |
> |
if (clist[n].nr == 0 || |
84 |
> |
clist[n].nr >= complist[i].nr) |
85 |
> |
complist[i].nr = 0; |
86 |
> |
else |
87 |
> |
complist[i].nr -= clist[n].nr; |
88 |
> |
break; |
89 |
> |
} |
90 |
> |
if (complist[i].nr != oldnr) |
91 |
> |
lastin = -1; /* flag sort */ |
92 |
> |
break; |
93 |
> |
} |
94 |
> |
if (i >= complen) |
95 |
> |
clist[n].nc = bnrays(hdlist[clist[n].hd], clist[n].bi); |
96 |
> |
} |
97 |
> |
/* complete list operations */ |
98 |
|
switch (op) { |
99 |
|
case BS_NEW: /* new computation set */ |
100 |
< |
if (complen) |
100 |
> |
listpos = 0; lastin = -1; |
101 |
> |
if (complen) /* free old list */ |
102 |
|
free((char *)complist); |
103 |
< |
if (nents <= 0) { |
104 |
< |
complist = NULL; |
45 |
< |
listpos = complen = 0; |
46 |
< |
lastin = -1; |
103 |
> |
complist = NULL; |
104 |
> |
if (!(complen = nents)) |
105 |
|
return; |
48 |
– |
} |
106 |
|
complist = (PACKHEAD *)malloc(nents*sizeof(PACKHEAD)); |
107 |
|
if (complist == NULL) |
108 |
|
goto memerr; |
109 |
|
bcopy((char *)clist, (char *)complist, nents*sizeof(PACKHEAD)); |
53 |
– |
complen = nents; /* finish initialization below */ |
110 |
|
break; |
111 |
|
case BS_ADD: /* add to computation set */ |
112 |
|
case BS_ADJ: /* adjust set quantities */ |
113 |
|
if (nents <= 0) |
114 |
|
return; |
115 |
< |
/* merge any common members */ |
60 |
< |
for (n = 0; n < nents; n++) { |
61 |
< |
for (i = 0; i < complen; i++) |
62 |
< |
if (clist[n].bi == complist[i].bi && |
63 |
< |
clist[n].hd == complist[i].hd) { |
64 |
< |
int oldnr = complist[i].nr; |
65 |
< |
if (op == BS_ADD) |
66 |
< |
complist[i].nr += clist[n].nr; |
67 |
< |
else /* op == BS_ADJ */ |
68 |
< |
complist[i].nr = clist[n].nr; |
69 |
< |
clist[n].nr = 0; |
70 |
< |
clist[n].nc = complist[i].nc; |
71 |
< |
if (complist[i].nr != oldnr) |
72 |
< |
lastin = -1; /* flag sort */ |
73 |
< |
break; |
74 |
< |
} |
75 |
< |
if (i >= complen) |
76 |
< |
clist[n].nc = bnrays(hdlist[clist[n].hd], |
77 |
< |
clist[n].bi); |
78 |
< |
} |
79 |
< |
/* sort updated list */ |
80 |
< |
sortcomplist(); |
81 |
< |
/* sort new entries */ |
115 |
> |
sortcomplist(); /* sort updated list & new entries */ |
116 |
|
qsort((char *)clist, nents, sizeof(PACKHEAD), beamcmp); |
117 |
|
/* what can't we satisfy? */ |
118 |
|
for (n = 0; n < nents && clist[n].nr > clist[n].nc; n++) |
136 |
|
lastin = complen-1; /* list is now sorted */ |
137 |
|
break; |
138 |
|
case BS_DEL: /* delete from computation set */ |
139 |
< |
if (nents <= 0) |
106 |
< |
return; |
107 |
< |
/* find each member */ |
108 |
< |
for (i = 0; i < complen; i++) |
109 |
< |
for (n = 0; n < nents; n++) |
110 |
< |
if (clist[n].bi == complist[i].bi && |
111 |
< |
clist[n].hd == complist[i].hd) { |
112 |
< |
if (clist[n].nr == 0 || |
113 |
< |
clist[n].nr >= complist[i].nr) |
114 |
< |
complist[i].nr = 0; |
115 |
< |
else |
116 |
< |
complist[i].nr -= clist[n].nr; |
117 |
< |
lastin = -1; /* flag full sort */ |
118 |
< |
break; |
119 |
< |
} |
120 |
< |
return; /* no display */ |
139 |
> |
return; /* already done */ |
140 |
|
default: |
141 |
|
error(CONSISTENCY, "bundle_set called with unknown operation"); |
142 |
|
} |
143 |
< |
if (outdev == NULL) |
144 |
< |
return; |
145 |
< |
n = 32*RPACKSIZ; /* allocate packet holder */ |
146 |
< |
p = (PACKHEAD *)malloc(packsiz(n)); |
147 |
< |
if (p == NULL) |
148 |
< |
goto memerr; |
149 |
< |
/* display what we have */ |
131 |
< |
for (i = 0; i < nents; i++) |
132 |
< |
if ((b = hdgetbeam(hdlist[clist[i].hd], clist[i].bi)) != NULL) { |
133 |
< |
if (b->nrm > n) { |
134 |
< |
n = b->nrm; |
135 |
< |
p = (PACKHEAD *)realloc((char *)p, packsiz(n)); |
136 |
< |
if (p == NULL) |
137 |
< |
goto memerr; |
138 |
< |
} |
139 |
< |
bcopy((char *)hdbray(b), (char *)packra(p), |
140 |
< |
b->nrm*sizeof(RAYVAL)); |
141 |
< |
p->hd = clist[i].hd; |
142 |
< |
p->bi = clist[i].bi; |
143 |
< |
p->nr = p->nc = b->nrm; |
144 |
< |
disp_packet(p); |
143 |
> |
if (outdev != NULL) { /* load and display beams we have */ |
144 |
> |
register HDBEAMI *hb; |
145 |
> |
|
146 |
> |
hb = (HDBEAMI *)malloc(nents*sizeof(HDBEAMI)); |
147 |
> |
for (i = 0; i < nents; i++) { |
148 |
> |
hb[i].h = hdlist[clist[i].hd]; |
149 |
> |
hb[i].b = clist[i].bi; |
150 |
|
} |
151 |
< |
free((char *)p); /* clean up */ |
152 |
< |
if (op == BS_NEW) { |
148 |
< |
done_packets(flush_queue()); /* empty queue, so we can... */ |
149 |
< |
for (i = 0; i < complen; i++) /* ...get number computed */ |
150 |
< |
complist[i].nc = bnrays(hdlist[complist[i].hd], |
151 |
< |
complist[i].bi); |
152 |
< |
listpos = 0; |
153 |
< |
lastin = -1; /* flag for initial sort */ |
151 |
> |
hdloadbeams(hb, nents, dispbeam); |
152 |
> |
free((char *)hb); |
153 |
|
} |
154 |
|
return; |
155 |
|
memerr: |
175 |
|
VSUM(edgeA, cp[1], cp[0], -1.0); |
176 |
|
VSUM(edgeB, cp[3], cp[1], -1.0); |
177 |
|
fcross(crossp[i], edgeA, edgeB); |
179 |
– |
VSUM(edgeA, cp[2], cp[3], -1.0); |
180 |
– |
VSUM(edgeB, cp[0], cp[2], -1.0); |
181 |
– |
fcross(v, edgeA, edgeB); |
182 |
– |
VSUM(crossp[i], crossp[i], v, 1.0); |
178 |
|
/* compute center */ |
179 |
|
cent[i][0] = 0.5*(cp[0][0] + cp[2][0]); |
180 |
|
cent[i][1] = 0.5*(cp[0][1] + cp[2][1]); |
183 |
|
/* compute difference vector */ |
184 |
|
VSUM(diffv, cent[1], cent[0], -1.0); |
185 |
|
for (i = 0; i < 2; i++) { /* compute volume contributions */ |
186 |
< |
vol[i] = 0.25*DOT(crossp[i], diffv); |
186 |
> |
vol[i] = 0.5*DOT(crossp[i], diffv); |
187 |
|
if (vol[i] < 0.) vol[i] = -vol[i]; |
188 |
|
} |
189 |
|
return(vol[0] + vol[1]); /* return total volume */ |
196 |
|
double frac; |
197 |
|
int i; |
198 |
|
register int j, k; |
199 |
< |
/* free old list */ |
200 |
< |
if (complen > 0) |
199 |
> |
/* free old list and empty queue */ |
200 |
> |
if (complen > 0) { |
201 |
|
free((char *)complist); |
202 |
+ |
done_packets(flush_queue()); |
203 |
+ |
} |
204 |
|
/* allocate beam list */ |
205 |
|
complen = 0; |
206 |
|
for (j = 0; hdlist[j] != NULL; j++) |
211 |
|
/* compute beam weights */ |
212 |
|
k = 0; |
213 |
|
for (j = 0; hdlist[j] != NULL; j++) { |
214 |
< |
frac = 512. * hdlist[j]->wg[0] * |
215 |
< |
hdlist[j]->wg[1] * hdlist[j]->wg[2]; |
214 |
> |
frac = 512. * VLEN(hdlist[j]->wg[0]) * |
215 |
> |
VLEN(hdlist[j]->wg[1]) * |
216 |
> |
VLEN(hdlist[j]->wg[2]); |
217 |
|
for (i = nbeams(hdlist[j]); i > 0; i--) { |
218 |
|
complist[k].hd = j; |
219 |
|
complist[k].bi = i; |
220 |
|
complist[k].nr = frac*beamvolume(hdlist[j], i) + 0.5; |
221 |
+ |
complist[k].nc = bnrays(hdlist[j], i); |
222 |
|
wtotal += complist[k++].nr; |
223 |
|
} |
224 |
|
} |
229 |
|
frac = 1024.*1024.*16384. / (wtotal*sizeof(RAYVAL)); |
230 |
|
while (k--) |
231 |
|
complist[k].nr = frac * complist[k].nr; |
232 |
< |
listpos = 0; lastin = -1; /* flag initial sort */ |
232 |
> |
listpos = 0; lastin = -1; /* perform initial sort */ |
233 |
> |
sortcomplist(); |
234 |
|
} |
235 |
|
|
236 |
|
|
237 |
|
mergeclists(cdest, cl1, n1, cl2, n2) /* merge two sorted lists */ |
238 |
< |
PACKHEAD *cdest; |
239 |
< |
PACKHEAD *cl1, *cl2; |
238 |
> |
register PACKHEAD *cdest; |
239 |
> |
register PACKHEAD *cl1, *cl2; |
240 |
|
int n1, n2; |
241 |
|
{ |
242 |
< |
int cmp; |
242 |
> |
register int cmp; |
243 |
|
|
244 |
|
while (n1 | n2) { |
245 |
|
if (!n1) cmp = 1; |
304 |
|
* list and start again from the beginning. Since |
305 |
|
* a merge sort is used, the sorting costs are minimal. |
306 |
|
*/ |
307 |
< |
next_packet(p) /* prepare packet for computation */ |
307 |
> |
next_packet(p, n) /* prepare packet for computation */ |
308 |
|
register PACKET *p; |
309 |
+ |
int n; |
310 |
|
{ |
311 |
|
register int i; |
312 |
|
|
320 |
|
p->nr = complist[listpos].nr - p->nc; |
321 |
|
if (p->nr <= 0) |
322 |
|
return(0); |
323 |
< |
if (p->nr > RPACKSIZ) |
324 |
< |
p->nr = RPACKSIZ; |
323 |
> |
#ifdef DEBUG |
324 |
> |
if (n < 1 | n > RPACKSIZ) |
325 |
> |
error(CONSISTENCY, "next_packet called with bad n value"); |
326 |
> |
#endif |
327 |
> |
if (p->nr > n) |
328 |
> |
p->nr = n; |
329 |
|
complist[listpos].nc += p->nr; /* find where this one would go */ |
330 |
|
while (lastin > listpos && |
331 |
|
beamcmp(complist+lastin, complist+listpos) > 0) |