1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
include <fset.h>
include "../lib/apphot.h"
include "../lib/polyphot.h"
# AP_YNEXTOBJ -- Read the next polygon from the list polygon and/or coordinate
# list.
int procedure ap_ynextobj (py, im, id, pl, cl, delim, x, y, maxnver, prev_num,
req_num, ld, pd)
pointer py # pointer to the apphot structre
pointer im # the input image descriptor
pointer id # pointer to image display stream
int pl # polygons file descriptor
int cl # coordinates file descriptor
int delim # delimiter character
real x[ARB] # x coordinates of the polygon vertices
real y[ARB] # y coordinates of the polygon vertices
int maxnver # maximum number of vertices
int prev_num # previous object
int req_num # requested object
int ld # current object
int pd # current polygon
real xshift, yshift
pointer sp, fname
int stdin, nskip, ncount, nver, stat
real apstatr()
int strncmp(), ap_yget(), ap_ycoords(), apstati()
errchk greactivate, gdeactivate, gscur
begin
# The coordinate list is undefined.
if (cl == NULL) {
# Get the input file name.
call smark (sp)
call salloc (fname, SZ_FNAME, TY_CHAR)
call fstats (pl, F_FILENAME, Memc[fname], SZ_FNAME)
# Compute the number of polygons that must be skipped.
if (strncmp ("STDIN", Memc[fname], 5) == 0) {
stdin = YES
nskip = 1
} else {
stdin = NO
if (req_num <= prev_num) {
call seek (pl, BOF)
nskip = req_num
} else
nskip = req_num - prev_num
}
# Initialize the polygon search.
ncount = 0
pd = prev_num
# Find the correct polygon.
repeat {
call apsetr (py, PYX, apstatr (py, PYCX))
call apsetr (py, PYY, apstatr (py, PYCY))
nver = ap_yget (py, im, pl, delim, x, y, maxnver)
if (nver == EOF) {
ncount = EOF
} else if (nver > 0) {
ncount = ncount + 1
pd = pd + 1
}
} until (ncount == EOF || ncount == nskip)
# Return the polygon number.
if (req_num <= prev_num)
pd = ncount
ld = pd
call sfree (sp)
if (ncount == EOF) {
return (EOF)
} else if (id != NULL) {
iferr {
call greactivate (id, 0)
call gscur (id, apstatr (py, PYCX), apstatr (py, PYCY))
call gdeactivate (id, 0)
} then
;
return (nver)
} else {
return (nver)
}
# Both the polygon and coordinate file are defined.
} else {
# Get the input file name.
call smark (sp)
call salloc (fname, SZ_FNAME, TY_CHAR)
call fstats (cl, F_FILENAME, Memc[fname], SZ_FNAME)
# Compute the number of objects that must be skipped.
if (strncmp ("STDIN", Memc[fname], 5) == 0) {
stdin = YES
nskip = 1
} else {
stdin = NO
if (req_num <= prev_num) {
call seek (cl, BOF)
call seek (pl, BOF)
pd = 0
nskip = req_num
} else
nskip = req_num - prev_num
}
# Initialize the polygon id.
ncount = 0
ld = prev_num
# Find the correct object and shift the coordinates.
repeat {
# Read the coordinates and the polygon.
stat = ap_ycoords (cl, delim, xshift, yshift, stdin)
if (stat == EOF) {
ncount = EOF
} else if (stat == NEXT_POLYGON || pd == 0) {
call apsetr (py, PYX, apstatr (py, PYCX))
call apsetr (py, PYY, apstatr (py, PYCY))
nver = ap_yget (py, im, pl, delim, x, y, maxnver)
if (nver == EOF)
ncount = EOF
else if (nver > 0)
pd = pd + 1
}
# Shift the polygon coordinates.
if (stat == THIS_OBJECT && ncount != EOF && nver > 0) {
switch (apstati(py,WCSIN)) {
case WCS_WORLD, WCS_PHYSICAL:
call ap_itol (py, xshift, yshift, xshift, yshift, 1)
case WCS_TV:
call ap_vtol (im, xshift, yshift, xshift, yshift, 1)
default:
;
}
call aaddkr (x, (xshift - apstatr (py, PYCX)), x, nver + 1)
call aaddkr (y, (yshift - apstatr (py, PYCY)), y, nver + 1)
call apsetr (py, PYCX, xshift)
call apsetr (py, PYCY, yshift)
switch (apstati(py,WCSOUT)) {
case WCS_WORLD, WCS_PHYSICAL:
call ap_ltoo (py, xshift, yshift, xshift, yshift, 1)
case WCS_TV:
call ap_ltov (im, xshift, yshift, xshift, yshift, 1)
default:
;
}
call apsetr (py, OPYCX, xshift)
call apsetr (py, OPYCY, yshift)
ncount = ncount + 1
ld = ld + 1
}
} until (ncount == EOF || ncount == nskip)
# Get the correct id.
if (req_num <= prev_num)
ld = ncount
call sfree (sp)
if (ncount == EOF) {
return (EOF)
} else if (id != NULL) {
iferr {
call greactivate (id, 0)
call gscur (id, apstatr (py, PYCX), apstatr (py, PYCY))
call gdeactivate (id, 0)
} then
;
return (nver)
} else {
return (nver)
}
}
end
|