# make the proxy server for remote procedure calls ro compas.geometry proxy = Proxy('compas.geometry') # define points of the CDT points = [[2.994817685045075, 10.855606612493078, 0.0], [4.185204599300653, 9.527867361977242, 0.0], [4.414125159734419, 10.718254276232818, 0.0], [5.925000858597267, 9.344730913630228, 0.0], [8.900968144236211, 10.809822500406325, 0.0], [9.496161601363999, 8.566401008155429, 0.0], [7.710581229980631, 7.9254234389408875, 0.0], [7.847933566240888, 6.414547740078039, 0.0], [3.9104999267801377, 4.9036720412151915, 0.0], [5.2909301507195865, 6.342692886748852, 0.0]] # define constrained segements of the CDT segments = list(pairwise(list(range(len(points))) + [0])) # compute vertices and faces of the CDT vertices, faces = proxy.conforming_delaunay_triangle(points, segments) # make mesh of the vertices and faces of the CDT mesh = Mesh.from_vertices_and_faces(vertices, faces) # visualise artist = MeshArtist(mesh, layer="RPC::CDT") artist.clear_layer() artist.draw_vertices() artist.draw_vertexlabels() artist.draw_faces()
def mesh_draw_vertex_labels(mesh, attr_name=None, layer=None, color=None, formatter=None): """Draw labels for the vertices of a mesh. Parameters ---------- mesh : compas.datastructures.Mesh A mesh object. attr_name : str (None) The name of the attribute value to display in the label. Default is is to display the vertex key. layer : str (None) The layer to draw in. Default is to draw in the current layer. color : str, tuple, list, dict (None) The color specififcation for the labels. Colors should be specified in the form of a string (hex colors) or as a tuple of RGB components. To apply the same color to all face labels, provide a single color specification. Individual colors can be assigned using a dictionary of key-color pairs. Missing keys will be assigned the default vertex color (``self.defaults['vertex.color']``). Default is to inherit color from the parent layer. formatter : callable (None) A formatting function. Defaults to the built-in ``str`` function. Notes ----- The labels are named using the following template: ``"{}.vertex.label.{}".format(self.mesh.name, key)``. This name is used afterwards to identify vertices of the meshin the Rhino model. Examples -------- >>> """ if not attr_name: attr_name = 'key' if formatter: assert callable(formatter), 'The provided formatter is not callable.' else: formatter = str text = {} for index, (key, attr) in enumerate(mesh.vertices(True)): if 'key' == attr_name: value = key elif 'index' == attr_name: value = index else: value = attr[attr_name] text[key] = formatter(value) artist = MeshArtist(mesh) artist.layer = layer artist.clear_vertexlabels() artist.draw_vertexlabels(text=text, color=color) artist.redraw()
def draw_vertexlabels(self, **kwattr): artist = MeshArtist(self) artist.draw_vertexlabels(**kwattr)
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( color={key: (255, 0, 0) for key in mesh.vertices_on_boundary()}) artist.draw_vertexlabels( text={key: str(mesh.vertex_degree(key)) for key in mesh.vertices()}) artist.draw_edges(keys=list(mesh.edges_on_boundary()), color=(255, 0, 0)) artist.draw_faces( color={ key: (150, 255, 150) for key in mesh.faces() if not mesh.is_face_on_boundary(key) })
# 2D Subdivision vertices = [[0.5, 0.0, 0.0], [0.0, 1.0, 0.0], [-0.5, 0.0, 0.0], [1.0, 1.0, 0.0]] faces = [[0, 1, 2], [1, 0, 3]] my_mesh = Mesh.from_vertices_and_faces(vertices, faces) artist = MeshArtist(my_mesh, layer="00_my_first mesh") artist.clear_layer() artist.draw_vertices() artist.draw_faces() artist.draw_edges() artist.draw_vertexlabels() artist.draw_facelabels() artist.draw_edgelabels() # iterate through the mesh # for key,attr in my_mesh.vertices(True): # print (key, attr['x'], attr['y'], attr['z']) # for key in my_mesh.faces(): # print(key) # for key in my_mesh.edges(): # print(key) # get topology information vertex = 0
path.append(current_key) if my_mesh.is_vertex_on_boundary(current_key): break neighbours = my_mesh.vertex_neighbors(current_key, ordered=True) i = neighbours.index(previous_key) previous_key, current_key = current_key, neighbours[i - 2] print(path) #visualize artist = MeshArtist(my_mesh) #artist.draw_vertices( #color={key: (255, 0, 0) for key in boundary_key}) artist.draw_vertices(path, color={key: (255, 0, 0) for key in [start_key]}) #artist.draw_vertices(neighbours) artist.draw_edges() artist.draw_faces() #artist.draw_vertexlabels( #text={key: str(key) for key in boundary_key},color={start_key: (255, 0, 0)}) #artist.draw_vertexlabels( #text={key: str(key) for key in [start_key]},color={start_key: (255, 0, 0)}) artist.draw_vertexlabels(text={key: str(key) for key in path}, color={key: (255, 0, 0) for key in path})
mesh_quads_to_triangles(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()] # ============================================================================== # Geodistance # ============================================================================== root = mesh.get_any_vertex() # D = igl.trimesh_geodistance_exact(V, F, key_index[root]) D = igl.trimesh_geodistance_heat(V, F, key_index[root]) # ============================================================================== # Visualization # ============================================================================== cmap = Colormap(D, 'red') artist = MeshArtist(mesh, layer="IGL::GeoDistance") artist.clear_layer() artist.draw_mesh() artist.draw_vertices( color={key: cmap(d) for key, d in zip(mesh.vertices(), D)}) artist.draw_vertexlabels(text={root: "root"}, color={0: (255, 255, 255)})