plotter = MeshPlotter(mesh, figsize=(12, 9)) plotter.draw_lines(lines) plotter.draw_faces() callback = partial(callback, plotter=plotter, filepath=THERE, export=EXPORT_PNG) # ========================================================================== # Set up K-Means algorithm # ========================================================================== faces = make_faces(str_mesh, vector_tag, weight=False) clusters = furthest_init(NUM, faces, callback=None) sel_clusters = clusters[-1] all_clusters = k_means(sel_clusters, faces, ITERS, MERGESPLIT, callback=None) final_clusters = all_clusters[-1] callback(1, clusters=final_clusters) # ========================================================================== # Visualization # ========================================================================== plotter.update(pause=0.5)
# Set up K-Means algorithm # ========================================================================== # define loss file errors = [] # NUM = 5 # number of clusters TEST_RANGE = 100 ITERS = 30 # number of iterations MERGESPLIT = False # merge split in k means. True is good for this example, but not for knitcandela! for num in range(1, TEST_RANGE): print('num clusters: ', num) faces = make_faces(str_mesh, vector_tag, weight=False) clusters = furthest_init(num, faces) sel_clusters = clusters[-1] all_clusters = k_means(sel_clusters, faces, ITERS, MERGESPLIT) final_clusters = all_clusters[-1] error = 0.0 for idx, cluster in final_clusters.items(): proxy = normalize_vector(cluster.proxy) fkeys = cluster.faces_keys for fkey in fkeys: vector = str_mesh.cMesh.get_face_attribute(fkey, vector_tag) vector = normalize_vector(vector) ali_vec = ut.align_vector(vector, proxy) difference = cg.subtract_vectors(ali_vec, proxy)