Changeset 679
- Timestamp:
- Dec 6, 2004, 3:47:05 PM (20 years ago)
- Location:
- inundation/ga/storm_surge/pmesh
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/ga/storm_surge/pmesh
- Property svn:externals set to
- Property xvn:externals set to alpha_shape https://datamining.anu.edu.au/svn/projects/ga/storm_surge/alpha_shape
-
inundation/ga/storm_surge/pmesh/mesh.py
r650 r679 15 15 16 16 import load_mesh.loadASCII 17 import alpha_shape.alpha_shape 17 18 18 19 import sys … … 28 29 # 1st and third values must be the same 29 30 #initialconversions = ['internal', 'external','internal'] 30 # FIXME: maybe make this a switch that the user can change? 31 # FIXME: maybe make this a switch that the user can change? - DSG 31 32 initialconversions = ['', 'external',''] 32 33 … … 137 138 outline=colour, 138 139 fill = 'white') 140 141 #return tags 139 142 140 143 def __repr__(self): … … 1012 1015 fd.close() 1013 1016 1014 def autoSegment (self):1017 def autoSegmentHull(self): 1015 1018 """ 1016 1019 initially work by running an executable … … 1030 1033 fd.write('\n') 1031 1034 fd.close() 1032 1033 # os.system('SET PATH=..\pmesh;%PATH%') # this doesn't work1034 #print "os.getcwd()",os.getcwd() # this could be usefull1035 #command = "k:\\EQRMsens\\" + s1036 #os.chdir(command)1037 #command = 'env'1038 #os.system(command)1039 1035 1040 1036 #run hull executable … … 1063 1059 newseg = Segment(v1, v2) 1064 1060 newsegs.append(newseg) 1061 self.userSegments.extend(newsegs) 1062 return newsegs 1063 1064 def autoSegment(self): 1065 """ 1066 1067 Precon: There must be 3 or more vertices in the userVertices structure 1068 """ 1069 1070 1071 points=[] 1072 for vertex in self.getUserVertices(): 1073 points.append((vertex.x,vertex.y)) 1074 1075 shape = alpha_shape.alpha_shape.Alpha_Shape(points) 1076 boundary_segs = shape.get_boundary() 1077 1078 newsegs = [] 1079 for seg in boundary_segs: 1080 v1 = self.userVertices[int(seg[0])] 1081 v2 = self.userVertices[int(seg[1])] 1082 if self.isUserSegmentNew(v1, v2): 1083 unique_seg = Segment(v1, v2) 1084 newsegs.append(unique_seg) 1065 1085 self.userSegments.extend(newsegs) 1066 1086 return newsegs … … 1479 1499 index += 1 1480 1500 index = 0 1501 1481 1502 # <index> [<MaxArea>|""] 1503 1504 #One line: <# of regions> 1505 fd.write(str(len(regions)) + 1506 " # <Region #> [Max Area] ...Mesh Regions..." + "\n") 1482 1507 for r in regions: 1483 1508 area = r.getMaxArea() … … 1635 1660 1636 1661 def square_outline(side_length = 1,up = "top", left = "left", right = "right", 1637 down = "bottom" ):1662 down = "bottom", regions = False): 1638 1663 1639 1664 a = Vertex (0,0) … … 1646 1671 s4 = Segment(d,c, marker = right) 1647 1672 s5 = Segment(a,c, marker = down) 1673 1674 if regions: 1675 e = Vertex (side_length/2,side_length/2) 1676 s6 = Segment(a,e, marker = down + left) 1677 s7 = Segment(b,e, marker = up + left) 1678 s8 = Segment(c,e, marker = down + right) 1679 s9 = Segment(d,e, marker = up + right) 1680 r1 = Region(side_length/2,3.*side_length/4, tag = up) 1681 r2 = Region(1.*side_length/4,side_length/2, tag = left) 1682 r3 = Region(3.*side_length/4,side_length/2, tag = right) 1683 r4 = Region(side_length/2,1.*side_length/4, tag = down) 1684 mesh = Mesh(userVertices=[a,b,c,d,e], 1685 userSegments=[s2,s3,s4,s5,s6,s7,s8,s9], 1686 regions = [r1,r2,r3,r4]) 1687 else: 1688 mesh = Mesh(userVertices=[a,b,c,d], 1689 userSegments=[s2,s3,s4,s5]) 1648 1690 1649 return Mesh(userVertices=[a,b,c,d], 1650 userSegments=[s2,s3,s4,s5]) 1691 return mesh 1692 1693 1651 1694 1652 1695 def region_strings2ints(region_list): -
inundation/ga/storm_surge/pmesh/pmesh.py
r654 r679 187 187 ('default', self.windowDefault, 'set default value for selected mode'), 188 188 ('joinVer', self.joinVerticesButton, 'add Segments to connect all vertices'), 189 ('autoSegHull', self.autoSegmentHullButton, 'add Segments to form alpha shape, using Hull'), 189 190 ('autoSeg', self.autoSegmentButton, 'add Segments to form alpha shape'), 190 191 ('meshGen', self.windowMeshGen, 'Generate Mesh')]: … … 339 340 340 341 342 def autoSegmentHullButton (self, parent): 343 self.autoSegment() 344 345 def autoSegmentHull (self): 346 """ 347 add Segments to bound all vertices 348 349 the parent attribute isn't used by this function. 350 need to userstand toolbarbutton.py to know how to 351 get rid of it. 352 """ 353 if len(self.mesh.getUserVertices()) >= 3: 354 newsegs = self.mesh.autoSegment() 355 for segment in newsegs: 356 self.serial +=1 357 self.uniqueID = 'M*%d' % self.serial 358 self.Segments.visualise(segment, 359 self.uniqueID, 360 self.canvas, 361 self.SCALE) 362 else: 363 showerror('pMesh', 364 'Three or more vetices are needed to be able to autosegment.') 365 341 366 def autoSegmentButton (self, parent): 342 367 self.autoSegment()
Note: See TracChangeset
for help on using the changeset viewer.