Changeset 6147
 Timestamp:
 Jan 13, 2009, 12:04:14 PM (14 years ago)
 Location:
 anuga_core/source/anuga/alpha_shape
 Files:

 2 edited
Legend:
 Unmodified
 Added
 Removed

anuga_core/source/anuga/alpha_shape/alpha_shape.py
r4955 r6147 20 20 21 21 import exceptions 22 from Numeric import array, Float, divide_safe, sqrt, product23 22 import random 24 23 25 24 from load_mesh.loadASCII import export_boundary_file 26 25 from anuga.geospatial_data.geospatial_data import Geospatial_data 26 27 import Numeric as num 28 27 29 28 30 class AlphaError(exceptions.Exception):pass … … 87 89 88 90 #Convert input to Numeric arrays 89 self.points = array(points).astype(Float)91 self.points = num.array(points).astype(num.Float) 90 92 91 93 … … 240 242 ind3 = [self.deltri[j][2] for j in range(len(self.deltri))] 241 243 242 x1 = array([ x[j] for j in ind1 ])243 y1 = array([ y[j] for j in ind1 ])244 x2 = array([ x[j] for j in ind2 ])245 y2 = array([ y[j] for j in ind2 ])246 x3 = array([ x[j] for j in ind3 ])247 y3 = array([ y[j] for j in ind3 ])244 x1 = num.array([ x[j] for j in ind1 ]) 245 y1 = num.array([ y[j] for j in ind1 ]) 246 x2 = num.array([ x[j] for j in ind2 ]) 247 y2 = num.array([ y[j] for j in ind2 ]) 248 x3 = num.array([ x[j] for j in ind3 ]) 249 y3 = num.array([ y[j] for j in ind3 ]) 248 250 249 251 x21 = x2x1 … … 287 289 (denom[k]< EPSILON and denom[k] > EPSILON)] 288 290 try: 289 dx = divide_safe(y31*dist21  y21*dist31,denom)290 dy = divide_safe(x21*dist31  x31*dist21,denom)291 dx = num.divide_safe(y31*dist21  y21*dist31,denom) 292 dy = num.divide_safe(x21*dist31  x31*dist21,denom) 291 293 except ZeroDivisionError: 292 294 raise AlphaError 293 295 294 self.triradius = 0.5* sqrt(dx*dx + dy*dy)296 self.triradius = 0.5*num.sqrt(dx*dx + dy*dy) 295 297 #print "triangle radii", self.triradius 296 298 … … 313 315 tri = self.deltri[t] 314 316 trinbr = self.deltrinbr[t] 315 dx = array([self.points[tri[(i+1)%3],0] 316 self.points[tri[(i+2)%3],0] for i in [0,1,2]])317 dy = array([self.points[tri[(i+1)%3],1] 318 self.points[tri[(i+2)%3],1] for i in [0,1,2]])319 elen = sqrt(dx*dx+dy*dy)317 dx = num.array([self.points[tri[(i+1)%3],0]  318 self.points[tri[(i+2)%3],0] for i in [0,1,2]]) 319 dy = num.array([self.points[tri[(i+1)%3],1]  320 self.points[tri[(i+2)%3],1] for i in [0,1,2]]) 321 elen = num.sqrt(dx*dx+dy*dy) 320 322 # really only need sign  not angle value: 321 anglesign = array([(dx[(i+1)%3]*dx[(i+2)%3]322 dy[(i+1)%3]*dy[(i+2)%3]) for i in [0,1,2]])323 anglesign = num.array([(dx[(i+1)%3]*dx[(i+2)%3] 324 dy[(i+1)%3]*dy[(i+2)%3]) for i in [0,1,2]]) 323 325 324 326 #print "dx ",dx,"\n" … … 594 596 tri = self.deltri[tind[0]] 595 597 596 dx = array([self.points[tri[(i+1)%3],0]  \597 self.points[tri[(i+2)%3],0] for i in [0,1,2]])598 dy = array([self.points[tri[(i+1)%3],1]  \599 self.points[tri[(i+2)%3],1] for i in [0,1,2]])600 anglesign = array([(dx[(i+1)%3]*dx[(i+2)%3]\601 dy[(i+1)%3]*dy[(i+2)%3]) for i in [0,1,2]])598 dx = num.array([self.points[tri[(i+1)%3],0]  \ 599 self.points[tri[(i+2)%3],0] for i in [0,1,2]]) 600 dy = num.array([self.points[tri[(i+1)%3],1]  \ 601 self.points[tri[(i+2)%3],1] for i in [0,1,2]]) 602 anglesign = num.array([(dx[(i+1)%3]*dx[(i+2)%3]\ 603 dy[(i+1)%3]*dy[(i+2)%3]) for i in [0,1,2]]) 602 604 # record any triangle that has an acute angle spanned by 603 605 #two edges along the boundary.. 
anuga_core/source/anuga/alpha_shape/test_alpha_shape.py
r4663 r6147 4 4 import sys 5 5 import unittest 6 from Numeric import allclose 6 7 import Numeric as num 7 8 8 9 try: … … 32 33 result = alpha.get_delaunay() 33 34 answer = [(0, 1, 5), (5, 1, 4), (4, 2, 3), (2, 4, 1)] 34 assert allclose(answer, result)35 assert num.allclose(answer, result) 35 36 36 37 def test_3_points_on_line(self): … … 63 64 #print "result",result 64 65 answer = [(5, 0), (0, 1), (4, 5), (2, 3), (3, 4), (1, 2)] 65 assert allclose(answer, result)66 assert num.allclose(answer, result) 66 67 67 68 … … 80 81 #print "result",result 81 82 answer = [(0, 3), (3, 6), (0, 1), (1, 2), (2, 3), (3, 4), (4, 5), (5, 6)] 82 assert allclose(answer, result)83 assert num.allclose(answer, result) 83 84 84 85 … … 97 98 #print "result",result 98 99 answer = [(5, 0), (0, 1), (4, 5), (2, 3), (3, 4), (1, 2)] 99 assert allclose(answer, result)100 assert num.allclose(answer, result) 100 101 101 102 … … 114 115 #print "result",result 115 116 answer = [(0, 3), (3, 6), (0, 1), (1, 2), (2, 3), (3, 4), (4, 5), (5, 6)] 116 assert allclose(answer, result)117 assert num.allclose(answer, result) 117 118 118 119 … … 132 133 #print "result",result 133 134 answer = [(0, 1), (1, 2), (2, 3), (3, 4), (4, 5), (5, 6), (6, 0)] 134 assert allclose(answer, result)135 assert num.allclose(answer, result) 135 136 136 137 … … 148 149 result = alpha.get_boundary() 149 150 answer = [(1, 0), (0, 5), (3, 2), (4, 3), (2, 6), (6, 1), (5, 4)] 150 assert allclose(answer, result)151 assert num.allclose(answer, result) 151 152 152 153 … … 222 223 #print "result",result 223 224 answer = [(1, 0), (4, 3), (0, 4), (3, 1)] 224 assert allclose(answer, result)225 assert num.allclose(answer, result) 225 226 226 227 def test_sharp_indents(self): … … 239 240 #print "result",result 240 241 answer = [(3, 4), (2, 3), (0, 1), (1, 2), (4, 0)] 241 assert allclose(answer, result)242 assert num.allclose(answer, result) 242 243 243 244 … … 392 393 (61, 62), (62, 63), (59, 60), (58, 59), (60, 61), \ 393 394 (46, 45)] 394 assert allclose(answer, result)395 assert num.allclose(answer, result) 395 396 # 396 397 if __name__ == "__main__":
Note: See TracChangeset
for help on using the changeset viewer.