1 """Voronoi/Delaunay Subdivision code
2
3 transcribed from Graphics Gems IV"""
4
5
6 import quadedge
7 import predicates
8
9 EPSILON=0.01
10
26
27
29 e=self.dumpEdges()
30
31 print "subdivision edges"
32 print "="*40
33 for edge in e:
34 print edge
35 print "="*40
36
37 for edge in e:
38 print edge
39 print "oNext",edge.oNext()
40 print "oPrev",edge.oPrev()
41 print "dNext",edge.dNext()
42 print "dPrev",edge.dPrev()
43 print "lNext",edge.lNext()
44 print "lPrev",edge.lPrev()
45 print "rNext",edge.rNext()
46 print "rPrev",edge.rPrev()
47 print "-"*20
48
49
50
52 e = self.locate(x)
53
54 if (x.samePoint(e.org(), EPSILON) or
55 x.samePoint(e.dest(), EPSILON)):
56
57 return
58 elif predicates.onEdge(x,e):
59 e = e.oNext()
60 quadedge.deleteEdge(e.oNext())
61
62
63 base = quadedge.makeEdge()
64
65 base.endPoints(e.org(), x)
66 quadedge.splice(base, e)
67 self.startingEdge = base
68
69 while 1:
70 base = connect(e, base.sym)
71 e = base.oPrev()
72
73 if e.lNext() is self.startingEdge:
74 break
75
76 while 1:
77 t = e.oPrev()
78 if (predicates.rightOf(t.dest(), e) and
79 predicates.inCircle(e.org(), t.dest(), e.dest(), x)):
80 swap(e)
81 e = e.oPrev()
82 elif e.oNext() is self.startingEdge:
83 return
84 else:
85 e = e.oNext().lPrev()
86
88 print
89 for d in self.dumpEdges():
90 print d
91
93 drawnEdges=[]
94 openEdges=[self.startingEdge]
95 self.startingEdge.tag=1
96
97 while openEdges:
98 e=openEdges.pop()
99 drawnEdges.append(e)
100 neighbors=[e.sym,
101 e.oNext(),
102 e.oPrev(),
103 e.dNext(),
104 e.dPrev()]
105 for n in neighbors:
106 if not n.tag:
107 n.tag=1
108 openEdges.append(n)
109
110 for d in drawnEdges:
111 d.tag=0
112 return drawnEdges
113
115 """returns an edge e, st either x is on e or e is an edge of a
116 triangle containing x. The search starts from the startingEdge
117 and proceeds in the general direction of x. Based on the
118 pseudocode in Guibas and Stolfi (1985, p. 121)."""
119
120
121 e=self.startingEdge
122
123 while 1:
124 if (x.samePoint(e.org(), EPSILON) or
125 x.samePoint(e.dest(), EPSILON)):
126 return e
127 elif predicates.rightOf(x,e):
128 e = e.sym
129 elif not predicates.rightOf(x, e.oNext()):
130 e = e.oNext()
131 elif not predicates.rightOf(x, e.dPrev()):
132 e = e.dPrev()
133 else:
134 return e
135
136
137
138
145
146
155