<commit_before>{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import k3d\n",
    "import math\n",
    "\n",
    "# Y-Z flip\n",
    "model_matrix = [\n",
    "    1.0, 0.0, 0.0, 0.0,\n",
    "    0.0, -1.0, 0.0, 0.0,\n",
    "    0.0, 0.0, 1.0, 0.0,\n",
    "    0.0, 0.0, 0.0, 1.0\n",
    "]\n",
    "\n",
    "texture = k3d.texture(open('assets/texture.png', 'br').read(), 'png', \n",
    "                      rotation=[math.radians(90),1,0,0], \n",
    "                      model_matrix = model_matrix)\n",
    "\n",
    "plot = k3d.plot()\n",
    "plot += texture\n",
    "plot.display()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "texture.binary = open('assets/mandelbrot.jpg', 'br').read()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from k3d.helpers import download\n",
    "filename = download('https://github.com/FNNDSC/data/raw/master/nifti/adi_brain/adi_brain.nii.gz')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import nibabel as nib\n",
    "nii_source = nib.load(filename)\n",
    "img = nii_source.get_fdata()\n",
    "dx, dy, dz = nii_source.header.get_zooms()\n",
    "img = np.swapaxes(img,0,2)\n",
    "nz, ny, nx = img.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from ipywidgets import widgets,interact\n",
    "import numpy as np\n",
    "\n",
    "plot = k3d.plot()\n",
    "\n",
    "bounds = [0, nx * dx, 0, ny * dy, 0, nz * dz]\n",
    "\n",
    "texture = k3d.texture(attribute=img[0,:,:], \n",
    "                      color_map=k3d.basic_color_maps.Jet, \n",
    "                      color_range=[0.0, 1024.0],\n",
    "                      bounds=bounds)\n",
    "plot += texture\n",
    "\n",
    "@interact(x=widgets.IntRangeSlider(value=[0, 1024], min=0, max=np.max(img), step=1, description='Color range:'))\n",
    "def g(x):\n",
    "    texture.color_range = x\n",
    "    \n",
    "@interact(z=widgets.IntSlider(value=0,min=0,max=img.shape[0]-1,step=1, description='Slice:'))\n",
    "def g(z):\n",
    "    texture.attribute =img[z, :, :]\n",<commit_msg>transform fixes + texture example<commit_after>{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import k3d\n",
    "import math\n",
    "import numpy as np\n",
    "\n",
    "# Y-Z flip\n",
    "model_matrix = [\n",
    "    1.0, 0.0, 0.0, 0.0,\n",
    "    0.0, -1.0, 0.0, 0.0,\n",
    "    0.0, 0.0, 1.0, 0.0,\n",
    "    0.0, 0.0, 0.0, 1.0\n",
    "]\n",
    "\n",
    "texture = k3d.texture(open('assets/texture.png', 'br').read(), 'png', \n",
    "                      rotation=[math.radians(90),1,0,0], \n",
    "                      model_matrix = model_matrix)\n",
    "\n",
    "plot = k3d.plot()\n",
    "plot += texture\n",
    "plot.display()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "texture.binary = open('assets/mandelbrot.jpg', 'br').read()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from k3d.helpers import download\n",
    "filename = download('https://github.com/FNNDSC/data/raw/master/nifti/adi_brain/adi_brain.nii.gz')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import nibabel as nib\n",
    "nii_source = nib.load(filename)\n",
    "img = nii_source.get_fdata()\n",
    "dx, dy, dz = nii_source.header.get_zooms()\n",
    "img = np.swapaxes(img,0,2)\n",
    "nz, ny, nx = img.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from ipywidgets import widgets,interact\n",
    "\n",
    "plot = k3d.plot()\n",
    "\n",
    "bounds = [0, nx * dx, 0, ny * dy, 0, nz * dz]\n",
    "\n",
    "texture = k3d.texture(attribute=img[0,:,:], \n",
    "                      color_map=k3d.basic_color_maps.Jet, \n",
    "                      color_range=[0.0, 1024.0],\n",
    "                      bounds=bounds)\n",
    "plot += texture\n",
    "\n",
    "@interact(x=widgets.IntRangeSlider(value=[0, 1024], min=0, max=np.max(img), step=1, description='Color range:'))\n",
    "def g(x):\n",
    "    texture.color_range = x\n",
    "    \n",
    "@interact(z=widgets.IntSlider(value=0,min=0,max=img.shape[0]-1,step=1, description='Slice:'))\n",
    "def g(z):\n",
    "    texture.attribute =img[z, :, :]\n",
{'fraction_non_alphanumeric': 0.23842018196856907, 'fraction_numerical': 0.028535980148883373, 'mean_word_length': 2.2354515050167225, 'pattern_counts': {'":': 52, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1642694', 'n_tokens_mistral': 2064, 'n_tokens_neox': 1974, 'n_words': 320}