.. 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 :ref:`Go to the end ` 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:: Python # Authors: # Guillaume Auzias # Julien Barrès # License: MIT # sphinx_gallery_thumbnail_number = 2 .. GENERATED FROM PYTHON SOURCE LINES 18-19 Importation of slam modules .. GENERATED FROM PYTHON SOURCE LINES 19-24 .. code-block:: Python import slam.io as sio import slam.geodesics as sgeo import numpy as np # import trimesh .. GENERATED FROM PYTHON SOURCE LINES 25-26 Mesh importation .. GENERATED FROM PYTHON SOURCE LINES 26-28 .. code-block:: Python mesh = sio.load_mesh("../examples/data/example_mesh.gii") .. GENERATED FROM PYTHON SOURCE LINES 29-30 Getting the index of vertices in specified geo_distance from a given vertex .. GENERATED FROM PYTHON SOURCE LINES 30-36 .. code-block:: Python vert_id = 528 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 .. code-block:: none [ 358 437 443 448 461 475 484 485 495 510 511 512 515 525 526 528 532 536 543 544 545 547 551 552 553 557 558 566 569 570 575 576 577 578 584 586 587 595 602 603 604 613 614 628 632 638 780 793 805 818 828 829 830 858 869 872 882 883 893 906 907 908 915 925 940 942 952 959 962 971 972 973 989 1016 1044 1047 1074 1083 1085 1087 1088 1116 1118 1140 2214 2242 2250] .. GENERATED FROM PYTHON SOURCE LINES 37-38 For every vertex, get all the vertices within the maximum distance .. GENERATED FROM PYTHON SOURCE LINES 38-41 .. code-block:: Python area_geodist = sgeo.local_gdist_matrix(mesh, max_geodist) print(area_geodist) .. rst-class:: sphx-glr-script-out .. code-block:: none Coords Values (1, 0) 1.4876632105329974 (2, 0) 9.365068219469078 (90, 0) 7.208488479252511 (91, 0) 5.722129342874235 (92, 0) 6.773604284049901 (93, 0) 8.226471227373226 (94, 0) 2.2879828843579544 (96, 0) 8.63887016200251 (97, 0) 6.413060772475285 (98, 0) 4.432708026561322 (100, 0) 7.486952780813035 (119, 0) 9.06050883606245 (120, 0) 8.675544881011426 (126, 0) 9.41292747701547 (127, 0) 8.681428164540284 (132, 0) 9.90150126826344 (308, 0) 4.426250247089545 (309, 0) 5.444558082819204 (310, 0) 5.135728908567185 (366, 0) 9.425233416634313 (656, 0) 1.71910439982715 (657, 0) 2.5174880510863535 (658, 0) 1.7560083966864473 (659, 0) 0.8296160840673167 (660, 0) 1.673685596179056 : : (2295, 2327) 9.879817790917961 (2297, 2327) 7.383691696003898 (2298, 2327) 6.8570354996593785 (2299, 2327) 5.60880227439795 (2300, 2327) 6.577496462739906 (2301, 2327) 7.71073001481728 (2306, 2327) 5.7417709677692645 (2307, 2327) 4.86790996090551 (2308, 2327) 6.798959513237353 (2309, 2327) 5.705536795886063 (2310, 2327) 8.147027808617544 (2311, 2327) 6.880279114694201 (2312, 2327) 4.342841017481767 (2313, 2327) 8.018776053384563 (2315, 2327) 9.02493752272895 (2316, 2327) 7.467794697964377 (2317, 2327) 6.308488855328874 (2318, 2327) 6.2399428907951995 (2319, 2327) 4.9475753932465 (2320, 2327) 3.957115227397595 (2322, 2327) 7.565028417965948 (2323, 2327) 9.966220628829761 (2324, 2327) 7.719768575721128 (2325, 2327) 3.275729108880324 (2326, 2327) 3.4246160173439923 .. GENERATED FROM PYTHON SOURCE LINES 42-43 Get the index of the vertices located less than 10mm from another vertex .. GENERATED FROM PYTHON SOURCE LINES 43-47 .. code-block:: Python local_dist_vert_id = 644 vert_distmap = area_geodist[local_dist_vert_id].toarray()[0] print(area_geodist) .. rst-class:: sphx-glr-script-out .. code-block:: none Coords Values (1, 0) 1.4876632105329974 (2, 0) 9.365068219469078 (90, 0) 7.208488479252511 (91, 0) 5.722129342874235 (92, 0) 6.773604284049901 (93, 0) 8.226471227373226 (94, 0) 2.2879828843579544 (96, 0) 8.63887016200251 (97, 0) 6.413060772475285 (98, 0) 4.432708026561322 (100, 0) 7.486952780813035 (119, 0) 9.06050883606245 (120, 0) 8.675544881011426 (126, 0) 9.41292747701547 (127, 0) 8.681428164540284 (132, 0) 9.90150126826344 (308, 0) 4.426250247089545 (309, 0) 5.444558082819204 (310, 0) 5.135728908567185 (366, 0) 9.425233416634313 (656, 0) 1.71910439982715 (657, 0) 2.5174880510863535 (658, 0) 1.7560083966864473 (659, 0) 0.8296160840673167 (660, 0) 1.673685596179056 : : (2295, 2327) 9.879817790917961 (2297, 2327) 7.383691696003898 (2298, 2327) 6.8570354996593785 (2299, 2327) 5.60880227439795 (2300, 2327) 6.577496462739906 (2301, 2327) 7.71073001481728 (2306, 2327) 5.7417709677692645 (2307, 2327) 4.86790996090551 (2308, 2327) 6.798959513237353 (2309, 2327) 5.705536795886063 (2310, 2327) 8.147027808617544 (2311, 2327) 6.880279114694201 (2312, 2327) 4.342841017481767 (2313, 2327) 8.018776053384563 (2315, 2327) 9.02493752272895 (2316, 2327) 7.467794697964377 (2317, 2327) 6.308488855328874 (2318, 2327) 6.2399428907951995 (2319, 2327) 4.9475753932465 (2320, 2327) 3.957115227397595 (2322, 2327) 7.565028417965948 (2323, 2327) 9.966220628829761 (2324, 2327) 7.719768575721128 (2325, 2327) 3.275729108880324 (2326, 2327) 3.4246160173439923 .. GENERATED FROM PYTHON SOURCE LINES 48-49 Arbitrary indices of mesh.vertices to test with .. GENERATED FROM PYTHON SOURCE LINES 49-54 .. code-block:: Python start = 0 end = int(len(mesh.vertices) / 2.0) path = sgeo.shortest_path(mesh, start, end) print(path) .. rst-class:: sphx-glr-script-out .. code-block:: none [0, np.int64(1506), np.int64(1511), np.int64(1525), np.int64(1534), np.int64(1535), np.int64(1537), np.int64(1582), np.int64(1625), np.int64(311), np.int64(396), np.int64(431), np.int64(780), np.int64(830), np.int64(883), np.int64(528), np.int64(558), np.int64(569), np.int64(595), np.int64(1074), np.int64(1083), np.int64(1102), np.int64(1135), np.int64(1134), 1164] .. GENERATED FROM PYTHON SOURCE LINES 55-57 VISUALIZATION USING plotly ############################################################################ .. GENERATED FROM PYTHON SOURCE LINES 57-85 .. code-block:: Python import slam.plot as splt display_settings = {} display_settings['colorbar_label'] = 'Distance' mesh_data = {} mesh_data['vertices'] = mesh.vertices mesh_data['faces'] = mesh.faces mesh_data['title'] = 'Geodesic Distance' intensity_data = {} intensity_data['values'] = geo_distance intensity_data["mode"] = "vertex" fig1 = splt.plot_mesh( mesh_data=mesh_data, intensity_data=intensity_data, display_settings=display_settings) fig1.show() fig1 mesh_data['title'] = 'Local Geodesic Distance' intensity_data['values'] = area_geodist[local_dist_vert_id].toarray().squeeze() fig2 = splt.plot_mesh( mesh_data=mesh_data, intensity_data=intensity_data, display_settings=display_settings) fig2.show() fig2 .. raw:: html


.. GENERATED FROM PYTHON SOURCE LINES 86-94 # 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 .. GENERATED FROM PYTHON SOURCE LINES 96-98 Visualizable two points points_visual = trimesh.points.PointCloud(mesh.vertices[[start, end]]) .. GENERATED FROM PYTHON SOURCE LINES 98-108 .. code-block:: Python # ############################################################################### # # 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 6.720 seconds) .. _sphx_glr_download_auto_examples_example_geodesic.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: example_geodesic.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: example_geodesic.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: example_geodesic.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_