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 numpy as np import numpy.random as nprand import matplotlib.pylab as plt from rads.enclosure import UBoxSet,Tree from rads.misc import gfx box = np.array([[0.0,0],[8,8]]) tree = Tree(box) for i in range(6): tree.subdivide() nprand.seed( 123 ) def test_one_box(box,tree,graphics=False,callback=None):#,f): print 'box',box[0],box[1],':', s = tree.search(box) print "" print "box search:", s print "len(s):", len( s ) boxes = tree.boxes() if graphics: plt.close() gfx.show_uboxes(boxes) gfx.show_uboxes(boxes, S=s, col='r') if len(s) < ((tree.dim**tree.depth)/2): # dim^depth/2 t = tree.insert(box) if graphics:
#!/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')