def triangulate_strips(zone):
    meshes = []
    for faces in zone:
        mesh = Mesh()
        mesh.update_default_vertex_attributes(FABRIC.default_vertex_attributes)
        mesh.update_default_edge_attributes(FABRIC.default_edge_attributes)
        mesh.update_default_face_attributes(FABRIC.default_face_attributes)

        for fkey in faces:
            keys = FABRIC.face_vertices(fkey)
            for key in keys:
                if key not in mesh.vertex:
                    attr = FABRIC.vertex[key].copy()
                    mesh.add_vertex(key=key, attr_dict=attr)
            attr = FABRIC.facedata[fkey].copy()
            mesh.add_face(keys, fkey=fkey, attr_dict=attr)

        for u, v, attr in mesh.edges(True):
            for name in attr:
                value = FABRIC.get_edge_attribute((u, v), name)
                attr[name] = value

        trimesh = mesh.copy()
        mesh_quads_to_triangles(trimesh, check_angles=True)
        meshes.append([mesh, trimesh])

    return meshes
Exemplo n.º 2
0
 def from_mesh(cls, compas_mesh):
     """Construct a `Mesh` message from a :class:`compas.datastructures.Mesh`.
     """
     mesh_quads_to_triangles(compas_mesh)
     vertices, faces = compas_mesh.to_vertices_and_faces()
     triangles = [MeshTriangle(face) for face in faces]
     vertices = [Point(*v) for v in vertices]
     return cls(triangles, vertices)
Exemplo n.º 3
0
def draw_mesh(mesh, hexcolor):
    mesh_quads_to_triangles(mesh)
    vertices, faces = mesh.to_vertices_and_faces()
    vertexcolors = [hexcolor] * len(vertices)
    faces = [f + [None, [vertexcolors[i] for i in f], None] for f in faces]
    geo = p3js.Geometry(vertices=vertices, faces=faces)
    geo.exec_three_obj_method('computeFaceNormals')
    return p3js.Mesh(
        geometry=geo,
        material=p3js.MeshLambertMaterial(vertexColors='VertexColors'),
        position=[0, 0, 0])
Exemplo n.º 4
0
    def build_collision_object(self, frame_id, id_name, compas_mesh,
                               operation):
        co = CollisionObject(header=Header(frame_id=frame_id), id=id_name)

        if compas_mesh:
            # ROS mesh message requires triangles
            mesh_quads_to_triangles(compas_mesh)
            mesh = Mesh.from_mesh(compas_mesh)
            co.meshes = [mesh]
            co.mesh_poses = [Pose()]

        if operation == 0:
            co.operation = CollisionObject.ADD
        elif operation == 1:
            co.operation = CollisionObject.REMOVE
        elif operation == 2:
            co.operation = CollisionObject.APPEND
        else:
            raise ValueError("Operation unknown")

        return co
Exemplo n.º 5
0
if __name__ == "__main__":

    import compas

    from compas.datastructures import Mesh
    from compas.datastructures import mesh_quads_to_triangles

    from compas_plotters import MeshPlotter

    mesh = Mesh.from_obj(compas.get('hypar.obj'))
    target = mesh.copy()

    points = mesh.vertices_attributes('xyz')
    points[:] = [[x, y, 0] for x, y, z in points]

    mesh_quads_to_triangles(target)

    pulled = trimesh_pull_points_numpy(target, points)

    plotter = MeshPlotter(mesh, figsize=(8, 5))
    plotter.defaults['vertex.fontsize'] = 6
    plotter.draw_vertices(text={
        key: "{:.1f}".format(attr['z'])
        for key, attr in mesh.vertices(True)
    },
                          radius=0.08)
    plotter.draw_faces()
    plotter.draw_points([{
        'pos': [x, y, z],
        'text': "{:.1f}".format(z),
        'radius': 0.08,
Exemplo n.º 6
0
import os
import compas
from compas.datastructures import Mesh
from compas.datastructures import mesh_quads_to_triangles
from compas.utilities import Colormap
from compas_plotters import MeshPlotter
import compas_libigl as igl

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

mesh = Mesh.from_json(FILE)
mesh_quads_to_triangles(mesh)

key_index = mesh.key_index()
index_key = mesh.index_key()

V = mesh.vertices_attributes('xyz')
F = [[key_index[key] for key in mesh.face_vertices(fkey)]
     for fkey in mesh.faces()]

root = mesh.get_any_vertex()

# D = igl.trimesh_geodistance_exact(V, F, 0)
D = igl.trimesh_geodistance_heat(V, F, key_index[root])

cmap = Colormap(D, 'red')

plotter = MeshPlotter(mesh, figsize=(8, 5))
plotter.draw_faces()
plotter.draw_vertices(
Exemplo n.º 7
0
from compas.datastructures import Mesh
from compas.datastructures import mesh_quads_to_triangles
from compas.datastructures import mesh_subdivide_quad
from compas_viewers.multimeshviewer import MultiMeshViewer
from compas_viewers.multimeshviewer import MeshObject
import compas_libigl as igl

# ==============================================================================
# Input Geometry
# ==============================================================================

# create a box mesh around the center of the world

box = Box.from_width_height_depth(5.0, 3.0, 1.0)
a = Mesh.from_shape(box)
mesh_quads_to_triangles(a)

# create a box mesh around the center of the world

box = Box.from_width_height_depth(1.0, 5.0, 3.0)
b = Mesh.from_shape(box)
mesh_quads_to_triangles(b)

# ==============================================================================
# Booleans
# ==============================================================================

# convert meshes to data

VA, FA = a.to_vertices_and_faces()
VB, FB = b.to_vertices_and_faces()
Exemplo n.º 8
0
cube = Box.from_width_height_depth(1.0, 1.0, 1.0)
sphere = Sphere(origin, 0.95 * sqrt(0.5 ** 2 + 0.5 ** 2))

xcyl = Cylinder(Circle(Plane(origin, Vector(1.0, 0.0, 0.0)), 0.35), 2.0)
ycyl = Cylinder(Circle(Plane(origin, Vector(0.0, 1.0, 0.0)), 0.35), 2.0)
zcyl = Cylinder(Circle(Plane(origin, Vector(0.0, 0.0, 1.0)), 0.35), 2.0)

a = Mesh.from_vertices_and_faces(cube.vertices, cube.faces)
a = mesh_subdivide_quad(a, k=3)
b = Mesh.from_vertices_and_faces(* sphere.to_vertices_and_faces(u=30, v=30))
c = Mesh.from_vertices_and_faces(* xcyl.to_vertices_and_faces(u=30))
d = Mesh.from_vertices_and_faces(* ycyl.to_vertices_and_faces(u=30))
e = Mesh.from_vertices_and_faces(* zcyl.to_vertices_and_faces(u=30))

mesh_quads_to_triangles(a)
mesh_quads_to_triangles(b)
mesh_quads_to_triangles(c)
mesh_quads_to_triangles(d)
mesh_quads_to_triangles(e)

VA = numpy.array(a.get_vertices_attributes('xyz'), dtype=numpy.float64)
FA = numpy.array([a.face_vertices(face) for face in a.faces()], dtype=numpy.int32)
VB = numpy.array(b.get_vertices_attributes('xyz'), dtype=numpy.float64)
FB = numpy.array([b.face_vertices(face) for face in b.faces()], dtype=numpy.int32)
VC = numpy.array(c.get_vertices_attributes('xyz'), dtype=numpy.float64)
FC = numpy.array([c.face_vertices(face) for face in c.faces()], dtype=numpy.int32)
VD = numpy.array(d.get_vertices_attributes('xyz'), dtype=numpy.float64)
FD = numpy.array([d.face_vertices(face) for face in d.faces()], dtype=numpy.int32)
VE = numpy.array(e.get_vertices_attributes('xyz'), dtype=numpy.float64)
FE = numpy.array([e.face_vertices(face) for face in e.faces()], dtype=numpy.int32)
Exemplo n.º 9
0
igl = Proxy('compas_libigl')
igl.stop_server()
igl.start_server()

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

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

mesh = Mesh.from_json(FILE)

tri = mesh.copy()
mesh_quads_to_triangles(tri)

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

M = tri.to_vertices_and_faces()
S = mesh.vertices_attribute('z')

vertices, edges = igl.trimesh_isolines(M, S, 50)

levels = groupby(sorted(edges, key=lambda edge: vertices[edge[0]][2]),
                 key=lambda edge: vertices[edge[0]][2])

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