example of differential geometry tools in slam

# Authors: Guillaume Auzias <guillaume.auzias@univ-amu.fr>

# License: MIT
# sphinx_gallery_thumbnail_number = 2

importation of slam modules

import slam.io as sio
import slam.differential_geometry as sdg
import numpy as np

loading an examplar mesh and corresponding texture

mesh_file = "../examples/data/example_mesh.gii"
texture_file = "../examples/data/example_texture.gii"
mesh = sio.load_mesh(mesh_file)
tex = sio.load_texture(texture_file)

compute various types of Laplacian of the mesh

lap, lap_b = sdg.compute_mesh_laplacian(mesh, lap_type="fem")
print(mesh.vertices.shape)
print(lap.shape)
lap, lap_b = sdg.compute_mesh_laplacian(mesh, lap_type="conformal")
lap, lap_b = sdg.compute_mesh_laplacian(mesh, lap_type="meanvalue")
lap, lap_b = sdg.compute_mesh_laplacian(mesh, lap_type="authalic")
  Computing Laplacian
    Computing mesh weights of type fem
    -edge length threshold needed for  0  values =  0.0  %
    -number of Nan in weights:  0  =  0.0  %
    -number of Negative values in weights:  936  =  6.706792777300086  %
    -nb Nan in Laplacian :  0
    -nb Inf in Laplacian :  0
(2328, 3)
(2328, 2328)
  Computing Laplacian
    Computing mesh weights of type conformal
    -edge length threshold needed for  0  values =  0.0  %
    -number of Nan in weights:  0  =  0.0  %
    -number of Negative values in weights:  936  =  6.706792777300086  %
    -nb Nan in Laplacian :  0
    -nb Inf in Laplacian :  0
  Computing Laplacian
    Computing mesh weights of type meanvalue
    -number of Nan in weights:  0  =  0.0  %
    -number of Negative values in weights:  0  =  0.0  %
    -nb Nan in Laplacian :  0
    -nb Inf in Laplacian :  0
  Computing Laplacian
    Computing mesh weights of type authalic
    -number of Nan in weights:  0  =  0.0  %
    -number of Negative values in weights:  0  =  0.0  %
    -nb Nan in Laplacian :  0
    -nb Inf in Laplacian :  0

smooth the mesh using Laplacian

s_mesh = sdg.laplacian_mesh_smoothing(mesh, nb_iter=100, dt=0.1)
    Smoothing mesh
  Computing Laplacian
    Computing mesh weights of type fem
    -edge length threshold needed for  0  values =  0.0  %
    -number of Nan in weights:  0  =  0.0  %
    -number of Negative values in weights:  936  =  6.706792777300086  %
    -nb Nan in Laplacian :  0
    -nb Inf in Laplacian :  0
0
10
20
30
40
50
60
70
80
90
    OK

compute the gradient of texture tex

triangle_grad = sdg.triangle_gradient(mesh, tex.darray[0])
print(triangle_grad)
grad = sdg.gradient(mesh, tex.darray[0])
print(grad)
norm_grad = sdg.norm_gradient(mesh, tex.darray[0])
print(norm_grad)
1 %
2 %
3 %
4 %
5 %
6 %
7 %
8 %
9 %
10 %
11 %
12 %
13 %
14 %
15 %
16 %
17 %
18 %
19 %
20 %
21 %
22 %
23 %
24 %
25 %
26 %
27 %
28 %
29 %
30 %
31 %
32 %
33 %
34 %
35 %
36 %
37 %
38 %
39 %
40 %
41 %
42 %
43 %
44 %
45 %
46 %
47 %
48 %
49 %
50 %
51 %
52 %
53 %
54 %
55 %
56 %
57 %
58 %
59 %
60 %
61 %
62 %
63 %
64 %
65 %
66 %
67 %
68 %
69 %
70 %
71 %
72 %
73 %
74 %
75 %
76 %
77 %
78 %
79 %
80 %
81 %
82 %
83 %
84 %
85 %
86 %
87 %
88 %
89 %
90 %
91 %
92 %
93 %
94 %
95 %
96 %
97 %
98 %
99 %
[[ 0.00434682  0.00094788 -0.01505408]
 [ 0.00294091  0.00038984 -0.00959341]
 [-0.0190667  -0.010571   -0.01175931]
 ...
 [ 0.0021132   0.00327109  0.01139427]
 [ 0.00167353  0.00282758  0.01242133]
 [ 0.00175571  0.00266182  0.01337094]]
1 %
2 %
3 %
4 %
5 %
6 %
7 %
8 %
9 %
10 %
11 %
12 %
13 %
14 %
15 %
16 %
17 %
18 %
19 %
20 %
21 %
22 %
23 %
24 %
25 %
26 %
27 %
28 %
29 %
30 %
31 %
32 %
33 %
34 %
35 %
36 %
37 %
38 %
39 %
40 %
41 %
42 %
43 %
44 %
45 %
46 %
47 %
48 %
49 %
50 %
51 %
52 %
53 %
54 %
55 %
56 %
57 %
58 %
59 %
60 %
61 %
62 %
63 %
64 %
65 %
66 %
67 %
68 %
69 %
70 %
71 %
72 %
73 %
74 %
75 %
76 %
77 %
78 %
79 %
80 %
81 %
82 %
83 %
84 %
85 %
86 %
87 %
88 %
89 %
90 %
91 %
92 %
93 %
94 %
95 %
96 %
97 %
98 %
99 %
[[-7.56323397e-03 -3.16016138e-03 -1.21617037e-02]
 [-7.34847031e-03  6.37035386e-05 -1.23221759e-02]
 [ 2.32632728e-03  1.88016554e-03 -3.03642984e-03]
 ...
 [ 4.04642855e-03  2.24089885e-03  1.09245023e-02]
 [ 1.60189335e-03 -1.08939493e-04  4.64315729e-03]
 [-1.52567188e-03 -5.57641899e-04  6.48352716e-04]]
1 %
2 %
3 %
4 %
5 %
6 %
7 %
8 %
9 %
10 %
11 %
12 %
13 %
14 %
15 %
16 %
17 %
18 %
19 %
20 %
21 %
22 %
23 %
24 %
25 %
26 %
27 %
28 %
29 %
30 %
31 %
32 %
33 %
34 %
35 %
36 %
37 %
38 %
39 %
40 %
41 %
42 %
43 %
44 %
45 %
46 %
47 %
48 %
49 %
50 %
51 %
52 %
53 %
54 %
55 %
56 %
57 %
58 %
59 %
60 %
61 %
62 %
63 %
64 %
65 %
66 %
67 %
68 %
69 %
70 %
71 %
72 %
73 %
74 %
75 %
76 %
77 %
78 %
79 %
80 %
81 %
82 %
83 %
84 %
85 %
86 %
87 %
88 %
89 %
90 %
91 %
92 %
93 %
94 %
95 %
96 %
97 %
98 %
99 %
[0.01466616 0.01434713 0.00426224 ... 0.01186339 0.00491293 0.001749  ]

VISUALIZATION USING INTERNAL TOOLS

import slam.plot as splt

# Plot Original Mesh
display_settings = {}
display_settings['colorbar_label'] = 'Curvature'
mesh_data = {}
mesh_data['vertices'] = mesh.vertices
mesh_data['faces'] = mesh.faces
mesh_data['title'] = 'Mean Curvature'
intensity_data = {}
intensity_data['values'] = tex.darray[0]
intensity_data["mode"] = "vertex"
fig1 = splt.plot_mesh(
    mesh_data=mesh_data,
    intensity_data=intensity_data,
    display_settings=display_settings)
fig1.show()

# Show the Norm of the Gradient of the Curvature

display_settings['colorbar_label'] = 'Gradient Magnitude'
mesh_data['title'] = 'Norm of the Gradient of Curvature'
intensity_data['values'] = norm_grad
intensity_data["mode"] = "vertex"
fig2 = splt.plot_mesh(
    mesh_data=mesh_data,
    intensity_data=intensity_data,
    display_settings=display_settings)
fig2.show()
fig2


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

Gallery generated by Sphinx-Gallery