@@ -31,10 +31,10 @@ def smooth_centroid_cpp(vertices, adjacency, fixed, kmax=100, callback=None, cal
3131 """
3232 """
3333 try :
34- smooth_centroid = ctypes .cdll .LoadLibrary (SO )
34+ smoothing = ctypes .cdll .LoadLibrary (SO )
3535 except Exception :
3636 try :
37- smooth_centroid = ctypes .cdll .LoadLibrary (DLL )
37+ smoothing = ctypes .cdll .LoadLibrary (DLL )
3838 except Exception :
3939 print (SO )
4040 print (DLL )
@@ -48,7 +48,6 @@ def smooth_centroid_cpp(vertices, adjacency, fixed, kmax=100, callback=None, cal
4848 v = len (vertices )
4949 nbrs = [len (adjacency [i ]) for i in range (v )]
5050 neighbours = [adjacency [i ] + [0 ] * (10 - nbrs [i ]) for i in range (v )]
51- fixed = [i in fixed for i in range (v )]
5251 # --------------------------------------------------------------------------
5352 # call
5453 # --------------------------------------------------------------------------
@@ -60,11 +59,15 @@ def smooth_centroid_cpp(vertices, adjacency, fixed, kmax=100, callback=None, cal
6059
6160 def wrapper (k ):
6261 print (k )
62+
63+ xyz = c_vertices .cdata
64+
6365 if k < kmax - 1 :
64- c_vertices .cdata [18 ][0 ] = 0.1 * (k + 1 )
65- callback (c_vertices .pydata )
66+ xyz [18 ][0 ] = 0.1 * (k + 1 )
6667
67- smooth_centroid .smooth_centroid .argtypes = [
68+ callback (xyz )
69+
70+ smoothing .smooth_centroid .argtypes = [
6871 c_int ,
6972 c_nbrs .ctype ,
7073 c_fixed .ctype ,
@@ -74,7 +77,7 @@ def wrapper(k):
7477 c_callback
7578 ]
7679
77- smooth_centroid .smooth_centroid (
80+ smoothing .smooth_centroid (
7881 c_int (v ),
7982 c_nbrs .cdata ,
8083 c_fixed .cdata ,
@@ -103,22 +106,11 @@ def wrapper(k):
103106
104107 mesh = Mesh .from_obj (compas .get ('faces.obj' ))
105108
106- dva = {'is_fixed' : False , }
107-
108- mesh .update_default_vertex_attributes (dva )
109-
110- # identify the fixed vertices
111- # and assign random prescribed force densities to the edges
112-
113- for key , attr in mesh .vertices (True ):
114- attr ['is_fixed' ] = mesh .vertex_degree (key ) == 2
115-
116109 # extract numerical data from the datastructure
117110
118111 vertices = mesh .get_vertices_attributes (('x' , 'y' , 'z' ))
119- edges = list (mesh .edges ())
120- fixed = list (mesh .vertices_where ({'is_fixed' : True }))
121112 adjacency = [mesh .vertex_neighbours (key ) for key in mesh .vertices ()]
113+ fixed = [int (mesh .vertex_degree (key ) == 2 ) for key in mesh .vertices ()]
122114
123115 # make a plotter for (dynamic) visualization
124116 # and define a callback function
@@ -150,18 +142,18 @@ def callback(xyz):
150142
151143 plotter .draw_lines (lines )
152144
153- # # draw the vertices and edges in the starting configuration
154- # # and pause for a second before starting the dynamic visualization
145+ # draw the vertices and edges in the starting configuration
146+ # and pause for a second before starting the dynamic visualization
155147
156- plotter .draw_vertices (facecolor = {key : '#000000' for key in mesh .vertices_where ({ 'is_fixed' : True }) })
148+ plotter .draw_vertices (facecolor = {key : '#000000' for key in mesh .vertices () if mesh . vertex_degree ( key ) == 2 })
157149 plotter .draw_edges ()
158150
159151 plotter .update (pause = 0.5 )
160152
161- # run the dynamic relaxation
153+ # run the smoother
162154
163155 xyz = smooth_centroid_cpp (vertices , adjacency , fixed , kmax = 50 , callback = callback )
164156
165- # # visualize the final geometry
157+ # keep the plot alive
166158
167159 plotter .show ()
0 commit comments