Skip to content

Commit

Permalink
update docs and examples
Browse files Browse the repository at this point in the history
  • Loading branch information
tomvanmele committed Mar 4, 2024
1 parent fdc0262 commit b7a5067
Show file tree
Hide file tree
Showing 15 changed files with 4,598 additions and 118 deletions.
15 changes: 14 additions & 1 deletion docs/api/compas_bender.bend.rst
Original file line number Diff line number Diff line change
@@ -1,2 +1,15 @@
********************************************************************************
bend
********************************************************************************

.. automodule:: compas_bender.bend
.. currentmodule:: compas_bender.bend


Functions
=========

.. autosummary::
:toctree: generated/
:nosignatures:

bend_splines
15 changes: 14 additions & 1 deletion docs/api/compas_bender.datastructures.rst
Original file line number Diff line number Diff line change
@@ -1,2 +1,15 @@
********************************************************************************
datastructures
********************************************************************************

.. automodule:: compas_bender.datastructures
.. currentmodule:: compas_bender.datastructures


Classes
=======

.. autosummary::
:toctree: generated/
:nosignatures:

BendNetwork
2 changes: 0 additions & 2 deletions docs/api/compas_bender.rhino.rst

This file was deleted.

12 changes: 11 additions & 1 deletion docs/api/compas_bender.rst
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
********************************************************************************
compas_bender
********************************************************************************

.. automodule:: compas_bender
.. currentmodule:: compas_bender


.. toctree::
:maxdepth: 1

compas_bender.bend
compas_bender.datastructures
956 changes: 955 additions & 1 deletion docs/examples/example_arch.json

Large diffs are not rendered by default.

25 changes: 11 additions & 14 deletions docs/examples/example_arch.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@
from math import fabs
from typing import List

from compas_view2.app import App
from compas_view2.objects import Collection
from compas_view2.shapes import Arrow

import compas
from compas.colors import Color
from compas.geometry import Cylinder
from compas.geometry import Vector
from compas.geometry import Polygon
from compas.geometry import Vector
from compas.geometry import sum_vectors
from compas.utilities import remap_values
from compas.colors import Color

from compas_bender.datastructures import BendNetwork
from compas_bender.bend import bend_splines

from compas_view2.app import App
from compas_view2.objects import Collection
from compas_view2.shapes import Arrow
from compas_bender.datastructures import BendNetwork

HERE = os.path.dirname(__file__)
FILE = os.path.join(HERE, "example_arch.json")
Expand Down Expand Up @@ -78,9 +77,7 @@
for node in network.nodes_where(is_anchor=True):
point = network.node_point(node)
nbrs = network.neighbors(node)
edges = [
(node, nbr) if network.has_edge(node, nbr) else (nbr, node) for nbr in nbrs
]
edges = [(node, nbr) if network.has_edge((node, nbr)) else (nbr, node) for nbr in nbrs]
forces = network.edges_attribute("f", keys=edges)
edgevectors: List[Vector] = [network.node_point(nbr) - point for nbr in nbrs]
edgevector = Vector(*sum_vectors(edgevectors))
Expand All @@ -107,7 +104,7 @@
pipes = []
pipe_properties = []
for u, v in spline["edges"]:
edge = (u, v) if network.has_edge(u, v) else (v, u)
edge = (u, v) if network.has_edge((u, v)) else (v, u)
index = edge_index[edge]
# bending moment
ma = Vector(*network.node_attributes(u, ["mx", "my", "mz"]))
Expand All @@ -122,7 +119,7 @@
line = network.edge_line((u, v))
radius = radii[index]
color = Color.red() if force > 0 else Color.blue()
pipe = Cylinder(((line.midpoint, line.direction), radius), line.length)
pipe = Cylinder.from_line_and_radius(line, radius)
pipes.append(pipe)
pipe_properties.append({"facecolor": color})
viewer.add(Collection(pipes, pipe_properties))
Expand All @@ -136,7 +133,7 @@
line = network.edge_line((u, v))
radius = radii[index]
color = Color.red() if force > 0 else Color.blue()
pipe = Cylinder(((line.midpoint, line.direction), radius), line.length)
pipe = Cylinder.from_line_and_radius(line, radius)
pipes.append(pipe)
pipe_properties.append({"facecolor": color})
viewer.add(Collection(pipes, pipe_properties))
Expand Down
35 changes: 17 additions & 18 deletions docs/examples/example_arch_input.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
from __future__ import print_function
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import os
import compas

import compas_rhino
import compas_rhino.objects

import compas
from compas.itertools import pairwise
from compas.tolerance import TOL
from compas_bender.datastructures import BendNetwork
from compas.utilities import geometric_key
from compas.utilities import pairwise

HERE = os.path.dirname(__file__)
FILE = os.path.join(HERE, "example_arch.json")
Expand All @@ -17,32 +19,29 @@
# Input
# ==============================================================================

guids = compas_rhino.get_lines(layer="lines")
lines = compas_rhino.get_line_coordinates(guids)
guids = compas_rhino.objects.get_lines(layer="lines")
lines = compas_rhino.objects.get_line_coordinates(guids)

guids = compas_rhino.get_points(layer="points")
points = compas_rhino.get_point_coordinates(guids)
guids = compas_rhino.objects.get_points(layer="points")
points = compas_rhino.objects.get_point_coordinates(guids)

guids = compas_rhino.get_polylines(layer="splines")
polylines = compas_rhino.get_polyline_coordinates(guids)
guids = compas_rhino.objects.get_polylines(layer="splines")
polylines = compas_rhino.objects.get_polyline_coordinates(guids)

# ==============================================================================
# Network from lines
# ==============================================================================

network = BendNetwork.from_lines(lines)

gkey_key = {
geometric_key(network.node_attributes(node, "xyz")): node
for node in network.nodes()
}
gkey_key = {TOL.geometric_key(network.node_attributes(node, "xyz")): node for node in network.nodes()}

# ==============================================================================
# Identify anchors
# ==============================================================================

for point in points:
gkey = geometric_key(point)
gkey = TOL.geometric_key(point)
if gkey in gkey_key:
key = gkey_key[gkey]
network.node_attribute(key, "is_anchor", True)
Expand All @@ -57,14 +56,14 @@
start = None
edges = []
for a, b in pairwise(polyline):
a_gkey = geometric_key(a)
b_gkey = geometric_key(b)
a_gkey = TOL.geometric_key(a)
b_gkey = TOL.geometric_key(b)
if a_gkey in gkey_key and b_gkey in gkey_key:
u = gkey_key[a_gkey]
v = gkey_key[b_gkey]
if start is None:
start = u
if network.has_edge(u, v):
if network.has_edge((u, v)):
edges.append((u, v))
else:
edges.append((v, u))
Expand Down
Loading

0 comments on commit b7a5067

Please sign in to comment.