.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/example_geodesic.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_geodesic.py: .. _example_geodesic: =================================== Geodesic in slam =================================== .. GENERATED FROM PYTHON SOURCE LINES 8-17 .. code-block:: default # Authors: # Guillaume Auzias # Julien Barrès # License: BSD (3-clause) # sphinx_gallery_thumbnail_number = 2 .. GENERATED FROM PYTHON SOURCE LINES 18-19 Importation of slam modules .. GENERATED FROM PYTHON SOURCE LINES 19-26 .. code-block:: default import slam.plot as splt import slam.io as sio import slam.geodesics as sgeo import numpy as np # import trimesh .. GENERATED FROM PYTHON SOURCE LINES 27-28 Mesh importation .. GENERATED FROM PYTHON SOURCE LINES 28-30 .. code-block:: default mesh = sio.load_mesh("../examples/data/example_mesh.gii") .. GENERATED FROM PYTHON SOURCE LINES 31-32 Getting the vertex index in specified geo_distance of vert .. GENERATED FROM PYTHON SOURCE LINES 32-40 .. code-block:: default vert_id = 200 max_geodist = 10 geo_distance = sgeo.compute_gdist(mesh, vert_id) area_geodist_vi = np.where(geo_distance < max_geodist)[0] print(area_geodist_vi) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none [ 11 35 44 47 50 51 52 55 145 147 151 152 159 170 171 173 174 175 176 182 183 184 191 192 193 199 200 212 213 219 223 233 334 354 357 722 723 724 735 736 737 739 749 750 752 761 786 787 803 823 832 864 867 897 899 901 920 922 932 933 934 936 945 969 978 979 980 982 983 992 993 1001 1002 1003 1004 1011 1012 1019 1030 1037 1864 1887 1888 1889 1890 1920 1931 1932 1941 1942 1943 1944 1945 1961 1962 1963 1964 1965 1966 1967 1968 1985 1986 1987 1988 1989 1990 2001 2002 2003 2004 2005 2006 2007 2018 2019 2020 2021 2022 2023 2024 2025 2028 2029 2042 2047 2069 2070 2071 2075 2076 2077 2078 2080 2095 2109 2110 2111 2141 2150 2151 2152 2169 2170 2180 2181 2182 2183 2194 2195 2196 2207] .. GENERATED FROM PYTHON SOURCE LINES 41-42 Visualization .. GENERATED FROM PYTHON SOURCE LINES 42-48 .. code-block:: default visb_sc = splt.visbrain_plot( mesh=mesh, tex=geo_distance, caption="geodesic distance", cblabel="distance" ) visb_sc.preview() .. image:: /auto_examples/images/sphx_glr_example_geodesic_001.png :alt: example geodesic :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 49-50 Getting the vertex index in specified geo_distance of vert .. GENERATED FROM PYTHON SOURCE LINES 50-60 .. code-block:: default area_geodist = sgeo.local_gdist_matrix(mesh, max_geodist) visb_sc2 = splt.visbrain_plot( mesh=mesh, tex=area_geodist[0].toarray().squeeze(), caption="local geodesic distance", cblabel="distance", ) visb_sc2.preview() .. image:: /auto_examples/images/sphx_glr_example_geodesic_002.png :alt: example geodesic :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 61-62 Get the vertex index .. GENERATED FROM PYTHON SOURCE LINES 62-70 .. code-block:: default indices = [] for i in range(mesh.vertices.shape[0]): vert_distmap = area_geodist[i].toarray()[0] area_geodist_v = np.where(vert_distmap > 0)[0] indices += [area_geodist_v] .. GENERATED FROM PYTHON SOURCE LINES 71-72 Arbitrary indices of mesh.vertices to test with .. GENERATED FROM PYTHON SOURCE LINES 72-79 .. code-block:: default start = 0 end = int(len(mesh.vertices) / 2.0) path = sgeo.shortest_path(mesh, start, end) print(path) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none [0, 1506, 1511, 1525, 1534, 1535, 1537, 1582, 1625, 311, 396, 431, 780, 830, 883, 528, 558, 569, 595, 1074, 1083, 1102, 1135, 1134, 1164] .. GENERATED FROM PYTHON SOURCE LINES 80-103 # Visualization using pyglet mesh.visual.face_colors = [100, 100, 100, 100] ############################################################################### # Path3D with the path between the points path_visual = trimesh.load_path(mesh.vertices[path]) path_visual ############################################################################### # Visualizable two points points_visual = trimesh.points.PointCloud(mesh.vertices[[start, end]]) ############################################################################### # Create a scene with the mesh, path, and points scene = trimesh.Scene([ points_visual, path_visual, mesh]) scene.show(smooth=False) .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 4.215 seconds) .. _sphx_glr_download_auto_examples_example_geodesic.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_geodesic.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: example_geodesic.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_