Changeset 404
- Timestamp:
- Oct 15, 2004, 8:53:19 AM (20 years ago)
- Location:
- inundation/ga/storm_surge/pmesh
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/ga/storm_surge/pmesh/mesh.py
r369 r404 3 3 """General 2D triangular classes for triangular mesh generation. 4 4 5 Note: A .index attribute is added to objects such as vertices and 6 segments, often when reading and writing to files. This information 7 should not be used as percistant information. It is not the 'index' of 8 an element in a list. 9 10 5 11 Copyright 2003/2004 6 12 Ole Nielsen, Stephen Roberts, Duncan Gray, Christopher Zoppou … … 346 352 347 353 Segment.set_default_tag("") 354 348 355 class Mesh: 349 356 """ … … 548 555 self.userSegments.append(s) 549 556 return s 550 551 557 552 558 def clearTriangulation(self): … … 690 696 pointlist=[] 691 697 pointattributelist=[] 698 692 699 index = 0 693 694 700 for vertex in self.userVertices: 695 701 vertex.index = index … … 904 910 #print "@#@#@#" 905 911 906 index = 0912 #index = 0 907 913 for point in genDict['pointlist']: 908 914 v=Vertex(point[0], point[1]) 909 v.index = index910 index +=1915 #v.index = index 916 #index +=1 911 917 self.userVertices.append(v) 912 918 913 index = 0919 #index = 0 914 920 for seg,marker in map(None,genDict['segmentlist'],genDict['segmentmarkerlist']): 915 921 segObject = Segment( self.userVertices[seg[0]], 916 922 self.userVertices[seg[1]], marker = marker ) 917 segObject.index = index918 index +=1923 #segObject.index = index 924 #index +=1 919 925 self.userSegments.append(segObject) 920 926 … … 929 935 # index += 1 930 936 931 index = 0937 #index = 0 932 938 for point in genDict['holelist']: 933 939 h=Hole(point[0], point[1]) 934 h.index = index935 index +=1940 #h.index = index 941 #index +=1 936 942 self.holes.append(h) 937 943 938 index = 0944 #index = 0 939 945 for reg,att,maxArea in map(None, 940 946 genDict['regionlist'], … … 945 951 tag = att, 946 952 maxArea = maxArea) 947 Object.index = index948 index +=1953 #Object.index = index 954 #index +=1 949 955 self.regions.append(Object) 950 956 957 def addVertsSegs(self, outlineDict): 958 """ 959 Add out-line (user Mesh) attributes given a dictionary of the lists 960 point list: [(x1,y1),(x2,y2),...] (Tuples of doubles) 961 segment list: [(point1,point2),(p3,p4),...] (Tuples of integers) 962 #segment marker list: [S1Marker, S2Marker, ...] (list of ints) 963 """ 964 965 print "@#@#@#" 966 print outlineDict 967 print "@#@#@#" 968 969 localUserVertices = [] 970 #index = 0 971 for point in outlineDict['pointlist']: 972 v=Vertex(point[0], point[1]) 973 #v.index = index 974 #index +=1 975 self.userVertices.append(v) 976 localUserVertices.append(v) 977 978 #index = 0 979 for seg in map(None,outlineDict['segmentlist']): 980 segObject = Segment( localUserVertices[seg[0]], 981 localUserVertices[seg[1]] ) 982 #segObject.index = index 983 #index +=1 984 self.userSegments.append(segObject) 951 985 952 986 def TestautoSegment(self): … … 1485 1519 1486 1520 load_mesh.loadASCII.export_xya_file(ofile, xya_dict, title, delimiter = " ") 1487 1521 1522 def importUngenerateFile(ofile): 1523 """ 1524 import a file, ofile, with the format 1525 [poly] 1526 poly format: 1527 First line: <# of vertices> <x centroid> <y centroid> 1528 Following lines: <x> <y> 1529 last line: "END" 1530 """ 1531 fd = open(ofile,'r') 1532 Dict = readUngenerateFile(fd) 1533 fd.close() 1534 return Dict 1535 1536 def readUngenerateFile(fd): 1537 """ 1538 import a file, ofile, with the format 1539 [poly] 1540 poly format: 1541 First line: <# of polynomial> <x centroid> <y centroid> 1542 Following lines: <x> <y> 1543 last line: "END" 1544 """ 1545 END_DELIMITER = 'END\n' 1546 1547 points = [] 1548 segments = [] 1549 1550 isEnd = False 1551 line = fd.readline() #not used <# of polynomial> <x> <y> 1552 while not isEnd: 1553 line = fd.readline() 1554 fragments = line.split() 1555 vert = [float(fragments.pop(0)),float(fragments.pop(0))] 1556 points.append(vert) 1557 PreviousVertIndex = len(points)-1 1558 firstVertIndex = PreviousVertIndex 1559 1560 line = fd.readline() #Read the next line 1561 while line <> END_DELIMITER: 1562 #print "line >" + line + "<" 1563 fragments = line.split() 1564 vert = [float(fragments.pop(0)),float(fragments.pop(0))] 1565 points.append(vert) 1566 ThisVertIndex = len(points)-1 1567 segment = [PreviousVertIndex,ThisVertIndex] 1568 segments.append(segment) 1569 PreviousVertIndex = ThisVertIndex 1570 line = fd.readline() #Read the next line 1571 i =+ 1 1572 # Remove the last segment and the last vertex 1573 # then add a segment from the second last vert to the 1st vert 1574 points.pop() 1575 segments.pop() 1576 ThisVertIndex = len(points)-1 1577 segments.append([ThisVertIndex, firstVertIndex]) 1578 1579 line = fd.readline() # read <# of polynomial> <x> <y> OR END 1580 #print "line >>" + line + "<<" 1581 if line == END_DELIMITER: 1582 isEnd = True 1583 1584 #print "points", points 1585 #print "segments", segments 1586 ungenerated_dict = {} 1587 ungenerated_dict['pointlist'] = points 1588 ungenerated_dict['segmentlist'] = segments 1589 return ungenerated_dict 1488 1590 1489 1591 def importMeshFromFile(ofile): … … 1695 1797 1696 1798 if __name__ == "__main__": 1697 # THIS CAN BE DELETED 1698 list = ["internal boundary","sea","river inlet", 1699 "","sea","","moat","internal boundary"] 1700 #list = ["sea","river inlet","","sea","","moat"] 1701 list = [] 1702 print list 1703 preset = [""] 1704 print preset 1705 [intlist, converter] = segment_strings2ints(list, preset) 1706 print "intlist",intlist 1707 print "converter",converter 1708 newlist = segment_ints2strings(intlist, converter) 1709 print newlist 1710 print "***************************" 1711 list = [(4,5,"lo"),(3,2,"mo"),(3,2,"ro")] 1712 #list = [] 1713 print "list",list 1714 [newlist, converter] = region_strings2ints(list) 1715 print "newlist",newlist 1716 trilist = [] 1717 for x in newlist: 1718 trilist.append([x[2]]) 1719 print "trilist",trilist 1720 oldlist = region_ints2strings(trilist, converter) 1721 print "oldlist",oldlist 1799 #from mesh import * 1800 # THIS CAN BE DELETED 1801 m = Mesh() 1802 dict = importUngenerateFile("ungen_test.txt") 1803 m.addVertsSegs(dict) 1804 print m -
inundation/ga/storm_surge/pmesh/pmesh.py
r349 r404 100 100 self.menuBar.addmenuitem('File', 'separator') 101 101 self.menuBar.addmenuitem('File', 'command', 102 'Add ungenerated file from arcGIS', 103 label='Add ungenerated file...', 104 command=self.ImportUngenerate) 105 106 self.menuBar.addmenuitem('File', 'command', 102 107 'Export ASCII obj', 103 label='Export ASCII obj ...',108 label='Export ASCII obj', 104 109 command=self.exportObj) 105 110 … … 123 128 command=self.autoSegment) 124 129 self.menuBar.addmenuitem('File', 'command', 'Normalise mesh', 125 label='Normalise mesh ...', command=self.normaliseMesh)130 label='Normalise mesh', command=self.normaliseMesh) 126 131 self.menuBar.addmenuitem('File', 'command', 'Normalise mesh for glutobj', 127 label='Normalise mesh for glutobj ...', command=self.normalise4ObjMesh)132 label='Normalise mesh for glutobj', command=self.normalise4ObjMesh) 128 133 self.menuBar.addmenuitem('File', 'separator') 129 134 self.menuBar.addmenuitem('File', 'command', 'Exit program', … … 150 155 t.cycle("DrawMode") 151 156 if key == 'pointer': #FIXME - this is specified in line 925 as well 152 self.curFunc 157 self.curFunc = self.drawVertex 153 158 t.setInitialSunkenButton("DrawMode") 154 self.modeClass[key] 159 self.modeClass[key] = Mode 155 160 # for actions that occur when the mouse goes down 156 self.mouseDownFunc[key] = mouseDownFunc161 self.mouseDownFunc[key] = mouseDownFunc 157 162 158 163 def createZooms(self): … … 752 757 'No triangulation to export.') 753 758 754 755 759 760 761 def ImportUngenerate(self): 762 ofile = tkFileDialog.askopenfilename(initialdir=self.currentPath, 763 filetypes=[ ("ungenerated polygon information", "txt"), 764 ("All Files", "*")]) 765 if ofile == "": 766 # The user cancelled the loading action 767 return 768 769 try: 770 self.clearSelections() 771 self.canvas.delete(ALL) 772 dict = mesh.importUngenerateFile(ofile) 773 self.mesh.addVertsSegs(dict) 774 775 except SyntaxError: 776 #this is assuming that the SyntaxError is thrown in 777 #loadxyafile 778 showerror('File error', 779 ofile + ' is not in the correct format.') 780 except IOError: 781 #!!! this error type can not be thrown? 782 showerror('File error', 783 'file ' + ofile + ' could not be found.') 784 except RuntimeError: 785 showerror('File error', 786 'file ' + ofile + ' has an unknown file type.') 787 788 self.visualiseMesh(self.mesh) 789 756 790 def exportASCIIsegmentoutlinefile(self): 757 791 fileType = "tsh"
Note: See TracChangeset
for help on using the changeset viewer.