.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/example_differential_geometry.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_differential_geometry.py: .. _example_differential_geometry: =================================== example of differential geometry tools in slam =================================== .. GENERATED FROM PYTHON SOURCE LINES 8-15 .. code-block:: default # Authors: Guillaume Auzias # License: BSD (3-clause) # sphinx_gallery_thumbnail_number = 2 .. GENERATED FROM PYTHON SOURCE LINES 16-17 importation of slam modules .. GENERATED FROM PYTHON SOURCE LINES 17-21 .. code-block:: default import slam.io as sio import slam.differential_geometry as sdg import slam.plot as splt .. GENERATED FROM PYTHON SOURCE LINES 22-23 loading an examplar mesh and corresponding texture and show it .. GENERATED FROM PYTHON SOURCE LINES 23-33 .. code-block:: default 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) visb_sc = splt.visbrain_plot( mesh=mesh, tex=tex.darray[0], caption="mesh with curvature", cblabel="curvature" ) visb_sc.preview() .. image:: /auto_examples/images/sphx_glr_example_differential_geometry_001.png :alt: example differential geometry :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 34-35 compute various types of Laplacian of the mesh .. GENERATED FROM PYTHON SOURCE LINES 35-42 .. code-block:: default 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") .. rst-class:: sphx-glr-script-out Out: .. code-block:: none 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 .. GENERATED FROM PYTHON SOURCE LINES 43-44 smooth the mesh using Laplacian .. GENERATED FROM PYTHON SOURCE LINES 44-46 .. code-block:: default s_mesh = sdg.laplacian_mesh_smoothing(mesh, nb_iter=100, dt=0.1) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none 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 .. GENERATED FROM PYTHON SOURCE LINES 47-48 show it .. GENERATED FROM PYTHON SOURCE LINES 48-51 .. code-block:: default visb_sc = splt.visbrain_plot(mesh=s_mesh, caption="smoothed mesh") visb_sc.preview() .. image:: /auto_examples/images/sphx_glr_example_differential_geometry_002.png :alt: example differential geometry :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 52-53 compute the gradient of texture tex .. GENERATED FROM PYTHON SOURCE LINES 53-60 .. code-block:: default 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) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none 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 ] .. GENERATED FROM PYTHON SOURCE LINES 61-62 show it .. GENERATED FROM PYTHON SOURCE LINES 62-70 .. code-block:: default visb_sc = splt.visbrain_plot( mesh=mesh, tex=norm_grad, caption="norm of the gradient of curvature", cblabel="gradient magnitude", ) visb_sc.preview() .. image:: /auto_examples/images/sphx_glr_example_differential_geometry_003.png :alt: example differential geometry :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 71-72 compute the depth potential function .. GENERATED FROM PYTHON SOURCE LINES 72-74 .. code-block:: default dpf = sdg.depth_potential_function(mesh, tex.darray[0], [0.3]) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none 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 .. GENERATED FROM PYTHON SOURCE LINES 75-76 show it .. GENERATED FROM PYTHON SOURCE LINES 76-80 .. code-block:: default visb_sc = splt.visbrain_plot( mesh=mesh, tex=dpf[0], caption="depth potential function", cblabel="dpf" ) visb_sc.preview() .. image:: /auto_examples/images/sphx_glr_example_differential_geometry_004.png :alt: example differential geometry :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 5.618 seconds) .. _sphx_glr_download_auto_examples_example_differential_geometry.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_differential_geometry.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: example_differential_geometry.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_