Changeset 1107


Ignore:
Timestamp:
Mar 18, 2005, 2:28:19 PM (20 years ago)
Author:
duncan
Message:

new alpha shape features.

Location:
inundation/ga/storm_surge/pmesh
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • inundation/ga/storm_surge/pmesh/mesh.py

    r1074 r1107  
    12371237        self.userSegments.extend(newsegs)
    12381238        return newsegs
    1239     def autoSegmentFilter(self,):
    1240         pass
     1239    def autoSegmentFilter(self,raw_boundary=True,
     1240                    remove_holes=False,
     1241                    smooth_indents=False,
     1242                    expand_pinch=False):
     1243        """
     1244        Precon: There is a self.shape
     1245        """
     1246        #FIXME remove the precon.  Internally check
     1247        return self._boundary2mesh(raw_boundary=raw_boundary,
     1248                    remove_holes=remove_holes,
     1249                    smooth_indents=smooth_indents,
     1250                    expand_pinch=expand_pinch)
     1251       
    12411252   
    12421253    def autoSegment(self, alpha = None,
    1243                                  raw_boundary=True,
    1244                                  remove_holes=False,
    1245                                  smooth_indents=False,
    1246                                  expand_pinch=False):
     1254                    raw_boundary=True,
     1255                    remove_holes=False,
     1256                    smooth_indents=False,
     1257                    expand_pinch=False):
    12471258        """
    12481259        Precon: There must be 3 or more vertices in the userVertices structure
    12491260        """
    1250        
     1261        self._createBoundary(alpha=alpha)
     1262        return self._boundary2mesh(raw_boundary=raw_boundary,
     1263                    remove_holes=remove_holes,
     1264                    smooth_indents=smooth_indents,
     1265                    expand_pinch=expand_pinch)
     1266
     1267    def _createBoundary(self,alpha=None):
     1268        """
     1269        """
    12511270        points=[]
    12521271        for vertex in self.getUserVertices():
    12531272            points.append((vertex.x,vertex.y))
    12541273        self.shape = alpha_shape.alpha_shape.Alpha_Shape(points, alpha = alpha)
     1274
     1275    def _boundary2mesh(self, raw_boundary=True,
     1276                    remove_holes=False,
     1277                    smooth_indents=False,
     1278                    expand_pinch=False):
     1279        """
     1280        Precon there must be a shape object.
     1281        """
    12551282        self.shape.set_boundary_type(raw_boundary=raw_boundary,
    12561283                                 remove_holes=remove_holes,
  • inundation/ga/storm_surge/pmesh/pmesh.py

    r1033 r1107  
    657657        add Segments to bound all vertices
    658658       
    659         the parent attribute isn't used by this function.
    660         need to userstand toolbarbutton.py to know how to
    661         get rid of it.
    662659        """
    663660        if len(self.mesh.getUserVertices()) >= 3:
    664             if alpha == None:
    665                 newsegs, ObjectsToVisuallyDelete, self.meshLastAlpha = self.mesh.autoSegment(remove_holes=remove_holes,
    666                                  smooth_indents=smooth_indents,
    667                                  expand_pinch=expand_pinch)
    668             else:
    669                 newsegs, ObjectsToVisuallyDelete, self.meshLastAlpha = self.mesh.autoSegment(alpha=alpha, remove_holes=remove_holes,
    670                                  smooth_indents=smooth_indents,
    671                                  expand_pinch=expand_pinch)
    672                
     661            newsegs, ObjectsToVisuallyDelete, self.meshLastAlpha = \
     662                     self.mesh.autoSegment(alpha=alpha,
     663                                           remove_holes=remove_holes,
     664                                           smooth_indents=smooth_indents,
     665                                           expand_pinch=expand_pinch)
    673666            #print "newsegs",newsegs
    674667            #print "ObjectsToVisuallyDelete",ObjectsToVisuallyDelete
     
    691684
    692685    def autoSegmentFilter (self):
    693         dialog = autoSegmentFilterDialog(self.canvas)
    694         dialog.use_optimum.get() == SET_ALPHA
     686        dialog = AutoSegmentFilterDialog(self.canvas)
     687        newsegs, ObjectsToVisuallyDelete, self.meshLastAlpha = \
     688                 self.mesh.autoSegmentFilter(raw_boundary=dialog.raw_boundary.get(),
     689                             remove_holes=dialog.remove_holes.get(),
     690                             smooth_indents=dialog.smooth_indents.get(),
     691                             expand_pinch=dialog.expand_pinch.get())
     692        #print "newsegs",newsegs
     693        #print "ObjectsToVisuallyDelete",ObjectsToVisuallyDelete
     694           
     695        for drawOb in ObjectsToVisuallyDelete:
     696            self.UserMesh.unvisualise(drawOb, self.canvas)
     697               
     698        for segment in newsegs:
     699            self.serial +=1
     700            self.uniqueID = 'M*%d' % self.serial
     701            self.Segments.visualise(segment,
     702                                    self.uniqueID,
     703                                    self.canvas,
     704                                    self.SCALE)
    695705       
    696706    def joinVerticesButton (self, parent):
     
    16021612    Dialog box for adding segments
    16031613    """
    1604     def __init__(self, parent, alpha):
    1605         self.alpha = alpha
     1614    def __init__(self, parent):
    16061615        Dialog.__init__(self, parent)
    16071616       
     
    16161625                                   #  It doesn't
    16171626        self.boundary_type = IntVar()
    1618                                    
    1619         #self.use_optimum.set(NO_SELECTION)
    1620         self.ck = Radiobutton(master, value = AUTO, variable=self.use_optimum)
    1621         self.ck.grid(row=1, column=0)
    1622         Label(master, text='Use optimum alpha').grid(row=1, column=1, sticky=W)
    1623 
    1624         self.ck2 = Radiobutton(master, value = SET_ALPHA,
    1625                                variable=self.use_optimum)
    1626         self.ck2.grid(row=2, column=0)
    1627        
    1628         Label(master, text='alpha:').grid(row=2, column=1, sticky=W)
    1629         if (self.alpha):
    1630             alphaVar = StringVar()
    1631             alphaVar.set(self.alpha)
    1632             self.alpha_str  = Entry(master,
    1633                                      textvariable = alphaVar,
    1634                                      width = 16, name ="entry")
    1635         else:
    1636             self.alpha_str = Entry(master, width = 16, name ="entry")
    1637        
    1638         self.alpha_str.grid(row=2, column=3, sticky=W)
    1639 
     1627                     
    16401628        #boundary type buttons
    1641         self.ck3 = Radiobutton(master, value = mesh.RAW,
    1642                                variable=self.boundary_type)
     1629        self.raw_boundary = IntVar()
     1630        self.remove_holes = IntVar()
     1631        self.smooth_indents = IntVar()
     1632        self.expand_pinch = IntVar()
     1633       
     1634        self.ck3 = Checkbutton(master, state=NORMAL,
     1635                               variable=self.raw_boundary)
    16431636        self.ck3.grid(row=3, column=0)
    16441637        Label(master, text='Raw boundary').grid(row=3, column=1, sticky=W)
    16451638        #
    1646         self.ck4 = Radiobutton(master, value = mesh.REMOVE_HOLES,
    1647                                variable=self.boundary_type)
     1639        self.ck4 = Checkbutton(master, state=NORMAL,
     1640                               variable=self.remove_holes)
    16481641        self.ck4.grid(row=4, column=0)
    16491642        Label(master, text='Remove small holes').grid(row=4,column=1, sticky=W)
    16501643        #
    1651         self.ck5 = Radiobutton(master, value = mesh.REMOVE_SHARP_INDENTS,
    1652                                variable=self.boundary_type)
     1644        self.ck5 = Checkbutton(master,state=NORMAL,
     1645                               variable=self.smooth_indents)
    16531646        self.ck5.grid(row=5, column=0)
    16541647        Label(master,
    1655               text='Remove small holes \n& sharp indents').grid(row=5,
    1656                                                               column=1,
    1657                                                               sticky=W)
     1648              text='Remove sharp indents').grid(row=5, column=1, sticky=W)
    16581649        #
    1659         self.ck6 = Radiobutton(master, value = mesh.REMOVE_PINCH_OFF,
    1660                                variable=self.boundary_type)
     1650        self.ck6 = Checkbutton(master,state=NORMAL,
     1651                               variable=self.expand_pinch)
    16611652        self.ck6.grid(row=6, column=0)
    16621653        Label(master,
    1663               text='Remove small holes & \nsharp indents & pinch off').grid( \
    1664                                                               row=6,
    1665                                                               column=1,
    1666                                                               sticky=W)
    1667 
    1668        
    1669         self.alpha  = 0
    1670         self.alphaValueOk = False
    1671        
    1672 
    1673     def apply(self):
    1674         """
    1675         check entered values
    1676         """
    1677         try:
    1678             self.alpha = float(self.alpha_str.get())
    1679             self.alphaValueOk = True
    1680            
    1681         except ValueError:
    1682             pass
    1683             #showerror('Bad Alpha value',
    1684             #                       'Alpha is negative.')
    1685 
     1654              text='Remove pinch off').grid(row=6, column=1,  sticky=W)
     1655       
     1656       
    16861657
    16871658
Note: See TracChangeset for help on using the changeset viewer.