Changeset 829


Ignore:
Timestamp:
Feb 2, 2005, 12:10:28 PM (19 years ago)
Author:
prow
Message:

Adding visualise/unvisualise. Adding files for gradient func

Location:
inundation/ga/storm_surge/pmesh
Files:
9 added
1 deleted
2 edited

Legend:

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

    r824 r829  
    3030SET_COLOUR='red'
    3131
     32
     33
     34   
     35def gradient_python(x0, y0, x1, y1, x2, y2, q0, q1, q2):
     36    """
     37    """
     38   
     39    det = (y2-y0)*(x1-x0) - (y1-y0)*(x2-x0)           
     40    a = (y2-y0)*(q1-q0) - (y1-y0)*(q2-q0)
     41    a /= det
     42
     43    b = (x1-x0)*(q2-q0) - (x2-x0)*(q1-q0)
     44    b /= det           
     45
     46    return a, b
     47
     48##############################################
     49#Initialise module
     50
     51import compile
     52if compile.can_use_C_extension('util_ext.c'):
     53    from util_ext import gradient, point_on_line
     54else:
     55    gradient = gradient_python
    3256
    3357# 1st and third values must be the same
     
    17371761        return userVertices, userSegments
    17381762
    1739     def threshold(self,setName,min=None,max=None):
    1740         """
    1741         threshold using d/A, not d
     1763    def threshold(self,setName,min=None,max=None,attribute_name = 'elevation'):
     1764        """
     1765        threshold using d
    17421766        """
    17431767        triangles = self.sets[self.setID[setName]]
    17441768        A = []
     1769
     1770        if attribute_name in self.attributeTitles:
     1771            i = self.attributeTitles.index(attribute_name)
    17451772        if not max == None:
    17461773            for t in triangles:
    1747                 if (min<self.av_att(t)<max):
     1774                if (min<self.av_att(t,i)<max):
    17481775                    A.append(t)
    17491776        else:
    17501777            for t in triangles:
    1751                 if (min<self.av_att(t)):
     1778                if (min<self.av_att(t,i)):
    17521779                    A.append(t)
    17531780        self.sets[self.setID[setName]] = A
    17541781
    1755 
    1756     def av_att(self,triangle):
     1782    def general_threshold(self,setName,min=None,max=None,attribute_name = 'elevation',function = None):
     1783        """
     1784        threshold using  d
     1785        """
     1786        triangles = self.sets[self.setID[setName]]
     1787        A = []
     1788
     1789        if attribute_name in self.attributeTitles:
     1790            i = self.attributeTitles.index(attribute_name)
     1791        if not max == None:
     1792            for t in triangles:
     1793                if (min<function(t,i)<max):
     1794                    A.append(t)
     1795        else:
     1796            for t in triangles:
     1797                if (min<self.function(t,i)):
     1798                    A.append(t)
     1799        self.sets[self.setID[setName]] = A
     1800
     1801    def av_att(self,triangle,i):
    17571802    #evaluates the average attribute of the vertices of a triangle.
    17581803        V = triangle.getVertices()
    1759         a0 = (V[0].attributes[0])
    1760         a1 = (V[1].attributes[0])
    1761         a2 = (V[2].attributes[0])
     1804        a0 = (V[0].attributes[i])
     1805        a1 = (V[1].attributes[i])
     1806        a2 = (V[2].attributes[i])
    17621807        return (a0+a1+a2)/3
    17631808
    1764     def Courant_threshold(self,setName,min=None,max=None):
    1765         """
    1766         threshold using d/A, not d
    1767         """
    1768         triangles = self.sets[self.setID[setName]]
    1769         A = []
    1770         if not max == None:
    1771             for t in triangles:
    1772                 if (min<self.Courant_ratio(t)<max):
    1773                     A.append(t)
    1774         else:
    1775             for t in triangles:
    1776                 if (min<self.av_att(t)):
    1777                     A.append(t)
    1778         self.sets[self.setID[setName]] = A
    1779 
    1780 
    1781 
    1782     def Courant_ratio(self,triangle):
     1809    def Courant_ratio(self,triangle,index):
    17831810        """
    17841811        Not the true Courant ratio, just elevation on area
    17851812        """
    1786         e = self.av_att(triangle)
     1813        e = self.av_att(triangle,index)
    17871814        A = triangle.calcArea()
    17881815        return e/A
     1816
     1817    def Gradient(self,triangle,index):
     1818        V = triangle.vertices
     1819        x0, y0, x1, y1, x2, y2, q0, q1, q2 = V[0].x,V[0].y,V[1].x,V[1].y,V[2].x,V[2].y,V[0].attributes[index],V[1].attributes[index],V[2].attributes[index]
     1820        grad_x,grad_y = gradient(x0, y0, x1, y1, x2, y2, q0, q1, q2)
     1821        if ((grad_x**2)+(grad_y**2))**(0.5)<0:
     1822            print ((grad_x**2)+(grad_y**2))**(0.5)
     1823        return ((grad_x**2)+(grad_y**2))**(0.5)
     1824   
    17891825
    17901826    def append_triangle(self,triangle):
  • inundation/ga/storm_surge/pmesh/pmesh.py

    r828 r829  
    234234                               statushelp='' )
    235235
     236    def createVisualiseIcons(self):
     237        """
     238        Add Edit buttons to the top of the GUI
     239        """
     240        ToolBarButton(self, self.toolbar, 'sep', 'sep.gif', width=10,
     241                      state='disabled')
     242        for key, func, balloon in [
     243                ('visualise', self.visualise, 'Visualise mesh triangles'),
     244                ('unvisualise', self.unvisualise, 'Do not visualise mesh triangles (for large meshes)')]:
     245            ToolBarButton(self, self.toolbar, key, '%s.gif' %key,
     246                          command=func, balloonhelp=balloon,
     247                               statushelp='' )
    236248
    237249
     
    351363        self.visualiseMesh(self.mesh)
    352364
     365    def visualise(self,parent):
     366        self.Visualise = True
     367        self.visualiseMesh(self.mesh)
     368
     369    def unvisualise(self,parent):
     370        self.Visualise = False
    353371
    354372    def createMesh(self):
     
    874892        visualise vertices, segments, triangulation, holes
    875893        """
    876         for triangle in mesh.getTriangulation():
    877             self.serial +=1
    878             self.uniqueID = 'M*%d' % self.serial
    879             self.Triangles.visualise(triangle,
    880                                     self.uniqueID,
    881                                     self.canvas,
    882                                     self.SCALE)
    883 
    884         Triangles = mesh.sets[mesh.setID[self.selSet]]
    885         for triangle in Triangles:
    886             triangle.draw(self.canvas,1,
    887                           scale = self.SCALE,
    888                           colour = SET_COLOUR)
     894        if self.Visualise:
     895            for triangle in mesh.getTriangulation():
     896                self.serial +=1
     897                self.uniqueID = 'M*%d' % self.serial
     898                self.Triangles.visualise(triangle,
     899                                        self.uniqueID,
     900                                        self.canvas,
     901                                        self.SCALE)
     902
     903        if self.Visualise:
     904            Triangles = mesh.sets[mesh.setID[self.selSet]]
     905            for triangle in Triangles:
     906                triangle.draw(self.canvas,1,
     907                              scale = self.SCALE,
     908                              colour = SET_COLOUR)
    889909
    890910        for segment in mesh.getUserSegments():
     
    12591279        self.createSetTools()
    12601280        self.createSetIcons()
     1281        self.createVisualiseIcons()
    12611282        #self.addVertsAndSegs() # !!!DSG start pmesh with a triangle
    12621283        self.selectFunc('pointer')
    12631284        self.currentPath = os.getcwd()
     1285
     1286        self.Visualise = True
    12641287
    12651288    def loadtestmesh(self,ofile):
Note: See TracChangeset for help on using the changeset viewer.