class BoxTree( Tree ): """ Inherits from Tree. Local wrapper for functionality. Making it a separate object in case it has to do new and exciting things (like stretch boxes in odd ways). """ def __init__( self, region, depth=6 ): """ Initialize BoxTree with (compact) 'region'. Specify depth if desired. Number of boxes will equal (dim^depth)/2. """ self.tree = Tree( region, full=True ) for i in range( depth ): self.tree.subdivide() def insert( self, box ): return self.tree.insert( box ) def search( self, box ): return self.tree.search( box ) def boxes( self ): return self.tree.boxes() def remove( self, boxes ): self.tree.remove( boxes )
class BoxTree(Tree): """ Inherits from Tree. Mostly local wrapper for functionality. """ def __init__(self, region, depth=6): """ Initialize BoxTree with (compact) 'region'. Specify depth if desired. Number of boxes will equal (dim^depth)/2. """ self.tree = Tree(region) for i in range(depth): self.tree.subdivide() def insert(self, box): return self.tree.insert(box) def search(self, box): return self.tree.search(box) def boxes(self): return self.tree.boxes()
#!/usr/bin/python import sys sys.path.append("cython/build/") #import cyboxset from rads.enclosure import UBoxSet #import cytree from rads.enclosure import Tree from rads.misc import gfx import numpy as np box = np.array([[0.0,0],[8,8]]) t = Tree(box) t.subdivide() t.subdivide() t.subdivide() print t.insert(box/8 + 0.5) print t.insert(np.array([[4,4],[1,1]])) print t.insert(np.array([3,3])) print t.search(np.array([3,3])) ubs = t.boxes() print ubs gfx.show_uboxes(ubs, col='c', ecol='b')