Skip to content

Commit 9355a5f

Browse files
committed
simplification of the cpp smoothing
1 parent 8987646 commit 9355a5f

File tree

3 files changed

+19
-29
lines changed

3 files changed

+19
-29
lines changed

src/compas/geometry/algorithms/_smoothing_cpp/src/main.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,17 @@ using namespace std;
77

88
extern "C"
99
{
10-
typedef void callback_smoothing(int k);
10+
typedef void callback(int k);
1111

12-
void smooth_centroid(int v, int *nbrs, int *fixed, double **vertices, int **neighbours, int kmax, callback_smoothing func);
12+
void smooth_centroid(int v, int *nbrs, int *fixed, double **vertices, int **neighbours, int kmax, callback func);
1313
}
1414

15-
void smooth_centroid(int v, int *nbrs, int *fixed, double **vertices, int **neighbours, int kmax, callback_smoothing func)
15+
void smooth_centroid(int v, int *nbrs, int *fixed, double **vertices, int **neighbours, int kmax, callback func)
1616
{
1717
int k;
1818
int i;
1919
int j, n;
2020
double cx, cy, cz;
21-
double c;
2221

2322
vector< vector<double> > xyz(v, vector<double>(3, 0.0));
2423

src/compas/geometry/algorithms/smoothing_cpp.py

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -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()

src/compas/hpc/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
.. autosummary::
2929
:toctree: generated/
3030
31-
sum_vectors_numba
3231
norm_vector_numba
3332
norm_vectors_numba
3433
length_vector_numba

0 commit comments

Comments
 (0)