Exemplo n.º 1
0
    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()
Exemplo n.º 2
0
def generate(points):
    """Given a list of points construct balanced kd-tree."""
    if len(points) == 0:
        return None

    # VERTICAL=1 is the initial division
    tree = KDTree()
    tree.root = generateSubTree(1, 2, points, 0, len(points) - 1)
    propagate(tree.root, maxRegion)
    return tree
Exemplo n.º 3
0
 def reset(self):
     """Reset to initial state."""
     self.tree = KDTree()
     self.paint()