def visualize_gaussian_integration(ga: GaussianAccumulatorKDPy, mesh: o3d.geometry.TriangleMesh, ds=50, min_samples=10000, max_phi=100, integrate_kwargs=dict()): num_buckets = ga.num_buckets to_integrate_normals = np.asarray(mesh.triangle_normals) # remove normals on bottom half of sphere to_integrate_normals, _ = filter_normals_by_phi(to_integrate_normals, max_phi=180) # determine optimal sampling num_normals = to_integrate_normals.shape[0] ds_normals = int(num_normals / ds) to_sample = max(min([num_normals, min_samples]), ds_normals) ds_step = int(num_normals / to_sample) # perform sampling of normals to_integrate_normals = to_integrate_normals[0:num_normals:ds_step, :] mask = np.asarray(ga.mask) query_size = to_integrate_normals.shape[0] mask = np.ones((np.asarray(ga.mesh.triangles).shape[0], ), dtype=bool) mask[num_buckets:] = False class_name_str = type(ga).__name__ # integrate normals if class_name_str in [ 'GaussianAccumulatorKD', 'GaussianAccumulatorOpt', 'GaussianAccumulatorS2' ]: to_integrate_normals = MatX3d(to_integrate_normals) # mask = np.ma.make_mask(mask) # triangles = np.asarray(ga.mesh.triangles) t0 = time.perf_counter() neighbors_idx = np.asarray( ga.integrate(to_integrate_normals, **integrate_kwargs)) t1 = time.perf_counter() elapsed_time = (t1 - t0) * 1000 print( "{}; KD tree size: {}; Query Size (K): {}; Execution Time(ms): {:.1f}". format(class_name_str, num_buckets, query_size, elapsed_time)) normalized_counts = np.asarray(ga.get_normalized_bucket_counts()) color_counts = get_colors(normalized_counts)[:, :3] # print(normalized_counts) refined_icosahedron_mesh = create_open_3d_mesh( np.asarray(ga.mesh.triangles), np.asarray(ga.mesh.vertices)) # Colorize normal buckets colored_icosahedron = assign_vertex_colors(refined_icosahedron_mesh, color_counts, mask) return colored_icosahedron, np.asarray(to_integrate_normals), neighbors_idx
def extract_chart(mesh, chart_idx=0): triangles = np.asarray(mesh.triangles) vertices = np.asarray(mesh.vertices) num_triangles = triangles.shape[0] chart_size = int(num_triangles / 5) chart_start_idx = chart_idx * chart_size chart_end_idx = chart_start_idx + chart_size triangles_chart = triangles[chart_start_idx:chart_end_idx, :] chart_mesh = create_open_3d_mesh(triangles_chart, vertices) chart_mesh.vertex_colors = mesh.vertex_colors return chart_mesh, chart_start_idx, chart_end_idx
def integrate_normals_and_visualize(to_integrate_normals, ga): to_integrate_normals_mat = MatX3d(to_integrate_normals) t0 = time.perf_counter() neighbors_idx = np.asarray(ga.integrate(to_integrate_normals_mat)) t1 = time.perf_counter() elapsed_time = (t1 - t0) * 1000 normalized_counts = np.asarray(ga.get_normalized_bucket_counts()) color_counts = get_colors(normalized_counts)[:, :3] refined_icosahedron_mesh = create_open_3d_mesh( np.asarray(ga.mesh.triangles), np.asarray(ga.mesh.vertices)) # Colorize normal buckets colored_icosahedron = assign_vertex_colors(refined_icosahedron_mesh, color_counts, None) return colored_icosahedron
def main(): kwargs_base = dict(level=4, max_phi=180) kwargs_s2 = dict(**kwargs_base) ga_cpp_s2 = GaussianAccumulatorS2(**kwargs_s2) normals_sorted_cube_hilbert = np.asarray(ga_cpp_s2.get_bucket_normals()) refined_icosahedron_mesh = create_open_3d_mesh( np.asarray(ga_cpp_s2.mesh.triangles), np.asarray(ga_cpp_s2.mesh.vertices)) indices = np.asarray(ga_cpp_s2.get_bucket_sfc_values()) colors = indices / np.iinfo(indices.dtype).max colors = cm.viridis(colors)[:, :3] lm = LineMesh(normals_sorted_cube_hilbert * 1.01, colors=colors, radius=0.004) # colored_icosahedron = assign_vertex_colors(refined_icosahedron_mesh, colors) # plot_meshes([refined_icosahedron_mesh, create_line_set(normals_sorted_cube_hilbert * 1.01)]) ls = o3d.geometry.LineSet.create_from_triangle_mesh( refined_icosahedron_mesh) refined_icosahedron_mesh.paint_uniform_color([0.5, 0.5, 0.5]) plot_meshes([refined_icosahedron_mesh, ls, *lm.cylinder_segments])
def decompose(ico): triangles = np.asarray(ico.triangles) vertices = np.asarray(ico.vertices) ico_o3d = create_open_3d_mesh(triangles, vertices) return triangles, vertices, ico_o3d