diff --git a/yt-volume_rendering/1_simple_render_and_tf.ipynb b/yt-volume_rendering/1_simple_render_and_tf.ipynb new file mode 100644 index 0000000..840c4dc --- /dev/null +++ b/yt-volume_rendering/1_simple_render_and_tf.ipynb @@ -0,0 +1,86 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "import yt\n", + "import numpy as np\n", + "from yt.testing import fake_vr_orientation_test_ds\n", + "\n", + "ds = fake_vr_orientation_test_ds()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "# now we do volume rendering\n", + "sc = yt.create_scene(ds, field='density')\n", + "sc.render()\n", + "sc.show(sigma_clip=6.0)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "# now we do volume rendering\n", + "sc = yt.create_scene(ds, field='density')\n", + "# Change transfer function\n", + "tf = yt.ColorTransferFunction((np.log10(0.1), np.log10(1.)))\n", + "tf.sample_colormap(np.log10(0.9), 0.01, colormap=\"spectral\")\n", + "tf.sample_colormap(np.log10(0.8), 0.01, colormap=\"spectral\")\n", + "tf.sample_colormap(np.log10(0.6), 0.01, colormap=\"spectral\")\n", + "tf.sample_colormap(np.log10(0.2), 0.01, colormap=\"spectral\")\n", + "render_source = sc.get_source(0)\n", + "render_source.transfer_function = tf" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "sc.render()\n", + "sc.show(sigma_clip=6.0)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/yt-volume_rendering/2_camera_and_lens.ipynb b/yt-volume_rendering/2_camera_and_lens.ipynb new file mode 100644 index 0000000..3690f96 --- /dev/null +++ b/yt-volume_rendering/2_camera_and_lens.ipynb @@ -0,0 +1,135 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "import yt\n", + "import numpy as np\n", + "from yt.testing import fake_vr_orientation_test_ds\n", + "\n", + "ds = fake_vr_orientation_test_ds()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "# now we do volume rendering\n", + "sc = yt.create_scene(ds, field='density')\n", + "# Change transfer function\n", + "tf = yt.ColorTransferFunction((np.log10(0.1), np.log10(1.)))\n", + "tf.sample_colormap(np.log10(0.9), 0.01, colormap=\"spectral\")\n", + "tf.sample_colormap(np.log10(0.8), 0.01, colormap=\"spectral\")\n", + "tf.sample_colormap(np.log10(0.6), 0.01, colormap=\"spectral\")\n", + "tf.sample_colormap(np.log10(0.2), 0.01, colormap=\"spectral\")\n", + "render_source = sc.get_source(0)\n", + "render_source.transfer_function = tf" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "# plane-parallel lens\n", + "cam = sc.add_camera(ds, lens_type='plane-parallel')\n", + "cam.resolution = (500, 500) # equivalent with cam.set_resolution()\n", + "cam.width = ds.quan(4, 'code_length') # equivalent with cam.set_width()\n", + "cam.position = ds.arr([2.5, 0, 0], 'code_length') # equivalent with cam.set_position()\n", + "cam.switch_orientation(normal_vector=[-1, 0, 0],\n", + " north_vector=[0, 0, 1])\n", + "sc.render()\n", + "sc.show(sigma_clip=2.0)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "# perspective lens\n", + "cam = sc.add_camera(ds, lens_type='perspective')\n", + "cam.resolution = (500, 500)\n", + "cam.width = ds.arr([2, 2, 1], 'code_length')\n", + "cam.position = ds.arr([2.5, 0, 0], 'code_length')\n", + "cam.switch_orientation(normal_vector=[-1, 0, 0],\n", + " north_vector=[0 ,0, 1])\n", + "sc.render()\n", + "sc.show(sigma_clip=6.0)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "# spherical lens\n", + "cam = sc.add_camera(ds, lens_type='spherical')\n", + "cam.resolution = (1000, 500)\n", + "cam.position = ds.arr([0.5, 0, 0], 'code_length')\n", + "cam.switch_orientation(normal_vector=[-1 ,0 ,0],\n", + " north_vector=[0 ,0 ,1])\n", + "sc.render()\n", + "sc.show(sigma_clip=6.0)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "# stereo-spherical lens (another similar lens is stereo-perspective)\n", + "cam = sc.add_camera(ds, lens_type='stereo-spherical')\n", + "cam.disparity = ds.domain_width[0] * 1.5e-3 # separation between two eyes\n", + "cam.resolution = (1000, 1000)\n", + "cam.position = ds.arr([0.5, 0, 0], 'code_length')\n", + "cam.switch_orientation(normal_vector=[-1 ,0, 0],\n", + " north_vector=[0, 0, 1])\n", + "sc.render()\n", + "sc.show(sigma_clip=6.0)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/yt-volume_rendering/3_move_camera.ipynb b/yt-volume_rendering/3_move_camera.ipynb new file mode 100644 index 0000000..1715ed2 --- /dev/null +++ b/yt-volume_rendering/3_move_camera.ipynb @@ -0,0 +1,128 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "import yt\n", + "import numpy as np\n", + "from yt.testing import fake_vr_orientation_test_ds\n", + "\n", + "ds = fake_vr_orientation_test_ds()\n", + "\n", + "# now we do volume rendering\n", + "sc = yt.create_scene(ds, field='density')\n", + "# Change transfer function\n", + "tf = yt.ColorTransferFunction((np.log10(0.1), np.log10(1.)))\n", + "tf.sample_colormap(np.log10(0.9), 0.01, colormap=\"spectral\")\n", + "tf.sample_colormap(np.log10(0.8), 0.01, colormap=\"spectral\")\n", + "tf.sample_colormap(np.log10(0.6), 0.01, colormap=\"spectral\")\n", + "tf.sample_colormap(np.log10(0.2), 0.01, colormap=\"spectral\")\n", + "render_source = sc.get_source(0)\n", + "render_source.transfer_function = tf" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "# perspective camera\n", + "cam = sc.add_camera(ds, lens_type='perspective')\n", + "cam.resolution = (500, 500)\n", + "cam.width = ds.arr([2, 2, 1], 'code_length')\n", + "cam.position = ds.arr([2.5, 0, 0], 'code_length')\n", + "cam.switch_orientation(normal_vector=[-1, 0, 0],\n", + " north_vector=[0, 0, 1])\n", + "sc.render()\n", + "sc.show(sigma_clip=6.0)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "# move cam by one step\n", + "cam.position = ds.arr([4, 0, 0], 'code_length')\n", + "sc.render()\n", + "sc.show(sigma_clip=6.0)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "# move cam by several steps\n", + "final_position = ds.arr([2.5, 0, 0], 'code_length')\n", + "for i in cam.iter_move(final_position, 5):\n", + " sc.save('move_%04d' % i, sigma_clip=6.0)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "# rotate cam by one step\n", + "rot_center = ds.arr([0, 0, 0], 'code_length')\n", + "angle = np.pi / 4.\n", + "cam.rotate(angle, rot_vector=[0, 0, 1], rot_center=rot_center)\n", + "sc.render()\n", + "sc.show(sigma_clip=6.0)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "# rotate cam by several steps\n", + "final_angle = -np.pi / 2.\n", + "for i in cam.iter_rotate(final_angle, 5, rot_vector=[-1, 1, 0], rot_center=rot_center):\n", + " sc.save('rotation_%04d' % i, sigma_clip=6.0)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +}