Skip to content

Commit

Permalink
temp update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
tomvanmele committed May 14, 2024
1 parent 031ac6b commit 47e3199
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 80 deletions.
4 changes: 2 additions & 2 deletions notebooks/test_blockmodel.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@
"# for element in model.elements():\n",
"# viewer.scene.add(element.geometry, color=Color.from_hex('#cccccc'), show_faces=False, show_edges=True)\n",
"\n",
"for polygon in interfaces:\n",
" viewer.scene.add(polygon, color=Color.red())\n",
"# for polygon in interfaces:\n",
"# viewer.scene.add(polygon, color=Color.red())\n",
"\n",
"viewer.show()"
]
Expand Down
1 change: 1 addition & 0 deletions scripts/blockmodel_arch.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions scripts/crossvault_meshes.json

Large diffs are not rendered by default.

34 changes: 10 additions & 24 deletions scripts/fea_beam.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@
from compas_fea2.problem import FieldOutput
from compas_fea2.problem import LoadCombination
from compas_fea2.units import units

# from compas_viewer import Viewer
# from compas_viewer.components.renderer.camera import Position
from compas_viewer import Viewer
from compas_viewer.components.renderer.camera import Position

compas_fea2.set_backend("compas_fea2_opensees")

Expand Down Expand Up @@ -46,7 +45,6 @@

model.add_part(part)
model.add_fix_bc(nodes=nodes[:1])
# model.add_pin_bc(nodes=[nodes[0], nodes[-1]])

# model.summary()
# model.show(draw_bcs=0.1)
Expand All @@ -66,9 +64,6 @@

step = problem.steps_order[-1]

# problem.show()
# problem.show_deformed(step, scale_factor=1, original=0)

lines = []
for result in problem.displacement_field.results(step):
# print(result.u1)
Expand All @@ -79,21 +74,12 @@
lines.append(Line.from_point_and_vector(result.location.point, result.vector * 10))


# viewer = Viewer()
# viewer.renderer.camera.near = 1e0
# viewer.renderer.camera.far = 1e5
# viewer.renderer.camera.pan_delta = 100
# viewer.renderer.camera.position = Position((5000, -5000, 5000))
# viewer.renderer.camera.target = Position((5000, 2000, 0))
# viewer.renderer.config.gridsize = (20000, 20, 20000, 20)

# for element in part.elements:
# # print(element.shape)
# # print(element.volume)
# # print(element.weight)
# viewer.scene.add(element.shape)

# for line in lines:
# viewer.scene.add(line)
viewer = Viewer()
viewer.renderer.camera.near = 1e0
viewer.renderer.camera.far = 1e5
viewer.renderer.camera.pan_delta = 100
viewer.renderer.camera.position = Position((5000, -5000, 5000))
viewer.renderer.camera.target = Position((5000, 2000, 0))
viewer.renderer.config.gridsize = (20000, 20, 20000, 20)

# viewer.show()
viewer.show()
15 changes: 9 additions & 6 deletions scripts/test_blockmodel_arch.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import pathlib

import compas
from compas.colors import Color
from compas_assembly.geometry import Arch
Expand Down Expand Up @@ -40,7 +42,8 @@
# Export
# =============================================================================

compas.json_dump(model, "test.json")
here = pathlib.Path(__file__).parent
compas.json_dump(model, here / "blockmodel_arch.json")

# =============================================================================
# Viz
Expand All @@ -58,7 +61,7 @@
color = Color(0.8, 0.8, 0.8)
show_faces = False

viewer.scene.add(element.geometry, show_points=False, show_faces=show_faces, facecolor=color, linecolor=color.contrast)
viewer.scene.add(element.geometry, show_points=False, show_faces=show_faces, facecolor=color)

for interaction in model.interactions():
interaction: ContactInterface
Expand All @@ -71,31 +74,31 @@
for line in interaction.compressionforces:
viewer.scene.add(
line,
lineswidth=3,
linewidth=3,
linecolor=Color.blue(),
show_points=False,
)

for line in interaction.tensionforces:
viewer.scene.add(
line,
lineswidth=3,
linewidth=3,
linecolor=Color.red(),
show_points=False,
)

for line in interaction.frictionforces:
viewer.scene.add(
line,
lineswidth=3,
linewidth=3,
linecolor=Color.cyan(),
show_points=False,
)

for line in interaction.resultantforce:
viewer.scene.add(
line,
lineswidth=5,
linewidth=5,
linecolor=Color.green(),
show_points=False,
)
Expand Down
8 changes: 6 additions & 2 deletions scripts/test_blockmodel_arch_load.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import pathlib

import compas
from compas_model.models import Model
from compas_model.viewers import BlockModelViewer

model: Model = compas.json_load("test.json")
here = pathlib.Path(__file__).parent
model: Model = compas.json_load(here / "blockmodel_arch.json")

viewer = BlockModelViewer(model)
viewer = BlockModelViewer()
viewer.add(model, show_blockfaces=False, show_interfaces=True, show_contactforces=True)
viewer.show()
14 changes: 12 additions & 2 deletions scripts/test_blockmodel_vault.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pathlib

import compas
from compas.datastructures import Mesh
from compas.files import OBJ
from compas.geometry import Scale
Expand All @@ -21,6 +22,7 @@
for name in obj.objects: # type: ignore
vertices, faces = obj.objects[name] # type: ignore
mesh = Mesh.from_vertices_and_faces(vertices, faces)
mesh.transform(Scale.from_factors([0.025, 0.025, 0.025]))
mesh.name = name
meshes.append(mesh)

Expand All @@ -34,7 +36,7 @@
block = BlockElement(shape=mesh)
model.add_element(block)

model.transform(Scale.from_factors([0.025, 0.025, 0.025]))
# model.transform(Scale.from_factors([0.025, 0.025, 0.025]))

# =============================================================================
# Compute interfaces
Expand All @@ -52,9 +54,17 @@
element: BlockElement
element.is_support = True

# =============================================================================
# Export
# =============================================================================

here = pathlib.Path(__file__).parent
compas.json_dump(meshes, here / "crossvault_meshes.json")

# =============================================================================
# Visualisation
# =============================================================================

viewer = BlockModelViewer(model, show_blockfaces=False, show_interfaces=True)
viewer = BlockModelViewer()
viewer.add(model, show_blockfaces=False, show_interfaces=True)
viewer.show()
137 changes: 93 additions & 44 deletions src/compas_model/viewers/blockmodelviewer.py
Original file line number Diff line number Diff line change
@@ -1,67 +1,116 @@
from compas.colors import Color
from compas.datastructures import Mesh
from compas.geometry import Line
from compas_viewer import Viewer

from compas_model.elements import BlockElement
from compas_model.elements import BlockGeometry
from compas_model.interactions import ContactInterface
from compas_model.models import Model


class BlockModelViewer:
def __init__(self, blockmodel: Model, show_blockfaces=True, show_interfaces=False, show_contactforces=False):
self.viewer = Viewer()
self.add(blockmodel, show_blockfaces=show_blockfaces, show_interfaces=show_interfaces, show_contactforces=show_contactforces)
class BlockModelViewer(Viewer):
def add(self, blockmodel: Model, show_blockfaces=True, show_interfaces=False, show_contactforces=False):
color_support: Color = Color.red().lightened(50)
color_interface: Color = Color(0.9, 0.9, 0.9)

def show(self):
self.viewer.show()
# add blocks and supports

supports: list[BlockGeometry] = []
blocks: list[BlockGeometry] = []

def add(self, blockmodel: Model, show_blockfaces, show_interfaces, show_contactforces):
for element in blockmodel.elements():
element: BlockElement

if element.is_support:
color: Color = Color.red().lightened(50)
show_faces = True
supports.append(
(
element.geometry,
{
"name": f"Support_{len(supports)}",
"show_points": False,
"show_faces": True,
"facecolor": color_support,
"linecolor": color_support.contrast,
},
)
)
else:
color = Color(0.9, 0.9, 0.9)
show_faces = show_blockfaces
blocks.append(
(
element.geometry,
{
"name": f"Block_{len(blocks)}",
"show_points": False,
"show_faces": False,
"facecolor": color_support,
"linecolor": Color(0.3, 0.3, 0.3),
},
)
)

self.scene.add(
supports,
name="Supports",
)
self.scene.add(
blocks,
name="Blocks",
)

# add interfaces and interface forces

self.viewer.scene.add(element.geometry, show_points=False, show_faces=show_faces, facecolor=color, linecolor=color.contrast)
interfaces: list[Mesh] = []
compressionforces: list[Line] = []
tensionforces: list[Line] = []
frictionforces: list[Line] = []
resultantforces: list[Line] = []

for interaction in blockmodel.interactions():
interaction: ContactInterface

if show_interfaces:
self.viewer.scene.add(interaction.mesh, show_points=False, facecolor=Color(0.9, 0.9, 0.9))
interfaces.append(interaction.mesh)

if show_contactforces:
for line in interaction.compressionforces:
self.viewer.scene.add(
line,
lineswidth=3,
linecolor=Color.blue(),
show_points=False,
)
compressionforces += interaction.compressionforces
tensionforces += interaction.tensionforces
frictionforces += interaction.frictionforces
resultantforces += interaction.resultantforce

for line in interaction.tensionforces:
self.viewer.scene.add(
line,
lineswidth=3,
linecolor=Color.red(),
show_points=False,
)
if show_interfaces:
self.scene.add(
interfaces,
name="Interfaces",
show_points=False,
facecolor=color_interface,
linecolor=color_interface.contrast,
)

for line in interaction.frictionforces:
self.viewer.scene.add(
line,
lineswidth=3,
linecolor=Color.cyan(),
show_points=False,
)

for line in interaction.resultantforce:
self.viewer.scene.add(
line,
lineswidth=5,
linecolor=Color.green(),
show_points=False,
)
if show_contactforces:
self.scene.add(
compressionforces,
name="Compression",
linewidth=3,
linecolor=Color.blue(),
show_points=False,
)
self.scene.add(
tensionforces,
name="Tension",
linewidth=3,
linecolor=Color.red(),
show_points=False,
)
self.scene.add(
frictionforces,
name="Friction",
linewidth=3,
linecolor=Color.cyan(),
show_points=False,
)
self.scene.add(
resultantforces,
name="Resultants",
linewidth=5,
linecolor=Color.green(),
show_points=False,
)

0 comments on commit 47e3199

Please sign in to comment.