def main(): EXAMPLE_INDEX = 2 kwargs_base = dict(level=4, max_phi=180) kwargs_s2 = dict(**kwargs_base) kwargs_opt_integrate = dict(num_nbr=12) query_max_phi = kwargs_base['max_phi'] - 5 # Get an Example Mesh ga_cpp_s2 = GaussianAccumulatorS2(**kwargs_s2) example_mesh = o3d.io.read_triangle_mesh(str(ALL_MESHES[EXAMPLE_INDEX])) r = ALL_MESHES_ROTATIONS[EXAMPLE_INDEX] example_mesh_filtered = example_mesh if r is not None: example_mesh_filtered = example_mesh_filtered.rotate(r.as_matrix()) example_mesh_filtered = example_mesh_filtered.filter_smooth_laplacian( 5) example_mesh_filtered.compute_triangle_normals() np.save('fixtures/normals/basement.npy', np.asarray(example_mesh_filtered.triangle_normals)) colored_icosahedron_s2, normals, neighbors_s2 = visualize_gaussian_integration( ga_cpp_s2, example_mesh_filtered, max_phi=query_max_phi, integrate_kwargs=kwargs_opt_integrate) o3d.visualization.draw_geometries([example_mesh_filtered]) o3d.visualization.draw_geometries([colored_icosahedron_s2]) # Visualize unwrapping ico_chart_ = IcoCharts(4) t2 = time.perf_counter() normalized_bucket_counts_by_vertex = ga_cpp_s2.get_normalized_bucket_counts_by_vertex( True) ico_chart_.fill_image(normalized_bucket_counts_by_vertex) find_peaks_kwargs = dict(threshold_abs=50, min_distance=1, exclude_border=False, indices=False) print(np.asarray(ico_chart_.image).shape) cluster_kwargs = dict(t=0.1, criterion='distance') _, _, avg_peaks, _ = find_peaks_from_ico_charts( ico_chart_, np.asarray(normalized_bucket_counts_by_vertex), find_peaks_kwargs=find_peaks_kwargs, cluster_kwargs=cluster_kwargs) t3 = time.perf_counter() print(t3 - t2) print(avg_peaks) full_image = np.asarray(ico_chart_.image) plt.imshow(full_image) plt.axis('off') # plt.xticks(np.arange(0, full_image.shape[1], step=1)) # plt.yticks(np.arange(0, full_image.shape[0], step=1)) plt.show()
def get_image_peaks(ga_cpp_s2, level=2, **kwargs): ico_chart = IcoCharts(level) normalized_bucket_counts_by_vertex = ga_cpp_s2.get_normalized_bucket_counts_by_vertex( True) ico_chart.fill_image(normalized_bucket_counts_by_vertex) find_peaks_kwargs = dict(threshold_abs=25, min_distance=1, exclude_border=False, indices=False) cluster_kwargs = dict(t=0.10, criterion='distance') average_filter = dict(min_total_weight=0.10) peaks, clusters, avg_peaks, avg_weights = find_peaks_from_ico_charts( ico_chart, np.asarray(normalized_bucket_counts_by_vertex), find_peaks_kwargs, cluster_kwargs, average_filter) gaussian_normals_sorted = np.asarray(ico_chart.sphere_mesh.vertices) pcd_all_peaks = get_pc_all_peaks(peaks, clusters, gaussian_normals_sorted) arrow_avg_peaks = get_arrow_normals(avg_peaks, avg_weights) return [pcd_all_peaks, *arrow_avg_peaks]
def example_normals(normals: np.ndarray): LEVEL = 2 kwargs_base = dict(level=LEVEL, max_phi=180) kwargs_s2 = dict(**kwargs_base) # Create Gaussian Accumulator ga_cpp_s2 = GaussianAccumulatorS2(**kwargs_s2) # Integrate the normals and get open3d visualization colored_icosahedron = integrate_normals_and_visualize(normals, ga_cpp_s2) o3d.visualization.draw_geometries([colored_icosahedron]) # Create the IcoChart for unwrapping ico_chart_ = IcoCharts(LEVEL) normalized_bucket_counts_by_vertex = ga_cpp_s2.get_normalized_bucket_counts_by_vertex( True) ico_chart_.fill_image(normalized_bucket_counts_by_vertex) triangles_vertex_14 = [2, 15, 7, 260, 267, 256] # 2D Peak Detection find_peaks_kwargs = dict(threshold_abs=20, min_distance=1, exclude_border=False, indices=False) cluster_kwargs = dict(t=0.2, criterion='distance') average_filter = dict(min_total_weight=0.05) _, _, avg_peaks, _ = find_peaks_from_ico_charts( ico_chart_, np.asarray(normalized_bucket_counts_by_vertex), find_peaks_kwargs=find_peaks_kwargs, cluster_kwargs=cluster_kwargs) print("Detected Peaks: {}".format(avg_peaks)) full_image = np.asarray(ico_chart_.image) plt.imshow(full_image) plt.xticks(np.arange(0, full_image.shape[1], step=1)) plt.yticks(np.arange(0, full_image.shape[0], step=1)) plt.show() # Don't forget to reset the GA ga_cpp_s2.clear_count()
def analyze_mesh(mesh): """Demonstrates unwrapping and peak detection of a S2 Histogram""" LEVEL = 4 kwargs_base = dict(level=LEVEL, max_phi=180) kwargs_s2 = dict(**kwargs_base) kwargs_opt_integrate = dict(num_nbr=12) # Create Gaussian Accumulator ga_cpp_s2 = GaussianAccumulatorS2(**kwargs_s2) # This function will integrate the normals and return an open3d mesh for visualization. colored_icosahedron_s2, _, _ = visualize_gaussian_integration( ga_cpp_s2, mesh, max_phi=kwargs_base['max_phi'], integrate_kwargs=kwargs_opt_integrate) num_triangles = ga_cpp_s2.num_buckets # for verification ico_s2_organized_mesh = ga_cpp_s2.copy_ico_mesh(True) _, _, ico_o3d_s2_om = decompose(ico_s2_organized_mesh) colors_s2 = get_colors(range(num_triangles), colormap=plt.cm.tab20)[:, :3] colored_ico_s2_organized_mesh = assign_vertex_colors( ico_o3d_s2_om, colors_s2) # Demonstrate the five charts for visualization bucket_counts = np.asarray(ga_cpp_s2.get_normalized_bucket_counts(True)) bucket_colors = get_colors(bucket_counts)[:, :3] charts_triangles = [] for chart_idx in range(5): chart_size = int(num_triangles / 5) chart_start_idx = chart_idx * chart_size chart_end_idx = chart_start_idx + chart_size icochart_square = refine_icochart(level=LEVEL, square=True) _, _, icochart_square_o3d = decompose(icochart_square) colored_icochart_square = assign_vertex_colors( icochart_square_o3d, bucket_colors[chart_start_idx:chart_end_idx, :]) charts_triangles.append(colored_icochart_square) # Plot the unwrapped icosahedron new_charts = translate_meshes(charts_triangles, current_translation=-4.0, axis=1) all_charts = functools.reduce(lambda a, b: a + b, new_charts) plot_meshes(colored_ico_s2_organized_mesh, colored_icosahedron_s2, all_charts, mesh) ico_chart_ = IcoCharts(LEVEL) normalized_bucket_counts_by_vertex = ga_cpp_s2.get_normalized_bucket_counts_by_vertex( True) ico_chart_.fill_image(normalized_bucket_counts_by_vertex) find_peaks_kwargs = dict(threshold_abs=25, min_distance=1, exclude_border=False, indices=False) average_filter = dict(min_total_weight=0.05) _, _, avg_peaks, _ = find_peaks_from_ico_charts( ico_chart_, np.asarray(normalized_bucket_counts_by_vertex), find_peaks_kwargs=find_peaks_kwargs, average_filter=average_filter) print(avg_peaks) full_image = np.asarray(ico_chart_.image) plt.imshow(full_image) plt.xticks(np.arange(0, full_image.shape[1], step=1)) plt.yticks(np.arange(0, full_image.shape[0], step=1)) plt.show()