Ignore:
Timestamp:
May 16, 2005, 4:23:25 PM (19 years ago)
Author:
duncan
Message:

cleaning up importing/exporting in pmesh

File:
1 edited

Legend:

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

    r1395 r1401  
    545545        for element in dic_mesh.keys():
    546546            dic[element] = dic_mesh[element]
    547        
     547        for element in dic.keys():
     548            dic[element].sort()
     549           
    548550        # A dic for the exported/imported m
    549551        dic_other = other.Mesh2triangList()
     
    551553        for element in dic_mesh.keys():
    552554            dic_other[element] = dic_mesh[element]
     555        for element in dic.keys():
     556            dic_other[element].sort()
    553557
    554558        #print "dsg************************8"
     
    569573        PreCondition: maxArea is a double
    570574        """
    571         print "mode ",mode
     575        #print "mode ",mode
    572576        if mode == None:
    573577            self.mode = ""
     
    736740        Precondition: Each vertex has a dupindex, which is the list
    737741        index.
     742
     743        Note: this removes vertices that have the same x,y values,
     744        not duplicate instances in the Vertices list.
    738745        """
    739746        remove = []
     
    13121319                                 expand_pinch=expand_pinch)
    13131320        boundary_segs = self.shape.get_boundary()
    1314         print "boundary_segs",boundary_segs
     1321        #print "boundary_segs",boundary_segs
    13151322        segs2delete = self.alphaUserSegments
    13161323
     
    16221629            #Most probably, the Tkinter module is not available.
    16231630            #"""
    1624      # FIXME let's not use this function,
    1625      # use export _mesh_file instead
    1626     def export_triangulation_file(self,ofile):
    1627         """
    1628         export a file, ofile, with the format
    1629        
    1630         First line:  <# of vertices> <# of attributes>
    1631         Following lines:  <vertex #> <x> <y> [attributes]
    1632         One line:  <vertex attribute titles>
    1633         One line:  <# of triangles>
    1634         Following lines:  <triangle #> <vertex #>  <vertex #> <vertex #> <neigbouring triangle #> <neigbouring triangle #> <neigbouring triangle #> [attribute of region]
    1635         One line:  <# of segments>
    1636         Following lines:  <segment #> <vertex #>  <vertex #> [boundary tag]
    1637         """
    1638         gen_dict = self.Mesh2IODict()
    1639         if (ofile[-4:] == ".tsh"):
    1640             fd = open(ofile,'w')
    1641             load_mesh.loadASCII.write_ASCII_triangulation(fd,gen_dict)
    1642             self.writeASCIImesh(fd,
    1643                                 self.userVertices,
    1644                                 self.getUserSegments(),
    1645                                 self.holes,
    1646                                 self.regions)   
    1647             fd.close()
    1648         elif (ofile[-4:] == ".msh"):
    1649             #print "mesh gen_dict",gen_dict
    1650             load_mesh.loadASCII.write_msh_file(ofile, gen_dict)
    16511631           
    1652 # self.writeASCIImesh(fd, does anything use this?
    1653 
    1654     #FIXME this function has a bug..       
    1655     def exportASCIIsegmentoutlinefile(self,ofile):
    1656         """
    1657         export a file, ofile, with no triangulation and only vertices connected to segments.
    1658         """
    1659         fd = open(ofile,'w')
    1660         meshDict = {}
    1661        
    1662         meshDict['vertices'] = []
    1663         meshDict['vertex_attributes'] = []
    1664         meshDict['segments'] = []
    1665         meshDict['segment_tags'] = []
    1666         meshDict['triangles'] = []
    1667         meshDict['triangle_tags'] = []
    1668         meshDict['triangle_neighbors'] = []
    1669        
    1670         load_mesh.loadASCII.write_ASCII_triangulation(fd,meshDict)
    1671         self.writeASCIIsegmentoutline(fd,
    1672                             self.userVertices,
    1673                             self.getUserSegments(),
    1674                             self.holes,
    1675                             self.regions)   
    1676         fd.close()
    16771632
    16781633    def exportASCIIobj(self,ofile):
     
    17061661                     + str(tri.vertices[1].index1) + " "
    17071662                     + str(tri.vertices[2].index1) + "\n")
    1708 
    1709     #FIXME I think this has a bug...           
    1710     def writeASCIIsegmentoutline(self,
    1711                        fd,
    1712                        userVertices,
    1713                        userSegments,
    1714                        holes,
    1715                        regions):
    1716         """Write the user mesh info, only with vertices that are connected to segs
    1717         """
    1718         verts = []
    1719         #dupindex = 0
    1720         for seg in self.userSegments:
    1721             verts.append(seg.vertices[0])
    1722             verts.append(seg.vertices[1])
    1723         print 'verts>',verts
    1724 
    1725         verts, count = self.removeDuplicatedVertices(verts)
    1726         print 'verts no dups>',verts
    1727         self.writeASCIImesh(fd,
    1728                             verts,
    1729                             self.getUserSegments(),
    1730                             self.holes,
    1731                             self.regions)
     1663           
     1664    def exportASCIIsegmentoutlinefile(self,ofile):
     1665        """Write the boundary user mesh info, eg
     1666         vertices that are connected to segments,
     1667         segments
     1668        """
     1669       
     1670        verts = {}
     1671        for seg in self.getUserSegments():
     1672            verts[seg.vertices[0]] = seg.vertices[0]
     1673            verts[seg.vertices[1]] = seg.vertices[1]
     1674        #print "verts.values()",verts.values()
     1675        meshDict = self.Mesh2IOOutlineDict(userVertices=verts.values())
     1676        load_mesh.loadASCII.export_mesh_file(ofile,meshDict)
    17321677       
    17331678        # exportASCIImeshfile   - this function is used
     
    17401685        load_mesh.loadASCII.export_mesh_file(ofile,dict)
    17411686
    1742     # is this function obsolete?
    1743     def writeASCIImesh(self,
    1744                        fd,
    1745                        userVertices,
    1746                        userSegments,
    1747                        holes,
    1748                        regions):
    1749        
    1750         #print "mesh.writeASCIImesh*********"
    1751         #print "dict",dict
    1752         #print "mesh*********"
    1753         load_mesh.loadASCII.write_ASCII_outline(fd, dict)
    1754 
    1755                 #FIXME the title is wrong, need more comments
    1756     def exportxyafile(self,ofile):
    1757         """
    1758         export a file, ofile, with the format
    1759        
    1760         First line:  <# of vertices> <# of attributes>
    1761         Following lines:  <vertex #> <x> <y> [attributes]
    1762         """
    1763         #load_mesh.loadASCII
    1764         #FIXME, this should be a mesh2io method
    1765         if self.meshVertices == []:
    1766             Vertices = self.userVertices
     1687    def exportPointsFile(self,ofile):
     1688        """
     1689        export a points (.xya or .pts)  file, ofile.
     1690       
     1691        """
     1692       
     1693        mesh_dict = self.Mesh2IODict()
     1694        point_dict = {}
     1695        point_dict['attributelist'] = {} #this will need to be expanded..
     1696                                         # if attributes are brought back in.
     1697        point_dict['geo_reference'] = self.geo_reference
     1698        if mesh_dict['vertices'] == []:
     1699            point_dict['pointlist'] = mesh_dict['points']
    17671700        else:
    1768             Vertices = self.meshVertices
    1769            
    1770         numVert = str(len(Vertices))
    1771        
    1772         if Vertices == []:
    1773             raise RuntimeError
    1774         numVertAttrib = str(len(Vertices[0].attributes))
    1775         #title = numVert + " " + numVertAttrib + " # <vertex #> <x> <y> [attributes]"
    1776 
    1777         #Convert the Vertices to pointlist and pointattributelist
    1778         xya_dict = {}
    1779         pointattributes = []
    1780         points = []
    1781        
    1782         for vert in Vertices:
    1783             points.append([vert.x,vert.y])
    1784             pointattributes.append(vert.attributes)
    1785            
    1786         xya_dict['pointlist'] = points
    1787         xya_dict['pointattributelist'] = pointattributes
    1788         xya_dict['geo_reference'] = self.geo_reference
    1789 
    1790         load_mesh.loadASCII.export_points_file(ofile, xya_dict)
     1701            point_dict['pointlist'] = mesh_dict['vertices']
     1702
     1703        load_mesh.loadASCII.export_points_file(ofile,point_dict)
    17911704
    17921705       
     
    18441757        vertices=[]
    18451758        vertex_attributes=[]
    1846 
    18471759
    18481760        self.maxVertexIndex=0
     
    19631875        #print "*(*("
    19641876        return meshDict
    1965          
    19661877
    19671878    def IOTriangulation2Mesh(self, genDict):
     
    20101921                self.meshTriangles[index].setAttribute("")
    20111922            else:
    2012                 # Note, is the first attribute always the region att?
    2013                 # haven't confirmed this
    2014                 #Peter - I think so (from manuel)
    2015                 #...the first such value is assumed to be a regional attribute...
    20161923                self.meshTriangles[index].setAttribute(att)
    20171924            index += 1
Note: See TracChangeset for help on using the changeset viewer.