Geodesic in slam

# Authors:
# Guillaume Auzias <guillaume.auzias@univ-amu.fr>
# Julien Barrès <julien.barres@etu.univ-amu.fr>

# License: MIT
# sphinx_gallery_thumbnail_number = 2

Importation of slam modules

import slam.io as sio
import slam.geodesics as sgeo
import numpy as np
# import trimesh

Mesh importation

mesh = sio.load_mesh("../examples/data/example_mesh.gii")

Getting the index of vertices in specified geo_distance from a given vertex

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)
[ 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]

For every vertex, get all the vertices within the maximum distance

area_geodist = sgeo.local_gdist_matrix(mesh, max_geodist)
print(area_geodist)
<Compressed Sparse Column sparse matrix of dtype 'float64'
        with 269350 stored elements and shape (2328, 2328)>
  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

Get the index of the vertices located less than 10mm from another vertex

local_dist_vert_id = 644
vert_distmap = area_geodist[local_dist_vert_id].toarray()[0]
print(area_geodist)
<Compressed Sparse Column sparse matrix of dtype 'float64'
        with 269350 stored elements and shape (2328, 2328)>
  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

Arbitrary indices of mesh.vertices to test with

start = 0
end = int(len(mesh.vertices) / 2.0)
path = sgeo.shortest_path(mesh, start, end)
print(path)
[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]

VISUALIZATION USING plotly

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


# Visualization using pyglet mesh.visual.face_colors = [100, 100, 100, 100]

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)

Total running time of the script: (0 minutes 6.582 seconds)

Gallery generated by Sphinx-Gallery