.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/tutorials/tuto_plot_create_geometry_from_svg.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_tutorials_tuto_plot_create_geometry_from_svg.py: Creating a geometry with Inkscape ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This is a tutorial that shows you how to draw a geometry in Inkscape and load it in tofu. .. GENERATED FROM PYTHON SOURCE LINES 10-18 To see a tutorial on how to draw a vessel's geometry on Inkscape by tracing an image from a PDF file for example, and save it to a `svg` file, to load it and use it in tofu, you can check the video below. Basically, you just need to use straight *Bezier curves* to draw the closed polygons that will define the vessel and optionally the structures. To define a PFC structure, just add a fill color. You can also draw a line to automatically scale the configuration to a known measure. .. GENERATED FROM PYTHON SOURCE LINES 22-32 .. raw:: html
.. GENERATED FROM PYTHON SOURCE LINES 34-36 Now, on how to load it and use it in tofu (also shown in the video). We start by importing `tofu`. .. GENERATED FROM PYTHON SOURCE LINES 36-39 .. code-block:: default import tofu as tf .. GENERATED FROM PYTHON SOURCE LINES 40-43 `tofu` provides a geometry helper function that allows creating a configuration from a `svg` file. Supposing you saved it in a file named `"myfirstgeom.svg"`, do .. GENERATED FROM PYTHON SOURCE LINES 43-45 .. code-block:: default config = tf.geom.Config.from_svg("myfirstgeom.svg", Name="Test", Exp="Test") .. rst-class:: sphx-glr-script-out Out: .. code-block:: none The following structures were loaded: - Ves: vessel (9 pts, None) - PFC: struct1 (5 pts, #000080) - PFC: struct2 (5 pts, #d40000) from /home/lasofivec/tofu/examples/tutorials/myfirstgeom.svg .. GENERATED FROM PYTHON SOURCE LINES 46-48 It already gives you some information on what you loaded, but to see what it actually contains: .. GENERATED FROM PYTHON SOURCE LINES 48-50 .. code-block:: default print(config) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none tot. Struct tot. occur tot. points ----------- ---------- ----------- 3 3 15 class Name SaveName nP noccur move color visible ----- ------- ----------------------------------------------------- -- ------ ---- ------------------------ ------- Ves vessel TFG_Ves_ExpTest_vessel_sh00000_Vers1.5.0-3-g96c1c10c 7 0 None ( 0.0, 0.0, 0.0, 1.0) True PFC struct1 TFG_PFC_ExpTest_struct1_sh00000_Vers1.5.0-3-g96c1c10c 4 0 None ( 0.0, 0.0, 0.5, 1.0) True PFC struct2 TFG_PFC_ExpTest_struct2_sh00000_Vers1.5.0-3-g96c1c10c 4 0 None (0.83, 0.0, 0.0, 1.0) True .. GENERATED FROM PYTHON SOURCE LINES 51-52 To plot it, simply do .. GENERATED FROM PYTHON SOURCE LINES 52-54 .. code-block:: default config.plot() .. image-sg:: /auto_examples/tutorials/images/sphx_glr_tuto_plot_create_geometry_from_svg_001.png :alt: Test :srcset: /auto_examples/tutorials/images/sphx_glr_tuto_plot_create_geometry_from_svg_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out Out: .. code-block:: none /home/lasofivec/tofu/tofu/geom/_def.py:127: MatplotlibDeprecationWarning: The set_window_title function was deprecated in Matplotlib 3.4 and will be removed two minor releases later. Use manager.set_window_title or GUI-specific methods instead. f.canvas.set_window_title(wintit) [, ] .. GENERATED FROM PYTHON SOURCE LINES 55-58 We can see that the z- and r-axis might not be exactly what we wanted. We might also want to adjust the scale. Tofu let's fix those parameters when loading the configuration. .. GENERATED FROM PYTHON SOURCE LINES 58-65 .. code-block:: default config = tf.geom.Config.from_svg("myfirstgeom.svg", Name="Test", Exp="Test", z0=-140, r0=10, scale=0.5 ) config.plot() .. image-sg:: /auto_examples/tutorials/images/sphx_glr_tuto_plot_create_geometry_from_svg_002.png :alt: Test :srcset: /auto_examples/tutorials/images/sphx_glr_tuto_plot_create_geometry_from_svg_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out Out: .. code-block:: none The following structures were loaded: - Ves: vessel (9 pts, None) - PFC: struct1 (5 pts, #000080) - PFC: struct2 (5 pts, #d40000) from /home/lasofivec/tofu/examples/tutorials/myfirstgeom.svg /home/lasofivec/tofu/tofu/geom/_def.py:127: MatplotlibDeprecationWarning: The set_window_title function was deprecated in Matplotlib 3.4 and will be removed two minor releases later. Use manager.set_window_title or GUI-specific methods instead. f.canvas.set_window_title(wintit) [, ] .. GENERATED FROM PYTHON SOURCE LINES 66-68 Or, even better, if you have a figure where there is known measure you can let tofu scale the figure automatically for you .. GENERATED FROM PYTHON SOURCE LINES 68-78 .. code-block:: default config = tf.geom.Config.from_svg( "from_pdf.svg", Name="Traced from pdf", Exp="Test", res=10, point_ref1=(0.7, -2), point_ref2=(2.8, 2) ) config.plot() # sphinx_gallery_thumbnail_number = 3 .. image-sg:: /auto_examples/tutorials/images/sphx_glr_tuto_plot_create_geometry_from_svg_003.png :alt: Traced from pdf :srcset: /auto_examples/tutorials/images/sphx_glr_tuto_plot_create_geometry_from_svg_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out Out: .. code-block:: none The following structures were loaded: - Ves: path10373 (23 pts, None) - Ves: vesinner (11 pts, None) - Ves: vesouter (11 pts, None) - PFC: path10375 (5 pts, #00ccff) - PFC: path10410 (5 pts, #00ffcc) - PFC: path10445 (5 pts, #55ff99) - PFC: path10480 (5 pts, #6f916f) - PFC: path10515 (5 pts, #37c871) - PFC: path10550 (5 pts, #ff8080) - PFC: path10651 (5 pts, #ff8080) - PFC: path10686 (5 pts, #ff8080) - PFC: path10721 (5 pts, #ff8080) - PFC: path10756 (5 pts, #ff8080) - PFC: path10791 (5 pts, #ff8080) - PFC: path10826 (5 pts, #ff8080) - PFC: path10861 (5 pts, #ffaaaa) - PFC: path10896 (5 pts, #ffb380) - PFC: path10931 (5 pts, #ff9955) - PFC: path10966 (5 pts, #ff7f2a) - PFC: path11150 (5 pts, #8080ff) - PFC: path11185 (5 pts, #8787de) from /home/lasofivec/tofu/examples/tutorials/from_pdf.svg /home/lasofivec/tofu/tofu/geom/_def.py:127: MatplotlibDeprecationWarning: The set_window_title function was deprecated in Matplotlib 3.4 and will be removed two minor releases later. Use manager.set_window_title or GUI-specific methods instead. f.canvas.set_window_title(wintit) [, ] .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.950 seconds) .. _sphx_glr_download_auto_examples_tutorials_tuto_plot_create_geometry_from_svg.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: tuto_plot_create_geometry_from_svg.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: tuto_plot_create_geometry_from_svg.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_