Changeset 3072
- Timestamp:
- Jun 5, 2006, 12:03:41 PM (18 years ago)
- Location:
- inundation/pyvolution
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/pyvolution/general_mesh.py
r2866 r3072 1 2 from Numeric import concatenate, reshape, take 3 from Numeric import array, zeros, Int, Float, sqrt, sum 1 4 2 5 from coordinate_transforms.geo_reference import Geo_reference … … 65 68 66 69 if verbose: print 'General_mesh: Building basic mesh structure' 67 68 from Numeric import array, zeros, Int, Float, sqrt, sum69 70 70 71 self.triangles = array(triangles,Int) … … 192 193 193 194 194 def get_vertex_coordinates(self, obj =False):195 def get_vertex_coordinates(self, obj=False, absolute=False): 195 196 """Return all vertex coordinates. 196 197 Return all vertex coordinates for all triangles as an Nx6 array … … 202 203 FIXME - Maybe use something referring to unique vertices? 203 204 204 205 """ 205 Boolean keyword argument absolute determines whether coordinates 206 are to be made absolute by taking georeference into account 207 """ 208 209 V = self.vertex_coordinates 210 if absolute is True: 211 V0 = self.geo_reference.get_absolute(V[:,0:2]) 212 V1 = self.geo_reference.get_absolute(V[:,2:4]) 213 V2 = self.geo_reference.get_absolute(V[:,4:6]) 214 215 V = concatenate( (V0, V1, V2), axis=1 ) 216 206 217 207 218 if obj is True: 208 from Numeric import concatenate, reshape209 V = self.vertex_coordinates210 219 #return concatenate( (V[:,0:2], V[:,2:4], V[:,4:6]), axis=0) 211 220 … … 213 222 return reshape(V, (3*N, 2)) 214 223 else: 215 return self.vertex_coordinates216 217 218 def get_vertex_coordinate(self, i, j ):224 return V 225 226 227 def get_vertex_coordinate(self, i, j, absolute=False): 219 228 """Return coordinates for vertex j of the i'th triangle. 220 229 Return value is the numeric array slice [x, y] 221 230 """ 222 return self.vertex_coordinates[i, 2*j:2*j+2] 231 232 V = self.get_vertex_coordinates(absolute=absolute) 233 return V[i, 2*j:2*j+2] 234 235 ##return self.vertex_coordinates[i, 2*j:2*j+2] 223 236 224 237 … … 231 244 #See quantity.get_vertex_values 232 245 #FIXME (Ole) - oh yes they should 233 234 from Numeric import zeros, Float235 246 236 247 N = self.number_of_elements … … 251 262 """ 252 263 253 from Numeric import take254 255 264 if (indices == None): 256 265 indices = range(len(self)) #len(self)=number of elements … … 259 268 260 269 #FIXME - merge these two (get_vertices and get_triangles) 261 def get_triangles(self, obj =False):270 def get_triangles(self, obj=False): 262 271 """Get connetivity 263 272 Return triangles (triplets of indices into point coordinates) … … 269 278 270 279 if obj is True: 271 from Numeric import array, reshape, Int272 280 m = len(self) #Number of triangles 273 281 M = 3*m #Total number of unique vertices … … 320 328 321 329 322 def get_extent(self ):330 def get_extent(self, absolute=False): 323 331 """Return min and max of all x and y coordinates 324 """ 325 326 327 C = self.get_vertex_coordinates() 332 333 Boolean keyword argument absolute determines whether coordinates 334 are to be made absolute by taking georeference into account 335 """ 336 337 338 339 C = self.get_vertex_coordinates(absolute=absolute) 328 340 X = C[:,0:6:2].copy() 329 341 Y = C[:,1:6:2].copy() -
inundation/pyvolution/mesh.py
r3062 r3072 426 426 427 427 428 def get_boundary_polygon(self, verbose =False):428 def get_boundary_polygon(self, verbose=False): 429 429 """Return bounding polygon for mesh (counter clockwise) 430 430 … … 432 432 If multiple vertex values are present, the algorithm will select the 433 433 path that contains the mesh. 434 435 All points are in absolute UTM coordinates 434 436 """ 435 437 … … 438 440 439 441 440 # FIXME (Ole): Make sure all points are absolute UTM441 442 442 # Get mesh extent 443 xmin, xmax, ymin, ymax = self.get_extent( ) # FIXME: Make Absolute443 xmin, xmax, ymin, ymax = self.get_extent(absolute=True) 444 444 pmin = ensure_numeric([xmin, ymin]) 445 445 pmax = ensure_numeric([xmax, ymax]) … … 456 456 if edge_id == 2: a = 0; b = 1 457 457 458 # FIXME: Make Absolute 459 A = self.get_vertex_coordinate(i, a) # Start460 B = self.get_vertex_coordinate(i, b) # End 458 A = self.get_vertex_coordinate(i, a, absolute=True) # Start 459 B = self.get_vertex_coordinate(i, b, absolute=True) # End 460 461 461 462 462 # Take the point closest to pmin as starting point … … 488 488 489 489 490 490 491 491 #Start with smallest point and follow boundary (counter clock wise) 492 492 polygon = [p0] # Storage for final boundary polygon 493 point_registry = {} # Keep track of storage to avoid multiple runs around boundary 494 # This will only be the case if there are more than one candidate 495 # FIXME (Ole): Perhaps we can do away with polygon and use 496 # only point_registry to save space. 493 point_registry = {} # Keep track of storage to avoid multiple runs around 494 # boundary. This will only be the case if there are 495 # more than one candidate. 496 # FIXME (Ole): Perhaps we can do away with polygon 497 # and use only point_registry to save space. 497 498 498 499 point_registry[tuple(p0)] = 0 … … 509 510 510 511 if verbose: 511 print 'Point %s has multiple candidates: %s' %(str(p0), candidate_list) 512 print 'Point %s has multiple candidates: %s'\ 513 %(str(p0), candidate_list) 512 514 513 515 … … 516 518 v_prev = p0 - polygon[-2] # Vector that leads to p0 517 519 else: 518 # FIXME (Ole): What do we do if the first point has multiple candidates? 520 # FIXME (Ole): What do we do if the first point has multiple 521 # candidates? 519 522 # Being the lower left corner, perhaps we can use the 520 523 # vector [1, 0], but I really don't know if this is completely … … 530 533 vc = pc-p0 # Candidate vector 531 534 532 # Angle between each candidate and the previous vector in [-pi, pi] 535 # Angle between each candidate and the previous vector 536 # in [-pi, pi] 533 537 ac = angle(vc, v_prev) 534 538 if ac > pi: ac = pi-ac -
inundation/pyvolution/test_mesh.py
r3057 r3072 944 944 'FAILED!') 945 945 946 def FIXME_test_mesh_get_boundary_polygon_with_georeferencing(self):946 def test_mesh_get_boundary_polygon_with_georeferencing(self): 947 947 948 948 # test … … 957 957 958 958 relative_points = geo.change_points_geo_ref(absolute_points) 959 #relative_points = absolute_points #uncomment to make test pass! 959 960 #print 'Relative', relative_points 961 #print 'Absolute', absolute_points 962 960 963 mesh = Mesh(relative_points, vertices, geo_reference=geo) 961 964 boundary_polygon = mesh.get_boundary_polygon() 965 962 966 assert allclose(absolute_points, boundary_polygon) 967 963 968 #------------------------------------------------------------- 964 969 if __name__ == "__main__": 965 #suite = unittest.makeSuite(Test_Mesh,'test_ boundary_polygon')970 #suite = unittest.makeSuite(Test_Mesh,'test_mesh_get_boundary_polygon_with_georeferencing') 966 971 suite = unittest.makeSuite(Test_Mesh,'test') 967 972 runner = unittest.TextTestRunner()
Note: See TracChangeset
for help on using the changeset viewer.