Changeset 364


Ignore:
Timestamp:
Oct 6, 2004, 7:10:14 PM (20 years ago)
Author:
duncan
Message:

adding vert attribute titles
crippling loading vert attributes

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

Legend:

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

    r363 r364  
    6767       
    6868    ######### loading the point title info
     69    line = fd.readline()
     70    #print "point title comments",line
    6971    vertTitle = []
    7072    for index in range(int(NumOfVertAttributes)):       
     
    7577    ######### loading the triangle info
    7678    line = fd.readline()
    77     #print line
     79    #print "triangle comments",line
    7880    fragments = line.split()
    7981    #for fragment in fragments:
     
    103105    ######### loading the segment info
    104106    line = fd.readline()
    105     #print line
     107    print "seg comment line",line
    106108    fragments = line.split()
    107109    #for fragment in fragments:
     
    306308    vertices = gen_dict['generatedpointlist']
    307309    vertices_attributes = gen_dict['generatedpointattributelist']
    308     vertices_attribute_titles = gen_dict['generatedpointattributetitlelist']
     310    try:
     311        vertices_attribute_titles = gen_dict['generatedpointattributetitlelist']
     312   
     313    except KeyError, e:
     314        #FIXME is this the best way?
     315        if vertices_attributes == [] or vertices_attributes[0] == []:
     316             vertices_attribute_titles = []
     317        else:
     318            raise KeyError, e
     319       
    309320    triangles = gen_dict['generatedtrianglelist']
    310321    triangles_attributes = gen_dict['generatedtriangleattributelist']
     
    335346
    336347    # write comments for title
    337     fd.write(" # attribute column titles ...Triangulation Vertex Titles..." + "\n")
     348    fd.write("# attribute column titles ...Triangulation Vertex Titles..." + "\n")
    338349    for title in vertices_attribute_titles:
    339350        fd.write(title + "\n")
  • inundation/ga/storm_surge/pmesh/load_mesh/loadASCIIHarness.py

    r349 r364  
    2525        e_att = [2,2]
    2626        a_xy = [0.0, 0.0]
    27         a = Vertex ( a_xy[0],a_xy[1], attributes =a_att)
    28         d = Vertex (0.0, 4.0, attributes =d_att)
    29         f = Vertex (4.0,0.0, attributes =f_att)
    30         e = Vertex (1.0,1.0, attributes =e_att)
     27        a = Vertex ( a_xy[0],a_xy[1]) #, attributes =a_att)
     28        d = Vertex (0.0, 4.0) #, attributes =d_att)
     29        f = Vertex (4.0,0.0) #, attributes =f_att)
     30        e = Vertex (1.0,1.0) #, attributes =e_att)
    3131   
    3232        s1 = Segment(a,d, marker = "50")
     
    4747        fileName = tempfile.mktemp(".txt")
    4848        #print "fileName",fileName
    49         m.exportASCIItrianglulationfile(fileName)
     49        m.export_ASCII_trianglulation_file(fileName)
    5050       
    5151        dict = import_trianglulation(fileName)
     
    152152        self.failUnless(m.userVertices[0].y == 0.0,
    153153                        'loadxy, test 2 failed')
    154         self.failUnless(m.userVertices[0].attributes == [10.0,0.0],
    155                         'loadxy, test 2.2 failed')
     154        #self.failUnless(m.userVertices[0].attributes == [10.0,0.0],
     155        #                'loadxy, test 2.2 failed')
    156156        self.failUnless(m.userVertices[1].x == 0.0,
    157157                        'loadxy, test 3 failed')
    158158        self.failUnless(m.userVertices[1].y == 1.0,
    159159                        'loadxy, test 4 failed')
    160         self.failUnless(m.userVertices[1].attributes == [0.0,10.0],
    161                         'loadxy, test 5 failed')
     160        #self.failUnless(m.userVertices[1].attributes == [0.0,10.0],
     161        #                'loadxy, test 5 failed')
    162162#-------------------------------------------------------------
    163163if __name__ == "__main__":
  • inundation/ga/storm_surge/pmesh/mesh.py

    r355 r364  
    917917            index +=1
    918918            self.userSegments.append(segObject)
    919         index = 0
    920         for att in genDict['pointattributelist']:
    921             if att == None:
    922                 self.userVertices[index].setAttributes([])
    923             else:
    924                 self.userVertices[index].setAttributes(att)
    925             index += 1
     919
     920# Remove the loading of attribute info.
     921# Have attribute info added using least_squares in pyvolution
     922#         index = 0
     923#         for att in genDict['pointattributelist']:
     924#             if att == None:
     925#                 self.userVertices[index].setAttributes([])
     926#             else:
     927#                 self.userVertices[index].setAttributes(att)
     928#            index += 1
    926929       
    927930        index = 0
     
    12681271        """
    12691272        fd = open(ofile,'w')
    1270         self.writeASCIItrianglulation(fd,
    1271                                  self.meshVertices,
    1272                                  self.meshTriangles,
    1273                                  self.meshSegments)
    1274         self.writeASCIImesh(fd,
    1275                             self.userVertices,
    1276                             self.userSegments,
    1277                             self.holes,
    1278                             self.regions)   
    1279         fd.close()
    1280 
    1281     def export_ASCII_trianglulation_file(self,ofile):
    1282         """
    1283         export a file, ofile, with the format
    1284        
    1285         First line:  <# of vertices> <# of attributes>
    1286         Following lines:  <vertex #> <x> <y> [attributes]
    1287         One line:  <# of triangles>
    1288         Following lines:  <triangle #> <vertex #>  <vertex #> <vertex #> <neigbouring triangle #> <neigbouring triangle #> <neigbouring triangle #> [attribute of region]
    1289         One line:  <# of segments>
    1290         Following lines:  <segment #> <vertex #>  <vertex #> [boundary marker]
    1291         """
    1292         fd = open(ofile,'w')
    12931273        gen_dict = self.Mesh2MeshList()
    12941274        load_mesh.loadASCII.write_ASCII_trianglulation(fd,gen_dict)
     
    13051285        """
    13061286        fd = open(ofile,'w')
    1307         self.writeASCIItrianglulation(fd,
    1308                                  [],
    1309                                  [],
    1310                                  [])
     1287        meshDict = {}
     1288       
     1289        meshDict['generatedpointlist'] = []
     1290        meshDict['generatedpointattributelist'] = []
     1291        meshDict['generatedsegmentlist'] = []
     1292        meshDict['generatedsegmentmarkerlist'] = []
     1293
     1294        meshDict['generatedtrianglelist'] = []
     1295        meshDict['generatedtriangleattributelist'] = []
     1296        meshDict['generatedtriangleneighborlist'] = []
     1297       
     1298        load_mesh.loadASCII.write_ASCII_trianglulation(fd,meshDict)
    13111299        self.writeASCIIsegmentoutline(fd,
    13121300                            self.userVertices,
     
    13691357                            self.holes,
    13701358                            self.regions)   
    1371                
    1372     def writeASCIItrianglulation(self,
    1373                                  fd,
    1374                                  meshVertices,
    1375                                  meshTriangles,
    1376                                  meshSegments):
    1377    
    1378         numVert = str(len(meshVertices))
    1379         if (numVert == "0"):
    1380             numVertAttrib = "0"
    1381         else:
    1382             numVertAttrib = str(len(meshVertices[0].attributes))
    1383         fd.write(numVert + " " + numVertAttrib + " # <vertex #> <x> <y> [attributes] ...Triangulation Vertices..." + "\n")
    1384        
    1385         #<vertex #> <x> <y> [attributes]
    1386         index = 0
    1387         for vert in meshVertices:
    1388             vert.index = index
    1389             index += 1
    1390             attlist = ""
    1391             for att in vert.attributes:
    1392                 attlist = attlist + str(att)+" "
    1393             attlist.strip()
    1394             fd.write(str(vert.index) + " "
    1395                      + str(vert.x) + " "
    1396                      + str(vert.y) + " "
    1397                      + attlist + "\n")
    1398         #<# of triangles>
    1399         fd.write(str(len(meshTriangles)) + " # <triangle #> [<vertex #>] [<neigbouring triangle #>] [attribute of region] ...Triangulation Triangles..." + "\n")
    1400        
    1401         # <triangle #> <vertex #>  <vertex #> <vertex #> <neigbouring triangle #> <neigbouring triangle #> <neigbouring triangle #> [attribute of region]
    1402         for tri in meshTriangles:
    1403             neighbors = ""
    1404 
    1405             for neighbor in tri.neighbors:
    1406                 if neighbor:
    1407                     neighbors += str(neighbor.index) + " "
    1408                 else:
    1409                     neighbors +=  "-1  "
    1410                
    1411             #for att in vert.attributes:
    1412             #    attlist = attlist + str(att)+" "
    1413             fd.write(str(tri.index) + " "
    1414                      + str(tri.vertices[0].index) + " "
    1415                      + str(tri.vertices[1].index) + " "
    1416                      + str(tri.vertices[2].index) + " "
    1417                      + neighbors + " "
    1418                      + str(tri.attribute) + "\n")
    1419            
    1420         #One line:  <# of segments>
    1421         fd.write(str(len(meshSegments)) +
    1422                  " # <segment #> <vertex #>  <vertex #> [boundary marker] ...Triangulation Segments..." + "\n")
    1423        
    1424         #Following lines:  <segment #> <vertex #>  <vertex #> [boundary marker]
    1425         for seg in meshSegments:
    1426             fd.write(str(seg.index) + " "
    1427                      + str(seg.vertices[0].index) + " "
    1428                      + str(seg.vertices[1].index) + " "
    1429                      + str(seg.marker) + "\n")
    1430        
     1359           
    14311360    def exportASCIImeshfile(self,ofile):
    14321361        """
     
    15541483        xya_dict['pointattributelist'] = pointattributes
    15551484
    1556         load_mesh.loadASCII.export_xya_file(ofile, xya_dict, title)
     1485        load_mesh.loadASCII.export_xya_file(ofile, xya_dict, title, delimiter = " ")
    15571486
    15581487
  • inundation/ga/storm_surge/pmesh/meshHarness.py

    r355 r364  
    390390    def test_asciiFile(self):
    391391   
    392         a = Vertex (0.0, 0.0, attributes = [1.1])
    393         d = Vertex (0.0, 4.0, attributes = [1.2])
    394         f = Vertex (4.0,0.0, attributes = [1.3])
    395         e = Vertex (1.0,1.0, attributes = [1.4])
     392        a = Vertex (0.0, 0.0)  #, attributes = [1.1])
     393        d = Vertex (0.0, 4.0)  #, attributes = [1.2])
     394        f = Vertex (4.0,0.0)  #, attributes = [1.3])
     395        e = Vertex (1.0,1.0)  #, attributes = [1.4])
    396396   
    397397        s1 = Segment(a,d)
     
    417417        #    print l,"<"
    418418        #print "@^@^"
    419         self.failUnless(lFile[0] == "5 1 # <vertex #> <x> <y> [attributes] ...Triangulation Vertices..."
     419
     420        self.failUnless(lFile[0] == "5 0 # <vertex #> <x> <y> [attributes] ...Triangulation Vertices..."
    420421                        ,
    421422                        'Ascii file is wrong, vertex title')
    422         self.failUnless(lFile[1] == "0 0.0 0.0 1.1 " and
    423                         lFile[2] == "1 0.0 4.0 1.2 " and
    424                         lFile[3] == "2 4.0 0.0 1.3 " and
    425                         lFile[4] == "3 1.0 1.0 1.4 " and
    426                         lFile[5] == "4 2.0 2.0 1.25 "
     423        self.failUnless(lFile[1] == "0 0.0 0.0 " and #1.1 " and
     424                        lFile[2] == "1 0.0 4.0 " and #1.2 " and
     425                        lFile[3] == "2 4.0 0.0 " and #1.3 " and
     426                        lFile[4] == "3 1.0 1.0 " and #1.4 " and
     427                        lFile[5] == "4 2.0 2.0 "  #1.25 "
    427428                        ,
    428429                        'Ascii file is wrong, vertex')
    429         self.failUnless(lFile[6] == "4 # <triangle #> [<vertex #>] [<neigbouring triangle #>] [attribute of region] ...Triangulation Triangles..." and
    430                         lFile[7] == "0 3 2 4 -1  2 3  " and
    431                         lFile[8] == "1 1 0 3 3 2 -1   " and
    432                         lFile[9] == "2 3 4 1 -1  1 0  " and
    433                         lFile[10] == "3 2 3 0 1 -1  0  "
     430       
     431        self.failUnless(lFile[6] == "# attribute column titles ...Triangulation Vertex Titles..."
     432                        ,
     433                        'Ascii file is wrong, attribute column title')
     434        self.failUnless(lFile[7] == "4 # <triangle #> [<vertex #>] [<neigbouring triangle #>] [attribute of region] ...Triangulation Triangles..." and
     435                        lFile[8] == "0 3 2 4 -1 2 3  " and
     436                        lFile[9] == "1 1 0 3 3 2 -1  " and
     437                        lFile[10] == "2 3 4 1 -1 1 0  " and
     438                        lFile[11] == "3 2 3 0 1 -1 0  "
    434439                        ,
    435440                        'Ascii file is wrong, triangle')
    436441
    437         self.failUnless(lFile[11] == "5 # <segment #> <vertex #>  <vertex #> [boundary marker] ...Triangulation Segments..." and
    438                         lFile[12] == "0 0 1 external" and
    439                         lFile[13] == "1 1 4 external" and
    440                         lFile[14] == "2 2 0 external" and
    441                         lFile[15] == "3 0 3 internal" and
    442                         lFile[16] == "4 4 2 external" ,
     442        self.failUnless(lFile[12] == "5 # <segment #> <vertex #>  <vertex #> [boundary marker] ...Triangulation Segments..." and
     443                        lFile[13] == "0 0 1 external" and
     444                        lFile[14] == "1 1 4 external" and
     445                        lFile[15] == "2 2 0 external" and
     446                        lFile[16] == "3 0 3 internal" and
     447                        lFile[17] == "4 4 2 external" ,
    443448                        'Ascii file is wrong, segment')
    444449       
    445         self.failUnless(lFile[17] == '4 1 # <vertex #> <x> <y> [attributes] ...Mesh Vertices...',
     450        self.failUnless(lFile[18] == '4 0 # <vertex #> <x> <y> [attributes] ...Mesh Vertices...',
    446451                        'Ascii file is wrong, Mesh Vertices Title')
    447452       
    448         self.failUnless(lFile[18] == '0 0.0 0.0 1.1 ' and
    449                         lFile[19] == '1 0.0 4.0 1.2 ' and
    450                         lFile[20] == '2 4.0 0.0 1.3 ' and
    451                         lFile[21] == '3 1.0 1.0 1.4 ',
     453        self.failUnless(lFile[19] == '0 0.0 0.0 ' and #1.1 ' and
     454                        lFile[20] == '1 0.0 4.0 ' and #1.2 ' and
     455                        lFile[21] == '2 4.0 0.0 ' and #1.3 ' and
     456                        lFile[22] == '3 1.0 1.0 ' #1.4 '
     457                        ,
    452458                        'Ascii file is wrong, Mesh Vertices II')
    453459       
    454         self.failUnless(lFile[22] == '4 # <segment #> <vertex #>  <vertex #> [boundary marker] ...Mesh Segments...' and
    455                         lFile[23] == '0 0 1 ' and
    456                         lFile[24] == '1 1 2 ' and
    457                         lFile[25] == '2 0 2 ' and
    458                         lFile[26] == '3 0 3 ' and
    459                         lFile[27] == '0 # <Hole #> <x> <y> ...Mesh Holes...' and
    460                         lFile[28] == '0 # <Region #> <x> <y> <tag>...Mesh Regions...'
     460        self.failUnless(lFile[23] == '4 # <segment #> <vertex #>  <vertex #> [boundary marker] ...Mesh Segments...' and
     461                        lFile[24] == '0 0 1 ' and
     462                        lFile[25] == '1 1 2 ' and
     463                        lFile[26] == '2 0 2 ' and
     464                        lFile[27] == '3 0 3 ' and
     465                        lFile[28] == '0 # <Hole #> <x> <y> ...Mesh Holes...' and
     466                        lFile[29] == '0 # <Region #> <x> <y> <tag>...Mesh Regions...'
    461467                        ,
    462468                        'Ascii file is wrong, Mesh Segments')       
     469
    463470 
    464 
    465471    def test_ascii_file(self):
    466472   
    467         a = Vertex (0.0, 0.0, attributes = [1.1])
    468         d = Vertex (0.0, 4.0, attributes = [1.2])
    469         f = Vertex (4.0,0.0, attributes = [1.3])
    470         e = Vertex (1.0,1.0, attributes = [1.4])
     473        a = Vertex (0.0, 0.0) #, attributes = [1.1])
     474        d = Vertex (0.0, 4.0) #, attributes = [1.2])
     475        f = Vertex (4.0,0.0) #, attributes = [1.3])
     476        e = Vertex (1.0,1.0) #, attributes = [1.4])
    471477   
    472478        s1 = Segment(a,d)
     
    482488       
    483489        fileName = tempfile.mktemp(".txt")
    484         m.export_ASCII_trianglulation_file(fileName)
     490        m.exportASCIItrianglulationfile(fileName)
    485491        file = open(fileName)
    486492        lFile = file.read().split('\n')
     
    488494        os.remove(fileName)
    489495       
    490         print "@^@^"
    491         for l in lFile:
    492             print l,"<"
    493         print "@^@^"
    494         self.failUnless(lFile[0] == "5 1 # <vertex #> <x> <y> [attributes] ...Triangulation Vertices..."
     496        #print "@^@^"
     497        #for l in lFile:
     498        #    print l,"<"
     499        #print "@^@^"
     500        self.failUnless(lFile[0] == "5 0 # <vertex #> <x> <y> [attributes] ...Triangulation Vertices..."
    495501                        ,
    496502                        'Ascii file is wrong, vertex title')
    497         self.failUnless(lFile[1] == "0 0.0 0.0 1.1 " and
    498                         lFile[2] == "1 0.0 4.0 1.2 " and
    499                         lFile[3] == "2 4.0 0.0 1.3 " and
    500                         lFile[4] == "3 1.0 1.0 1.4 " and
    501                         lFile[5] == "4 2.0 2.0 1.25 "
     503        self.failUnless(lFile[1] == "0 0.0 0.0 " and #1.1 " and
     504                        lFile[2] == "1 0.0 4.0 " and #1.2 " and
     505                        lFile[3] == "2 4.0 0.0 " and #1.3 " and
     506                        lFile[4] == "3 1.0 1.0 " and #1.4 " and
     507                        lFile[5] == "4 2.0 2.0 "  #1.25 "
    502508                        ,
    503509                        'Ascii file is wrong, vertex')
    504         self.failUnless(lFile[6] == "4 # <triangle #> [<vertex #>] [<neigbouring triangle #>] [attribute of region] ...Triangulation Triangles..." and
    505                         lFile[7] == "0 3 2 4 -1 2 3  " and
    506                         lFile[8] == "1 1 0 3 3 2 -1  " and
    507                         lFile[9] == "2 3 4 1 -1 1 0  " and
    508                         lFile[10] == "3 2 3 0 1 -1 0  "
     510       
     511        self.failUnless(lFile[6] == "# attribute column titles ...Triangulation Vertex Titles..."
     512                        ,
     513                        'Ascii file is wrong, attribute column title')
     514        self.failUnless(lFile[7] == "4 # <triangle #> [<vertex #>] [<neigbouring triangle #>] [attribute of region] ...Triangulation Triangles..." and
     515                        lFile[8] == "0 3 2 4 -1 2 3  " and
     516                        lFile[9] == "1 1 0 3 3 2 -1  " and
     517                        lFile[10] == "2 3 4 1 -1 1 0  " and
     518                        lFile[11] == "3 2 3 0 1 -1 0  "
    509519                        ,
    510520                        'Ascii file is wrong, triangle')
    511521
    512         self.failUnless(lFile[11] == "5 # <segment #> <vertex #>  <vertex #> [boundary marker] ...Triangulation Segments..." and
    513                         lFile[12] == "0 0 1 external" and
    514                         lFile[13] == "1 1 4 external" and
    515                         lFile[14] == "2 2 0 external" and
    516                         lFile[15] == "3 0 3 internal" and
    517                         lFile[16] == "4 4 2 external" ,
     522        self.failUnless(lFile[12] == "5 # <segment #> <vertex #>  <vertex #> [boundary marker] ...Triangulation Segments..." and
     523                        lFile[13] == "0 0 1 external" and
     524                        lFile[14] == "1 1 4 external" and
     525                        lFile[15] == "2 2 0 external" and
     526                        lFile[16] == "3 0 3 internal" and
     527                        lFile[17] == "4 4 2 external" ,
    518528                        'Ascii file is wrong, segment')
    519529       
    520         self.failUnless(lFile[17] == '4 1 # <vertex #> <x> <y> [attributes] ...Mesh Vertices...',
     530        self.failUnless(lFile[18] == '4 0 # <vertex #> <x> <y> [attributes] ...Mesh Vertices...',
    521531                        'Ascii file is wrong, Mesh Vertices Title')
    522532       
    523         self.failUnless(lFile[18] == '0 0.0 0.0 1.1 ' and
    524                         lFile[19] == '1 0.0 4.0 1.2 ' and
    525                         lFile[20] == '2 4.0 0.0 1.3 ' and
    526                         lFile[21] == '3 1.0 1.0 1.4 ',
     533        self.failUnless(lFile[19] == '0 0.0 0.0 ' and #1.1 ' and
     534                        lFile[20] == '1 0.0 4.0 ' and #1.2 ' and
     535                        lFile[21] == '2 4.0 0.0 ' and #1.3 ' and
     536                        lFile[22] == '3 1.0 1.0 ' #1.4 '
     537                        ,
    527538                        'Ascii file is wrong, Mesh Vertices II')
    528539       
    529         self.failUnless(lFile[22] == '4 # <segment #> <vertex #>  <vertex #> [boundary marker] ...Mesh Segments...' and
    530                         lFile[23] == '0 0 1 ' and
    531                         lFile[24] == '1 1 2 ' and
    532                         lFile[25] == '2 0 2 ' and
    533                         lFile[26] == '3 0 3 ' and
    534                         lFile[27] == '0 # <Hole #> <x> <y> ...Mesh Holes...' and
    535                         lFile[28] == '0 # <Region #> <x> <y> <tag>...Mesh Regions...'
     540        self.failUnless(lFile[23] == '4 # <segment #> <vertex #>  <vertex #> [boundary marker] ...Mesh Segments...' and
     541                        lFile[24] == '0 0 1 ' and
     542                        lFile[25] == '1 1 2 ' and
     543                        lFile[26] == '2 0 2 ' and
     544                        lFile[27] == '3 0 3 ' and
     545                        lFile[28] == '0 # <Hole #> <x> <y> ...Mesh Holes...' and
     546                        lFile[29] == '0 # <Region #> <x> <y> <tag>...Mesh Regions...'
    536547                        ,
    537548                        'Ascii file is wrong, Mesh Segments')       
     
    589600        e_att = [2.0,2.0]
    590601        a_xy = [0.0, 0.0]
    591         a = Vertex ( a_xy[0],a_xy[1], attributes =a_att)
    592         d = Vertex (0.0, 4.0, attributes =d_att)
    593         f = Vertex (4.0,0.0, attributes =f_att)
    594         e = Vertex (1.0,1.0, attributes =e_att)
     602        a = Vertex ( a_xy[0],a_xy[1]) #, attributes =a_att)
     603        d = Vertex (0.0, 4.0) #, attributes =d_att)
     604        f = Vertex (4.0,0.0) #, attributes =f_att)
     605        e = Vertex (1.0,1.0) #, attributes =e_att)
    595606   
    596607        s1 = Segment(a,d, marker = "50")
     
    609620        #print "****************** fileName", fileName
    610621        m.exportASCIItrianglulationfile(fileName)
    611         #print m
     622        print "******************"
     623        print "m", m
     624        print "******************"
    612625        m_returned = importMeshFromFile(fileName)
    613         #print m_returned
     626        print "m_returned",m_returned
     627        print "******************"
    614628        #print "****************** fileName", fileName
    615629        os.remove(fileName)
Note: See TracChangeset for help on using the changeset viewer.