{
  "nbformat_minor": 0, 
  "nbformat": 4, 
  "cells": [
    {
      "execution_count": null, 
      "cell_type": "code", 
      "source": [
        "%matplotlib inline"
      ], 
      "outputs": [], 
      "metadata": {
        "collapsed": false
      }
    }, 
    {
      "source": [
        "\nFusion3D example\n================\n\nFusion3D (mesh + texture from a volume) in Anatomist\n\n"
      ], 
      "cell_type": "markdown", 
      "metadata": {}
    }, 
    {
      "execution_count": null, 
      "cell_type": "code", 
      "source": [
        "from __future__ import absolute_import\nimport anatomist.api as anatomist\n# to expand the mesh bigger\nfrom soma import aims\nfrom soma.qt_gui.qt_backend import Qt\nimport numpy as np\nimport sys\n\nrunloop = False\nif Qt.QApplication.instance() is None:\n    runloop = True\n\n# initialize Anatomist\na = anatomist.Anatomist()\n\n# load a volume in anatomist\navol = a.loadObject('irm.ima')\namesh = a.loadObject('test.mesh')\n\n# this is to make the mesh bigger compared to the volume size\ntr = aims.AffineTransformation3d()\ntr.fromMatrix(np.matrix([[8., 0, 0, 204.4],\n                         [0, 8., 0, 132.5],\n                         [0, 0, 8., 68.4]]))\naims.SurfaceManip.meshTransform(amesh.toAimsObject(), tr)\namesh.UpdateMinAndMax()\n\n# fusion the objects\nfusion = a.fusionObjects(objects=[avol, amesh], method=\"Fusion3DMethod\")\n# params of the fusion\na.execute(\"Fusion3DParams\", object=fusion,\n          method=\"line\", submethod=\"mean\", depth=4, step=1)\n\n# open a window\nwin = a.createWindow('Axial')\n# put volume in window\na.addObjects([fusion], [win])\n\n# export the fusion texture in a file.\nfusion.exportTexture(\"fusion.tex\")\n\n\n# display in matplotlib for sphinx_gallery\nimport matplotlib\nmatplotlib.use('agg', force=True)  # force agg\nwin.imshow(show=True)\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 fusion, win, amesh, avol, tr"
      ], 
      "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"
      }
    }
  }
}