{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "#

     Volume renderings in Lightning" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "##
Setup" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from lightning import Lightning\n", "\n", "from colorsys import hsv_to_rgb\n", "from numpy import ndarray, linspace" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Connect to server" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
Lightning initialized
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "Connected to server at http://public.lightning-viz.org\n" ] }, { "data": { "application/javascript": [ "(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require==\"function\"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error(\"Cannot find module '\"+o+\"'\")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require==\"function\"&&require;for(var o=0;o" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "lgn = Lightning(ipython=True, host='http://public.lightning-viz.org')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "##
Color cubes" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Volume rendering lets you render a sequence of images as a 3D volume.\n", "
\n", "Lightining currently assumes isotropic images, so the sampling in x,y, and z should be comparable.\n", "
\n", "Visualizing color spaces is a fun way to explore volume rendering. We'll generate RGB and HSV cubes." ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [], "source": [ "nx, ny, nz = (50, 50, 50)\n", "rgb = ndarray((nx,ny,nz,3))\n", "hsv = ndarray((nx,ny,nz,3))\n", "for i, ii in enumerate(linspace(0,1,nx)):\n", " for j, jj in enumerate(linspace(0,1,ny)):\n", " for k, kk in enumerate(linspace(0,1,nz)):\n", " position = (i, j, k)\n", " rgb[position] = (kk, jj, ii)\n", " hsv[position] = hsv_to_rgb(jj, ii, kk)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Render RGB cube" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "lgn.volume([x for x in rgb])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Render HSV cube" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "lgn.volume([x for x in hsv])" ] } ], "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.9" } }, "nbformat": 4, "nbformat_minor": 0 }