.. 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 Click :ref:`here ` 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-15 .. code-block:: default # Authors: Tianqi SONG # License: BSD (3-clause) # sphinx_gallery_thumbnail_number = 2 .. GENERATED FROM PYTHON SOURCE LINES 16-17 importation of slam modules .. GENERATED FROM PYTHON SOURCE LINES 17-23 .. code-block:: default import numpy as np import trimesh.visual.color import slam.surface_profiling as surfpf import slam.io as sio .. GENERATED FROM PYTHON SOURCE LINES 24-25 loading an example mesh .. GENERATED FROM PYTHON SOURCE LINES 25-27 .. code-block:: default mesh = sio.load_mesh("data/example_mesh.gii") .. GENERATED FROM PYTHON SOURCE LINES 28-29 Select a vertex and get the coordinate and normal. .. GENERATED FROM PYTHON SOURCE LINES 29-33 .. code-block:: default vert_index = 1000 vert0 = mesh.vertices[vert_index] norm0 = mesh.vertex_normals[vert_index] .. GENERATED FROM PYTHON SOURCE LINES 34-37 Set the parameters for surface profiling initial direction of rotation, rotation angle, length and number of sampling steps .. GENERATED FROM PYTHON SOURCE LINES 37-42 .. code-block:: default init_rot_dir = np.array([1, 1, 1]) - vert0 rot_angle = 10 r_step = 0.1 max_samples = 45 .. GENERATED FROM PYTHON SOURCE LINES 43-44 Surface profiling .. GENERATED FROM PYTHON SOURCE LINES 44-48 .. code-block:: default profile_points = surfpf.surface_profiling_vert( vert0, norm0, init_rot_dir, rot_angle, r_step, max_samples, mesh ) .. GENERATED FROM PYTHON SOURCE LINES 49-50 Visualize result .. GENERATED FROM PYTHON SOURCE LINES 50-88 .. code-block:: default 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.171 seconds) .. _sphx_glr_download_auto_examples_example_surface_profiling.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: example_surface_profiling.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: example_surface_profiling.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_