aboutsummaryrefslogtreecommitdiff
path: root/noao/astutil/pdm/pdmundelete.x
blob: 2f5f0e311529593238eb158c3aaed66b5aaf7f0e (plain) (blame)
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
include <mach.h>
include <ctype.h>
include <error.h>
include <gset.h>
include "pdm.h"

define	MSIZE		2.0		# Mark size

# PDM_UNDELETE -- Undelete the nearest deleted point from the plot
# and set it's inuse array entry to one (in-use).

int procedure pdm_undelete (pdmp, cx, cy, ptype)

pointer	pdmp			# pointer to PDM data structure
double	cx, cy			# device coordinates of point to undelete
int	ptype			# plot type flag

pointer	gp
real	x, y
int	npt, i, j, index
real	x0, y0, r2, r2min

begin
	gp = PDM_GP(pdmp)
	npt = PDM_NPT(pdmp)

	if (ptype == DATAPLOT) {
	    # Transform world cursor coordinates to NDC.
	    call gctran (gp, real(cx), real(cy), x, y, 1, 0)

	    # Search for nearest point not in-use.
	    j = 0
	    r2min = MAX_REAL
	    do i = 1, npt {
	        if (PDM_INUSE(pdmp,i) == 1)
		    next

	        call gctran (gp, real(PDM_X(pdmp,i)), real(PDM_DY(pdmp,i)),
			     x0, y0, 1, 0)
		
	        r2 = (x0 - x) ** 2 + (y0 - y) ** 2
	        if (r2 < r2min) {
		    r2min = r2
		    j = i
	        }
	    }

	    # Unmark the deleted point and reset the weight.
	    if (j != 0) {
	        call gscur (gp, real(PDM_X(pdmp,j)), real(PDM_DY(pdmp,j)))
	        call gseti (gp, G_PMLTYPE, GL_CLEAR)
	        call gmark (gp, real(PDM_X(pdmp,j)), real(PDM_DY(pdmp,j)),
			    GM_CROSS, MSIZE, MSIZE)
	        call gseti (gp, G_PMLTYPE, GL_SOLID)
		if (PDM_NPT(pdmp) <= PDM_PLUSPOINT(pdmp))
	            call gpmark (gp, real(PDM_X(pdmp,j)), real(PDM_DY(pdmp,j)),
		        1, GM_PLUS, MSIZE, MSIZE)
		else
	            call gpmark (gp, real(PDM_X(pdmp,j)), real(PDM_DY(pdmp,j)),
		        1, GM_POINT, 1.0, 1.0)
	        PDM_INUSE(pdmp,j) = 1
		call gflush (gp)
	    }

	    return (j)
	} else if (ptype == PHASEPLOT) {
	    # Transform world cursor coordinates to NDC.
	    call gctran (gp, real(cx), real(cy), x, y, 1, 0)

	    # Search for nearest point not in-use.
	    j = 0
	    r2min = MAX_REAL
	    do i = 1, npt {
		index = PDM_SORT(pdmp,i)
	        if (PDM_INUSE(pdmp,index) == 1)
		    next

	        call gctran (gp, real(PDM_XPH(pdmp,i)), real(PDM_YPH(pdmp,i)),
			     x0, y0, 1, 0)
		
	        r2 = (x0 - x) ** 2 + (y0 - y) ** 2
	        if (r2 < r2min) {
		    r2min = r2
		    j = i
	        }
	    }

	    # Unmark the deleted point and reset the weight.
	    if (j != 0) {
	        call gscur (gp, real(PDM_XPH(pdmp,j))+1.0,
		    real(PDM_YPH(pdmp,j)))
	        call gseti (gp, G_PMLTYPE, GL_CLEAR)
	        call gmark (gp, real(PDM_XPH(pdmp,j))+1.0,
		    real(PDM_YPH(pdmp,j)), GM_CROSS, MSIZE, MSIZE)
	        call gseti (gp, G_PMLTYPE, GL_SOLID)
		if (PDM_NPT(pdmp) <= PDM_PLUSPOINT(pdmp))
	            call gpmark (gp, real(PDM_XPH(pdmp,j))+1.0,
		    real(PDM_YPH(pdmp,j)), 1, GM_PLUS, MSIZE, MSIZE)
		else
	            call gpmark (gp, real(PDM_XPH(pdmp,j))+1.0,
		    real(PDM_YPH(pdmp,j)), 1, GM_POINT, 1.0, 1.0)

	        call gscur (gp, real(PDM_XPH(pdmp,j)), real(PDM_YPH(pdmp,j)))
	        call gseti (gp, G_PMLTYPE, GL_CLEAR)
	        call gmark (gp, real(PDM_XPH(pdmp,j)), real(PDM_YPH(pdmp,j)),
			    GM_CROSS, MSIZE, MSIZE)
	        call gseti (gp, G_PMLTYPE, GL_SOLID)
		if (PDM_NPT(pdmp) <= PDM_PLUSPOINT(pdmp))
	            call gpmark (gp, real(PDM_XPH(pdmp,j)),
		    real(PDM_YPH(pdmp,j)), 1, GM_PLUS, MSIZE, MSIZE)
		else
	            call gpmark (gp, real(PDM_XPH(pdmp,j)),
		    real(PDM_YPH(pdmp,j)), 1, GM_POINT, 1.0, 1.0)
		
		# Calculate which point this corresponds to.
		index = PDM_SORT(pdmp,j)
	        PDM_INUSE(pdmp,index) = 1
		call gflush (gp)
	    }

	    return (index)
	} else
	    return (0)
end