.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/example_mapping.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_mapping.py: .. _example_mapping: =================================== Mapping example in slam =================================== .. GENERATED FROM PYTHON SOURCE LINES 8-16 .. code-block:: Python # Authors: # Guillaume Auzias # Julien Barrès # License: MIT # sphinx_gallery_thumbnail_number = 2 .. GENERATED FROM PYTHON SOURCE LINES 17-21 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 ############################################################################## .. GENERATED FROM PYTHON SOURCE LINES 23-24 Importation of slam modules .. GENERATED FROM PYTHON SOURCE LINES 24-30 .. code-block:: Python import slam.generate_parametric_surfaces as sps import numpy as np import slam.topology as stop import slam.mapping as smap import slam.distortion as sdst .. GENERATED FROM PYTHON SOURCE LINES 31-32 Generation of an open mesh .. GENERATED FROM PYTHON SOURCE LINES 32-36 .. code-block:: Python K = [-1, -1] open_mesh = sps.generate_quadric(K, nstep=[5, 5]) open_mesh_boundary = stop.mesh_boundary(open_mesh) .. GENERATED FROM PYTHON SOURCE LINES 37-38 Mapping onto a planar disk .. GENERATED FROM PYTHON SOURCE LINES 38-40 .. code-block:: Python disk_mesh = smap.disk_conformal_mapping(open_mesh) .. rst-class:: sphx-glr-script-out .. code-block:: none 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: 8 = 8.333333333333334 % -nb Nan in Laplacian : 0 -nb Inf in Laplacian : 0 Boundary Size: (12,) Laplacian Size: (21, 21) .. GENERATED FROM PYTHON SOURCE LINES 41-42 Compute distortion measures between original and planar representations .. GENERATED FROM PYTHON SOURCE LINES 42-49 .. code-block:: Python angle_diff = sdst.angle_difference(disk_mesh, open_mesh) area_diff = sdst.area_difference(disk_mesh, open_mesh) edge_diff = sdst.edge_length_difference(disk_mesh, open_mesh) print(np.mean(angle_diff)) print(np.mean(area_diff)) print(np.mean(edge_diff)) .. rst-class:: sphx-glr-script-out .. code-block:: none 2.64338815386942e-18 -0.014540348040227516 -0.03317681682098698 .. GENERATED FROM PYTHON SOURCE LINES 50-89 VISUALIZATION USING EXTERNAL TOOLS ############################################################################ # Visualization with visbrain import slam.plot as splt from vispy.scene import Line from visbrain.objects import VispyObj, SourceObj # Visualization of the open mesh visb_sc = splt.visbrain_plot(mesh=open_mesh, caption="open mesh") for bound in open_mesh_boundary: points = open_mesh.vertices[bound] s_rad = SourceObj( "rad", points, color="red", symbol="square", radius_min=10) visb_sc.add_to_subplot(s_rad) lines = Line(pos=open_mesh.vertices[bound], width=10, color="b") # wrap the vispy object using visbrain l_obj = VispyObj("line", lines) visb_sc.add_to_subplot(l_obj) visb_sc.preview() # Visualization of the same mesh mapped onto a disk visb_sc2 = splt.visbrain_plot(mesh=disk_mesh, caption="disk mesh") for bound in open_mesh_boundary: points = disk_mesh.vertices[bound] s_rad = SourceObj( "rad", points, color="red", symbol="square", radius_min=10) visb_sc2.add_to_subplot(s_rad) lines = Line(pos=disk_mesh.vertices[bound], width=10, color="b") # wrap the vispy object using visbrain l_obj = VispyObj("line", lines) visb_sc2.add_to_subplot(l_obj) visb_sc2.preview() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.013 seconds) .. _sphx_glr_download_auto_examples_example_mapping.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: example_mapping.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: example_mapping.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: example_mapping.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_