example of differential geometry tools in slam

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

# License: MIT
# sphinx_gallery_thumbnail_number = 2
NOTE: there is no visualization tool in slam, but we provide at the

end of this script exemplare code to do the visualization with an external solution


importation of slam modules

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

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.00094788 -0.01505408  0.00434682]
 [ 0.00038984 -0.00959341  0.00294091]
 [-0.010571   -0.01175931 -0.0190667 ]
 ...
 [ 0.00327109  0.01139427  0.0021132 ]
 [ 0.00282758  0.01242133  0.00167353]
 [ 0.00266182  0.01337094  0.00175571]]
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 %
[[-3.16016138e-03 -1.21617037e-02 -7.56323397e-03]
 [ 6.37035386e-05 -1.23221759e-02 -7.34847031e-03]
 [ 1.88016554e-03 -3.03642985e-03  2.32632729e-03]
 ...
 [ 2.24089885e-03  1.09245023e-02  4.04642855e-03]
 [-1.08939493e-04  4.64315729e-03  1.60189335e-03]
 [-5.57641899e-04  6.48352716e-04 -1.52567188e-03]]
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  ]

compute the depth potential function

dpf = sdg.depth_potential_function(mesh, tex.darray[0], [0.3])
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

VISUALIZATION USING EXTERNAL TOOLS

# import visbrain # visu using visbrain visb_sc = splt.visbrain_plot(

mesh=mesh, tex=tex.darray[0], caption=”mesh with curvature”, cblabel=”curvature”

) visb_sc.preview() ############################################################################### # show the smoothed mesh visb_sc = splt.visbrain_plot( mesh=s_mesh, caption=”smoothed mesh” ) visb_sc.preview() ############################################################################### # show the norm of the gradient of the curvature visb_sc = splt.visbrain_plot(

mesh=mesh, tex=norm_grad, caption=”norm of the gradient of curvature”, cblabel=”gradient magnitude”,

) visb_sc.preview() ############################################################################### # show the depth potential function visb_sc = splt.visbrain_plot(

mesh=mesh, tex=dpf[0], caption=”depth potential function”, cblabel=”dpf”

) visb_sc.preview()

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

Gallery generated by Sphinx-Gallery