Skip to content

Commit

Permalink
tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
tomvanmele committed Nov 18, 2023
1 parent 6e4b4ba commit 054c081
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 15 deletions.
8 changes: 1 addition & 7 deletions docs/examples/intersections.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import compas
import compas_libigl as igl

from compas.geometry import Point, Line, Translation
from compas.geometry import Point, Line
from compas.datastructures import Mesh
from compas.colors import Color

Expand All @@ -14,12 +14,6 @@

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

z = mesh.vertices_attribute("z")
zmin = min(z)

T = Translation.from_vector([0, 0, -zmin])
mesh.transform(T)

trimesh = mesh.copy()
trimesh.quads_to_triangles()

Expand Down
119 changes: 111 additions & 8 deletions docs/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,115 @@
Tutorial
********************************************************************************

* Similar input parameters as hte original code
* Meshes represented by a list of vertices and a list of triangles
* Both Python lists and Numpy arrays are supported
* Most functions are implemented as pluggables for plugins of COMPAS core
* Therefore, the code can be used from compas_libigl or from compas directly
* Results can easily be visualized using the COMPAS Viewer
* Since the binding is generated with PyBind11 and wraps C++ code, it cannot be used in Rhino/Grasshopper directly
* However it can be used there through RPC
.. rst-class:: lead

:mod:`compas_libigl` provides bindings for the libigl library.
It doesn't cover the entire library, but only for specific functions.
Currently, the following functions are supported:

* :func:`compas_libigl.intersection_ray_mesh`
* :func:`compas_libigl.intersection_rays_mesh`
* :func:`compas_libigl.trimesh_boundaries`
* :func:`compas_libigl.trimesh_gaussian_curvature`
* :func:`compas_libigl.trimesh_principal_curvature`
* :func:`compas_libigl.trimesh_geodistance`
* :func:`compas_libigl.trimesh_isolines`
* :func:`compas_libigl.trimesh_massmatrix`
* :func:`compas_libigl.trimesh_harmonic`
* :func:`compas_libigl.trimesh_lscm`
* :func:`compas_libigl.trimesh_remesh_along_isoline`
* :func:`compas_libigl.quadmesh_planarize`


Input/Output
============

The function signatures of the bindings are similar to the original libigl functions.
Meshes are represented by a tuple containing a list/array of vertices and a list/array of faces.
Most functions require the input mesh to be a triangle mesh.

.. code-block:: python
import compas
import compas_libigl
from compas.datastructures import Mesh
mesh = Mesh.from_obj(compas.get("tubemesh.obj"))
mesh.quads_to_triangles()
V, F = mesh.to_vertices_and_faces()
source = trimesh.vertex_sample(size=1)[0]
distance = compas_libigl.trimesh_geodistance(
(V, F),
source,
method="heat",
)
Both Python lists and Numpy arrays are supported.

.. code-block:: python
import numpy
import compas
import compas_libigl
from compas.datastructures import Mesh
mesh = Mesh.from_obj(compas.get("tubemesh.obj"))
mesh.quads_to_triangles()
vertices, faces = mesh.to_vertices_and_faces()
V = numpy.array(vertices, dtype=float)
F = numpy.array(faces, dtype=int)
source = trimesh.vertex_sample(size=1)[0]
distance = compas_libigl.trimesh_geodistance(
(V, F),
source,
method="heat",
)
Pluggables
==========


Visualisation
=============


Working in Rhino/Grasshopper
============================

The bindings are generated with PyBind11 and wrap the C++ code of libigl.
Therefore, the bindings are not compatible with IronPython and cannot be used in Rhino/Grasshopper directly.
However, they can be used in Rhino/Grasshopper through RPC.

.. code-block:: python
import compas
from compas.rpc import Proxy
from compas.datastructures import Mesh
from compas.datastructures import mesh_flatness
from compas.colors import Color, ColorMap
from compas.artists import Artist
compas_libigl = Proxy('compas_libigl')
mesh = Mesh.from_obj(compas.get("tubemesh.obj"))
V, F = mesh.to_vertices_and_faces()
V2 = compas_libigl.quadmesh_planarize((V, F), 100, 0.005)
mesh = Mesh.from_vertices_and_faces(V2, F)
dev = mesh_flatness(mesh, maxdev=TOL)
cmap = ColorMap.from_two_colors(Color.white(), Color.blue())
facecolor={
face: (cmap(dev[face]) if dev[face] <= 1.0 else Color.red())
for face in mesh.faces()
}
artist = Artist(mesh, layer="libigl::quadmesh_planarize")
artist.draw(facecolor=facecolor, disjoint=True)

0 comments on commit 054c081

Please sign in to comment.