| 50 |
|
if (complist == NULL) |
| 51 |
|
goto memerr; |
| 52 |
|
bcopy((char *)clist, (char *)complist, nents*sizeof(PACKHEAD)); |
| 53 |
< |
complen = nents; |
| 54 |
< |
listpos = 0; |
| 55 |
< |
lastin = -1; /* flag for initial sort */ |
| 53 |
> |
complen = nents; /* finish initialization below */ |
| 54 |
|
break; |
| 55 |
|
case BS_ADD: /* add to computation set */ |
| 56 |
|
case BS_ADJ: /* adjust set quantities */ |
| 57 |
|
if (nents <= 0) |
| 58 |
|
return; |
| 59 |
|
/* merge any common members */ |
| 60 |
< |
for (i = 0; i < complen; i++) { |
| 61 |
< |
for (n = 0; n < nents; n++) |
| 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 = 1; |
| 71 |
< |
lastin = -1; /* flag full sort */ |
| 70 |
> |
clist[n].nc = complist[i].nc; |
| 71 |
> |
if (complist[i].nr != oldnr) |
| 72 |
> |
lastin = -1; /* flag sort */ |
| 73 |
|
break; |
| 74 |
|
} |
| 75 |
< |
if (n >= nents) |
| 76 |
< |
clist[i].nc = bnrays(hdlist[clist[i].hd], |
| 77 |
< |
clist[i].bi); |
| 75 |
> |
if (i >= complen) |
| 76 |
> |
clist[n].nc = bnrays(hdlist[clist[n].hd], |
| 77 |
> |
clist[n].bi); |
| 78 |
|
} |
| 79 |
|
/* sort updated list */ |
| 80 |
|
sortcomplist(); |
| 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 */ |
| 154 |
|
} |
| 155 |
|
return; |
| 156 |
|
memerr: |
| 158 |
|
} |
| 159 |
|
|
| 160 |
|
|
| 161 |
< |
int |
| 162 |
< |
weightf(hp, x0, x1, x2) /* voxel weighting function */ |
| 161 |
< |
register HOLO *hp; |
| 162 |
< |
register int x0, x1, x2; |
| 163 |
< |
{ |
| 164 |
< |
switch (vlet(OCCUPANCY)) { |
| 165 |
< |
case 'U': /* uniform weighting */ |
| 166 |
< |
return(1); |
| 167 |
< |
case 'C': /* center weighting (crude) */ |
| 168 |
< |
x0 += x0 - hp->grid[0] + 1; |
| 169 |
< |
x0 = abs(x0)*hp->grid[1]*hp->grid[2]; |
| 170 |
< |
x1 += x1 - hp->grid[1] + 1; |
| 171 |
< |
x1 = abs(x1)*hp->grid[0]*hp->grid[2]; |
| 172 |
< |
x2 += x2 - hp->grid[2] + 1; |
| 173 |
< |
x2 = abs(x2)*hp->grid[0]*hp->grid[1]; |
| 174 |
< |
return(hp->grid[0]*hp->grid[1]*hp->grid[2] - |
| 175 |
< |
(x0+x1+x2)/3); |
| 176 |
< |
default: |
| 177 |
< |
badvalue(OCCUPANCY); |
| 178 |
< |
} |
| 179 |
< |
} |
| 180 |
< |
|
| 181 |
< |
|
| 182 |
< |
/* The following is by Daniel Cohen, taken from Graphics Gems IV, p. 368 */ |
| 183 |
< |
long |
| 184 |
< |
lineweight(hp, x, y, z, dx, dy, dz) /* compute weights along a line */ |
| 161 |
> |
double |
| 162 |
> |
beamvolume(hp, bi) /* compute approximate volume of a beam */ |
| 163 |
|
HOLO *hp; |
| 164 |
< |
int x, y, z, dx, dy, dz; |
| 164 |
> |
int bi; |
| 165 |
|
{ |
| 166 |
< |
long wres = 0; |
| 167 |
< |
int n, sx, sy, sz, exy, exz, ezy, ax, ay, az, bx, by, bz; |
| 168 |
< |
|
| 169 |
< |
sx = sgn(dx); sy = sgn(dy); sz = sgn(dz); |
| 170 |
< |
ax = abs(dx); ay = abs(dy); az = abs(dz); |
| 171 |
< |
bx = 2*ax; by = 2*ay; bz = 2*az; |
| 172 |
< |
exy = ay-ax; exz = az-ax; ezy = ay-az; |
| 173 |
< |
n = ax+ay+az + 1; /* added increment to visit last */ |
| 174 |
< |
while (n--) { |
| 175 |
< |
wres += weightf(hp, x, y, z); |
| 176 |
< |
if (exy < 0) { |
| 177 |
< |
if (exz < 0) { |
| 178 |
< |
x += sx; |
| 179 |
< |
exy += by; exz += bz; |
| 180 |
< |
} else { |
| 181 |
< |
z += sz; |
| 182 |
< |
exz -= bx; ezy += by; |
| 183 |
< |
} |
| 184 |
< |
} else { |
| 185 |
< |
if (ezy < 0) { |
| 186 |
< |
z += sz; |
| 209 |
< |
exz -= bx; ezy += by; |
| 210 |
< |
} else { |
| 211 |
< |
y += sy; |
| 212 |
< |
exy -= bx; ezy -= bz; |
| 213 |
< |
} |
| 214 |
< |
} |
| 166 |
> |
GCOORD gc[2]; |
| 167 |
> |
FVECT cp[4], edgeA, edgeB, cent[2]; |
| 168 |
> |
FVECT v, crossp[2], diffv; |
| 169 |
> |
double vol[2]; |
| 170 |
> |
register int i; |
| 171 |
> |
/* get grid coordinates */ |
| 172 |
> |
if (!hdbcoord(gc, hp, bi)) |
| 173 |
> |
error(CONSISTENCY, "bad beam index in beamvolume"); |
| 174 |
> |
for (i = 0; i < 2; i++) { /* compute cell area vectors */ |
| 175 |
> |
hdcell(cp, hp, gc+i); |
| 176 |
> |
VSUM(edgeA, cp[1], cp[0], -1.0); |
| 177 |
> |
VSUM(edgeB, cp[3], cp[1], -1.0); |
| 178 |
> |
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); |
| 183 |
> |
/* compute center */ |
| 184 |
> |
cent[i][0] = 0.5*(cp[0][0] + cp[2][0]); |
| 185 |
> |
cent[i][1] = 0.5*(cp[0][1] + cp[2][1]); |
| 186 |
> |
cent[i][2] = 0.5*(cp[0][2] + cp[2][2]); |
| 187 |
|
} |
| 188 |
< |
return(wres); |
| 188 |
> |
/* compute difference vector */ |
| 189 |
> |
VSUM(diffv, cent[1], cent[0], -1.0); |
| 190 |
> |
for (i = 0; i < 2; i++) { /* compute volume contributions */ |
| 191 |
> |
vol[i] = 0.25*DOT(crossp[i], diffv); |
| 192 |
> |
if (vol[i] < 0.) vol[i] = -vol[i]; |
| 193 |
> |
} |
| 194 |
> |
return(vol[0] + vol[1]); /* return total volume */ |
| 195 |
|
} |
| 196 |
|
|
| 197 |
|
|
| 198 |
|
init_global() /* initialize global ray computation */ |
| 199 |
|
{ |
| 200 |
|
long wtotal = 0; |
| 223 |
– |
int i, j; |
| 224 |
– |
int lseg[2][3]; |
| 201 |
|
double frac; |
| 202 |
< |
register int k; |
| 202 |
> |
int i; |
| 203 |
> |
register int j, k; |
| 204 |
|
/* free old list */ |
| 205 |
|
if (complen > 0) |
| 206 |
|
free((char *)complist); |
| 213 |
|
error(SYSTEM, "out of memory in init_global"); |
| 214 |
|
/* compute beam weights */ |
| 215 |
|
k = 0; |
| 216 |
< |
for (j = 0; hdlist[j] != NULL; j++) |
| 216 |
> |
for (j = 0; hdlist[j] != NULL; j++) { |
| 217 |
> |
frac = 512. * hdlist[j]->wg[0] * |
| 218 |
> |
hdlist[j]->wg[1] * hdlist[j]->wg[2]; |
| 219 |
|
for (i = nbeams(hdlist[j]); i > 0; i--) { |
| 241 |
– |
hdlseg(lseg, hdlist[j], i); |
| 220 |
|
complist[k].hd = j; |
| 221 |
|
complist[k].bi = i; |
| 222 |
< |
complist[k].nr = lineweight( hdlist[j], |
| 245 |
< |
lseg[0][0], lseg[0][1], lseg[0][2], |
| 246 |
< |
lseg[1][0] - lseg[0][0], |
| 247 |
< |
lseg[1][1] - lseg[0][1], |
| 248 |
< |
lseg[1][2] - lseg[0][2] ); |
| 222 |
> |
complist[k].nr = frac*beamvolume(hdlist[j], i) + 0.5; |
| 223 |
|
wtotal += complist[k++].nr; |
| 224 |
|
} |
| 225 |
+ |
} |
| 226 |
|
/* adjust weights */ |
| 227 |
< |
if (vdef(DISKSPACE)) { |
| 227 |
> |
if (vdef(DISKSPACE)) |
| 228 |
|
frac = 1024.*1024.*vflt(DISKSPACE) / (wtotal*sizeof(RAYVAL)); |
| 229 |
< |
if (frac < 0.95 | frac > 1.05) |
| 230 |
< |
while (k--) |
| 231 |
< |
complist[k].nr = frac * complist[k].nr; |
| 232 |
< |
} |
| 229 |
> |
else |
| 230 |
> |
frac = 1024.*1024.*16384. / (wtotal*sizeof(RAYVAL)); |
| 231 |
> |
while (k--) |
| 232 |
> |
complist[k].nr = frac * complist[k].nr; |
| 233 |
|
listpos = 0; lastin = -1; /* flag initial sort */ |
| 234 |
|
} |
| 235 |
|
|