Changeset 7703
- Timestamp:
- Apr 29, 2010, 6:23:15 PM (15 years ago)
- Location:
- anuga_core/source/anuga/utilities
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/utilities/quad.py
r7317 r7703 19 19 20 20 Public Methods: 21 prune()22 21 insert(point) 23 22 search(x, y) 24 collapse()25 23 split() 26 24 store() … … 80 78 """ 81 79 branch = [] 82 points = [] 83 if self.children: 84 for child in self: 85 if child.contains(x,y): 86 brothers = list(self.children) 87 brothers.remove(child) 88 branch.append(brothers) 89 points, branch = child.search_branch(x,y, branch, 90 get_vertices=get_vertices) 91 else: 92 # Leaf node: Get actual waypoints 93 points = self.retrieve(get_vertices=get_vertices) 94 self.branch = branch 80 points, branch = self.search_branch(x, y, branch, get_vertices=get_vertices) 81 self.branch = branch 95 82 return points 96 83 … … 102 89 if self.children: 103 90 for child in self: 104 if child.contains(x,y):91 if (child.western <= x < child.eastern) and (child.southern <= y < child.northern): 105 92 brothers = list(self.children) 106 93 brothers.remove(child) … … 129 116 130 117 131 def contains( *args):118 def contains(self, point_id): 132 119 """True only if P's coordinates lie within cell boundaries 133 120 This methods has two forms: … … 135 122 cell.contains(index) 136 123 #True if cell contains indexed point 137 cell.contains(x, y) 138 #True if cell contains point (x,y) 139 """ 140 self = args[0] 141 if len(args) == 2: 142 point_id = int(args[1]) 143 x, y = self.mesh.get_node(point_id, absolute=True) 144 elif len(args) == 3: 145 x = float(args[1]) 146 y = float(args[2]) 147 else: 148 msg = 'Number of arguments to method must be two or three' 149 raise msg 150 151 if y < self.southern: return False 152 if y >= self.northern: return False 153 if x < self.western: return False 154 if x >= self.eastern: return False 155 return True 124 """ 125 x, y = self.mesh.get_node(point_id, absolute=True) 126 127 return (self.western <= x < self.eastern) and (self.southern <= y < self.northern) 156 128 157 129 … … 319 291 for child in self: # split (possibly newly created) 320 292 child.split(threshold) # child cells recursively 321 322 323 324 def collapse(self,threshold=None): 325 """ 326 collapse child cells into immediate parent if total number of contained waypoints 327 in subtree below is less than or equal to threshold. 328 All waypoints are then moved into parent cell and 329 children are removed. If self is a leaf node initially, do nothing. 330 """ 331 332 if threshold is None: 333 threshold = self.max_points_per_cell 334 335 336 if self.children: # Parent cell 337 if self.count() <= threshold: # collapse 338 points = self.retrieve() # Get all points from child cells 339 self.clear() # Remove children, self is now a leaf node 340 self.insert(points) # Insert all points in local storage 341 else: 342 for child in self: # Check if any sub tree can be collapsed 343 child.collapse(threshold) 293 344 294 345 295 -
anuga_core/source/anuga/utilities/test_quad.py
r7276 r7703 98 98 assert self.cell.count() == 8 99 99 100 101 102 def test_collapse(self):103 self.cell.insert([0,1,2,3,4,5,6,7], split = False)104 105 #Split maximally106 self.cell.split(1)107 108 #Now there are children109 assert self.cell.children is not None110 assert self.cell.count() == 8111 112 #Collapse113 self.cell.collapse(8)114 115 #No children116 assert self.cell.children is None117 assert self.cell.count() == 8118 100 119 101 def test_build_quadtree(self):
Note: See TracChangeset
for help on using the changeset viewer.