Changeset 828


Ignore:
Timestamp:
Feb 2, 2005, 11:31:04 AM (20 years ago)
Author:
prow
Message:

Adding gradient selector
Made general_threshold selector that is passed a function (ie gradient, average_attribute), and used that for threshold, Courant threshold and gradient threshold. Added files needed to compile C gradient.

File:
1 edited

Legend:

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

    r825 r828  
    2020APPLICATION_NAME = 'Pmesh'
    2121SET_COLOUR = 'red'
     22DEFAULT_ATTRIBUTE = 'elevation'
    2223
    2324NO_SELECTION = 0
     
    213214                ('threshold', self.threshold, 'threshold the set'),
    214215                ('Courant_threshold', self.Courant_threshold, 'Courant_threshold the set'),
    215                 ('polyset', self.triangles_to_polySet, 'make a poly set out of selected triangles'),     
    216                 ('refineSet', self.refineSet, 'Refine the set')]:
     216                ('gradient_threshold', self.gradient_threshold, 'gradient_threshold the set'),
     217                ('polyset', self.triangles_to_polySet, 'make a poly set out of selected triangles')]:     
     218                #('refineSet', self.refineSet, 'Refine the set')]:
    217219            ToolBarButton(self, self.toolbar, key, '%s.gif' %key,
    218220                          command=func, balloonhelp=balloon,
     
    257259        self.visualiseMesh(self.mesh)
    258260
    259 
    260 
    261     def threshold(self, parent):
     261    def general_threshold(self,parent,function,function_description):
    262262        """
    263263        add a vertex using a window and entering x y values.
     
    270270            self.selectAllTriangles(parent)
    271271
    272         dialog = ThresholdDialog(self.canvas)
     272        dialog = GeneralThresholdDialog(self.canvas,self.mesh.attributeTitles,function_description)
    273273        if dialog.minmaxValuesOk:
    274274            self.canvas.delete(ALL)
    275             self.mesh.threshold(self.selSet,min=dialog.min,max=dialog.max)
     275            min = dialog.min
     276            max = dialog.max
     277            attribute_name = dialog.attribute_name
     278            self.mesh.general_threshold(self.selSet,min=min,max=max,attribute_name = attribute_name,function=function)
    276279            self.visualiseMesh(self.mesh)
    277280
    278     def Courant_threshold(self, parent):
     281    def threshold(self, parent):
    279282        """
    280283        add a vertex using a window and entering x y values.
     
    284287        get rid of it.
    285288        """
    286         if self.selSet == 'None':
    287             self.selectAllTriangles(parent)
    288 
    289         dialog = Courant_ThresholdDialog(self.canvas)
    290         if dialog.minmaxValuesOk:
    291             self.canvas.delete(ALL)
    292             self.mesh.Courant_threshold(self.selSet,min=dialog.min,max=dialog.max)
    293             self.visualiseMesh(self.mesh)
    294            
     289        function = self.mesh.av_att
     290        function_description = 'average attribute of triangle'
     291        self.general_threshold(parent,function,function_description)
     292
     293
     294    def Courant_threshold(self, parent):
     295        """
     296        add a vertex using a window and entering x y values.
     297
     298        the parent attribute isn't used by this function.
     299        need to userstand toolbarbutton.py to know how to
     300        get rid of it.
     301        """
     302        function = self.mesh.Courant_ratio
     303        function_description = 'average attribute/area of triangle'
     304        self.general_threshold(parent,function,function_description)
     305
     306    def gradient_threshold(self, parent):
     307        """
     308        add a vertex using a window and entering x y values.
     309
     310        the parent attribute isn't used by this function.
     311        need to userstand toolbarbutton.py to know how to
     312        get rid of it.
     313        """
     314        function = self.mesh.Gradient
     315        function_description = 'average gradient of triangle'
     316        self.general_threshold(parent,function,function_description)
    295317
    296318    def triangles_to_polySet(self,parent):
     
    14631485            showerror('Bad mesh generation values',
    14641486                                   'Values are out of range.')
    1465 
    1466 
    1467 class  ThresholdDialog(Dialog):
     1487class  GeneralThresholdDialog(Dialog):
    14681488    """
    14691489    Dialog box for thresholding a set by entering minimum
    14701490    and maximum values
    14711491    """
     1492    def __init__(self,
     1493                 parent,
     1494                 attribute_titles,
     1495                 function_description):
     1496        self.attribute_titles=attribute_titles
     1497        self.function_description=function_description
     1498
     1499        Dialog.__init__(self, parent)
     1500
     1501
    14721502    def body(self, master):
    14731503        """
     
    14751505        """
    14761506        self.title("Threshold selected set")
    1477        
    1478         Label(master, text='minimum attribute:').grid(row=0, sticky=W)
    1479         Label(master, text='maximum attribute:').grid(row=1, sticky=W)
    1480 
    1481         self.minstr   = Entry(master, width = 16, name ="entry")
    1482         self.maxstr   = Entry(master, width = 16)
     1507        blurb1 = 'Threshold selected set between minimum'
     1508        blurb2 = 'and maximum ' + self.function_description
     1509
     1510        Label(master,text=blurb1).grid(row=0, sticky=W)
     1511        Label(master,text=blurb2).grid(row=1, sticky=W)
     1512
     1513        Label(master, text='minimum attribute:').grid(row=2, sticky=W)
     1514        Label(master, text='maximum attribute:').grid(row=3, sticky=W)
     1515        Label(master, text='attribute name').grid(row=4, sticky=W)
     1516
     1517
     1518        nameVar = StringVar()
     1519        nameVar.set('elevation')
     1520
     1521        self.minstr = Entry(master, width = 16, name ="entry")
     1522        self.maxstr = Entry(master, width = 16)
     1523        self.attstr = Entry(master, width = 16,textvariable = nameVar)
    14831524       
    1484         self.minstr.grid(row=0, column=1, sticky=W)
    1485         self.maxstr.grid(row=1, column=1, sticky=W)
     1525        self.minstr.grid(row=2, column=1, sticky=W)
     1526        self.maxstr.grid(row=3, column=1, sticky=W)
     1527        self.attstr.grid(row=4, column=1, sticky=W)
    14861528        self.minstr.focus_force()
    14871529        self.min  = 0
    14881530        self.max  = 0
     1531        self.attribute_name = 'elevation'
    14891532        self.minmaxValuesOk = False
    14901533       
     
    14951538            self.max = float(self.maxstr.get())
    14961539        except ValueError:
    1497             self.ValuesOk = False
     1540            self.minmaxValuesOk = False
    14981541            showerror('Bad mesh generation values',
    14991542                                   ' Values are not numbers.')
    1500 
    1501 
    1502 class  Courant_ThresholdDialog(Dialog):
     1543        try:
     1544            self.attribute_titles.index(self.attstr.get())#dodgey.
     1545            self.attribute_name = self.attstr.get()
     1546        except ValueError:
     1547            self.minmaxValuesOk = False
     1548            showerror('Bad attribute name',
     1549                                   ' Attribute not in mesh.')
     1550
     1551class  ThresholdDialog(Dialog):
    15031552    """
    1504     Dialog box for Courant_thresholding a set by entering minimum
     1553    Dialog box for thresholding a set by entering minimum
    15051554    and maximum values
    15061555    """
     1556    def __init__(self,
     1557                 parent,
     1558                 attribute_titles):
     1559        self.attribute_titles=attribute_titles
     1560        Dialog.__init__(self, parent)
     1561
     1562
    15071563    def body(self, master):
    15081564        """
    15091565        GUI description
    15101566        """
    1511         self.title("Courant_Threshold selected set")
     1567        self.title("Threshold selected set")
    15121568       
    15131569        Label(master, text='minimum attribute:').grid(row=0, sticky=W)
    15141570        Label(master, text='maximum attribute:').grid(row=1, sticky=W)
     1571        Label(master, text='attribute name').grid(row=2, sticky=W)
     1572
     1573
     1574        nameVar = StringVar()
     1575        nameVar.set('elevation')
    15151576
    15161577        self.minstr   = Entry(master, width = 16, name ="entry")
    15171578        self.maxstr   = Entry(master, width = 16)
     1579        self.attstr   = Entry(master, width = 16,textvariable = nameVar)
    15181580       
    15191581        self.minstr.grid(row=0, column=1, sticky=W)
    15201582        self.maxstr.grid(row=1, column=1, sticky=W)
     1583        self.attstr.grid(row=2, column=1, sticky=W)
    15211584        self.minstr.focus_force()
    15221585        self.min  = 0
    15231586        self.max  = 0
     1587        self.attribute_name = 'elevation'
    15241588        self.minmaxValuesOk = False
    15251589       
     
    15301594            self.max = float(self.maxstr.get())
    15311595        except ValueError:
    1532             self.ValuesOk = False
     1596            self.minmaxValuesOk = False
    15331597            showerror('Bad mesh generation values',
    15341598                                   ' Values are not numbers.')
     1599        try:
     1600            self.attribute_titles.index(self.attstr.get())#dodgey.
     1601            self.attribute_name = self.attstr.get()
     1602        except ValueError:
     1603            self.minmaxValuesOk = False
     1604            showerror('Bad attribute name',
     1605                                   ' Attribute not in mesh.')
     1606
     1607
     1608class  Courant_ThresholdDialog(Dialog):
     1609    """
     1610    Dialog box for thresholding a set by entering minimum
     1611    and maximum values
     1612    """
     1613    def __init__(self,
     1614                 parent,
     1615                 attribute_titles):
     1616        self.attribute_titles=attribute_titles
     1617        Dialog.__init__(self, parent)
     1618
     1619
     1620    def body(self, master):
     1621        """
     1622        GUI description
     1623        """
     1624        self.title("Courant_Threshold selected set")
     1625       
     1626        Label(master, text='minimum attribute:').grid(row=0, sticky=W)
     1627        Label(master, text='maximum attribute:').grid(row=1, sticky=W)
     1628        Label(master, text='attribute name').grid(row=2, sticky=W)
     1629
     1630
     1631        nameVar = StringVar()
     1632        nameVar.set('elevation')
     1633
     1634        self.minstr   = Entry(master, width = 16, name ="entry")
     1635        self.maxstr   = Entry(master, width = 16)
     1636        self.attstr   = Entry(master, width = 16,textvariable = nameVar)
     1637       
     1638        self.minstr.grid(row=0, column=1, sticky=W)
     1639        self.maxstr.grid(row=1, column=1, sticky=W)
     1640        self.attstr.grid(row=2, column=1, sticky=W)
     1641        self.minstr.focus_force()
     1642        self.min  = 0
     1643        self.max  = 0
     1644        self.attribute_name = 'elevation'
     1645        self.minmaxValuesOk = False
     1646       
     1647    def apply(self):
     1648        self.minmaxValuesOk = True
     1649        try:
     1650            self.min = float(self.minstr.get())
     1651            self.max = float(self.maxstr.get())
     1652        except ValueError:
     1653            self.minmaxValuesOk = False
     1654            showerror('Bad mesh generation values',
     1655                                   ' Values are not numbers.')
     1656        try:
     1657            self.attribute_titles.index(self.attstr.get())#dodgey.
     1658            self.attribute_name = self.attstr.get()
     1659        except ValueError:
     1660            self.minmaxValuesOk = False
     1661            showerror('Bad attribute name',
     1662                                   ' Attribute not in mesh.')
    15351663
    15361664
Note: See TracChangeset for help on using the changeset viewer.