Changeset 2200 for inundation/pmesh/mesh.py
- Timestamp:
- Jan 11, 2006, 5:31:49 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/pmesh/mesh.py
r2144 r2200 28 28 import load_mesh 29 29 from coordinate_transforms.geo_reference import Geo_reference,DEFAULT_ZONE 30 from utilities.polygon import point_in_polygon 30 31 31 32 SET_COLOUR='red' … … 185 186 Defined by a point in the hole enclosed by segments. 186 187 """ 188 187 189 HOLECORNERLENGTH = 6 190 188 191 def draw(self, canvas, tags, colour = 'purple',scale = 1, xoffset = 0, yoffset =0, ): 189 192 x = scale*(self.x + xoffset) … … 396 399 Null represents no neighbor 397 400 """ 398 self.attribute = attribute 401 self.attribute = attribute #this is a string 399 402 400 403 def __repr__(self): … … 501 504 self.meshVertices=[] 502 505 503 #Peters stuff504 # FIXME (DSG) Sets of what?505 506 self.setID={} 506 507 #a dictionary of names. … … 667 668 self.regions.append(h) 668 669 return h 669 670 671 #FIXME(DSG-DSG) remove EN, have a relative flag. 670 672 def addRegionEN(self, x,y): 671 673 h=Region(x-self.geo_reference.xllcorner, … … 673 675 self.regions.append(h) 674 676 return h 675 677 def addRegionFromPolygon(self, polygon, tags=None, 678 maxArea=None, Geo_ref=None): 679 #take into account georef 680 #create points, segs and tags 681 region_dict = {} 682 region_dict['points'] = polygon 683 684 #Create segments 685 #E.g. [[0,1], [1,2], [2,3], [3,0]] 686 segments = [] 687 N = len(polygon) 688 for i in range(N): 689 lo = i 690 hi = (lo + 1) % N 691 segments.append( [lo, hi] ) 692 region_dict['segments'] = segments 693 694 695 #Create tags 696 #E.g. ['wall', 'wall', 'ocean', 'wall'] 697 698 segment_tags = ['']*N 699 if tags is not None: 700 for key in tags: 701 indices = tags[key] 702 for i in indices: 703 segment_tags[i] = key 704 region_dict['segment_tags'] = segment_tags 705 706 self.addVertsSegs(region_dict) #this is assuming absolute geos 707 708 #get inner point 709 inner_point = point_in_polygon(polygon) 710 inner = self.addRegionEN(inner_point[0], inner_point[1]) 711 712 if maxArea is not None: 713 inner.setMaxArea(maxArea) 714 676 715 def getUserVertices(self): 677 716 return self.userVertices … … 1312 1351 segs2delete = self.alphaUserSegments 1313 1352 #FIXME(DSG-DSG) this algorithm needs comments 1314 #FIXME(DSG-DSG) can it be sped up? It's slow1315 1353 new_segs = {} 1316 1354 #alpha_segs = [] … … 1603 1641 yoffset = HEIGHT - b 1604 1642 return [SCALE, xoffset, yoffset] 1605 1606 def plotMeshTriangle(self,tag = 0,WIDTH = 400,HEIGHT = 400): 1607 """ 1608 Plots all node connections. 1609 tag = 0 (no node numbers), tag = 1 (node numbers) 1610 """ 1611 1612 try: 1613 from Tkinter import Tk, Frame, Button, Canvas, BOTTOM, Label 1614 1615 [SCALE, xoffset, yoffset] = self.scaleoffset( WIDTH, HEIGHT) 1616 1617 root = Tk() 1618 frame = Frame(root) 1619 frame.pack() 1620 button = Button(frame, text="OK", fg="red", command=frame.quit) 1621 button.pack(side=BOTTOM) 1622 canvas = Canvas(frame,bg="white", width=WIDTH, height=HEIGHT) 1623 canvas.pack() 1624 text = Label(frame, width=20, height=10, text='triangle mesh') 1625 text.pack() 1626 1627 #print self.meshTriangles 1628 for triangle in self.meshTriangles: 1629 triangle.draw(canvas,1, 1630 scale = SCALE, 1631 xoffset = xoffset, 1632 yoffset = yoffset ) 1633 1634 root.mainloop() 1635 1636 except: 1637 print "Unexpected error:", sys.exc_info()[0] 1638 raise 1639 1640 #print """ 1641 #node::plot Failed. 1642 #Most probably, the Tkinter module is not available. 1643 #""" 1644 1645 def plotUserSegments(self,tag = 0,WIDTH = 400,HEIGHT = 400): 1646 """ 1647 Plots all node connections. 1648 tag = 0 (no node numbers), tag = 1 (node numbers) 1649 """ 1650 1651 try: 1652 from Tkinter import Tk, Frame, Button, Canvas, BOTTOM, Label 1653 1654 [SCALE, xoffset, yoffset] = self.scaleoffset( WIDTH, HEIGHT) 1655 1656 root = Tk() 1657 frame = Frame(root) 1658 frame.pack() 1659 button = Button(frame, text="OK", fg="red", command=frame.quit) 1660 button.pack(side=BOTTOM) 1661 canvas = Canvas(frame, bg="white", width=WIDTH, height=HEIGHT) 1662 canvas.pack() 1663 text = Label(frame, width=20, height=10, text='user segments') 1664 text.pack() 1665 1666 for segment in self.getUserSegments(): 1667 segment.draw(canvas,SCALE, xoffset, yoffset ) 1668 1669 root.mainloop() 1670 1671 except: 1672 print "Unexpected error:", sys.exc_info()[0] 1673 raise 1674 1675 #print """ 1676 #node::plot Failed. 1677 #Most probably, the Tkinter module is not available. 1678 #""" 1679 1680 1643 1644 1681 1645 def exportASCIIobj(self,ofile): 1682 1646 """
Note: See TracChangeset
for help on using the changeset viewer.