{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "##
Slice in a volume bounded by an isosurface

Brain slice
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "A 3D array stores the values of a scalar field defined on a volume. We illustrate how is defined a slice in the sub-volume bounded by an isosurface, without visualizing the isosurface.\n", " \n", "We are using the same data file, `MNI152.npy`, as in the notebook `13-Isosurface-Marching-Cube-Meshing_jl.ipynb` \n", "Hence, here is drawn a slice in the brain illustrated in that notebook. " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "using PlotlyJS\n", "using NPZ\n", "include(\"src/plotlyju.jl\");" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "brain_vol = npzread(\"data/MNI152.npy\");\n", "m, n, p= size(brain_vol)\n", "\n", "x = 1:m\n", "y = 1:n\n", "z = 1:p\n", "X = [xi for xi in x, yi in y, zi in z]\n", "Y = [yi for xi in x, yi in y, zi in z]\n", "Z = [zi for xi in x, yi in y, zi in z];\n", "\n", "pl_brain = [[0.0, \"#4a4b66\"], #custom colorscale for brain, derived from Matplotlib bone\n", " [0.125, \"#5d617d\"],\n", " [0.25, \"#707b8f\"],\n", " [0.375, \"#8294a1\"],\n", " [0.5, \"#94aeb4\"],\n", " [0.625, \"#aac5c7\"],\n", " [0.75, \"#c5dada\"],\n", " [0.875, \"#e2eded\"],\n", " [1.0, \"#ffffff\"]];\n", "\n", "isosurf = isosurface(surface_show=false, surface_count=1, \n", " colorscale=pl_brain,\n", " showscale=false,\n", " x=vec(X),\n", " y=vec(Y),\n", " z=vec(Z),\n", " value=vec(brain_vol),\n", " slices=attr(x= attr(show=true, \n", " fill= 1.0, \n", " locations= [43])), \n", " isomin= 0, \n", " isomax= maximum(brain_vol))\n", "\n", "\n", "layout= Layout(width=500, \n", " height=500, \n", " scene=attr(camera=attr(eye=attr(x=1.48, y=1.48, z=0.6)),\n", " #xaxis=attr(visible=false),\n", " #yaxis=attr(visible=false), \n", " #zaxis=attr(visible=false),\n", " aspectmode=\"data\"),\n", " margin=attr(t=10, r=0, b=8, l=0))\n", "\n", "\n", "\n", "pl = Plot(isosurf, layout, style=plotlyju)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![MNI-x-slice](images/xslice43.png)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Animation: successive x-slices." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![anim](images/x-slices-anim.gif)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "@webio": { "lastCommId": null, "lastKernelId": null }, "kernelspec": { "display_name": "Julia 1.6.1", "language": "julia", "name": "julia-1.6" }, "language_info": { "file_extension": ".jl", "mimetype": "application/julia", "name": "julia", "version": "1.6.1" } }, "nbformat": 4, "nbformat_minor": 2 }