Changeset 4665 for anuga_core/source/anuga/pmesh/mesh.py
- Timestamp:
- Aug 8, 2007, 9:39:22 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/pmesh/mesh.py
r4663 r4665 28 28 29 29 #import load_mesh 30 from anuga.coordinate_transforms.geo_reference import Geo_reference,DEFAULT_ZONE 30 from anuga.coordinate_transforms.geo_reference import Geo_reference, \ 31 DEFAULT_ZONE 31 32 from anuga.utilities.polygon import point_in_polygon 32 33 from anuga.load_mesh.loadASCII import NOMAXAREA, export_mesh_file, \ … … 40 41 import kinds 41 42 except ImportError: 42 # Hand-built mockup of the things we need from the kinds package, since it 43 # Hand-built mockup of the things we need from the kinds package, since it 43 44 # was recently removed from the standard Numeric distro. Some users may 44 45 # not have it by default. … … 89 90 Returns the distance from this point to another 90 91 """ 91 SumOfSquares = ((self.x - OtherPoint.x)**2) + ((self.y - OtherPoint.y)**2) 92 SumOfSquares = ((self.x - OtherPoint.x)**2) + \ 93 ((self.y - OtherPoint.y)**2) 92 94 return math.sqrt(SumOfSquares) 93 95 … … 154 156 155 157 VERTEXSQUARESIDELENGTH = 6 156 def draw(self, canvas, tags, colour = 'black',scale = 1, xoffset = 0, yoffset =0, ): 158 def draw(self, canvas, tags, colour = 'black',scale = 1, xoffset = 0, 159 yoffset =0, ): 157 160 x = scale*(self.x + xoffset) 158 161 y = -1*scale*(self.y + yoffset) # - since for a canvas - is up … … 189 192 HOLECORNERLENGTH = 6 190 193 191 def draw(self, canvas, tags, colour = 'purple',scale = 1, xoffset = 0, yoffset =0, ): 194 def draw(self, canvas, tags, colour = 'purple',scale = 1, xoffset = 0, 195 yoffset =0, ): 192 196 x = scale*(self.x + xoffset) 193 197 y = -1*scale*(self.y + yoffset) # - since for a canvas - is up … … 260 264 return len(self.attributes)> 1 261 265 262 def draw(self, canvas, tags, scale=1, xoffset = 0, yoffset =0, colour = "black"): 266 def draw(self, canvas, tags, scale=1, xoffset = 0, yoffset =0, 267 colour = "black"): 263 268 """ 264 269 Draw a black cross, returning the objectID … … 301 306 """ 302 307 303 def __init__(self, vertex1, vertex2, vertex3, attribute = None, neighbors = None ): 308 def __init__(self, vertex1, vertex2, vertex3, attribute = None, 309 neighbors = None ): 304 310 """ 305 311 Vertices, the initial arguments, are listed in counterclockwise order. … … 347 353 else: 348 354 if offset == 1: 349 self.vertices = [self.vertices[1],self.vertices[2],self.vertices[0]] 350 self.neighbors = [self.neighbors[1],self.neighbors[2],self.neighbors[0]] 355 self.vertices = [self.vertices[1],self.vertices[2], 356 self.vertices[0]] 357 self.neighbors = [self.neighbors[1],self.neighbors[2], 358 self.neighbors[0]] 351 359 if offset == 2: 352 self.vertices = [self.vertices[2],self.vertices[0],self.vertices[1]] 353 self.neighbors = [self.neighbors[2],self.neighbors[0],self.neighbors[1]] 360 self.vertices = [self.vertices[2],self.vertices[0], 361 self.vertices[1]] 362 self.neighbors = [self.neighbors[2],self.neighbors[0], 363 self.neighbors[1]] 354 364 355 365 def rotate_longest_side(self): … … 395 405 return a+b+c 396 406 397 def setNeighbors(self,neighbor1 = None, neighbor2 = None, neighbor3 =None):407 def setNeighbors(self,neighbor1=None, neighbor2=None, neighbor3=None): 398 408 """ 399 409 neighbor1 is the triangle opposite vertex1 and so on. … … 413 423 414 424 415 def draw(self, canvas, tags, scale=1, xoffset = 0, yoffset =0, colour = "green"): 425 def draw(self, canvas, tags, scale=1, xoffset=0, yoffset=0, 426 colour="green"): 416 427 """ 417 428 Draw a triangle, returning the objectID … … 448 459 449 460 450 def draw(self, canvas, tags,scale=1 , xoffset=0 , yoffset=0,colour='blue'):461 def draw(self, canvas, tags,scale=1, xoffset=0, yoffset=0,colour='blue'): 451 462 x=[] 452 463 y=[] … … 529 540 User attributes describe the mesh region/segments/vertices/attributes 530 541 531 mesh attributes describe the mesh that is produced eg triangles and vertices. 542 mesh attributes describe the mesh that is produced eg triangles and 543 vertices. 532 544 All point information is relative to the geo_reference passed in 533 545 … … 682 694 return self._addRegion(x, y) 683 695 696 def build_grid(self, vert_rows, vert_columns): 697 """ 698 Build a grid with vert_rows number of vertex rows and 699 vert_columns number if vertex columns 700 701 Grid spacing of 1, the origin is the lower left hand corner. 702 703 FIXME(DSG-DSG) no test. 704 """ 705 706 for i in range(vert_rows): 707 for j in range(vert_columns): 708 self.addUserVertex(j,i) 709 self.auto_segment() 710 self.generateMesh(mode = "Q", minAngle=20.0) 711 684 712 # Depreciated 685 713 def addRegionEN(self, x,y): … … 1141 1169 segconverter) 1142 1170 #print "processed gen",generatedMesh['generatedsegmentmarkerlist'] 1143 #print "generatedtriangleattributelist",generatedMesh['generatedtriangleattributelist']1144 1171 generatedMesh['generatedtriangleattributelist'] = \ 1145 1172 region_ints2strings(generatedMesh['generatedtriangleattributelist'], … … 1670 1697 for vertex in self.getUserVertices(): 1671 1698 points.append((vertex.x,vertex.y)) 1672 self.shape = anuga.alpha_shape.alpha_shape.Alpha_Shape(points, alpha = alpha) 1699 self.shape = anuga.alpha_shape.alpha_shape.Alpha_Shape(points, 1700 alpha=alpha) 1673 1701 1674 1702 … … 2683 2711 tag = parent_segment.tag 2684 2712 offspring = [line] 2685 offspring.extend(self.subtract_line(user_line,line)) 2713 offspring.extend(self.subtract_line(user_line, 2714 line)) 2686 2715 affine_lines.remove(user_line) 2687 2716 for newline in offspring: … … 2695 2724 point_keys[point]=vert 2696 2725 line_vertices.append(vert) 2697 segment = Segment(line_vertices[0],line_vertices[1],tag) 2726 segment = Segment(line_vertices[0], 2727 line_vertices[1],tag) 2698 2728 userSegments[newline]=segment 2699 2729 affine_lines.append(newline) … … 2714 2744 point_keys[point]=vert 2715 2745 line_vertices.append(vert) 2716 segment = Segment(line_vertices[0],line_vertices[1],tag) 2746 segment = Segment(line_vertices[0], 2747 line_vertices[1],tag) 2717 2748 userSegments[line]=segment 2718 2749 affine_lines.append(line) … … 2819 2850 return ((x1-x0)**2-(y1-y0)**2)**0.5 2820 2851 2821 def threshold(self,setName,min=None,max=None,attribute_name ='elevation'):2852 def threshold(self,setName,min=None,max=None,attribute_name='elevation'): 2822 2853 """ 2823 2854 threshold using d … … 3316 3347 """ 3317 3348 3318 new_triangle1 = Triangle(new_point,triangle.vertices[0],triangle.vertices[1],attribute = triangle.attribute, neighbors = None) 3319 new_triangle2 = Triangle(new_point,triangle.vertices[2],triangle.vertices[0],attribute = triangle.attribute, neighbors = None) 3349 new_triangle1 = Triangle(new_point,triangle.vertices[0], 3350 triangle.vertices[1], 3351 attribute = triangle.attribute, 3352 neighbors = None) 3353 new_triangle2 = Triangle(new_point,triangle.vertices[2], 3354 triangle.vertices[0], 3355 attribute = triangle.attribute, 3356 neighbors = None) 3320 3357 3321 3358 new_triangle1.setNeighbors(triangle.neighbors[2],None,new_triangle2) … … 3358 3395 if not self.neighbour is None: 3359 3396 self.neighbour.rotate_longest_side() 3360 self.next_case = self.get_next_case(mesh,self.neighbour,self.current_triangle) 3397 self.next_case = self.get_next_case(mesh,self.neighbour, 3398 self.current_triangle) 3361 3399 if self.case == 'vertex': 3362 3400 self.new_point=self.old_point … … 3393 3431 attributes.append(att) 3394 3432 new_coordinate = [((a[0]-b[0])/2+b[0]),((a[1]-b[1])/2+b[1])] 3395 newVertex = Vertex(new_coordinate[0],new_coordinate[1], attributes = attributes) 3433 newVertex = Vertex(new_coordinate[0],new_coordinate[1], 3434 attributes = attributes) 3396 3435 mesh.maxVertexIndex+=1 3397 3436 newVertex.index = mesh.maxVertexIndex
Note: See TracChangeset
for help on using the changeset viewer.