Skip to content

Commit c4d2b7c

Browse files
author
andrewtliew
committed
Merge remote-tracking branch 'origin/master'
2 parents fadbbde + a983f42 commit c4d2b7c

File tree

19 files changed

+1054
-659
lines changed

19 files changed

+1054
-659
lines changed

src/compas/datastructures/network/network.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
from compas.datastructures.network.operations import network_split_edge
3333

34-
# from compas.topology import bfs_traverse
34+
# from compas.topology import breadth_first_traverse
3535

3636

3737
__author__ = 'Tom Van Mele'
@@ -517,7 +517,7 @@ def number_of_halfedges(self):
517517
# return False
518518

519519
# root = self.get_any_vertex()
520-
# nodes = bfs_traverse(self.halfedge, root)
520+
# nodes = breadth_first_traverse(self.halfedge, root)
521521

522522
# return len(nodes) == self.number_of_vertices()
523523

src/compas/geometry/__init__.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@
5353
.. autosummary::
5454
:toctree: generated/
5555
56-
aabb
57-
aabb_xy
58-
obb_numpy
59-
obb_xy_numpy
56+
bounding_box
57+
bounding_box_xy
58+
oriented_bounding_box_numpy
59+
oriented_bounding_box_xy_numpy
6060
6161
**fitting**
6262
@@ -89,9 +89,9 @@
8989
.. autosummary::
9090
:toctree: generated/
9191
92-
scalarfield_contours
93-
mesh_contours
94-
mesh_isolines
92+
scalarfield_contours_numpy
93+
mesh_contours_numpy
94+
mesh_isolines_numpy
9595
9696
**parallelisation**
9797

src/compas/geometry/algorithms/bbox.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010

1111

1212
__all__ = [
13-
'aabb',
14-
'aabb_xy',
15-
'obb_numpy',
16-
'obb_xy_numpy',
13+
'bounding_box',
14+
'bounding_box_xy',
15+
'oriented_bounding_box_numpy',
16+
'oriented_bounding_box_xy_numpy',
1717
]
1818

1919

20-
def aabb(points):
20+
def bounding_box(points):
2121
"""Computes the axis-aligned minimum bounding box of a list of points.
2222
2323
Parameters
@@ -54,7 +54,7 @@ def aabb(points):
5454
(min_x, max_y, max_z)]
5555

5656

57-
def aabb_xy(points):
57+
def bounding_box_xy(points):
5858
"""Compute the axis-aligned minimum bounding box of a list of points in the XY-plane.
5959
6060
Note
@@ -89,7 +89,7 @@ def aabb_xy(points):
8989
(min_x, max_y, 0.0)]
9090

9191

92-
def obb_numpy(points):
92+
def oriented_bounding_box_numpy(points):
9393
"""Compute the oriented minimum bounding box of a set of points in 3D space.
9494
9595
Note
@@ -122,7 +122,7 @@ def obb_numpy(points):
122122
from compas.plotters import create_axes_3d
123123
from compas.geometry import rotation_matrix
124124
from compas.geometry import transform
125-
from compas.geometry import obb_numpy
125+
from compas.geometry import oriented_bounding_box_numpy
126126
127127
clouds = []
128128
@@ -167,7 +167,7 @@ def obb_numpy(points):
167167
bounds.plot(axes)
168168
169169
for cloud in clouds:
170-
bbox = obb_numpy(cloud)
170+
bbox = oriented_bounding_box_numpy(cloud)
171171
172172
Cloud3D(cloud).plot(axes)
173173
Box(bbox[1]).plot(axes)
@@ -224,7 +224,7 @@ def obb_numpy(points):
224224
return hull, bbox, volume
225225

226226

227-
def obb_xy_numpy(points):
227+
def oriented_bounding_box_xy_numpy(points):
228228
"""Compute the oriented minimum bounding box of set of points in the XY plane.
229229
230230
Note

src/compas/geometry/algorithms/isolines.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010

1111

1212
__all__ = [
13-
'scalarfield_contours',
14-
'mesh_contours',
15-
'mesh_isolines',
13+
'scalarfield_contours_numpy',
14+
'mesh_contours_numpy',
15+
'mesh_isolines_numpy',
1616
]
1717

1818

@@ -32,7 +32,7 @@
3232
# ==============================================================================
3333

3434

35-
def scalarfield_contours(xy, s, N=50):
35+
def scalarfield_contours_numpy(xy, s, N=50):
3636
r"""Compute the contour lines of a scalarfield.
3737
3838
Note
@@ -67,7 +67,7 @@ def scalarfield_contours(xy, s, N=50):
6767
from compas.datastructures import Mesh
6868
from compas.geometry import centroid_points
6969
from compas.geometry import distance_point_point
70-
from compas.geometry import scalarfield_contours
70+
from compas.geometry import scalarfield_contours_numpy
7171
7272
mesh = Mesh.from_obj(compas.get('faces.obj'))
7373
@@ -77,7 +77,7 @@ def scalarfield_contours(xy, s, N=50):
7777
7878
xy = [point[0:2] for point in points]
7979
80-
levels, contours = scalarfield_contours(xy, distances)
80+
levels, contours = scalarfield_contours_numpy(xy, distances)
8181
8282
for i in range(len(contours)):
8383
level = levels[i]
@@ -121,7 +121,7 @@ def scalarfield_contours(xy, s, N=50):
121121
return levels, contours
122122

123123

124-
def mesh_contours(mesh, N=50):
124+
def mesh_contours_numpy(mesh, N=50):
125125
"""Compute the contours of the mesh.
126126
127127
Note
@@ -151,18 +151,18 @@ def mesh_contours(mesh, N=50):
151151
152152
import compas
153153
from compas.datastructures import Mesh
154-
from compas.geometry import mesh_contours
154+
from compas.geometry import mesh_contours_numpy
155155
156156
mesh = Mesh.from_obj(compas.get('hypar.obj'))
157-
print(mesh_contours(mesh))
157+
print(mesh_contours_numpy(mesh))
158158
159159
"""
160160
xy = [mesh.vertex_coordinates(key, 'xy') for key in mesh.vertices()]
161161
z = [mesh.vertex_coordinates(key, 'z') for key in mesh.vertices()]
162162
return scalarfield_contours(xy, z, N)
163163

164164

165-
def mesh_isolines(mesh, attr_name, N=50):
165+
def mesh_isolines_numpy(mesh, attr_name, N=50):
166166
"""Compute the isolines of a specified attribute of the vertices of a mesh.
167167
168168
Parameters

src/compas/hpc/numba/drx.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
from scipy.sparse import find
1414

1515
from compas.numerical import uvw_lengths
16-
from compas.numerical.algorithms.drx import _beam_data
17-
from compas.numerical.algorithms.drx import _create_arrays
16+
from compas.numerical.algorithms.drx_numpy import _beam_data
17+
from compas.numerical.algorithms.drx_numpy import _create_arrays
1818

1919
from compas.hpc.numba.geometry import numba_cross
2020
from compas.hpc.numba.geometry import numba_vdot

src/compas/numerical/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
1717
dr
1818
dr_numpy
19-
drx
19+
drx_numpy
2020
fd_numpy
2121
pca_numpy
2222

src/compas/numerical/algorithms/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
from .dr import *
22
from .dr_numpy import *
3-
from .drx import *
3+
from .drx_numpy import *
44
from .fd_numpy import *
55
from .pca_numpy import *
66

77
from .dr import __all__ as a
88
from .dr_numpy import __all__ as b
9-
from .drx import __all__ as c
9+
from .drx_numpy import __all__ as c
1010
from .fd_numpy import __all__ as d
1111
from .pca_numpy import __all__ as e
1212

src/compas/numerical/algorithms/dr.py

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,13 @@ def dr(vertices, edges, fixed, loads, qpre, fpre, lpre, linit, E, radius,
8383
import compas
8484
from compas.datastructures import Network
8585
from compas.plotters import NetworkPlotter
86-
from compas.numerical import dr
8786
from compas.utilities import i_to_rgb
87+
from compas.numerical import dr
88+
89+
# make a network
90+
# and set the default vertex and edge attributes
91+
92+
network = Network.from_obj(compas.get('lines.obj'))
8893
8994
dva = {
9095
'is_fixed': False,
@@ -108,22 +113,23 @@ def dr(vertices, edges, fixed, loads, qpre, fpre, lpre, linit, E, radius,
108113
'radius': 0.0,
109114
}
110115
111-
network = Network.from_obj(compas.get('lines.obj'))
112-
113116
network.update_default_vertex_attributes(dva)
114117
network.update_default_edge_attributes(dea)
115118
119+
# identify the fixed vertices
120+
# and assign random prescribed force densities to the edges
121+
116122
for key, attr in network.vertices(True):
117123
attr['is_fixed'] = network.vertex_degree(key) == 1
118124
119125
for u, v, attr in network.edges(True):
120126
attr['qpre'] = 1.0 * random.randint(1, 7)
121127
122-
k_i = network.key_index()
128+
# extract numerical data from the datastructure
123129
124130
vertices = network.get_vertices_attributes(('x', 'y', 'z'))
125-
edges = [(k_i[u], k_i[v]) for u, v in network.edges()]
126-
fixed = [k_i[key] for key in network.vertices_where({'is_fixed': True})]
131+
edges = list(network.edges())
132+
fixed = network.vertices_where({'is_fixed': True})
127133
loads = network.get_vertices_attributes(('px', 'py', 'pz'))
128134
qpre = network.get_edges_attribute('qpre')
129135
fpre = network.get_edges_attribute('fpre')
@@ -132,6 +138,11 @@ def dr(vertices, edges, fixed, loads, qpre, fpre, lpre, linit, E, radius,
132138
E = network.get_edges_attribute('E')
133139
radius = network.get_edges_attribute('radius')
134140
141+
# make a plotter for (dynamic) visualization
142+
# plot the lines of the original configuration of the network as reference
143+
144+
plotter = NetworkPlotter(network)
145+
135146
lines = []
136147
for u, v in network.edges():
137148
lines.append({
@@ -141,26 +152,31 @@ def dr(vertices, edges, fixed, loads, qpre, fpre, lpre, linit, E, radius,
141152
'width': 0.5
142153
})
143154
144-
plotter = NetworkPlotter(network)
145155
plotter.draw_lines(lines)
146156
147-
xyz, q, f, l, r = dr(vertices, edges, fixed, loads,
148-
qpre, fpre, lpre,
149-
linit, E, radius,
157+
# run the dynamic relaxation
158+
# update vertices and edges
159+
# visualize the final geometry
160+
# color the edges according to the size of the forces
161+
# set the width of the edges proportional to the internal forces
162+
163+
xyz, q, f, l, r = dr(vertices, edges, fixed, loads, qpre, fpre, lpre, linit, E, radius,
150164
kmax=100)
151165
152166
for key, attr in network.vertices(True):
153-
index = k_i[key]
154-
attr['x'] = xyz[index][0]
155-
attr['y'] = xyz[index][1]
156-
attr['z'] = xyz[index][2]
167+
attr['x'] = xyz[key][0]
168+
attr['y'] = xyz[key][1]
169+
attr['z'] = xyz[key][2]
157170
158171
for index, (u, v, attr) in enumerate(network.edges(True)):
159172
attr['f'] = f[index]
160173
attr['l'] = l[index]
161174
162175
fmax = max(network.get_edges_attribute('f'))
163176
177+
plotter.clear_vertices()
178+
plotter.clear_edges()
179+
164180
plotter.draw_vertices(
165181
facecolor={key: '#000000' for key in network.vertices_where({'is_fixed': True})}
166182
)

0 commit comments

Comments
 (0)