.. 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_graph_building.py: Graph building -------------- Creating a complete graph and nomenclature in Python .. image:: /auto_examples/images/sphx_glr_graph_building_001.png :class: sphx-glr-single-img .. code-block:: default from __future__ import print_function from __future__ import absolute_import import anatomist.direct.api as ana from soma import aims from soma.qt_gui.qt_backend import Qt import sys # create graph structure graph = aims.Graph('RoiArg') # these are needed for internal conversions graph['type.global.tri'] = 'roi.global.tri' graph['roi.global.tri'] = 'roi roi_global.gii aims_mesh' # create 2 nodes v = graph.addVertex('roi') mesh = aims.SurfaceGenerator.sphere([0, 0, 0], 10, 100) aims.GraphManip.storeAims(graph, v, 'aims_mesh', mesh) v['name'] = 'sphere1' v = graph.addVertex('roi') mesh = aims.SurfaceGenerator.sphere([0, 0, 100], 10, 100) aims.GraphManip.storeAims(graph, v, 'aims_mesh', mesh) v['name'] = 'sphere2' # create a corresponding nomenclature hie = aims.Hierarchy() hie.setSyntax('hierarchy') hie['graph_syntax'] = 'RoiArg' n = aims.Tree(True, 'fold_name') n['name'] = 'sphere1' n['color'] = aims.vector_S32([255, 255, 0]) hie.insert(n) n = aims.Tree(True, 'fold_name') n['name'] = 'sphere2' n['color'] = aims.vector_S32([0, 255, 0]) hie.insert(n) runloop = Qt.QApplication.instance() is not None # create anatomist objects a = ana.Anatomist() ahie = a.toAObject(hie) ahie.releaseAppRef() agraph = a.toAObject(graph) agraph.releaseAppRef() # display graph w = a.createWindow('3D') w.addObjects(agraph, add_children=True) br = a.createWindow('Browser') br.addObjects(ahie) w.sphinx_gallery_snapshot() if runloop and 'sphinx_gallery' not in sys.modules: Qt.QApplication.instance().exec_() if runloop or 'sphinx_gallery' in sys.modules: del w, br, agraph, ahie, v, graph, hie, n .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.453 seconds) .. _sphx_glr_download_auto_examples_graph_building.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download :download:`Download Python source code: graph_building.py ` .. container:: sphx-glr-download :download:`Download Jupyter notebook: graph_building.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_