20 |
|
|
21 |
|
int |
22 |
|
npixels(vp, hr, vr, hp, bi) /* compute appropriate number to evaluate */ |
23 |
< |
VIEW *vp; |
23 |
> |
register VIEW *vp; |
24 |
|
int hr, vr; |
25 |
|
HOLO *hp; |
26 |
|
int bi; |
27 |
|
{ |
28 |
< |
static VIEW vdo, vlast; |
29 |
< |
static HOLO *hplast; |
28 |
> |
VIEW vrev; |
29 |
|
GCOORD gc[2]; |
30 |
< |
FVECT cp[4]; |
31 |
< |
FVECT ip[4]; |
33 |
< |
double d; |
30 |
> |
FVECT cp[4], ip[4]; |
31 |
> |
double af, ab; |
32 |
|
register int i; |
33 |
|
/* compute cell corners in image */ |
34 |
|
if (!hdbcoord(gc, hp, bi)) |
35 |
|
error(CONSISTENCY, "bad beam index in npixels"); |
36 |
< |
/* has holodeck or view changed? */ |
37 |
< |
if (hp != hplast || bcmp((char *)vp, (char *)&vlast, sizeof(VIEW))) { |
38 |
< |
copystruct(&vdo, vp); |
39 |
< |
if (sect_behind(hp, &vdo)) { /* reverse view sense */ |
40 |
< |
vdo.vdir[0] = -vdo.vdir[0]; |
41 |
< |
vdo.vdir[1] = -vdo.vdir[1]; |
44 |
< |
vdo.vdir[2] = -vdo.vdir[2]; |
45 |
< |
setview(&vdo); |
36 |
> |
hdcell(cp, hp, gc+1); /* find cell on front image */ |
37 |
> |
for (i = 0; i < 4; i++) { |
38 |
> |
viewloc(ip[i], vp, cp[i]); |
39 |
> |
if (ip[i][2] < 0.) { |
40 |
> |
af = 0; |
41 |
> |
goto getback; |
42 |
|
} |
43 |
< |
hplast = hp; |
44 |
< |
copystruct(&vlast, vp); |
43 |
> |
ip[i][0] *= (double)hr; /* scale by resolution */ |
44 |
> |
ip[i][1] *= (double)vr; |
45 |
|
} |
46 |
< |
hdcell(cp, hp, gc+1); /* find cell on image */ |
46 |
> |
/* compute front area */ |
47 |
> |
af = (ip[1][0]-ip[0][0])*(ip[2][1]-ip[0][1]) - |
48 |
> |
(ip[2][0]-ip[0][0])*(ip[1][1]-ip[0][1]); |
49 |
> |
af += (ip[2][0]-ip[3][0])*(ip[1][1]-ip[3][1]) - |
50 |
> |
(ip[1][0]-ip[3][0])*(ip[2][1]-ip[3][1]); |
51 |
> |
if (af >= 0) af *= 0.5; |
52 |
> |
else af *= -0.5; |
53 |
> |
getback: |
54 |
> |
copystruct(&vrev, vp); /* compute reverse view */ |
55 |
> |
for (i = 0; i < 3; i++) { |
56 |
> |
vrev.vdir[i] = -vp->vdir[i]; |
57 |
> |
vrev.vup[i] = -vp->vup[i]; |
58 |
> |
vrev.hvec[i] = -vp->hvec[i]; |
59 |
> |
vrev.vvec[i] = -vp->vvec[i]; |
60 |
> |
} |
61 |
> |
hdcell(cp, hp, gc); /* find cell on back image */ |
62 |
|
for (i = 0; i < 4; i++) { |
63 |
< |
viewloc(ip[i], &vdo, cp[i]); |
63 |
> |
viewloc(ip[i], &vrev, cp[i]); |
64 |
|
if (ip[i][2] < 0.) |
65 |
< |
return(0); |
65 |
> |
return((int)(af + 0.5)); |
66 |
|
ip[i][0] *= (double)hr; /* scale by resolution */ |
67 |
|
ip[i][1] *= (double)vr; |
68 |
|
} |
69 |
< |
/* compute quad area */ |
70 |
< |
d = (ip[1][0]-ip[0][0])*(ip[2][1]-ip[0][1]) - |
69 |
> |
/* compute back area */ |
70 |
> |
ab = (ip[1][0]-ip[0][0])*(ip[2][1]-ip[0][1]) - |
71 |
|
(ip[2][0]-ip[0][0])*(ip[1][1]-ip[0][1]); |
72 |
< |
d += (ip[2][0]-ip[3][0])*(ip[1][1]-ip[3][1]) - |
72 |
> |
ab += (ip[2][0]-ip[3][0])*(ip[1][1]-ip[3][1]) - |
73 |
|
(ip[1][0]-ip[3][0])*(ip[2][1]-ip[3][1]); |
74 |
< |
if (d < 0) |
75 |
< |
d = -d; |
76 |
< |
/* round off result */ |
77 |
< |
return((int)(.5*d+.5)); |
74 |
> |
if (ab >= 0) ab *= 0.5; |
75 |
> |
else ab *= -0.5; |
76 |
> |
/* round off smaller area */ |
77 |
> |
if (af <= ab) |
78 |
> |
return((int)(af + 0.5)); |
79 |
> |
return((int)(ab + 0.5)); |
80 |
|
} |
81 |
|
|
82 |
|
|