Example #1
0
if __name__ == '__main__':

	import random as rd
	import compas
	from compas_pattern.datastructures.mesh_quad.mesh_quad import QuadMesh
	from compas.datastructures import mesh_smooth_centroid
	from compas_plotters.meshplotter import MeshPlotter

	mesh = QuadMesh.from_obj(compas.get('faces.obj'))
	mesh.collect_strips()
	walker = Walker(mesh)
	walker.start()
	orders = [2,0,2]
	#orders = [rd.randint(0,1) for _ in range(10)]
	#orders = [2] + orders + [2]
	#orders = [2, 1, 3, 0, 3, 2, 1, 3, 2, 2]
	print(orders)
	walker.interpret_orders(orders)
	print(walker.polyedge)
	print('added: ', walker.added_polyedges)
	print('deleted: ', walker.delete_strips)

	mesh_smooth_centroid(walker.mesh, kmax=1)

	plotter = MeshPlotter(walker.mesh)
	plotter.draw_vertices(radius=.1, text='key')
	plotter.draw_edges()
	plotter.draw_faces()
	plotter.show()

Example #2
0
    def func0(mesh, vkey):
        normal = mesh.vertex_normal(vkey)
        return scale_vector(normal, 1)

    def func1(mesh, vkey):
        normal = mesh.vertex_normal(vkey)
        return scale_vector(normal, -1)

    mesh = QuadMesh.from_json('/Users/Robin/Desktop/json/debug.json')
    mesh.collect_strips()
    mesh.collect_polyedges()

    polyedge_key_to_colour = dense_quad_mesh_polyedge_2_coloring(mesh)
    polyedges_0 = [
        mesh.data['attributes']['polyedges'][key]
        for key, colour in polyedge_key_to_colour.items() if colour == 0
    ]
    polyedges_1 = [
        mesh.data['attributes']['polyedges'][key]
        for key, colour in polyedge_key_to_colour.items() if colour == 1
    ]

    vkey_to_group = fold_vertex_group(mesh, polyedges_1)
    #fold(mesh, vkey_to_group, func0, func1)

    plotter = MeshPlotter(mesh, figsize=(20, 20))
    plotter.draw_vertices(radius=0.4, text=vkey_to_group)
    plotter.draw_edges()
    plotter.draw_faces()
    plotter.show()
Example #3
0
	import compas
	from compas_pattern.datastructures.mesh_quad_coarse.mesh_quad_coarse import CoarseQuadMesh
	from compas.datastructures import mesh_smooth_centroid
	from compas_pattern.datastructures.mesh.operations import mesh_move_by
	from compas.datastructures import meshes_join
	from compas_plotters.meshplotter import MeshPlotter

	mesh = CoarseQuadMesh.from_obj(compas.get('faces.obj'))
	mesh.collect_strips()
	#polyedge = [0, 1, 2, 8, 14, 13, 12, 6, 0]
	#polyedge = [7, 8, 9, 15, 21, 20, 19, 13, 7]
	polyedge = [0, 1, 7, 6]
	add_strip(mesh, polyedge)
	mesh_smooth_centroid(mesh, kmax=10, fixed=mesh.vertices_on_boundary())
	plotter = MeshPlotter(mesh, figsize=(20, 20))
	plotter.draw_vertices(radius=0.1, text='key')
	plotter.draw_edges()
	plotter.draw_faces()
	plotter.show()

	# plotter = MeshPlotter(mesh, figsize = (20, 20))
	# plotter.draw_vertices(radius = 0.25, text='key')
	# plotter.draw_edges()
	# plotter.draw_faces(text='key')
	# plotter.show()

	# polyedges = [
	# 	[6, 7, 8, 9, 10, 11],
	# 	[0, 1, 2, 3, 4, 5],
	# 	[30, 31, 32, 33, 34, 35],
from compas_plotters.meshplotter import MeshPlotter

# read input data
filepath = 'data/01_decomposition.json'
with open(filepath, 'r') as fp:
    data = json.load(fp)

# get outer boundary polyline, inner boundary polylines, polyline features and point features
outer_boundary, inner_boundaries, polyline_features, point_features = data

# 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,
                              src='numpy')

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

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

# plot decomposition mesh
plotter = MeshPlotter(mesh, figsize=(5, 5))
plotter.draw_edges()
plotter.draw_vertices()
plotter.draw_faces()
plotter.show()
Example #5
0
# find_form(mesh)
# print('load path: ', load_path(mesh))

t0 = time.time()
opt_design = None
opt_param = None
opt_perf = None
n = 10
for i in range(n):
    t = float(i) / float(n)
    perf = func(t, mesh, polyline_points)
    if opt_perf is None or perf < opt_perf:
        opt_perf = perf
        opt_param = t
        opt_design = mesh.copy()
t1 = time.time()
print('computing time: ', t1 - t0)
print('opt parameter: ', opt_param, 'optimal performance: ', opt_perf)

# for vkey, attr in mesh.vertices(True):
#     attr['x'], attr['y'], attr['z'] = attr['x'], attr['z'], attr['y']

# t = [0.5]
# print(descent_numpy(t, func, iterations=100, gtol=10**(-1), bounds=[[0, 1]], args=(mesh, polyline_points)))

plotter = MeshPlotter(opt_design, figsize=(20, 20))
plotter.draw_vertices(radius=0.05)
plotter.draw_edges()
plotter.draw_faces()
plotter.show()
Example #6
0
import json

from compas_singular.datastructures import CoarsePseudoQuadMesh

from compas_plotters.meshplotter import MeshPlotter

# read input data
json_data = 'data/coarse_quad_mesh_british_museum_poles.json'

coarse_pseudo_quad_mesh = CoarsePseudoQuadMesh.from_json(json_data)

#plot coarse quad mesh
plotter = MeshPlotter(coarse_pseudo_quad_mesh, figsize=(5, 5))
plotter.draw_edges()
plotter.draw_vertices(radius=.05)
plotter.draw_faces()
plotter.show()

# collect strip data
coarse_pseudo_quad_mesh.collect_strips()

# densification with target length
coarse_pseudo_quad_mesh.set_strips_density_target(t=.5)
coarse_pseudo_quad_mesh.densification()

# plot dense quad mesh
plotter = MeshPlotter(coarse_pseudo_quad_mesh.get_quad_mesh(), figsize=(5, 5))
plotter.draw_edges()
plotter.draw_vertices(radius=.05)
plotter.draw_faces()
plotter.show()
Example #7
0
        [-30, 0, 0],
        [-30, -30, 0],
        [0, -30, 0],
        [30, -30, 0],
    ]

    for vector, mesh2 in zip(vectors, meshes):
        mesh2.collect_strips()
        fix_boundaries(mesh2)
        define_density(mesh2, 300)
        fix_boundaries(mesh2.get_quad_mesh())
        find_form(mesh2.get_quad_mesh(), 100.0)
        mesh_move_by(mesh2.get_quad_mesh(), vector)
        rotate_mesh(mesh2.get_quad_mesh())

    # for mesh2 in meshes:
    # 	if mesh2.get_quad_mesh() is None:
    # 		print('!')

    # for mesh in meshes:
    # 	plotter = MeshPlotter(mesh, figsize=(5.0, 5.0))
    # 	plotter.draw_edges()
    # 	plotter.draw_faces()
    # 	plotter.show()

    all_meshes = meshes_join([mesh2.get_quad_mesh() for mesh2 in meshes])
    plotter = MeshPlotter(all_meshes, figsize=(5.0, 5.0))
    plotter.draw_edges()
    plotter.draw_faces()
    plotter.show()
Example #8
0
    mesh_0.collect_polyedges()
    print(mesh_0.is_quadmesh())
    print(mesh_0.number_of_strips())

    # vertices = [[12.97441577911377, 24.33094596862793, 0.0], [18.310085296630859, 8.467333793640137, 0.0], [30.052173614501953, 18.846050262451172, 0.0], [17.135400772094727, 16.750551223754883, 0.0], [16.661802291870117, 22.973459243774414, 0.0], [14.180665969848633, 26.949295043945313, 0.0], [36.052761077880859, 26.372636795043945, 0.0], [26.180931091308594, 21.778648376464844, 0.0], [19.647378921508789, 12.288106918334961, 0.0], [9.355668067932129, 16.475896835327148, 0.0], [18.929227828979492, 16.271940231323242, 0.0], [7.34525203704834, 12.111981391906738, 0.0], [13.31309986114502, 14.699410438537598, 0.0], [18.699434280395508, 19.613750457763672, 0.0], [11.913931846618652, 10.593378067016602, 0.0], [17.163223266601563, 26.870658874511719, 0.0], [26.110898971557617, 26.634754180908203, 0.0], [22.851469039916992, 9.81414794921875, 0.0], [21.051292419433594, 7.556171894073486, 0.0], [22.1370792388916, 19.089054107666016, 0.0]]
    # faces = [[15, 5, 0, 4], [0, 9, 12, 4], [9, 11, 14, 12], [14, 1, 8, 12], [1, 18, 17, 8], [17, 2, 7, 8], [2, 6, 16, 7], [16, 15, 4, 7], [13, 19, 7, 4], [19, 10, 8, 7], [10, 3, 12, 8], [3, 13, 4, 12]]
    # mesh = QuadMesh.from_vertices_and_faces(vertices, faces)
    # mesh.collect_strips()
    # mesh.collect_polyedges()

    # mesh_0 = CoarseQuadMesh.from_quad_mesh(mesh)
    # mesh_0.collect_strips()
    # mesh_0.collect_polyedges()

    # print(mesh_0.number_of_strips())
    # print(mesh_0.data['attributes']['vertex_coarse_to_dense'])
    # print(mesh_0.data['attributes']['edge_coarse_to_dense'])

    # mesh_0.set_strips_density(1)
    # mesh_0.set_strip_density(0, 6)
    # mesh_0.set_strip_density(1, 5)
    # mesh_0.densification()
    #mesh_0.get_strip_densities()
    #mesh_smooth_centroid(mesh_0.quad_mesh, kmax = 10)

    plotter = MeshPlotter(mesh_0, figsize=(10, 10))
    plotter.draw_edges()
    plotter.draw_vertices()
    plotter.draw_faces()
    plotter.show()
Example #9
0
        string = lizard.from_vector_to_string(vector)
        #print(string)
        try:
            lizard.from_string_to_rules(string)
            # print(lizard.lizard)

            orders = [rd.randint(0, 1) for _ in range(5)]
            orders = [2] + orders + [2]
            orders = [2, 1, 3, 0, 3, 2, 1, 3, 2, 2]

            # print('boundaries 1/2')
            fix_boundaries(mesh)
            # print('densification')
            mesh.set_mesh_density_face_target(300)
            mesh.densification()
            # print('boundaries 2/2')
            fix_boundaries(mesh.get_quad_mesh())
            # print('form finding')
            find_form(mesh.get_quad_mesh(), 100.0)

            plotter = MeshPlotter(mesh.get_quad_mesh(), figsize=(10, 10))
            plotter.draw_vertices(radius=.1)  #, text='key')
            plotter.draw_edges()
            plotter.draw_faces()
            name = ''.join([str(i) for i in vector])
            plotter.save('../../../../data/3/' + name)
            # plotter.show()
            # print('done')
        except:
            pass