22from __future__ import absolute_import
33from __future__ import division
44
5- from numpy import asarray
6- from numpy import meshgrid
7- from numpy import linspace
8- from numpy import amax
9- from numpy import amin
10-
11- from scipy .interpolate import griddata
12- import matplotlib .pyplot as plt
135from compas .numerical import scalarfield_contours
146
157
@@ -35,12 +27,12 @@ def mesh_isolines_numpy(mesh, attr_name, N=50):
3527 Each isoline is a list of paths, and each path is a list polygons.
3628
3729 """
38- xy = [ mesh .vertex_coordinates ( key , "xy" ) for key in mesh . vertices ()]
39- s = [ mesh .vertex [ key ][ attr_name ] for key in mesh . vertices ()]
30+ xy = mesh .vertices_attributes ( "xy" )
31+ s = mesh .vertices_attribute ( attr_name )
4032 return scalarfield_contours (xy , s , N )
4133
4234
43- def mesh_contours_numpy (mesh , levels = 50 , density = 100 ):
35+ def mesh_contours_numpy (mesh , levels = 50 ):
4436 """Compute the contours of the mesh.
4537
4638 Parameters
@@ -49,8 +41,6 @@ def mesh_contours_numpy(mesh, levels=50, density=100):
4941 The mesh object.
5042 levels : int, optional
5143 The number of contours.
52- density : int, optional
53- The density of the interpolation grid.
5444
5545 Returns
5646 -------
@@ -66,34 +56,6 @@ def mesh_contours_numpy(mesh, levels=50, density=100):
6656 The contours are defined as the isolines of the z-coordinates of the vertices of the mesh.
6757
6858 """
69- xy = [mesh .vertex_attributes (key , "xy" ) for key in mesh .vertices ()]
70- z = [mesh .vertex_attribute (key , "z" ) for key in mesh .vertices ()]
71-
72- xy = asarray (xy )
73- z = asarray (z )
74- x = xy [:, 0 ]
75- y = xy [:, 1 ]
76-
77- X , Y = meshgrid (linspace (amin (x ), amax (x ), 2 * density ), linspace (amin (y ), amax (y ), 2 * density ))
78-
79- Z = griddata ((x , y ), z , (X , Y ), method = "cubic" )
80-
81- fig = plt .figure ()
82- ax = fig .add_subplot (111 , aspect = "equal" )
83- c = ax .contour (X , Y , Z , levels )
84-
85- contours = [0 ] * len (c .collections )
86- levels = c .levels
87-
88- for i , coll in enumerate (iter (c .collections )):
89- paths = coll .get_paths ()
90- contours [i ] = [0 ] * len (paths )
91- for j , path in enumerate (iter (paths )):
92- polygons = path .to_polygons ()
93- contours [i ][j ] = [0 ] * len (polygons )
94- for k , polygon in enumerate (iter (polygons )):
95- contours [i ][j ][k ] = polygon
96-
97- plt .close (fig )
98-
99- return levels , contours
59+ xy = mesh .vertices_attributes ("xy" )
60+ z = mesh .vertices_attribute ("z" )
61+ return scalarfield_contours (xy , z , levels )
0 commit comments