.. 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 Click :ref:`here ` 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-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-24 .. code-block:: default import numpy as np import trimesh.visual.color from matplotlib import pyplot as plt import slam.surface_profiling as surfpf import slam.io as sio .. GENERATED FROM PYTHON SOURCE LINES 25-26 loading an example mesh and its texture .. GENERATED FROM PYTHON SOURCE LINES 26-29 .. code-block:: default mesh = sio.load_mesh("data/example_mesh.gii") texture = sio.load_texture("data/example_texture.gii") .. GENERATED FROM PYTHON SOURCE LINES 30-31 Select a vertex and get the coordinate and normal. .. GENERATED FROM PYTHON SOURCE LINES 31-35 .. code-block:: default vert_index = 1500 vert0 = mesh.vertices[vert_index] norm0 = mesh.vertex_normals[vert_index] .. GENERATED FROM PYTHON SOURCE LINES 36-39 Set the parameters for surface profiling initial direction of rotation, rotation angle, length and number of sampling steps .. GENERATED FROM PYTHON SOURCE LINES 39-44 .. 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 45-46 Surface profiling, here we do the second round profiling .. GENERATED FROM PYTHON SOURCE LINES 46-54 .. code-block:: default 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 55-56 Compute texture values of profile points .. GENERATED FROM PYTHON SOURCE LINES 56-62 .. code-block:: default 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 63-65 Visualize result Generate colors of profile points .. GENERATED FROM PYTHON SOURCE LINES 65-92 .. code-block:: default # 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.104 seconds) .. _sphx_glr_download_auto_examples_example_profile_texture.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_profile_texture.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: example_profile_texture.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_