{
  "nbformat_minor": 0, 
  "nbformat": 4, 
  "cells": [
    {
      "execution_count": null, 
      "cell_type": "code", 
      "source": [
        "%matplotlib inline"
      ], 
      "outputs": [], 
      "metadata": {
        "collapsed": false
      }
    }, 
    {
      "source": [
        "\nGraph building\n--------------\n\nCreating a complete graph and nomenclature in Python\n\n"
      ], 
      "cell_type": "markdown", 
      "metadata": {}
    }, 
    {
      "execution_count": null, 
      "cell_type": "code", 
      "source": [
        "from __future__ import print_function\n\nfrom __future__ import absolute_import\nimport anatomist.direct.api as ana\nfrom soma import aims\nfrom soma.qt_gui.qt_backend import Qt\nimport sys\n\n# create graph structure\ngraph = aims.Graph('RoiArg')\n# these are needed for internal conversions\ngraph['type.global.tri'] = 'roi.global.tri'\ngraph['roi.global.tri'] = 'roi roi_global.gii aims_mesh'\n\n# create 2 nodes\nv = graph.addVertex('roi')\nmesh = aims.SurfaceGenerator.sphere([0, 0, 0], 10, 100)\naims.GraphManip.storeAims(graph, v, 'aims_mesh', mesh)\nv['name'] = 'sphere1'\nv = graph.addVertex('roi')\nmesh = aims.SurfaceGenerator.sphere([0, 0, 100], 10, 100)\naims.GraphManip.storeAims(graph, v, 'aims_mesh', mesh)\nv['name'] = 'sphere2'\n\n# create a corresponding nomenclature\nhie = aims.Hierarchy()\nhie.setSyntax('hierarchy')\nhie['graph_syntax'] = 'RoiArg'\nn = aims.Tree(True, 'fold_name')\nn['name'] = 'sphere1'\nn['color'] = aims.vector_S32([255, 255, 0])\nhie.insert(n)\nn = aims.Tree(True, 'fold_name')\nn['name'] = 'sphere2'\nn['color'] = aims.vector_S32([0, 255, 0])\nhie.insert(n)\n\nrunloop = Qt.QApplication.instance() is not None\n\n# create anatomist objects\na = ana.Anatomist()\nahie = a.toAObject(hie)\nahie.releaseAppRef()\nagraph = a.toAObject(graph)\nagraph.releaseAppRef()\n\n# display graph\nw = a.createWindow('3D')\nw.addObjects(agraph, add_children=True)\nbr = a.createWindow('Browser')\nbr.addObjects(ahie)\n\nw.sphinx_gallery_snapshot()\n\nif runloop and 'sphinx_gallery' not in sys.modules:\n    Qt.QApplication.instance().exec_()\nif runloop or 'sphinx_gallery' in sys.modules:\n    del w, br, agraph, ahie, v, graph, hie, n"
      ], 
      "outputs": [], 
      "metadata": {
        "collapsed": false
      }
    }
  ], 
  "metadata": {
    "kernelspec": {
      "display_name": "Python 2", 
      "name": "python2", 
      "language": "python"
    }, 
    "language_info": {
      "mimetype": "text/x-python", 
      "nbconvert_exporter": "python", 
      "name": "python", 
      "file_extension": ".py", 
      "version": "2.7.17", 
      "pygments_lexer": "ipython2", 
      "codemirror_mode": {
        "version": 2, 
        "name": "ipython"
      }
    }
  }
}