44
55import pickle
66import json
7+ import collections
78
89from copy import deepcopy
910from ast import literal_eval
@@ -619,11 +620,10 @@ def from_vertices_and_faces(cls, vertices, faces):
619620
620621 Parameters
621622 ----------
622- vertices : list
623- A list of vertices, represented by their XYZ coordinates.
624- faces : list
625- A list of faces.
626- Each face is a list of indices referencing the list of vertex coordinates.
623+ vertices : list, dict
624+ A list of vertices, represented by their XYZ coordinates, or a dictionary of vertex keys pointing to their XYZ coordinates.
625+ faces : list, dict
626+ A list of faces, represented by a list of indices referencing the list of vertex coordinates, or a dictionary of face keys pointing to a list of indices referencing the list of vertex coordinates.
627627
628628 Returns
629629 -------
@@ -644,11 +644,21 @@ def from_vertices_and_faces(cls, vertices, faces):
644644
645645 """
646646 mesh = cls ()
647- for vkey , vertex in enumerate (vertices ):
648- x , y , z = vertex
649- mesh .add_vertex (key = vkey , x = x , y = y , z = z )
650- for fkey , face in enumerate (faces ):
651- mesh .add_face (face , fkey = fkey )
647+
648+ if isinstance (vertices , collections .Sequence ):
649+ for x , y , z in iter (vertices ):
650+ mesh .add_vertex (x = x , y = y , z = z )
651+ elif isinstance (vertices , collections .Mapping ):
652+ for key , xyz in vertices .items ():
653+ mesh .add_vertex (key = key , attr_dict = {i : j for i , j in zip (['x' , 'y' , 'z' ], xyz )})
654+
655+ if isinstance (faces , collections .Sequence ):
656+ for face in iter (faces ):
657+ mesh .add_face (face )
658+ elif isinstance (faces , collections .Mapping ):
659+ for fkey , vertices in faces .items ():
660+ mesh .add_face (vertices , fkey )
661+
652662 return mesh
653663
654664 @classmethod
@@ -3169,24 +3179,62 @@ def plot(self,
31693179
31703180 # # mesh.add_face([a, b, c, d, e, f, g, h])
31713181
3172- for k in mesh .faces ():
3173- print (k , mesh .is_face_on_boundary (k ))
3182+ # for k in mesh.faces():
3183+ # print(k, mesh.is_face_on_boundary(k))
31743184
31753185
3176- print (list (mesh .edges (True )))
3186+ # print(list(mesh.edges(True)))
31773187
31783188
3179- plotter = MeshPlotter (mesh )
3189+ # plotter = MeshPlotter(mesh)
31803190
3181- plotter .draw_vertices ()
3182- plotter .draw_edges ()
3183- plotter .draw_faces (text = 'key' )
3184- plotter .show ()
3191+ # plotter.draw_vertices()
3192+ # plotter.draw_edges()
3193+ # plotter.draw_faces(text='key')
3194+ # plotter.show()
31853195
31863196 # print(mesh.get_vertices_attribute('x'))
31873197 # print(mesh.get_vertices_attributes('xy'))
31883198
31893199 # print(mesh.get_edges_attribute('q', 1.0))
31903200 # print(mesh.get_edges_attributes('qf', (1.0, 2.0)))
31913201
3202+ vertices = {
3203+ 0 : [0 , 0 , 0 ],
3204+ 1 : [1 , 1 , 0 ],
3205+ 2 : [1 , - 1 , 0 ],
3206+ 3 : [- 1 , - 1 , 0 ],
3207+ 18 : [- 1 , 1 , 0 ]
3208+ }
3209+ faces = {
3210+ 0 : [0 , 2 , 1 ],
3211+ 45 : [0 , 18 , 3 ]
3212+ }
31923213
3214+ mesh = Mesh .from_vertices_and_faces (vertices , faces )
3215+
3216+ plotter = MeshPlotter (mesh )
3217+ plotter .draw_vertices (text = 'key' )
3218+ plotter .draw_edges ()
3219+ plotter .draw_faces (text = 'key' )
3220+ plotter .show ()
3221+
3222+ vertices = [
3223+ [0 , 0 , 0 ],
3224+ [1 , 1 , 0 ],
3225+ [1 , - 1 , 0 ],
3226+ [- 1 , - 1 , 0 ],
3227+ [- 1 , 1 , 0 ]
3228+ ]
3229+ faces = [
3230+ [0 , 2 , 1 ],
3231+ [0 , 4 , 3 ]
3232+ ]
3233+
3234+ mesh = Mesh .from_vertices_and_faces (vertices , faces )
3235+
3236+ plotter = MeshPlotter (mesh )
3237+ plotter .draw_vertices (text = 'key' )
3238+ plotter .draw_edges ()
3239+ plotter .draw_faces (text = 'key' )
3240+ plotter .show ()
0 commit comments