Ignore:
Timestamp:
Dec 6, 2004, 3:47:05 PM (20 years ago)
Author:
duncan
Message:

adding in alphashape

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  
    1515
    1616import load_mesh.loadASCII
     17import alpha_shape.alpha_shape
    1718
    1819import sys
     
    2829# 1st and third values must be the same
    2930#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
    3132initialconversions = ['', 'external','']
    3233
     
    137138                                       outline=colour,
    138139                                       fill = 'white')
     140   
     141        #return tags
    139142     
    140143    def __repr__(self):
     
    10121015        fd.close()
    10131016
    1014     def autoSegment(self):
     1017    def autoSegmentHull(self):
    10151018        """
    10161019        initially work by running an executable
     
    10301033            fd.write('\n')
    10311034        fd.close()
    1032 
    1033         # os.system('SET PATH=..\pmesh;%PATH%') # this doesn't work
    1034         #print "os.getcwd()",os.getcwd()    # this could be usefull
    1035         #command = "k:\\EQRMsens\\" + s
    1036         #os.chdir(command)
    1037         #command = 'env'
    1038         #os.system(command)
    10391035       
    10401036        #run hull executable
     
    10631059                newseg = Segment(v1, v2)
    10641060                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)
    10651085        self.userSegments.extend(newsegs)
    10661086        return newsegs
     
    14791499            index += 1
    14801500        index = 0
     1501       
    14811502        # <index> [<MaxArea>|""]
     1503       
     1504        #One line:  <# of regions>
     1505        fd.write(str(len(regions)) +
     1506                 " # <Region #> [Max Area] ...Mesh Regions..." + "\n")
    14821507        for r in regions:
    14831508            area = r.getMaxArea()
     
    16351660   
    16361661def square_outline(side_length = 1,up = "top", left = "left", right = "right",
    1637                    down = "bottom"):
     1662                   down = "bottom", regions = False):
    16381663   
    16391664        a = Vertex (0,0)
     
    16461671        s4 = Segment(d,c, marker = right)
    16471672        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])
    16481690     
    1649         return Mesh(userVertices=[a,b,c,d],
    1650                  userSegments=[s2,s3,s4,s5])
     1691        return mesh
     1692
     1693   
    16511694
    16521695def region_strings2ints(region_list):
  • inundation/ga/storm_surge/pmesh/pmesh.py

    r654 r679  
    187187                ('default', self.windowDefault, 'set default value for selected mode'),
    188188                ('joinVer', self.joinVerticesButton, 'add Segments to connect all vertices'),     
     189                ('autoSegHull', self.autoSegmentHullButton, 'add Segments to form alpha shape, using Hull'), 
    189190                ('autoSeg', self.autoSegmentButton, 'add Segments to form alpha shape'),
    190191                ('meshGen', self.windowMeshGen, 'Generate Mesh')]:
     
    339340   
    340341   
     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 
    341366    def autoSegmentButton (self, parent):
    342367        self.autoSegment()
Note: See TracChangeset for help on using the changeset viewer.