{
  "nbformat_minor": 0, 
  "nbformat": 4, 
  "cells": [
    {
      "execution_count": null, 
      "cell_type": "code", 
      "source": [
        "%matplotlib inline"
      ], 
      "outputs": [], 
      "metadata": {
        "collapsed": false
      }
    }, 
    {
      "source": [
        "\nAIMS / Anatomist volume manipulation\n====================================\n\nLoading, handling and viewing a Volume with aims and anatomist\n\n"
      ], 
      "cell_type": "markdown", 
      "metadata": {}
    }, 
    {
      "execution_count": null, 
      "cell_type": "code", 
      "source": [
        "from __future__ import absolute_import\nimport anatomist.direct.api as anatomist\nfrom soma import aims\nfrom soma.qt_gui.qt_backend import Qt\nimport sys\n\n# load any volume as a aims.Volume_* object\nvol = aims.read('irm.ima')\n\nrunloop = False\nif Qt.QApplication.instance() is None:\n    runloop = True\n\n# initialize Anatomist\na = anatomist.Anatomist()\n\n# convert the AimsData volume to Anatomist API\navol = a.toAObject(vol)\navol.releaseAppRef()\n\nwin = a.createWindow('Axial')\n\n# put volume in window\nwin.addObjects(avol)\n\n# volume change and update test\n\n# using Numeric API\narr = vol.arraydata()\n# we're just printing a white square in the middle of the volume\narr[0, 50:70, 100:130, 100:130] = 255\n\n# update Anatomist object and its views\navol.setChanged()\navol.notifyObservers()\n\n\n# fusion test\n\n# have a second volume. We could have loaded another one\n# (and it would have been nicer on screen). This example also\n# shows the ability to share the volume data with multiple anatomist/aims\n# objects\navol2 = a.toAObject(vol)\navol2.releaseAppRef()\n\n# set a different palette on the second object so we can see something\na.setObjectPalette(avol2, 'Blue-Red-fusion')\n\n# another view\nwin2 = a.createWindow('Axial')\n\na.addObjects(avol2, win2)\n\n# create the fusion object\nfus = a.fusionObjects([avol, avol2], 'Fusion2DMethod')\n\n# show it\nwin3 = a.createWindow('Sagittal')\n\na.addObjects(fus, win3)\n\n\n# display in matplotlib for sphinx_gallery\nwin3.sphinx_gallery_snapshot()\nif runloop and 'sphinx_gallery' not in sys.modules:\n    Qt.QApplication.instance().exec_()\nif runloop or 'sphinx_gallery' in sys.modules:\n    del win, win2, win3, fus, avol, arr, avol2"
      ], 
      "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"
      }
    }
  }
}