Ignore:
Timestamp:
Jan 3, 2008, 9:58:32 PM (17 years ago)
Author:
duncan
Message:

Using a numeric array to store mesh triangulation info. The old way is also in place.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/pmesh/mesh.py

    r4899 r4901  
    520520                 vertices,
    521521                 triangle_tags,
    522                  triangle_neighbor,
     522                 triangle_neighbors,
    523523                 segment_tags,
    524524                 ):
    525525       
    526         self.triangles=ensure_numeric(triangles)
    527         self.triangle_neighbor=ensure_numeric(triangle_neighbor)
    528         self.triangle_tags=triangle_tags
    529         self.segments=ensure_numeric(segments)
    530        
    531         self.segment_tags=segment_tags # string
    532         self.vertices=ensure_numeric(vertices)
    533 
    534        
     526        self.triangles = ensure_numeric(triangles)
     527        self.triangle_neighbors = ensure_numeric(triangle_neighbors)
     528        self.triangle_tags = triangle_tags # list of strings
     529        self.segments = ensure_numeric(segments)
     530       
     531        self.segment_tags = segment_tags # list of strings
     532        self.vertices = ensure_numeric(vertices)
     533
     534       
     535    def draw_triangulation(self, canvas, scale=1, xoffset=0, yoffset=0,
     536             colour="green"):
     537        """
     538        Draw a triangle, returning the objectID
     539        """
     540       
     541        # FIXME(DSG-DSG) This could be a data structure that is
     542        # remembered and doesn't have any duplicates.
     543        # but I wouldn't be able to use create_polygon.
     544        # regard it as drawing a heap of segments
     545       
     546        for tri in self.triangles:
     547            vertices = []
     548            for v_index in range(3):
     549                vertices.append(self.vertices[tri[v_index]])
     550           
     551            objectID = canvas.create_polygon(
     552                scale*(vertices[1][0] + xoffset),
     553                scale*-1*(vertices[1][1] + yoffset),
     554                scale*(vertices[0][0] + xoffset),
     555                scale*-1*(vertices[0][1] + yoffset),
     556                scale*(vertices[2][0] + xoffset),
     557                scale*-1*(vertices[2][1] + yoffset),
     558                outline = colour,fill = ''
     559                )
     560 
    535561       
    536562class Mesh:
     
    575601        self.meshVertices=[]
    576602
     603        # Rigid
     604        self.tri_mesh=None
     605       
    577606        self.setID={}
    578607        #a dictionary of names.
     
    12111240        #print "generatedMesh",generatedMesh
    12121241        #print "##################"
    1213        
    12141242        self.setTriangulation(generatedMesh)
    12151243   
     
    15641592                    self.meshTriangles[index].setAttribute("")
    15651593                else:
    1566                     self.meshTriangles[index].setAttribute(att[0])
     1594                    self.meshTriangles[index].setAttribute(att)
    15671595                index += 1
    15681596           
     
    15881616                                                   ObjectNeighbor[2])
    15891617            index += 1
     1618       
     1619        # Setting up the rigid triangulation
     1620        self.tri_mesh = Rigid_triangulation(
     1621            genDict['generatedtrianglelist']
     1622            ,genDict['generatedsegmentlist']
     1623            ,genDict['generatedpointlist']
     1624            ,genDict['generatedtriangleattributelist']
     1625            ,genDict['generatedtriangleneighborlist']
     1626            ,genDict['generatedsegmentmarkerlist']
     1627            )
    15901628           
    15911629    def setMesh(self, genDict):
     
    22062244        meshDict['triangle_neighbors'] = triangle_neighbors
    22072245       
     2246        if self.tri_mesh is not None:
     2247            meshDict['triangles'] = self.tri_mesh.triangles
     2248            meshDict['triangle_tags'] = self.tri_mesh.triangle_tags
     2249            #print "mesh meshDict['triangle_tags']", meshDict['triangle_tags']
     2250            meshDict['triangle_neighbors'] = self.tri_mesh.triangle_neighbors
     2251        else:
     2252            meshDict['triangles'] = []
     2253            meshDict['triangle_tags'] = []
     2254            meshDict['triangle_neighbors'] = []
    22082255        #print "mesh.Mesh2IOTriangulationDict*)*)"
    22092256        #print meshDict
     
    22882335        """
    22892336        #Clear the current generated mesh values
    2290         self.meshTriangles=[]
    2291         self.attributeTitles=[]
    2292         self.meshSegments=[]
    2293         self.meshVertices=[]
    2294 
     2337        self.meshTriangles = []
     2338        self.attributeTitles = []
     2339        self.meshSegments = []
     2340        self.meshVertices = []
     2341        self.tri_mesh = None
     2342       
    22952343        #print "mesh.setTriangulation@#@#@#"
    22962344        #print genDict
     
    23532401            index += 1
    23542402
     2403        self.tri_mesh = Rigid_triangulation(
     2404            genDict['triangles']
     2405            ,genDict['segments']
     2406            ,genDict['vertices']
     2407            ,genDict['triangle_tags']
     2408            ,genDict['triangle_neighbors']
     2409            ,genDict['segment_tags']
     2410            )
    23552411
    23562412    def IOOutline2Mesh(self, genDict):
     
    31663222        for i in xrange(len(region_list)):
    31673223            temp = region_list[i]
    3168             returned_region_list.append([convertint2string[int(temp[0])]])
     3224            returned_region_list.append(convertint2string[int(temp[0])])
    31693225    return returned_region_list
    31703226
     
    39323988# instead of functionName
    39333989if __name__ == "__main__":
    3934     #from mesh import *
    3935     # THIS CAN BE DELETED
    3936     m = Mesh()
    3937     dict = importUngenerateFile("ungen_test.txt")
    3938     m.addVertsSegs(dict)
    3939     print m3
     3990    pass
Note: See TracChangeset for help on using the changeset viewer.