from compas.datastructures import Mesh from compas.topology import trimesh_remesh from compas.topology import delaunay_from_points from compas.topology import voronoi_from_delaunay from compas.geometry import pointcloud_xy from compas.plotters import MeshPlotter points = pointcloud_xy(10, (0, 10)) faces = delaunay_from_points(points) delaunay = Mesh.from_vertices_and_faces(points, faces) trimesh_remesh(delaunay, 1.0, allow_boundary_split=True) points = [delaunay.vertex_coordinates(key) for key in delaunay.vertices()] faces = delaunay_from_points(points) delaunay = Mesh.from_vertices_and_faces(points, faces) voronoi = voronoi_from_delaunay(delaunay) lines = [] for u, v in voronoi.edges(): lines.append({ 'start': voronoi.vertex_coordinates(u, 'xy'), 'end': voronoi.vertex_coordinates(v, 'xy'), 'width': 1.0 }) plotter = MeshPlotter(delaunay, figsize=(10, 6))
__author__ = ['Tom Van Mele', 'Matthias Rippmann'] __copyright__ = 'Copyright 2017, BRG - ETH Zurich', __license__ = 'MIT' __email__ = '*****@*****.**' # get the boundary curve # and divide into segments of a specific length 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 # and a callback for updating the conduit conduit = MeshConduit(mesh, refreshrate=2) def callback(mesh, k, args): conduit.redraw(k) # run the remeshing algorithm # and draw the result
from compas_rhino.helpers import MeshArtist __author__ = ['Tom Van Mele', 'Matthias Rippmann'] __copyright__ = 'Copyright 2017, BRG - ETH Zurich', __license__ = 'MIT' __email__ = '*****@*****.**' # select the points # select the boundary # select the hole(s) guids = compas_rhino.select_points("Select points.") points = compas_rhino.get_point_coordinates(guids) guid = compas_rhino.select_polyline("Select boundary.") boundary = compas_rhino.get_polyline_coordinates(guid) guids = compas_rhino.select_polylines("Select holes.") holes = [compas_rhino.get_polyline_coordinates(guid) for guid in guids] # make a delaunay triangulation # within the boundary # and around the holes faces = delaunay_from_points(points, boundary=boundary, holes=holes) mesh = Mesh.from_vertices_and_faces(points, faces) # draw the result artist = MeshArtist(mesh) artist.draw_faces(join_faces=True)
holes.append(crvs_opening_pts) # could be more efficient since holes already # assigned to another face are checked again attr['hole_polygons'] = holes #create triangular mesh for each face delaunay_meshes = [] count = 1 for fkey, attr in mesh.faces(True): polygon = attr['polygon'] holes = attr['hole_polygons'] #create flat list of all points points = polygon + [item for hole in holes for item in hole] #compute initial delaunay mesh based on all points for the current face faces = delaunay_from_points(points, boundary=polygon, holes=holes) delaunay = Mesh.from_vertices_and_faces(points, faces) rs.Prompt('Computing triangular mesh for face {} of {}'.format( count, mesh.number_of_faces())) #compute the remeshed delaunay for the current face trimesh_remesh(delaunay, target=trg_length, tol=0.05, kmax=300, allow_boundary_split=False, allow_boundary_swap=True, verbose=False) delaunay_meshes.append(delaunay)