Skip to content

Commit e886b20

Browse files
committed
smoothing cpp updates
1 parent 9355a5f commit e886b20

File tree

8 files changed

+56
-54
lines changed

8 files changed

+56
-54
lines changed

src/compas/datastructures/mixins/filters.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ def vertices_where(self, conditions, data=False):
3232
The next vertex that matches the condition.
3333
2-tuple
3434
The next vertex and its attributes, if ``data=True``.
35-
35+
3636
"""
37-
# keys = []
37+
# turn this inside out
3838
for key, attr in self.vertices(True):
3939
is_match = True
4040
for name, value in conditions.items():
@@ -55,8 +55,6 @@ def vertices_where(self, conditions, data=False):
5555
yield key, attr
5656
else:
5757
yield key
58-
# keys.append(key)
59-
# return keys
6058

6159

6260
class EdgeFilter(object):
91.6 KB
Binary file not shown.

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ void smooth_centroid(int v, int *nbrs, int *fixed, double **vertices, int **neig
4747
cz += xyz[n][2];
4848
}
4949

50-
vertices[i][0] = cx / nbrs[i];
51-
vertices[i][1] = cy / nbrs[i];
52-
vertices[i][2] = cz / nbrs[i];
50+
vertices[i][0] = cx / (float)nbrs[i];
51+
vertices[i][1] = cy / (float)nbrs[i];
52+
vertices[i][2] = cz / (float)nbrs[i];
5353
}
5454

5555
func(k);

src/compas/geometry/algorithms/smoothing_cpp.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ def smooth_centroid_cpp(vertices, adjacency, fixed, kmax=100, callback=None, cal
4444
# --------------------------------------------------------------------------
4545
if callback:
4646
assert callable(callback), 'The provided callback is not callable.'
47+
else:
48+
def callback(k, xyz):
49+
pass
4750

4851
v = len(vertices)
4952
nbrs = [len(adjacency[i]) for i in range(v)]
@@ -58,14 +61,7 @@ def smooth_centroid_cpp(vertices, adjacency, fixed, kmax=100, callback=None, cal
5861
c_callback = CFUNCTYPE(None, c_int)
5962

6063
def wrapper(k):
61-
print(k)
62-
63-
xyz = c_vertices.cdata
64-
65-
if k < kmax - 1:
66-
xyz[18][0] = 0.1 * (k + 1)
67-
68-
callback(xyz)
64+
callback(k, c_vertices.cdata)
6965

7066
smoothing.smooth_centroid.argtypes = [
7167
c_int,
@@ -101,6 +97,8 @@ def wrapper(k):
10197
from compas.plotters import MeshPlotter
10298
from compas.geometry import smooth_centroid_cpp
10399

100+
kmax = 50
101+
104102
# make a mesh
105103
# and set the default vertex and edge attributes
106104

@@ -112,13 +110,20 @@ def wrapper(k):
112110
adjacency = [mesh.vertex_neighbours(key) for key in mesh.vertices()]
113111
fixed = [int(mesh.vertex_degree(key) == 2) for key in mesh.vertices()]
114112

113+
slider = list(mesh.vertices_where({'x': (-0.1, 0.1), 'y': (9.9, 10.1)}))[0]
114+
115115
# make a plotter for (dynamic) visualization
116116
# and define a callback function
117117
# for plotting the intermediate configurations
118118

119119
plotter = MeshPlotter(mesh, figsize=(10, 7))
120120

121-
def callback(xyz):
121+
def callback(k, xyz):
122+
print(k)
123+
124+
if k < kmax - 1:
125+
xyz[slider][0] = 0.1 * (k + 1)
126+
122127
plotter.update_vertices()
123128
plotter.update_edges()
124129
plotter.update(pause=0.001)
@@ -152,7 +157,7 @@ def callback(xyz):
152157

153158
# run the smoother
154159

155-
xyz = smooth_centroid_cpp(vertices, adjacency, fixed, kmax=50, callback=callback)
160+
xyz = smooth_centroid_cpp(vertices, adjacency, fixed, kmax=kmax, callback=callback)
156161

157162
# keep the plot alive
158163

src/compas_rhino/cameras/__init__.py

Whitespace-only changes.

src/compas_rhino/conduits/lines.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,15 @@ class LinesConduit(Conduit):
6262
del conduit
6363
6464
"""
65-
def __init__(self, lines, thickness=1.0, color=None, **kwargs):
65+
def __init__(self, lines=None, thickness=1.0, color=None, **kwargs):
6666
super(LinesConduit, self).__init__(**kwargs)
67-
self.lines = lines
68-
self.n = len(lines)
67+
self.lines = lines or []
6968
self.thickness = thickness
7069
color = color or (255, 255, 255)
7170
self.color = FromArgb(*color)
7271

7372
def DrawForeground(self, e):
74-
lines = List[Line](self.n)
73+
lines = List[Line](len(self.lines))
7574
for start, end in self.lines:
7675
lines.Add(Line(Point3d(*start), Point3d(*end)))
7776
e.Display.DrawLines(lines, self.color, self.thickness)

src/compas_rhino/conduits/points.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626

2727
class PointsConduit(Conduit):
2828
""""""
29-
def __init__(self, points, radius=3, color=None, **kwargs):
29+
def __init__(self, points=None, radius=3, color=None, **kwargs):
3030
super(PointsConduit, self).__init__(**kwargs)
31-
self.points = points
32-
self.n = len(points)
31+
self.points = points or []
32+
self.n = len(self.points)
3333
self.radius = radius
3434
color = color or (255, 0, 0)
3535
self.color = FromArgb(*color)

src/compas_rhino/utilities/misc.py

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -79,36 +79,36 @@ def screenshot_current_view(path,
7979
return result
8080

8181

82-
def add_gui_helpers(helpers, overwrite=False, protected=False):
83-
def decorate(cls):
84-
# attr = {}
85-
for helper in helpers:
86-
# for name, value in helper.__dict__.items():
87-
for name, value in inspect.getmembers(helper):
88-
# magic methods
89-
if name.startswith('__') and name.endswith('__'):
90-
continue
91-
# protected / private methods
92-
if not protected and name.startswith('_'):
93-
continue
94-
# existing methods
95-
if not overwrite:
96-
if hasattr(cls, name):
97-
continue
98-
# attr[name] = value
99-
# try:
100-
# setattr(cls, name, value.__func__)
101-
# except:
102-
# setattr(cls, name, value)
103-
# inspect.ismethoddescriptor
104-
# inspect.isdatadescriptor
105-
if inspect.ismethod(value):
106-
setattr(cls, name, value.__func__)
107-
else:
108-
setattr(cls, name, value)
109-
# cls = type(cls.__name__, (cls, ), attr)
110-
return cls
111-
return decorate
82+
# def add_gui_helpers(helpers, overwrite=False, protected=False):
83+
# def decorate(cls):
84+
# # attr = {}
85+
# for helper in helpers:
86+
# # for name, value in helper.__dict__.items():
87+
# for name, value in inspect.getmembers(helper):
88+
# # magic methods
89+
# if name.startswith('__') and name.endswith('__'):
90+
# continue
91+
# # protected / private methods
92+
# if not protected and name.startswith('_'):
93+
# continue
94+
# # existing methods
95+
# if not overwrite:
96+
# if hasattr(cls, name):
97+
# continue
98+
# # attr[name] = value
99+
# # try:
100+
# # setattr(cls, name, value.__func__)
101+
# # except:
102+
# # setattr(cls, name, value)
103+
# # inspect.ismethoddescriptor
104+
# # inspect.isdatadescriptor
105+
# if inspect.ismethod(value):
106+
# setattr(cls, name, value.__func__)
107+
# else:
108+
# setattr(cls, name, value)
109+
# # cls = type(cls.__name__, (cls, ), attr)
110+
# return cls
111+
# return decorate
112112

113113

114114
def wait():

0 commit comments

Comments
 (0)