Exemple #1
0
from compas.datastructures import Network
from compas.datastructures import Mesh
import compas_rhino
from compas.datastructures import network_find_cycles
from compas_rhino.artists import MeshArtist
from compas.datastructures import mesh_smooth_centroid

# guids = compas_rhino.select_lines()
# lines = compas_rhino.get_line_coordinates(guids)
# network = Network.from_lines(lines)

# cycles = network_find_cycles(network, network.leaves())
# vertices = [network.node_coordinates(vkey) for vkey in network.nodes()]

# faces = cycles[1:]
# mesh = Mesh.from_vertices_and_faces(vertices, faces)
mesh = Mesh.from_obj('test6.obj')
fixed = list(mesh.vertices_where({'vertex_degree': 3}))
mesh_smooth_centroid(mesh, fixed=fixed)

artist = MeshArtist(mesh)
artist.draw_mesh()
key_index = mesh.key_index()

V = mesh.vertices_attributes('xyz')
F = [[key_index[key] for key in mesh.face_vertices(fkey)] for fkey in mesh.faces()]
S = mesh.vertices_attribute('z')
N = 50

vertices, levels = igl.trimesh_isolines(V, F, S, N)

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

smin = min(S)
smax = max(S)

lines = []
for scalar, edges in levels:
    for i, j in edges:
        lines.append({
            'start' : vertices[i],
            'end'   : vertices[j],
            'color' : i_to_rgb((scalar - smin) / (smax - smin))
        })

artist = MeshArtist(mesh, layer="IGL::Isolines")
artist.draw_faces()

compas_rhino.draw_lines(lines, layer=artist.layer, clear=False)
Exemple #3
0
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

from compas.datastructures import Mesh
from compas_rhino.artists import MeshArtist

mesh = Mesh.from_json('cablenet.json')

fabric = mesh.copy()
fabric.name = 'fabric'

# make a lookup dict for the vertex normals of the mesh vertices

for key, attr in fabric.vertices(True):
    nx, ny, nz = key_normal[key]

    # update the attributes of the fabric vertices
    # to be offset in the normal direction by 2cm

fabric.to_json('fabric.json')

artist = MeshArtist(fabric, layer="Fabric")

# clear the "Fabric" layer
# draw the fabric as a mesh
# specify a color for the mesh
Exemple #4
0
from shapes import Polyhedron
from compas_rhino.artists import MeshArtist
from compas.datastructures import Mesh

poly = Mesh.from_polyhedron(12)
print(poly)

artist = MeshArtist(poly, layer='00_my_mesh')

artist.clear_layer()
artist.draw_faces()
artist.draw_mesh(join_faces=True)
Exemple #5
0
    block.attributes['blank'] = blank
    block.attributes['bottom'] = bottom

    blocks.append(block)

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

with open(FILE, 'w') as f:
    json.dump(blocks, f, cls=DataEncoder)

# ==============================================================================
# Visualize
# ==============================================================================

compas_rhino.clear_layers(["ITA20::Assignment1"])

for block in blocks:
    artist = MeshArtist(block,
                        layer="ITA20::Assignment1::{}::Block".format(
                            block.name))
    artist.draw_faces(color={block.attributes['bottom']: (255, 0, 0)})

    blank = block.attributes['blank']

    artist = BoxArtist(blank,
                       layer="ITA20::Assignment1::{}::Blank".format(
                           block.name))
    artist.draw(show_edges=True, show_faces=False)
Exemple #6
0
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')

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

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="ITA20::Tubemesh")
artist.clear_layer()
artist.draw_faces(color={face: i_to_rgb(dev[face]) for face in mesh.faces()})
Exemple #7
0
import random

from compas.geometry import Pointcloud
from compas.geometry import Translation, Rotation
from compas.geometry import Box
from compas.geometry import is_point_infront_plane
from compas.datastructures import Mesh

from compas_rhino.artists import PointArtist
from compas_rhino.artists import MeshArtist

pcl = Pointcloud.from_bounds(10, 5, 3, 100)
box = Box.from_width_height_depth(2, 2, 2)

T = Translation.from_vector([5, 2.5, 1.5])
R = Rotation.from_axis_and_angle([0, 0, 1], random.random() * math.pi)

box.transform(T * R)
mesh = Mesh.from_shape(box)

colors = []
for point in pcl:
    colors.append((0, 0, 255))

PointArtist.draw_collection(pcl, colors=colors, layer="ITA20::PCL", clear=True)

artist = MeshArtist(mesh, layer="ITA20::Box")
artist.clear_layer()
artist.draw_faces()
artist.draw_edges()
Exemple #8
0
points = [[WIRE, 0, 0], [WIRE, 0, HEIGHT], [WIRE, TABLE, HEIGHT],
          [WIRE, TABLE, 0]]
polygon = Polygon(points)
artist = PolygonArtist(polygon,
                       layer="ITA20::HotWire::Right",
                       color=(0, 255, 0))
artist.draw(show_edges=True, show_face=False)

line = Line([0, 0, 0], [WIRE, 0, 0])
artist = LineArtist(line, color=(255, 255, 255), layer="ITA20::HotWire::Wire")
artist.draw()

# blank and block

artist = MeshArtist(block, layer="ITA20::HotWire::Block")
artist.draw_faces(color={left: (255, 0, 0), right: (0, 255, 0)})

artist = BoxArtist(blank, layer="ITA20::HotWire::Blank")
artist.draw(show_edges=True, show_faces=False)

# movement paths

artist = PolylineArtist(left_poly,
                        color=(255, 0, 0),
                        layer="ITA20::HotWire::LeftCut")
artist.draw()

artist = PolylineArtist(right_poly,
                        color=(0, 255, 0),
                        layer="ITA20::HotWire::RightCut")
Exemple #9
0
edges = list(mesh.edges())

# extract numerical data from the datastructure

vertices = mesh.get_vertices_attributes(('x', 'y', 'z'))
adjacency = [mesh.vertex_neighbors(key) for key in mesh.vertices()]
fixed = [int(mesh.vertex_degree(key) == 2) for key in mesh.vertices()]

# make a artist for (dynamic) visualization
# and define a callback function
# for plotting the intermediate configurations

slider = list(mesh.vertices_where({'x': (-0.1, 0.1), 'y': (9.9, 10.1)}))[0]

artist = MeshArtist(mesh, layer='SmoothMesh')
artist.clear_layer()


def callback(k, xyz):
    compas_rhino.wait()

    print(k)

    if k < kmax - 1:
        xyz[slider][0] = c_double(0.1 * (k + 1))

    pointsconduit.points = [
        mesh.vertex_coordinates(key) for key in mesh.vertices()
    ]
    linesconduit.lines = [mesh.edge_coordinates(u, v) for u, v in edges]
Exemple #10
0
import compas
from compas.datastructures import Mesh
from compas_rhino.artists import MeshArtist

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

artist = MeshArtist(mesh)
artist.draw_vertices()
artist.draw_faces()
artist.draw_edges()
Exemple #11
0
# Visualization
# ==============================================================================

flag = False
for i in frame_box_len_All_:

    if (flag == False):
        flag = True
        #artist = FrameArtist(frame, layer="SOUTH::Frame", scale=0.3)
        #artist.clear_layer()
        #artist.draw()

        artist = FrameArtist(i[0], layer="SOUTH::Frame1", scale=0.3)
        artist.clear_layer()
        artist.draw()
        artist = MeshArtist(i[1], layer="SOUTH::Bbox1")
        artist.clear_layer()
        artist.draw_mesh()

    else:
        #artist = FrameArtist(frame, layer="SOUTH::Frame", scale=0.3)
        #artist.draw()
        if (len(i) > 2):
            artist = FrameArtist(i[0], layer="SOUTH::Frame1", scale=0.3)
            artist.draw()
            artist = MeshArtist(i[1], layer="SOUTH::Bbox1")
            artist.draw_mesh()
            #artist.draw_vertexlabels()

#PointArtist.draw_collection(allIntersections,layer="SOUTH::Intersection", clear=True)
Exemple #12
0
# update default vertex attributes
mesh.update_default_vertex_attributes({'px': 0.0, 'py': 0.0, 'pz': 0.0})
mesh.update_default_edge_attributes({'q': 1.0})

# numerical data
xyz = mesh.get_vertices_attributes('xyz')
edges = list(mesh.edges())
fixed = list(mesh.vertices_where({'vertex_degree': 2}))
q = mesh.get_edges_attribute('q', 1.0)
loads = mesh.get_vertices_attributes(('px', 'py', 'pz'), (0.0, 0.0, 0.0))

# call to fd_numpy over proxy server
xyz, q, f, l, r = proxy.fd_numpy(xyz, edges, fixed, q, loads)

# update the mesh vertices
for key, attr in mesh.vertices(True):
    mesh.set_vertex_attributes(key, 'xyz', xyz[key])
    mesh.set_vertex_attributes(key, ('rx', 'ry', 'rz'), r[key])

# update the mesh edges
for index, (u, v, attr) in enumerate(mesh.edges(True)):
    attr['f'] = f[index][0]
    attr['l'] = l[index][0]

# visualise the result
artist = MeshArtist(mesh, layer="Mesh::FD")
artist.clear_layer()
artist.draw_vertices()
artist.draw()
Exemple #13
0
key_index = mesh.key_index()

# convert data to a numerical format
xyz = mesh.get_vertices_attributes('xyz')
edges = [(key_index[u], key_index[v]) for u, v in mesh.edges()]
fixed = [key_index[key] for key in mesh.vertices_where({'vertex_degree': 2})]
q = mesh.get_edges_attribute('q', 1.0)
loads = mesh.get_vertices_attributes(('px', 'py', 'pz'), (0.0, 0.0, 0.0))

# run the force density algorithm
# through the proxy
xyz, q, f, l, r = numerical.fd_numpy(xyz, edges, fixed, q, loads)

# update the mesh with the result
for key, attr in mesh.vertices(True):
    index = key_index[key]
    attr['x'] = xyz[index][0]
    attr['y'] = xyz[index][1]
    attr['z'] = xyz[index][2]

for index, (u, v, attr) in enumerate(mesh.edges(True)):
    attr['f'] = f[index][0]
    attr['l'] = l[index][0]

# visualise
artist = MeshArtist(mesh, layer="ForceDensityNumpy")
artist.clear_layer()
artist.draw_vertices()
artist.draw_edges()
artist.draw_faces()
import os
from compas.datastructures import Mesh
from compas_rhino.artists import MeshArtist

HERE = os.path.dirname(__file__)
DATA = os.path.join(HERE, '../data')
FILE = os.path.join(DATA, 'mesh.json')

mesh = Mesh.from_json(FILE)

artist = MeshArtist(mesh, layer="HiLo::Mesh")
artist.clear_layer()

artist.draw()
Exemple #15
0
from compas.datastructures import Mesh
from compas_rhino.artists import MeshArtist


mesh = Mesh.from_json('cablenet.json')

fabric = mesh.copy()
fabric.name = 'fabric'

# make a lookup dict for the vertex normals of the mesh vertices
key_normal = {key: mesh.vertex_normal(key) for key in mesh.vertices()}

for key, attr in fabric.vertices(True):
    nx, ny, nz = key_normal[key]

    # update the attributes of the fabric vertices
    # to be offset in the normal direction by 2cm
    attr['x'] += 0.02 * nx
    attr['y'] += 0.02 * ny
    attr['z'] += 0.02 * nz

fabric.to_json('fabric.json')

artist = MeshArtist(fabric, layer="Fabric")

# clear the "Fabric" layer
# draw the fabric as a mesh
# specify a color for the mesh
artist.clear_layer()
artist.draw_mesh()
Exemple #16
0
    artist.draw_vertices(color={key: '#ff0000' for key in mesh.vertices_where({'is_fixed': True})})
    artist.draw_edges()
    artist.redraw()


# make a control mesh
mesh = Mesh.from_polyhedron(6)

# give the mesh a name
mesh.attributes['name'] = 'Control'

# set default vertex attributes
mesh.update_default_vertex_attributes({'is_fixed': False})

# make an artist for visualisation
artist = MeshArtist(mesh, layer='SubdModeling::Control')

# draw the control mesh
draw()

# allow the user to change the attributes of the vertices
while True:
    keys = VertexSelector.select_vertices(mesh)
    if not keys:
        break
    VertexModifier.update_vertex_attributes(mesh, keys)
    draw()

# make a subd mesh (using catmullclark)
subd = mesh_subdivide(mesh, scheme='catmullclark', k=4, fixed=mesh.vertices_where({'is_fixed': True}))
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

from compas.datastructures import Mesh
from compas_rhino.artists import MeshArtist

mesh = Mesh.from_json('cablenet.json')

vertexcolor = {
    key: (255, 0, 0)
    for key in mesh.vertices_where({'is_anchor': True})
}
edgecolor = {key: (0, 0, 255) for key in mesh.edges_where({'is_joint': True})}

artist = MeshArtist(mesh, layer="Cablenet")

artist.clear_layer()
artist.draw_vertices(color=vertexcolor)
artist.draw_edges(color=edgecolor)
Exemple #18
0
from compas.datastructures import Mesh
from compas_assembly.datastructures import Assembly
from compas_assembly.datastructures import assembly_hull

# just so Rhino(Mac) gets the filepaths right

HERE = os.path.dirname(__file__)

# load an assembly from a JSON file

assembly = Assembly.from_json(
    os.path.join(HERE, '../data/wall_interfaces.json'))

# define a sequence of buildable blocks

sequence = [28, 22, 23, 16, 17, 18, 11, 12, 13, 5, 6, 7, 8, 0, 1, 2, 3, 38]

# hull of the sequence

vertices, faces = assembly_hull(assembly, keys=sequence)

hull = Mesh.from_vertices_and_faces(vertices, faces)

# visualise

artist = MeshArtist(hull, layer="Hull")
artist.clear_layer()
artist.draw()
artist.redraw()
Exemple #19
0
for fkey in edos.faces():
    vertices = edos.face_vertices(fkey)

    if len(vertices) != 4:
        continue

    # normals of the cablenet
    # coordinates of the extrados

    # bottom face coordinates offset from vertex coordinates

    top = []
    for point, normal in zip(bottom, normals):
        x = point[0] + 0.1 * normal[0]
        y = point[1] + 0.1 * normal[1]
        z = point[2] + 0.1 * normal[2]
        top.append([x, y, z])

    # vertices and faces of the block

    block = Mesh.from_vertices_and_faces(vertices, faces)
    block.name = "Block.{}".format(fkey)

    blocks.append(block)

# ==============================================================================
# Visualize the blocks
# ==============================================================================

artist = MeshArtist(None, layer="Blocks")
Exemple #20
0
boundary = rs.GetObject("Select Boundary Curve", 4)
length   = rs.GetReal("Select Edge Target Length", 2.0)
points   = rs.DivideCurve(boundary, rs.CurveLength(boundary) / length)

# generate a delaunay triangulation
# from the points on the boundary

faces = delaunay_from_points(points, boundary=points)
mesh = Mesh.from_vertices_and_faces(points, faces)


# make a conduit for visualization

conduit = MeshConduit(mesh, refreshrate=2)

# run the remeshing algorithm
# and draw the result

with conduit.enabled():
    trimesh_remesh(
        mesh,
        target=length,
        kmax=500,
        allow_boundary_split=True,
        allow_boundary_swap=True,
        callback=callback)

artist = MeshArtist(mesh)
artist.draw_faces(join_faces=True)
artist.redraw()
Exemple #21
0
for key, attr in mesh.vertices(True):
    attr['x'] = xyz[key][0]
    attr['y'] = xyz[key][1]
    attr['z'] = xyz[key][2]
    attr['rx'] = r[key][0]
    attr['ry'] = r[key][1]
    attr['rz'] = r[key][2]

for index, (u, v, attr) in enumerate(mesh.edges(True)):
    attr['f'] = f[index][0]

# ==============================================================================
# Visualize result
# ==============================================================================

artist = MeshArtist(mesh, layer="Mesh")
artist.clear_layer()
artist.draw_vertices(color={
    key: (255, 0, 0)
    for key in mesh.vertices_where({'is_fixed': True})
})
artist.draw_edges()
artist.draw_faces()

forces = []
for ..., ..., ... in mesh.edges(True):
    force = attr['...']
    ...= mesh.vertex_coordinates(u)
    ...= mesh.vertex_coordinates(v)
    radius = 0.01 * force
    forces.append({
volume = idos.copy()
volume.name = 'concrete1'

# flip its cycles to make the bottom normals point downwards

# set the key offset
dkey = volume._max_int_key + 1

# add the vertices of the extrados
for key, attr in edos.vertices(True):

# add the faces of the extrados
for fkey in edos.faces():
    vertices = edos.face_vertices(fkey)

# construct a polygon of boundary vertices

# add the "side" faces

# ==============================================================================
# Export and visualisation
# ==============================================================================

# export
volume.to_json('concrete1.json')

# visualize
artist = MeshArtist(volume, layer="Concrete1")
artist.clear_layer()
artist.draw_mesh(color=(0, 0, 255))
Exemple #23
0
# ==============================================================================
# Move the bunny to the origin and rotate it upright.
# ==============================================================================

vector = scale_vector(bunny.centroid(), -1)
T = Translation.from_vector(vector)
S = Scale.from_factors([100, 100, 100])
R = Rotation.from_axis_and_angle(Vector(1, 0, 0), math.radians(90))

bunny.transform(R * S * T)

# ==============================================================================
# Remesh
# ==============================================================================

num_edges = bunny.number_of_edges()
length = sum(bunny.edge_length(*edge) for edge in bunny.edges()) / num_edges

V, F = meshing.remesh(bunny.to_vertices_and_faces(), 2 * length, 10)

bunny = Mesh.from_vertices_and_faces(V, F)

# ==============================================================================
# Visualize
# ==============================================================================

artist = MeshArtist(bunny, layer="CGAL::Remesh::Bunny")
artist.clear_layer()
artist.draw_faces(join_faces=True)
artist.redraw()
# get input data
srf_guid = rs.GetObject('Rhino surface to decompose', filter=8) or []
crv_guids = rs.GetObjects('Rhino curves to integrate', filter=4) or []
pt_guids = rs.GetObjects('Rhino points to integrate', filter=1) or []

discretisation = rs.GetReal(
    'Value for precision - between 1 and 5 percent of scale',
    number=1,
    minimum=0)

# get outer boundary polyline, inner boundary polylines, polyline features and point features by mapping curved surface to plan and discretising its boundaries and features
outer_boundary, inner_boundaries, polyline_features, point_features = surface_discrete_mapping(
    srf_guid, discretisation, crv_guids=crv_guids, pt_guids=pt_guids)

# Delaunay triangulation of the surface formed by the planar polylines using the points as Delaunay vertices
mesh = boundary_triangulation(outer_boundary, inner_boundaries,
                              polyline_features, point_features)

# start instance for skeleton-based decomposition
decomposition = SkeletonDecomposition.from_mesh(mesh)

# build decomposition mesh
mesh = decomposition.decomposition_mesh(point_features)

# remap mesh on surface
RhinoSurface.from_guid(srf_guid).mesh_uv_to_xyz(mesh)

# draw decomposition mesh
MeshArtist(mesh).draw_mesh()
Exemple #25
0
# extract the input for the smoothing algorithm from the mesh
# and identify the boundary as fixed

vertices  = mesh.vertices_attributes('xyz')
faces     = [mesh.face_vertices(fkey) for fkey in mesh.faces()]
adjacency = [mesh.vertex_faces(key, ordered=True) for key in mesh.vertices()]
fixed     = set(mesh.vertices_on_boundary())

# run the smoothing algorithm

smooth_area(
    vertices,
    faces,
    adjacency,
    fixed=fixed,
    kmax=50,
    callback=callback)

# update the mesh

for key, attr in mesh.vertices(True):
    attr['x'] = vertices[key][0]
    attr['y'] = vertices[key][1]
    attr['z'] = vertices[key][2]

# visualize

artist = MeshArtist(mesh, layer='mesh-out')
artist.draw_faces(join_faces=True)
Exemple #26
0
    E = mesh.get_edges_attribute('E')
    radius = mesh.get_edges_attribute('radius')

    xyz, q, f, l, r = dr(vertices,
                         edges,
                         fixed,
                         loads,
                         qpre,
                         fpre,
                         lpre,
                         linit,
                         E,
                         radius,
                         kmax=100)

    for key, attr in mesh.vertices(True):
        index = k_i[key]
        attr['x'] = xyz[index][0]
        attr['y'] = xyz[index][1]
        attr['z'] = xyz[index][2]

    artist = MeshArtist(mesh, layer="XFunc::Mesh")

    artist.clear_layer()

    artist.draw_vertices()
    artist.draw_edges()
    artist.draw_faces()

    artist.redraw()
"""Assignment 01: Project box to xy-plane
"""
from compas.geometry import Box
from compas.geometry import Frame, Plane
from compas.geometry import Projection
from compas_rhino.artists import BoxArtist
from compas_rhino.artists import MeshArtist
from compas.datastructures import Mesh

# Define a Frame, which is not in the origin and a bit tilted to the world frame
frame = Frame([1, 2, 3], [-0.45, 0.1, 0.3], [1, 2, 1])

# Create a Box with that frame
box = Box(frame, 2, 3, 5)

# Create a Projection (can be orthogonal, parallel or perspective)
P = Projection.from_plane(Plane([0, 0, 0], [0, 0, 1]))

# Create a Mesh from the Box
mesh = Mesh.from_shape(box)

# Apply the Projection onto the mesh
mesh_projected = mesh.transformed(P)

# Create artists
artist1 = BoxArtist(box)
artist2 = MeshArtist(mesh_projected)

# Draw
artist1.draw()
artist2.draw_edges(color="#00ff00")
Exemple #28
0
    block = Mesh.from_vertices_and_faces(vertices, faces)
    blocks.append(block)
    
    
    all_vertices.extend(vertices)
    k = fkey * 8
    faces_ = [[0+k, 3+k, 2+k, 1+k],[4+k, 5+k, 6+k, 7+k], [4+k, 0+k, 1+k, 5+k], [2+k, 6+k, 5+k, 1+k], [6+k, 2+k, 3+k, 7+k], [0+k, 4+k, 7+k, 3+k]]
    all_faces.extend(faces_)

b = Cablenet.from_vertices_and_faces(all_vertices, all_faces)
# ==============================================================================
# Visualize
# ==============================================================================

#artist = MeshArtist(block, layer="Boxes::Test")
#artist.clear_layer()
#artist.draw_faces(join_faces=True,color=(0,255,255))
#artist.draw_vertexlabels()


for i,block in enumerate(blocks):
    artist = MeshArtist(block, layer="Boxes::Test")
    if i == 0:
        artist.clear_layer()
    artist.draw_faces(join_faces=True,color=(0,255,255))

artist_2 = MeshArtist(b, layer="Boxes::Group")
artist_2.clear_layer()
artist_2.draw_faces(join_faces=True,color=(0,255,255))

b.to_json(FILE_O)
Exemple #29
0
from compas.datastructures import Mesh
from compas_rhino.artists import MeshArtist


mesh = Mesh.from_json('cablenet.json')

fabric = mesh.copy()
fabric.name = 'fabric'

# make a lookup dict for the vertex normals of the mesh vertices
key_normal = {key: mesh.vertex_normal(key) for key in mesh.vertices()}

for key, attr in fabric.vertices(True):
    nx, ny, nz = key_normal[key]

    # update the attributes of the fabric vertices
    # to be offset in the normal direction by 2cm
    attr['x'] += 0.02 * nx
    attr['y'] += 0.02 * ny
    attr['z'] += 0.02 * nz

fabric.to_json('fabric.json')

artist = MeshArtist(fabric, layer="Fabric")

# clear the "Fabric" layer
# draw the fabric as a mesh
# specify a color for the mesh
artist.clear_layer()
artist.draw_mesh(color=(0, 255, 255))