.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/example_surface_profiling.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_example_surface_profiling.py: .. _example_surface_profiling: =================================== example of surface profiling in slam =================================== .. GENERATED FROM PYTHON SOURCE LINES 8-14 .. code-block:: Python # Authors: Tianqi SONG # License: MIT # sphinx_gallery_thumbnail_number = 2 .. GENERATED FROM PYTHON SOURCE LINES 15-19 NOTE: there is no visualization tool in slam, but we provide at the end of this script exemplare code to do the visualization with an external solution ############################################################################## .. GENERATED FROM PYTHON SOURCE LINES 21-22 importation of slam modules .. GENERATED FROM PYTHON SOURCE LINES 22-26 .. code-block:: Python import numpy as np import slam.surface_profiling as surfpf import slam.io as sio .. GENERATED FROM PYTHON SOURCE LINES 27-28 loading an example mesh .. GENERATED FROM PYTHON SOURCE LINES 28-30 .. code-block:: Python mesh = sio.load_mesh("../examples/data/example_mesh.gii") .. GENERATED FROM PYTHON SOURCE LINES 31-32 Select a vertex and get the coordinate and normal. .. GENERATED FROM PYTHON SOURCE LINES 32-36 .. code-block:: Python vert_index = 1000 vert0 = mesh.vertices[vert_index] norm0 = mesh.vertex_normals[vert_index] .. GENERATED FROM PYTHON SOURCE LINES 37-40 Set the parameters for surface profiling initial direction of rotation, rotation angle, length and number of sampling steps .. GENERATED FROM PYTHON SOURCE LINES 40-45 .. code-block:: Python init_rot_dir = np.array([1, 1, 1]) - vert0 rot_angle = 10 r_step = 0.1 max_samples = 45 .. GENERATED FROM PYTHON SOURCE LINES 46-47 Surface profiling .. GENERATED FROM PYTHON SOURCE LINES 47-51 .. code-block:: Python profile_points = surfpf.surface_profiling_vert( vert0, norm0, init_rot_dir, rot_angle, r_step, max_samples, mesh ) .. GENERATED FROM PYTHON SOURCE LINES 52-94 VISUALIZATION USING EXTERNAL TOOLS ############################################################################ import trimesh.visual.color ############################################################################### # Visualize result prof_points_mesh = profile_points.reshape( profile_points.shape[0] * profile_points.shape[1], 3 ) prof_points_colors = np.zeros(prof_points_mesh.shape) points_mesh = trimesh.points.PointCloud( prof_points_mesh, colors=np.array(prof_points_colors, dtype=np.uint8) ) # set the points colors red, yellow, green, blue = [ [255, 0, 0, 255], [255, 255, 0, 255], [0, 255, 0, 255], [0, 0, 255, 255], ] color_i = np.zeros(4) for i in range(len(prof_points_mesh)): degree = i / max_samples num_profiles = int(360 / rot_angle) segment_color = num_profiles / 3 if degree <= segment_color: color_i = trimesh.visual.color.linear_color_map( degree / segment_color, [red, yellow] ) elif segment_color < degree <= segment_color * 2: color_i = trimesh.visual.color.linear_color_map( degree / segment_color - 1, [yellow, green] ) elif segment_color * 2 < degree <= num_profiles: color_i = trimesh.visual.color.linear_color_map( degree / segment_color - 2, [green, blue] ) points_mesh.colors[i] = np.array(color_i) # create a scene with the mesh and profiling points scene = trimesh.Scene([points_mesh, mesh]) scene.show(smooth=False) .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.098 seconds) .. _sphx_glr_download_auto_examples_example_surface_profiling.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: example_surface_profiling.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: example_surface_profiling.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: example_surface_profiling.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_