Skip to content

Commit

Permalink
working on the mesh tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
tomvanmele committed Dec 21, 2023
1 parent 5dc2443 commit 168f084
Show file tree
Hide file tree
Showing 6 changed files with 237 additions and 17 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
125 changes: 125 additions & 0 deletions docs/userguide/basics.datastructures.meshes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
# type: ignore

# import compas
from compas.datastructures import Mesh
from compas_view2.app import App
from compas.colors import Color
from compas.geometry import Circle
from compas_view2.objects import Text

# mesh = Mesh.from_obj(compas.get("tubemesh.obj"))

# viewer = App(width=1600, height=900)
# viewer.add(mesh)
# viewer.view.camera.position = [1, -6, 1.5]
# viewer.view.camera.look_at([1, 0, 1])
# viewer.run()

# mesh = Mesh.from_meshgrid(dx=9, nx=9)

# viewer = App(viewport="top", width=1600, height=900)

# viewer.add(mesh)
# for vertex in range(30, 40):
# color = (1.0, 0.0, 0.0) if mesh.is_vertex_on_boundary(vertex) else (0.0, 0.0, 0.0)
# viewer.add(mesh.vertex_point(vertex), pointsize=20, pointcolor=color)

# viewer.view.camera.zoom_extents()
# viewer.view.camera.distance = 11
# viewer.run()

# mesh = Mesh.from_meshgrid(dx=9, nx=9)

# viewer = App(viewport="top", width=1600, height=900)

# red = Color.red()

# viewer.add(mesh, facecolor=(0.95, 0.95, 0.95), linewidth=2)
# viewer.add(
# Circle.from_point_and_radius(mesh.vertex_point(23) + [0, 0, 0.1], 0.1).to_polygon(100),
# facecolor=(1.0, 1.0, 1.0),
# linecolor=(0.0, 0.0, 0.0),
# linewidth=2,
# )

# for i, nbr in enumerate(mesh.vertex_neighbors(23, True)):
# print(nbr)
# viewer.add(
# Circle.from_point_and_radius(mesh.vertex_point(nbr) + [0, 0, 0.1], 0.2).to_polygon(100),
# facecolor=red.lightened(50),
# linecolor=red,
# )
# viewer.add(
# Text(
# str(i),
# mesh.vertex_point(nbr) + [0.09, -0.075, 0.1],
# height=50,
# )
# )

# viewer.view.camera.zoom_extents()
# viewer.view.camera.distance = 11
# viewer.run()

# mesh = Mesh.from_meshgrid(dx=9, nx=9)

# viewer = App(viewport="top", width=1600, height=900)

# red = Color.red()

# viewer.add(
# Circle.from_point_and_radius(mesh.vertex_point(23) + [0, 0, 0.1], 0.1).to_polygon(100),
# facecolor=(1.0, 1.0, 1.0),
# linecolor=(0.0, 0.0, 0.0),
# linewidth=2,
# )

# facecolors = {face: (0.95, 0.95, 0.95) for face in mesh.faces()}
# for i, face in enumerate(mesh.vertex_faces(23)):
# print(face)
# viewer.add(
# Text(
# str(i),
# mesh.face_centroid(face) + [0.09, -0.075, 0.1],
# height=50,
# )
# )
# facecolors[face] = red.lightened(50)

# viewer.add(mesh, facecolor=facecolors, linewidth=2)

# viewer.view.camera.zoom_extents()
# viewer.view.camera.distance = 11
# viewer.run()

# mesh = Mesh.from_meshgrid(dx=9, nx=9)

# viewer = App(viewport="top", width=1600, height=900)

# red = Color.red()

# viewer.add(mesh, facecolor=(0.95, 0.95, 0.95), linewidth=2)
# viewer.add(mesh.edge_line((20, 30)).translated([0, 0, 0.1]), linecolor=red, linewidth=10)

# for edge in mesh.edge_strip((20, 30)):
# viewer.add(mesh.edge_line(edge).translated([0, 0, 0.1]), linewidth=10)

# viewer.view.camera.zoom_extents()
# viewer.view.camera.distance = 11
# viewer.run()

mesh = Mesh.from_meshgrid(dx=9, nx=9)

viewer = App(viewport="top", width=1600, height=900)

red = Color.red()

viewer.add(mesh, facecolor=(0.95, 0.95, 0.95), linewidth=2)
viewer.add(mesh.edge_line((30, 31)).translated([0, 0, 0.1]), linecolor=red, linewidth=10)

for edge in mesh.edge_loop((30, 31)):
viewer.add(mesh.edge_line(edge).translated([0, 0, 0.1]), linewidth=10)

viewer.view.camera.zoom_extents()
viewer.view.camera.distance = 11
viewer.run()
129 changes: 112 additions & 17 deletions docs/userguide/basics.datastructures.meshes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -189,52 +189,147 @@ True

.. figure:: /_images/userguide/basics.datastructures.meshes.meshgrid-column3.png

>>> for i, nbr in enumerate(mesh.vertex_neighbors(23, ordered=True)):
... print(i, nbr)
...
0 22
1 13
2 24
3 33

.. figure:: /_images/userguide/basics.datastructures.meshes.vertex-neighbours.png

>>> for i, face in enumerate(mesh.vertex_faces(23)):
... print(i, face)
...
0 20
1 11
2 12
3 21

.. figure:: /_images/userguide/basics.datastructures.meshes.vertex-faces.png

>>> for i, nbr in enumerate(mesh.face_neighbors(21)):
... print(i, nbr)
...
0 20
1 22
2 23
3 24

.. figure:: /_images/userguide/basics.datastructures.meshes.face-neighbours.png

>>> for edge in mesh.edge_loop((30, 31)):
... print(edge)
...
(30, 31)
(31, 32)
(32, 33)
(33, 34)
(34, 35)
(35, 36)
(36, 37)
(37, 38)
(38, 39)

.. figure:: /_images/userguide/basics.datastructures.meshes.edge-loop.png

>>> for edge in mesh.edge_strip((20, 30)):
... print(edge)
...
(20, 30)
(21, 31)
(22, 32)
(23, 33)
(24, 34)
(25, 35)
(26, 36)
(27, 37)
(28, 38)
(29, 39)

.. figure:: /_images/userguide/basics.datastructures.meshes.edge-strip.png

Mesh Geometry
=============

Data Attributes
===============
* vertex_point
* vertex_area
* vertex_normal
* vertex_laplacian
* vertex_curvature

Additional data can be assigned to vertices, edges, and faces, as vertex/edge/face attributes, and to the overall mesh itself.
* face_area
* face_normal
* face_flatness
* face_circle
* face_centroid
* face_polygon

>>> mesh = Mesh.from_meshgrid(dx=10, dy=10, nx=10, ny=10)
* edge_vector
* edge_line
* edge_midpoint
* edge_length
* edge_direction

It is recommended to register default values for the vertex, edge and face attributes.

>>> mesh.update_default_vertex_attributes(is_fixed=False)
>>> mesh.update_default_edge_attributes(weight=1.0)
>>> mesh.update_default_face_attributes(color=None)
Data Attributes
===============

Attributes can be accessed per element, per group of elements, or for all elements at once.
Additional data can be assigned to vertices, edges, and faces, as vertex/edge/face attributes, and to the overall mesh itself.

>>> mesh.vertex_attribute(0, 'is_fixed')
False
>>> mesh.vertices_attribute('is_fixed', vertices=[])
* vertex_attribute
* edge_attribute
* face_attribute

>>> mesh.vertices_attribute(vertices=mesh.vertices_where(vertex_degree=2), is_anchor=True)
>>> mesh.edges_attribute(edges=mesh.edges_on_boundary(), weight=10.0)
* vertex_attributes
* edge_attributes
* face_attributes

>>>
* vertices_attribute
* edges_attribute
* faces_attribute

* vertices_attributes
* edges_attributes
* faces_attributes


Filtering
=========


* vertices_where
* edges_where
* faces_where


Mesh Serialisation
==================

>>> mesh.to_json('mesh.json')
>>> mesh = Mesh.from_json('mesh.json')
>>> mesh
<Mesh with 121 vertices and 200 faces>

>>> s = mesh.to_jsonstring()
>>> mesh = Mesh.from_jsonstring(s)
>>> mesh
<Mesh with 121 vertices and 200 faces>

>>> session = {}
>>> session = {'mesh': mesh, 'a': 1, 'b': 2}
>>> compas.json_dump(session, 'session.json')
>>> session = compas.json_load('session.json')
>>> mesh = session['mesh']
>>> mesh
<Mesh with 121 vertices and 200 faces>


A Simple Example
================

* mesh from obj
* mesh delete faces
* mesh remesh
* mesh dual
* mesh frame subdivision
* mesh to FE mesh

0 comments on commit 168f084

Please sign in to comment.