.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/example_profile_texture.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_profile_texture.py: .. _example_profile_texture: =================================== example of profile texture 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-18 VISUALIZATION USING EXTERNAL TOOLS ############################################################################ # Visualization with visbrain .. GENERATED FROM PYTHON SOURCE LINES 20-21 importation of slam modules .. GENERATED FROM PYTHON SOURCE LINES 21-25 .. code-block:: Python import numpy as np import slam.surface_profiling as surfpf import slam.io as sio .. GENERATED FROM PYTHON SOURCE LINES 26-27 loading an example mesh and its texture .. GENERATED FROM PYTHON SOURCE LINES 27-32 .. code-block:: Python mesh_file = "../examples/data/example_mesh.gii" texture_file = "../examples/data/example_texture.gii" mesh = sio.load_mesh(mesh_file) texture = sio.load_texture(texture_file) .. GENERATED FROM PYTHON SOURCE LINES 33-34 Select a vertex and get the coordinate and normal. .. GENERATED FROM PYTHON SOURCE LINES 34-38 .. code-block:: Python vert_index = 1500 vert0 = mesh.vertices[vert_index] norm0 = mesh.vertex_normals[vert_index] .. GENERATED FROM PYTHON SOURCE LINES 39-42 Set the parameters for surface profiling initial direction of rotation, rotation angle, length and number of sampling steps .. GENERATED FROM PYTHON SOURCE LINES 42-47 .. 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 48-49 Surface profiling, here we do the second round profiling .. GENERATED FROM PYTHON SOURCE LINES 49-64 .. code-block:: Python num_face = len(mesh.faces) mesh_faces_id = np.linspace(0, num_face, num_face + 1).astype(int) profile_samples, profile_co_faces = surfpf.second_round_profiling_vert( vert0, norm0, init_rot_dir, rot_angle, r_step, max_samples, mesh, mesh_faces_id ) profile_points = profile_samples[:, :, 2] .. GENERATED FROM PYTHON SOURCE LINES 65-66 Compute texture values of profile points .. GENERATED FROM PYTHON SOURCE LINES 66-72 .. code-block:: Python profile_samples = np.array([profile_samples]) profile_samples_fid = np.array([profile_co_faces]) profile_texture = surfpf.get_texture_value_on_profile( texture, mesh, profile_samples, profile_samples_fid ) .. GENERATED FROM PYTHON SOURCE LINES 73-103 VISUALIZATION USING EXTERNAL TOOLS ############################################################################ # Visualization with visbrain import trimesh.visual.color from matplotlib import pyplot as plt ############################################################################### # Generate colors of profile points # set color maps color_map = plt.get_cmap("jet", 12) # get texture value of profile points and mesh profile_tex = profile_texture.reshape(profile_texture.size) texture_value = texture.darray[0] # put them together to generate the colors prof_mesh_tex_color = np.hstack([profile_tex, texture_value]) prof_mesh_points_color = trimesh.visual.color.interpolate( prof_mesh_tex_color, color_map=color_map ) mesh.visual.vertex_colors = prof_mesh_points_color[profile_texture.size:] # Create point cloud of profiling points prof_points_mesh = profile_points.reshape( profile_points.shape[0] * profile_points.shape[1], 3 ) prof_points_colors = prof_mesh_points_color[: profile_texture.size] points_mesh = trimesh.points.PointCloud( prof_points_mesh, colors=np.array(prof_points_colors, dtype=np.uint8) ) scene = trimesh.Scene([points_mesh, mesh]) scene.show(smooth=False) .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.106 seconds) .. _sphx_glr_download_auto_examples_example_profile_texture.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: example_profile_texture.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: example_profile_texture.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: example_profile_texture.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_