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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
|
include <fset.h>
include "../lib/apphot.h"
include "../lib/fitsky.h"
include "../lib/polyphot.h"
# AP_YGET -- Procedure to fetch the coordinates of the vertices of a
# polygon from a text file.
int procedure ap_yget (py, im, fd, delim, x, y, max_nvertices)
pointer py # polyphot structure
pointer im # the input image descriptor
int fd # polygon file descriptor
int delim # delimiter character
real x[ARB] # x coords of vertices
real y[ARB] # y coords of vertices
int max_nvertices # maximum number of vertices
real xc, yc, r2max, r2, xtemp, ytemp
pointer sp, str
int i, nvertices, nreal, stat
char marker
real asumr()
int fscan(), nscan(), strncmp(), apstati()
begin
call smark (sp)
call salloc (str, SZ_LINE, TY_CHAR)
# Print prompts if input file is STDIN.
call fstats (fd, F_FILENAME, Memc[str], SZ_LINE)
if (strncmp ("STDIN", Memc[str], 5) == 0) {
call printf ("Type x and y coordinates of vertex\n")
call printf ("\t1 vertex per line\n")
call printf ("\t; to end polygon\n")
call printf ("\t^Z to end list\n")
call flush (STDOUT)
}
# Get the polygon.
nvertices = 0
stat = fscan (fd)
while (stat != EOF) {
# Read the vertices from the file
call gargr (xtemp)
call gargr (ytemp)
nreal = nscan ()
if (nreal != 2) {
call reset_scan ()
call gargc (marker)
if (int (marker) == delim)
break
nreal = nscan ()
}
# Store the vertices.
if (nreal >= 2) {
nvertices = nvertices + 1
if (nvertices <= max_nvertices) {
x[nvertices] = xtemp
y[nvertices] = ytemp
}
}
stat = fscan (fd)
}
if (nvertices == 0 && stat == EOF) {
nvertices = EOF
call apsetr (py, PYXMEAN, INDEFR)
call apsetr (py, PYYMEAN, INDEFR)
call apsetr (py, OPYXMEAN, INDEFR)
call apsetr (py, OPYYMEAN, INDEFR)
call apsetr (py, PYCX, INDEFR)
call apsetr (py, PYCY, INDEFR)
call apsetr (py, OPYCX, INDEFR)
call apsetr (py, OPYCY, INDEFR)
call apsetr (py, PYMINRAD, INDEFR)
call apseti (py, PYNVER, 0)
} else if (nvertices <= 2) {
call apsetr (py, PYXMEAN, INDEFR)
call apsetr (py, PYYMEAN, INDEFR)
call apsetr (py, OPYXMEAN, INDEFR)
call apsetr (py, OPYYMEAN, INDEFR)
call apsetr (py, PYCX, INDEFR)
call apsetr (py, PYCY, INDEFR)
call apsetr (py, OPYCX, INDEFR)
call apsetr (py, OPYCY, INDEFR)
call apsetr (py, PYMINRAD, INDEFR)
call apseti (py, PYNVER, 0)
nvertices = 0
} else {
# Add in the last vertex.
x[nvertices+1] = x[1]
y[nvertices+1] = y[1]
# Transform the input coordinates.
switch (apstati(py,WCSIN)) {
case WCS_WORLD, WCS_PHYSICAL:
call ap_itol (py, x, y, x, y, nvertices + 1)
case WCS_TV:
call ap_vtol (im, x, y, x, y, nvertices + 1)
default:
;
}
# Compute the mean polygon coordinates.
xc = asumr (x, nvertices) / nvertices
yc = asumr (y, nvertices) / nvertices
call apsetr (py, PYXMEAN, xc)
call apsetr (py, PYYMEAN, yc)
call apsetr (py, PYCX, xc)
call apsetr (py, PYCY, yc)
# Set the minimum size of the sky annulus.
r2max = 0.0
do i = 1, nvertices {
r2 = (x[i] - xc) ** 2 + (y[i] - yc) ** 2
if (r2 > r2max)
r2max = r2
}
switch (apstati(py,WCSOUT)) {
case WCS_WORLD, WCS_PHYSICAL:
call ap_ltoo (py, xc, yc, xc, yc, 1)
case WCS_TV:
call ap_ltov (im, xc, yc, xc, yc, 1)
default:
;
}
call apsetr (py, OPYXMEAN, xc)
call apsetr (py, OPYYMEAN, yc)
call apsetr (py, OPYCX, xc)
call apsetr (py, OPYCY, yc)
call apsetr (py, PYMINRAD, (sqrt (r2max) + 1.1))
call apseti (py, PYNVER, nvertices)
}
call sfree (sp)
return (nvertices)
end
# AP_YMKPOLY -- Mark the coordinates of a polygon on the display device.
int procedure ap_ymkpoly (py, im, id, x, y, max_nvertices, idflush)
pointer py # polyphot structure
pointer im # the input image descriptor
pointer id # display pointer
real x[ARB] # x coords of vertices
real y[ARB] # y coords of vertices
int max_nvertices # maximum number of vertices
int idflush # flush the imd interface ?
int i, nvertices, stat, wcs, key
pointer sp, cmd
real xtemp, ytemp, xc, yc, r2max, r2
real apstatr(), asumr()
int clgcur(), apstati()
errchk gscur
begin
# Reopen the device.
if (id != NULL)
call greactivate (id, 0)
# Initialize.
call smark (sp)
call salloc (cmd, SZ_LINE, TY_CHAR)
# Type prompt.
call printf (
"Mark polygon vertex [space=mark,q=quit].\n")
stat = clgcur ("icommands", xtemp, ytemp, wcs, key, Memc[cmd], SZ_LINE)
call ap_vtol (im, xtemp, ytemp, xtemp, ytemp, 1)
# Fetch the polygon and draw it on the display.
nvertices = 0
while (stat != EOF) {
if (key == 'q')
break
# Decode and draw vertices.
nvertices = nvertices + 1
if (nvertices <= max_nvertices) {
x[nvertices] = xtemp
y[nvertices] = ytemp
if (id != NULL) {
if (nvertices == 1)
call gamove (id, x[1], y[1])
else {
call gadraw (id, x[nvertices], y[nvertices])
if (idflush == YES)
call gframe (id)
else
call gflush (id)
}
}
} else
break
# Type prompt.
call printf (
"Mark polygon vertex [space=mark,q=quit].\n")
stat = clgcur ("icommands", xtemp, ytemp, wcs, key, Memc[cmd],
SZ_LINE)
call ap_vtol (im, xtemp, ytemp, xtemp, ytemp, 1)
}
call printf ("\n")
call sfree (sp)
# Return EOF or the number of vertices in the polygon.
if (stat == EOF) {
call apsetr (py, PYXMEAN, INDEFR)
call apsetr (py, PYYMEAN, INDEFR)
call apsetr (py, OPYXMEAN, INDEFR)
call apsetr (py, OPYYMEAN, INDEFR)
call apsetr (py, PYCX, INDEFR)
call apsetr (py, PYCY, INDEFR)
call apsetr (py, OPYCX, INDEFR)
call apsetr (py, OPYCY, INDEFR)
call apsetr (py, PYMINRAD, INDEFR)
call apseti (py, PYNVER, 0)
nvertices = EOF
} else if (nvertices <= 2) {
call apsetr (py, PYXMEAN, INDEFR)
call apsetr (py, PYYMEAN, INDEFR)
call apsetr (py, OPYXMEAN, INDEFR)
call apsetr (py, OPYYMEAN, INDEFR)
call apsetr (py, PYCX, INDEFR)
call apsetr (py, PYCY, INDEFR)
call apsetr (py, OPYCX, INDEFR)
call apsetr (py, OPYCY, INDEFR)
call apsetr (py, PYMINRAD, INDEFR)
call apseti (py, PYNVER, 0)
nvertices = 0
} else {
# Add the last vertex and close the polygon.
x[nvertices+1] = x[1]
y[nvertices+1] = y[1]
if (id != NULL) {
call gadraw (id, x[1], y[1])
if (idflush == YES)
call gframe (id)
else
call gflush (id)
}
# Compute and save the mean polygon coords.
xc = asumr (x, nvertices) / nvertices
yc = asumr (y, nvertices) / nvertices
call apsetr (py, PYXMEAN, xc)
call apsetr (py, PYYMEAN, yc)
call apsetr (py, PYCX, xc)
call apsetr (py, PYCY, yc)
if (id != NULL)
call gscur (id, apstatr (py, PYCX), apstatr (py, PYCY))
# Compute the mean sky annulus.
r2max = 0.0
do i = 1, nvertices {
r2 = (x[i] - xc) ** 2 + (y[i] - yc) ** 2
if (r2 > r2max)
r2max = r2
}
# Compute output coordinate centers.
switch (apstati(py,WCSOUT)) {
case WCS_WORLD, WCS_PHYSICAL:
call ap_ltoo (py, xc, yc, xc, yc, 1)
case WCS_TV:
call ap_ltov (im, xc, yc, xc, yc, 1)
default:
;
}
call apsetr (py, OPYXMEAN, xc)
call apsetr (py, OPYYMEAN, yc)
call apsetr (py, OPYCX, xc)
call apsetr (py, OPYCY, yc)
call apseti (py, PYNVER, nvertices)
call apsetr (py, PYMINRAD, (sqrt (r2max) + 1.1))
}
if (id != NULL)
call gdeactivate (id, 0)
return (nvertices)
end
|