本文整理匯總了Python中region.Region.unionPoint方法的典型用法代碼示例。如果您正苦於以下問題:Python Region.unionPoint方法的具體用法?Python Region.unionPoint怎麽用?Python Region.unionPoint使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類region.Region
的用法示例。
在下文中一共展示了Region.unionPoint方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: from region import Region [as 別名]
# 或者: from region.Region import unionPoint [as 別名]
class KDTreeApp:
def __init__(self):
"""App for creating KD tree dynamically and executing range queries."""
self.tree = KDTree()
# for range query
self.selectedRegion = None
self.master = tkinter.Tk()
self.master.title('KD Tree Range Query Application')
self.w = tkinter.Frame(self.master, width=410, height=410)
self.canvas = tkinter.Canvas(self.w, width=400, height=400)
self.paint()
self.canvas.bind("<Button-1>", self.click)
self.canvas.bind("<Button-3>", self.range) # when right mouse clicked
self.canvas.bind("<ButtonRelease-3>", self.clear)
self.canvas.bind("<B3-Motion>", self.range) # only when right mouse dragged
# Different bindings on Macintosh platform
self.canvas.bind("<Button-2>", self.range) # when right mouse clicked
self.canvas.bind("<ButtonRelease-2>", self.clear)
self.canvas.bind("<B2-Motion>", self.range) # only when right mouse dragged
self.w.pack()
def toCartesian(self, y):
"""Convert tkinter point into Cartesian."""
return self.w.winfo_height() - y
def toTk(self,y):
"""Convert Cartesian into tkinter point."""
if y == maxValue: return 0
tk_y = self.w.winfo_height()
if y != minValue:
tk_y -= y
return tk_y
def clear(self, event):
"""End of range search."""
self.selectedRegion = None
self.paint()
def range(self, event):
"""Initiate a range search using a selected rectangular region."""
p = (event.x, self.toCartesian(event.y))
if self.selectedRegion is None:
self.selectedStart = Region(p[X],p[Y], p[X],p[Y])
self.selectedRegion = self.selectedStart.unionPoint(p)
self.paint()
# return (node,status) where status is True if draining entire tree rooted at node. Draw these
# as shaded red rectangle to identify whole sub-tree is selected.
for pair in self.tree.range(self.selectedRegion):
p = pair[0].point
if pair[1]:
self.canvas.create_rectangle(pair[0].region.x_min, self.toTk(pair[0].region.y_min),
pair[0].region.x_max, self.toTk(pair[0].region.y_max),
fill='Red', stipple='gray12')
else:
self.canvas.create_rectangle(p[X] - RectangleSize, self.toTk(p[Y]) - RectangleSize,
p[X] + RectangleSize, self.toTk(p[Y]) + RectangleSize, fill='Red')
def click(self, event):
"""Add point to KDtree."""
p = (event.x, self.toCartesian(event.y))
self.tree.add(p)
self.paint()
def drawPartition (self, r, p, orient):
"""Draw partitioning line and points itself as a small square."""
if orient == VERTICAL:
self.canvas.create_line(p[X], self.toTk(r.y_min), p[X], self.toTk(r.y_max))
else:
xlow = r.x_min
if r.x_min <= minValue: xlow = 0
xhigh = r.x_max
if r.x_max >= maxValue: xhigh = self.w.winfo_width()
self.canvas.create_line(xlow, self.toTk(p[Y]), xhigh, self.toTk(p[Y]))
self.canvas.create_rectangle(p[X] - RectangleSize, self.toTk(p[Y]) - RectangleSize,
p[X] + RectangleSize, self.toTk(p[Y]) + RectangleSize, fill='Black')
def visit (self, n):
""" Visit node to paint properly."""
if n == None: return
self.drawPartition(n.region, n.point, n.orient)
self.visit (n.below)
#.........這裏部分代碼省略.........
示例2: __init__
# 需要導入模塊: from region import Region [as 別名]
# 或者: from region.Region import unionPoint [as 別名]
class KDTreeApp:
def __init__(self):
"""App for creating KD tree dynamically and executing range queries."""
self.tree = KDTree()
# for range query
self.selectedRegion = None
self.queryRect = None
master = tkinter.Tk()
master.maxsize(width=Size, height=Size+26)
master.minsize(width=Size, height=Size+26)
master.title('KD Tree Drawing and Query Application')
self.w = tkinter.Frame(master, width=Size, height=Size+26)
self.canvas = tkinter.Canvas(self.w, width=Size, height=Size)
self.paint()
b = tkinter.Button(master, text="Reset", command=self.reset)
b.pack()
self.canvas.bind("<Button-1>", self.click)
self.canvas.bind("<Button-3>", self.range) # when right mouse clicked
self.canvas.bind("<ButtonRelease-3>", self.clear)
self.canvas.bind("<B3-Motion>", self.range) # only when right mouse dragged
# Different bindings on Macintosh platform
self.canvas.bind("<Button-2>", self.range) # when right mouse clicked
self.canvas.bind("<ButtonRelease-2>", self.clear)
self.canvas.bind("<B2-Motion>", self.range) # only when right mouse dragged
self.canvas.pack()
self.w.pack()
def reset(self):
"""Reset to initial state."""
self.tree = KDTree()
self.paint()
def toCartesian(self, y):
"""Convert tkinter point into Cartesian."""
return Size - y
def toTk(self,y):
"""Convert Cartesian into tkinter point."""
if y == maxValue: return 0
tk_y = Size
if y != minValue:
tk_y -= y
return tk_y
def clear(self, event):
"""End of range search."""
self.selectedRegion = None
self.paint()
def range(self, event):
"""Initiate a range search using a selected rectangular region."""
p = (event.x, self.toCartesian(event.y))
if self.selectedRegion is None:
self.selectedStart = Region(p[X],p[Y], p[X],p[Y])
self.selectedRegion = self.selectedStart.unionPoint(p)
self.paint()
# return (node,sub-tree) where sub-tree is True if draining entire tree
# rooted at node. Draw these as shaded red rectangle to identify whole
# sub-tree is selected.
for pair in self.tree.range(self.selectedRegion):
p = pair[0].point
if pair[1]:
self.canvas.create_rectangle(pair[0].region.x_min, self.toTk(pair[0].region.y_min),
pair[0].region.x_max, self.toTk(pair[0].region.y_max),
fill='Red', stipple='gray12')
else:
self.canvas.create_rectangle(p[X] - BoxSize, self.toTk(p[Y]) - BoxSize,
p[X] + BoxSize, self.toTk(p[Y]) + BoxSize, fill='Red')
self.queryRect = self.canvas.create_rectangle(self.selectedRegion.x_min, self.toTk(self.selectedRegion.y_min),
self.selectedRegion.x_max, self.toTk(self.selectedRegion.y_max),
outline='Red', dash=(2, 4))
def click(self, event):
"""Add point to KDtree."""
p = (event.x, self.toCartesian(event.y))
self.tree.add(p)
self.paint()
def drawPartition (self, r, p, orient):
"""Draw partitioning line and points itself as a small square."""
if orient == VERTICAL:
self.canvas.create_line(p[X], self.toTk(r.y_min), p[X], self.toTk(r.y_max))
else:
xlow = r.x_min
if r.x_min <= minValue: xlow = 0
xhigh = r.x_max
#.........這裏部分代碼省略.........
示例3: __init__
# 需要導入模塊: from region import Region [as 別名]
# 或者: from region.Region import unionPoint [as 別名]
class QuadTreeApp:
def __init__(self):
"""App for creating Quad tree dynamically and executing range queries."""
self.tree = QuadTree(Region(0,0,W,H))
self.match = None
# for range query
self.selectedRegion = None
self.queryRect = None
self.master = tkinter.Tk()
self.master.title('Quad Tree Range Application')
self.w = tkinter.Frame(self.master, width=W, height=H)
self.canvas = tkinter.Canvas(self.w, width=W, height=H)
self.paint()
self.canvas.bind("<Button-1>", self.click)
self.canvas.bind("<Button-3>", self.range) # when right mouse clicked
self.canvas.bind("<ButtonRelease-3>", self.clear)
self.canvas.bind("<B3-Motion>", self.range) # only when right mouse dragged
# Different bindings on Macintosh platform
self.canvas.bind("<Button-2>", self.range) # when right mouse clicked
self.canvas.bind("<ButtonRelease-2>", self.clear)
self.canvas.bind("<B2-Motion>", self.range) # only when right mouse dragged
self.w.pack()
def toCartesian(self, y):
"""Convert tkinter point into Cartesian"""
return self.w.winfo_height() - y
def toTk(self,y):
"""Convert Cartesian into tkinter point."""
if y == maxValue: return 0
tk_y = self.w.winfo_height()
if y != minValue:
tk_y -= y
return tk_y
def clear(self, event):
"""End of range search."""
self.selectedRegion = None
self.paint()
def range(self, event):
"""Initiate a range search using a selected rectangular region."""
p = (event.x, self.toCartesian(event.y))
if self.selectedRegion is None:
self.selectedStart = Region(p[X],p[Y], p[X],p[Y])
self.selectedRegion = self.selectedStart.unionPoint(p)
self.paint()
# return (node,status) where status is True if draining entire tree rooted at node. Draw these
# all in Yellow using another inorder traversal
for pair in self.tree.range(self.selectedRegion):
if pair[1]:
self.canvas.create_rectangle(pair[0].region.x_min, self.toTk(pair[0].region.y_min),
pair[0].region.x_max, self.toTk(pair[0].region.y_max),
fill='Red', stipple='gray12')
else:
p = pair[0][0] # ignore data and grab point
self.canvas.create_rectangle(p[X] - RectangleSize, self.toTk(p[Y]) - RectangleSize,
p[X] + RectangleSize, self.toTk(p[Y]) + RectangleSize, fill='Red')
self.queryRect = self.canvas.create_rectangle(self.selectedRegion.x_min, self.toTk(self.selectedRegion.y_min),
self.selectedRegion.x_max, self.toTk(self.selectedRegion.y_max),
outline='Red', dash=(2, 4))
def click(self, event):
"""Add point to QuadTree."""
p = (event.x, self.toCartesian(event.y))
self.tree.add(p)
self.paint()
def visit (self, node):
""" Visit node to paint properly."""
if node == None: return
if node.points is None:
r = node.region
self.canvas.create_rectangle(r.x_min, self.toTk(r.y_min), r.x_max, self.toTk(r.y_max))
self.canvas.create_line(r.x_min, self.toTk(node.origin[Y]), r.x_max, self.toTk(node.origin[Y]),
fill='black', dash=(2, 4))
self.canvas.create_line(node.origin[X], self.toTk(r.y_min), node.origin[X], self.toTk(r.y_max),
fill='black', dash=(2, 4))
for n in node.children:
self.visit(n)
else:
for p in node.points:
self.canvas.create_rectangle(p[X] - RectangleSize, self.toTk(p[Y]) - RectangleSize,
#.........這裏部分代碼省略.........