<jupyter_start><jupyter_text>Example MeshThis is the example mesh that we will be using in our discussion<jupyter_code>import open3d as o3d
import numpy as np
import time
from fastgac.o3d_util import plot_meshes, assign_vertex_colors, create_open_3d_mesh, get_colors, get_arrow_normals
from examples.python.util.mesh_util import BASEMENT_CHAIR


mesh = o3d.io.read_triangle_mesh(str(BASEMENT_CHAIR))
mesh = mesh.compute_triangle_normals()
plot_meshes([mesh], axis_translate=[-1.00, 0, 1])
Image(f"{SRC_DOCS}/tutorials/example_mesh.png")<jupyter_output><empty_output><jupyter_text>Creating HistogramThis section will teach you first how to create the Gaussian Accumulator and then integrate triangle normals into its spherical histogram. We imported the class and then created the accumulator. The `level=3` indicates a third level of refinement of approximating a sphere. The higher the levels the more smooth-like sphere surface we get. I would stick to 3 or 4.<jupyter_code>from fastgac import GaussianAccumulatorS2
ga_cpp_s2 = GaussianAccumulatorS2(level=3)
ga_cpp_s2<jupyter_output><empty_output><jupyter_text>Next we need to integrate the triangle normals of the mesh into the GA. You generally do NOT need all the triangles, meaning you can randomly down-sample from the mesh. For this example we will just use all of them.<jupyter_code>from fastgac import MatX3d

num_triangles = np.asarray(mesh.triangle_normals).shape[0]
triangle_normals = MatX3d(np.asarray(mesh.triangle_normals))
t0 = time.perf_counter()
bucket_indices = ga_cpp_s2.integrate(triangle_normals)
t1 = time.perf_counter()

print(f"Integrated {num_triangles:d} triangle normals into the histogram in {(t1-t0) * 1000:.2f} milliseconds")<jupyter_output>Integrated 65051 triangle normals into the histogram in 7.63 milliseconds<jupyter_text>If you want to visualize this we have some helper functions here. This is totally optional.<jupyter_code># For visualization
normalized_counts = np.asarray(ga_cpp_s2.get_normalized_bucket_counts())
color_counts = get_colors(normalized_counts)[:, :3]
refined_icosahedron_mesh = create_open_3d_mesh(np.asarray(ga_cpp_s2.mesh.triangles), np.asarray(ga_cpp_s2.mesh.vertices))
# Colorize normal buckets
colored_icosahedron = assign_vertex_colors(refined_icosahedron_mesh, color_counts, None)
plot_meshes([colored_icosahedron], axis_translate=[-1.50, 0, 0])
Image(f"{SRC_DOCS}/tutorials/example_ga_color.png")<jupyter_output><empty_output><jupyter_text>Peak DetectionThis section will show you how to perform peak detection on the histogram. The basic idea is to unwrap the refined icosahedron into a 2D image and perform peak detection.<jupyter_code>from fastgac import IcoCharts
from fastgac.peak_and_cluster import find_peaks_from_ico_charts
import matplotlib.pyplot as plt

ico_chart = IcoCharts(level=3) # make sure it has the same level
normalized_bucket_counts_by_vertex = ga_cpp_s2.get_normalized_bucket_counts_by_vertex(True) # must be set to true
ico_chart.fill_image(normalized_bucket_counts_by_vertex)

plt.imshow(np.asarray(ico_chart.image))<jupyter_output><empty_output><jupyter_text>Each pixel on the image roughly corresponds to a *vertex* on the icosahedron.  We now perform peak detection. Note that there is some copy padding ghost cells but the function `find_peaks_from_ico_charts` will take care of that. Please see documentation on this function to learn what the parameters do.<jupyter_code># These are your configurable parameters
find_peaks_kwargs = dict(threshold_abs=50, min_distance=1, exclude_border=False, indices=False) # skimage.features.local_max
cluster_kwargs = dict(t=0.2, criterion='distance') # scipy.spatial.fcluster
average_filter = dict(min_total_weight=0.05) # noramlized avergate weight of each group must have this min value

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)
arrow_avg_peaks = get_arrow_normals(avg_peaks, avg_weights)

print(avg_peaks)
plot_meshes([colored_icosahedron, *arrow_avg_peaks], axis_translate=[-1.50, 0, 0])
Image(f"{SRC_DOCS}/tutorials/example_ga_peak.png")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.07494145199063232, 'fraction_numerical': 0.01522248243559719, 'mean_word_length': 7.69857433808554, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '224768', 'license': 'MIT', 'n_tokens_mistral': 1462, 'n_tokens_neox': 1392, 'n_words': 375, 'path': 'docs/tutorial/Python/basicdemo.ipynb', 'repo_name': 'JeremyBYU/FastGaussianAccumulator', 'size': '4270'}