Changeset 7721 for anuga_core/source/anuga/geometry/quad.py
- Timestamp:
- May 12, 2010, 2:45:56 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/geometry/quad.py
r7720 r7721 2 2 3 3 This is a generic structure that can be used to store any geometry in a quadtree. 4 4 It is naive, and does not exploit any coherency - it merely tests a bounding 5 box against all other bounding boxes in its heirarchy. 6 7 It returns a list of bounding boxes which intersect with the test box, which 8 must then be iterated over to detect actual intersections. 5 9 6 10 """ … … 15 19 """class Cell 16 20 17 One cell in the plane delimited by southern, northern, 18 western, eastern boundaries. 21 One cell in the plane. 19 22 """ 20 23 21 24 def __init__(self, extents, parent, 22 25 name = 'cell'): 26 """ Construct a new cell. 27 extents is an AABB defining a region on the plane. 28 parent is the node above this one, or None if it is root. 29 """ 23 30 24 31 # Initialise base classes … … 62 69 63 70 def insert(self, new_leaf): 64 # process list items sequentially 71 """ Insert a leaf into the quadtree. 72 new_leaf is a tuple of (AABB extents, data), where data can 73 be any user data (geometry, triangle index, etc.). 74 """ 65 75 if type(new_leaf)==type(list()): 66 76 for leaf in new_leaf: … … 71 81 72 82 def _insert(self, new_leaf): 83 """ Internal recursive insert. 84 new_leaf is a tuple of (AABB extents, data), where data can 85 be any user data (geometry, triangle index, etc.). 86 """ 73 87 new_region, data = new_leaf 74 88 … … 93 107 #return 94 108 95 # option 2 - try splitting 2 ways 109 # option 2 - try splitting 2 ways - no diff noticed in practise 96 110 if subregion1.is_trivial_in(new_region): 97 111 self.children = [Cell(subregion1, self), Cell(subregion2, self)] … … 108 122 109 123 def retrieve(self): 110 """Get all leaves from this tree. """ 124 """Get all leaves from this tree. 125 return a traversal of the entire tree. 126 """ 111 127 112 128 leaves_found = list(self.leaves) … … 121 137 122 138 def count(self): 123 """Count all leaves from this tree. """ 139 """Count all leaves from this tree. 140 return num of leaves in the tree. 141 """ 124 142 125 143 leaves_found = len(self.leaves) … … 134 152 135 153 def show(self, depth=0): 136 """Traverse tree below self 154 """Traverse tree below self, dumping all information. 137 155 """ 138 156 if depth == 0: … … 159 177 160 178 def test_leaves(self, x): 179 """ Test all leaves to see if they intersect x. 180 x is a point to test 181 return a list of leaves that intersect x 182 """ 161 183 intersecting_regions = [] 162 184 … … 171 193 172 194 def get_siblings(self): 173 """ return parent and siblings of this node. 195 """ return siblings of this node. If there is no parent, it 196 returns an empty list. 174 197 """ 175 198 if not self.parent:
Note: See TracChangeset
for help on using the changeset viewer.