Ejemplo n.º 1
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()})
Ejemplo n.º 2
0
    key_index = mesh.key_index()

    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))

    xyz, q, f, l, r = numerical.fd_numpy(xyz, edges, fixed, q, loads)

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

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

    artist = MeshArtist(mesh)
    artist.draw_vertices()
    artist.draw_edges()
    artist.draw_faces()
    artist.redraw()
Ejemplo n.º 3
0
import os
import compas

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, 'faces.obj')

mesh = Mesh.from_obj(FILE)

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

artist.draw_vertices()
artist.draw_edges()
artist.draw_faces()
# ------------------------------------------------------------------------------
# 3. reciprocate
# ------------------------------------------------------------------------------
volmesh_reciprocate(forcediagram,
                    formdiagram,
                    kmax=500,
                    weight=1,
                    edge_min=0.5,
                    edge_max=20,
                    tolerance=0.01)

force_artist = VolMeshArtist(forcediagram, layer=force_layer)
form_artist = NetworkArtist(formdiagram, layer=form_layer)

scaled_cell_artist = MeshArtist(None, layer=force_layer)
prism_artist = MeshArtist(None, layer=force_layer)

force_artist.draw_faces()
form_artist.draw_edges()

# ------------------------------------------------------------------------------
# 4. draw unified diagram
# ------------------------------------------------------------------------------

while True:

    rs.EnableRedraw(True)

    alpha = rs.GetReal('unified diagram scale', minimum=0.01, maximum=1.0)
Ejemplo n.º 5
0
# ==============================================================================
# Geodistance
# ==============================================================================

D = igl.trimesh_geodistance(M, source)

# ==============================================================================
# Visualization
# ==============================================================================

Dmin = min(D)
Dmax = max(D)

cmap = Colormap(D, 'red')

artist = MeshArtist(mesh, layer="IGL::GeoDistance")
artist.clear_layer()
artist.draw_mesh()

spheres = []
for key, d in zip(mesh.vertices(), D):
    radius = 0.5 * (d - Dmin) / (Dmax - Dmin)
    spheres.append({
        'pos': mesh.vertex_coordinates(key),
        'radius': radius if key != source else 0.5,
        'color': cmap(d) if key != source else (255, 255, 255)
    })

compas_rhino.draw_spheres(spheres,
                          layer=artist.layer,
                          clear=False,
Ejemplo n.º 6
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)
C = igl.mesh_intersection(A, B)
c_intersection = Mesh.from_vertices_and_faces(*C)

C = igl.mesh_difference(A, B)
c_diff = Mesh.from_vertices_and_faces(*C)

# ==============================================================================
# Visualization
# ==============================================================================

c_union.transform(Translation([7.5, 0, 0]))
c_intersection.transform(Translation([15, 0, 0]))
c_diff.transform(Translation([22.5, 0, 0]))

artist = MeshArtist(a, layer="IGL::A")
artist.clear_layer()
artist.draw_mesh(color=[255, 0, 0])

artist = MeshArtist(b, layer="IGL::B")
artist.clear_layer()
artist.draw_mesh(color=[0, 0, 255])

artist = MeshArtist(c_union, layer="IGL::Union")
artist.clear_layer()
artist.draw_mesh(color=[225, 0, 255])

artist = MeshArtist(c_intersection, layer="IGL::Intersection")
artist.clear_layer()
artist.draw_mesh(color=[0, 255, 0])
Ejemplo n.º 8
0
    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
    vertices = bottom[::-1] + top
    faces = [[0, 1, 2, 3], [4, 5, 6, 7], [4, 7, 0, 3], [7, 6, 1, 0],
             [2, 1, 6, 5], [5, 4, 3, 2]]

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

    blocks.append(block)

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

artist = MeshArtist(None, layer="Blocks")
artist.clear_layer()

b = len(blocks)

for i, block in enumerate(blocks):
    artist.mesh = block
    artist.draw_mesh(color=i_to_rgb(i / b))

artist.redraw()
Ejemplo n.º 9
0
import os
import compas

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

HERE = os.path.dirname(__file__)

FILE_I = os.path.join(HERE, 'sessions', 'bm_vertical_equilibrium',
                      'bm_a_06_vertical.rv2')
FILE_O = os.path.join(HERE, 'data', 'form.json')

session = compas.json_load(FILE_I)

form = Mesh.from_data(session['data']['form'])
form.to_json(FILE_O)

artist = MeshArtist(form, layer="RV2::Mesh")
artist.clear_layer()
artist.draw_faces(join_faces=True)
Ejemplo n.º 10
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()
Ejemplo n.º 11
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)
Ejemplo n.º 12
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)
# 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()
Ejemplo n.º 14
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
Ejemplo n.º 15
0
 def redraw_saved_meshes(self):
     self.undraw_saved_mesh()
     for mesh in self.saved_meshes.keys():
         guid = MeshArtist(self.processing_func(mesh)).draw_mesh()
         self.guid_to_mesh_saved[guid] = mesh
Ejemplo n.º 16
0
    origin = ...
    normal = ...
    plane = add_vectors(origin, ...), normal

    top = []
    for a in bottom:
        b = ...
        ... = intersection_line_plane(...)
        top.append(...)

    top[:] = ...

    vertices = ... + ...
    faces = [[0, 3, 2, 1], ..., [3, 0, 4, 7], [2, 3, 7, 6], [1, 2, 6, 5], [0, 1, 5, 4]]

    block = Mesh.from_...(...)

    blocks.append(block)

# ==============================================================================
# Visualize the block with a mesh artist in the specified layer. Use
# `draw_faces` (with `join_faces=True`) instead of `draw_mesh` to get a flat
# shaded result. Also draw the vertex labels tovisualize the cycle directions.
# ==============================================================================

artist = MeshArtist(None, layer="...")
artist.clear_layer()

for mesh in blocks:
    ...
Ejemplo n.º 17
0
 def redraw_suggested_meshes(self):
     self.undraw_suggested_meshes()
     for mesh in self.suggested_delete_meshes.keys(
     ) + self.suggested_add_meshes.keys():
         guid = MeshArtist(self.processing_func(mesh)).draw_mesh()
         self.guid_to_mesh_suggested[guid] = mesh
import compas
from compas.datastructures import Mesh
from compas_rhino.artists import MeshArtist

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

artist = MeshArtist(mesh, layer='Tubemesh')
artist.clear_layer()
artist.draw()
artist.draw_vertexnormals()
# `draw_faces` (with `join_faces=True`) instead of `draw_mesh` to get a flat
# shaded result. Also draw the vertex labels tovisualize the cycle directions.
# ==============================================================================

# artist = MeshArtist(cablenet, layer="Cablenet::Mesh")
# artist.clear_layer()
# artist.draw_mesh()

blocks_list = []
FILE_I = os.path.join(HERE, 'mesh.json')

for mesh in blocks:
    index = blocks.index(mesh)
    FILE_T = os.path.join(HERE, 'temp.json')  

    mesh.to_json(FILE_T, pretty=True)

    with open(FILE_T) as json_file: 
        container = json.load(json_file)

    blocks_list.append(container)

    artist = MeshArtist(mesh, layer="Blocks::Block" + str(index))
    artist.clear_layer()
    artist.draw_faces(join_faces=True, color=(0, 255, 255))
    artist.draw_vertexlabels()

with open(FILE_I, 'w') as json_file:
    json.dump(blocks_list,json_file)

Ejemplo n.º 20
0
        x, y, z = surf.closest_point(vertices[index])
        vertices[index][0] = x
        vertices[index][1] = y
        vertices[index][2] = z

    conduit.lines = [[vertices[u], vertices[v]] for u, v in edges]
    conduit.redraw(k)


# with the conduit enabled
# run the smoothing algorithm
# update the mesh when smoothing is done
# and draw the result

with conduit.enabled():
    smooth_area(vertices,
                faces,
                adjacency,
                fixed=fixed,
                kmax=100,
                callback=callback)

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

artist = MeshArtist(mesh, layer='SmoothingOnSurface::Output')
artist.clear_layer()
artist.draw_mesh()
Ejemplo n.º 21
0
Archivo: block.py Proyecto: tetov/ITA19
bottom = points[:]
top = []
for point, normal in zip(points, normals):
    xyz = add_vectors(point, scale_vector(normal, THICKNESS))
    top.append(xyz)

# ==============================================================================
# The vertices of the block mesh are simply the vertices of the bottom and top
# faces. The faces themselves are defined such that once the block is formed
# all face normals point towards the exterior of the block.
# Note that this means that the order of the vertices of the bottom block has
# to be reversed.
# ==============================================================================

vertices = bottom + top
faces = [[0, 3, 2, 1], [4, 5, 6, 7], [3, 0, 4, 7], [2, 3, 7, 6], [1, 2, 6, 5],
         [0, 1, 5, 4]]

block = Mesh.from_vertices_and_faces(vertices, faces)

# ==============================================================================
# Visualize the block with a mesh artist in the specified layer. Use
# `draw_faces` (with `join_faces=True`) instead of `draw_mesh` to get a flat
# shaded result. Also draw the vertex labels tovisualize the cycle directions.
# ==============================================================================

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

for a, b in pairwise(boundary):
    volume.add_face([b, a, a + max_vertex, b + max_vertex])

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

session['idos'] = idos
session['edos'] = edos
session['volume'] = volume

compas.json_dump(session, FILE)

# ==============================================================================
# visualize
# ==============================================================================

artist = MeshArtist(idos, layer="HiLo::Concrete1::Idos")
artist.clear_layer()
artist.draw_mesh(disjoint=True, color=(255, 0, 0))

artist = MeshArtist(edos, layer="HiLo::Concrete1::Edos")
artist.clear_layer()
artist.draw_mesh(disjoint=True, color=(0, 0, 255))

artist = MeshArtist(volume, layer="HiLo::Concrete1::Volume")
artist.clear_layer()
artist.draw_mesh(disjoint=True)
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))
Ejemplo n.º 24
0
from compas.geometry import Box
from compas.geometry import Frame
from compas.geometry import Projection, Plane, Vector
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_1 = Frame([7, 7, 7], [0.5, 1, 0], [1, 0, 0.5])

# Create a Box with that frame
box_1 = Box(frame_1, 1, 2, 3)

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

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

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

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

# Draw
artist1.draw()
artist2.draw_edges(color="#00ff00")
Ejemplo n.º 25
0
"""
width, length, height = 1, 1, 8
box = Box(F, width, length, height)

#create projection
projection_plane = Plane([0, 0, 0], [0, 0, 1])  #world XY plane
P = Projection.from_plane(projection_plane)  #orthogonal projection

print("Projection:\n", P)
"""
CREATE PROJECTED MESH
"""
mesh_01 = Mesh.from_shape(box)
projected_mesh = mesh_01

try:
    projected_mesh.transform(P)
except:
    print("Something went wrong with the projection")
"""
ARTISTS
"""
artist_01 = BoxArtist(box, layer='box')
artist_02 = MeshArtist(mesh_01, layer='box::projection edges')

artist_01.clear_layer()
artist_02.clear_layer()

artist_01.draw()
artist_02.draw_edges(color="#00ff00")
    faces = [[0, 3, 2, 1], [4, 5, 6, 7], [3, 0, 4, 7], [0, 1, 5, 4],
             [1, 2, 6, 5], [1, 2, 6, 5], [2, 3, 7, 6]]

    block = Mesh.from_vertices_and_faces(vertices, faces)
    blocks.append(block)

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

flag = False
for i in blocks:

    if (flag == False):
        flag = True
        artist = MeshArtist(i, layer="Boxes::Test")
        artist.clear_layer()
    else:
        artist = MeshArtist(i, layer="Boxes::Test")
        artist.draw_faces(join_faces=True, color=(0, 255, 255))
        #artist.draw_vertexlabels()

#Write Meshes To Json
# put all the mesh.data from all meshes in one dictionary
meshes_data = {}
for index, mesh in enumerate(blocks):
    meshes_data[index] = mesh.data

# save the dictionary to a json file
with open('blocks.json', 'w+') as fp:
    json.dump(meshes_data, fp, sort_keys=True, indent=4)
Ejemplo n.º 27
0
# ==============================================================================

blank = Box.from_bounding_box(block.bounding_box())
blank.xsize += 50
blank.ysize += 50
blank.zsize += 50

# ==============================================================================
# Store blank as attribute of block
# ==============================================================================

block.attributes['blank'] = blank

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

block.to_json(FILE)

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

compas_rhino.clear()

artist = MeshArtist(block, layer="ITA20::HotWire::Block")
artist.draw_faces()

artist = BoxArtist(blank, layer="ITA20::HotWire::Blank")
artist.draw(show_edges=True, show_faces=False)
Ejemplo n.º 28
0
 def redraw_current_mesh(self):
     self.undraw_current_mesh()
     guid = MeshArtist(self.processing_func(self.mesh)).draw_mesh()
     self.guid_to_mesh_current[guid] = self.mesh
Ejemplo n.º 29
0
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()

boundary = mesh.vertices_on_boundary()
special5 = list(mesh.vertices_where({'vertex_degree': 5}))
special6 = list(mesh.vertices_where({'vertex_degree': 6}))

color = {vertex: (255, 0, 0) for vertex in boundary}
color.update({vertex: (0, 255, 0) for vertex in special5})
color.update({vertex: (0, 0, 255) for vertex in special6})

artist.draw_vertices(
    vertices=boundary + special5 + special6,
    color=color
)

color = {face: (255, 0, 0) for face in mesh.faces_on_boundary()}
color.update({face: (0, 255, 0) for vertex in special5 for face in mesh.vertex_faces(vertex)})
color.update({face: (0, 0, 255) for vertex in special6 for face in mesh.vertex_faces(vertex)})

artist.draw_faces(
Ejemplo n.º 30
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()