import compas_libigl as igl

from compas.datastructures import Mesh
from compas.utilities import Colormap
from compas_plotters import MeshPlotter

# ==============================================================================
# Input geometry
# ==============================================================================

mesh = Mesh.from_off(igl.get('tubemesh.off'))
mesh.quads_to_triangles()

# ==============================================================================
# Mass matrix
# ==============================================================================

mass = igl.trimesh_massmatrix(mesh)

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

cmap = Colormap(mass, 'red')

plotter = MeshPlotter(mesh, figsize=(8, 5))
plotter.draw_vertices(radius=0.2,
                      facecolor={
                          key: cmap(mass[index])
                          for index, key in enumerate(mesh.vertices())
                      })
Example #2
0
import math
import compas_libigl as igl
from compas.datastructures import Mesh
from compas.utilities import Colormap, rgb_to_hex
from compas.geometry import Line, Polyline, Rotation, Scale
from compas_viewers.objectviewer import ObjectViewer

# ==============================================================================
# Input geometry
# ==============================================================================

mesh = Mesh.from_off(igl.get_beetle())

Rx = Rotation.from_axis_and_angle([1, 0, 0], math.radians(90))
Rz = Rotation.from_axis_and_angle([0, 0, 1], math.radians(90))
S = Scale.from_factors([10, 10, 10])

mesh.transform(S * Rz * Rx)

# ==============================================================================
# Isolines
# ==============================================================================

scalars = mesh.vertices_attribute('z')
vertices, edges = igl.trimesh_isolines(mesh.to_vertices_and_faces(), scalars,
                                       10)
isolines = igl.groupsort_isolines(vertices, edges)

# ==============================================================================
# Visualisation
# ==============================================================================
Example #3
0
import os
import compas
from compas.datastructures import Mesh
from compas.datastructures import mesh_flatness
from compas_plotters import MeshPlotter
from compas.utilities import i_to_rgb
import compas_libigl as igl

TOL = 0.02
MAXDEV = 0.005
KMAX = 500
HERE = os.path.dirname(__file__)

mesh = Mesh.from_off(compas.get('tubemesh.off'))

vertices, faces = mesh.to_vertices_and_faces()
vertices = igl.planarize_quads(vertices, faces, KMAX, MAXDEV)

mesh = Mesh.from_vertices_and_faces(vertices, faces)
dev = mesh_flatness(mesh, maxdev=TOL)

plotter = MeshPlotter(mesh, figsize=(8, 5))
plotter.draw_faces(
    facecolor={fkey: i_to_rgb(dev[fkey])
               for fkey in mesh.faces()})
plotter.show()
Example #4
0
def test_from_off():
    mesh = Mesh.from_off(compas.get('cube.off'))
    assert mesh.number_of_faces() == 6
    assert mesh.number_of_vertices() == 8
    assert mesh.number_of_edges() == 12
Example #5
0
def test_is_regular():
    mesh = Mesh.from_off(compas.get('cube.off'))
    assert mesh.is_regular()

    mesh.insert_vertex(0)
    assert not mesh.is_regular()
import compas_libigl as igl

from compas.datastructures import Mesh
from compas.utilities import Colormap
from compas_plotters import MeshPlotter

# ==============================================================================
# Input geometry
# ==============================================================================

mesh = Mesh.from_off(igl.get('camelhead.off'))
mesh_harmonic = mesh.copy()
mesh_lscm = mesh.copy()

# ==============================================================================
# Harmonic parametrisation
# ==============================================================================

harmonic_uv = igl.trimesh_harmonic(mesh)

for index, key in enumerate(mesh.vertices()):
    mesh_harmonic.vertex_attributes(key, 'xy', harmonic_uv[index])

# ==============================================================================
# Least-squares conformal map
# ==============================================================================

lscm_uv = igl.trimesh_lscm(mesh)

for index, key in enumerate(mesh.vertices()):
    mesh_lscm.vertex_attributes(key, 'xy', lscm_uv[index])
import compas
from compas.datastructures import Mesh
from compas.datastructures import mesh_flatness
from compas.utilities import i_to_rgb
from compas_rhino.artists import MeshArtist
from compas.rpc import Proxy

TOL = 0.02
MAXDEV = 0.005
KMAX = 500

igl = Proxy('compas_libigl')
# igl.stop_server()
# igl.start_server()

HERE = os.path.dirname(__file__)
FILE = os.path.join(HERE, '..', 'data', 'tubemesh.off')

mesh = Mesh.from_off(FILE)

V, F = mesh.to_vertices_and_faces()
V2 = igl.quadmesh_planarize((V, F), KMAX, MAXDEV)

mesh = Mesh.from_vertices_and_faces(V2, F)

dev = mesh_flatness(mesh, maxdev=TOL)

artist = MeshArtist(mesh, layer="IGL::PlanarizeQuads")
artist.clear_layer()
artist.draw_faces(color={fkey: i_to_rgb(dev[fkey]) for fkey in mesh.faces()})