{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "fd3ae2cc4d53416c918729a89d0dc30e", "version_major": 2, "version_minor": 0 }, "text/plain": [ "interactive(children=(IntSlider(value=2, description='color', max=3), Output()), _dom_classes=('widget-interac…" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "aad45ba0cc4245d08235b88cfe6c53c8", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Output()" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import k3d\n", "import numpy as np\n", "from ipywidgets import interact, IntSlider\n", "\n", "width = height = length = 3\n", "\n", "color_map = (0xFF0000, 0x00FF00, 0x0000FF)\n", "voxels = np.ones(width * height * length, dtype=np.uint8).reshape((length, height, width))\n", "obj = k3d.voxels(voxels, color_map)\n", "\n", "plot = k3d.plot(voxel_paint_color=2)\n", "plot += obj\n", "\n", "@interact(color=IntSlider(value=plot.voxel_paint_color, min=0, max=len(color_map)))\n", "def color(color):\n", " plot.voxel_paint_color = color\n", "\n", "plot.display()" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n", " 1, 1, 1, 1, 1], dtype=uint8)" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "obj.voxels.flatten() # initial data" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Edit object (add/remove some voxels)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "plot.mode = 'change'" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "obj.fetch_data('voxels') # this is an async operation" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n", " 1, 1, 1, 1, 1], dtype=uint8)" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "obj.voxels.flatten() # updated data" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "obj.visible = False" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "obj.visible = True" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.3" }, "nbTranslate": { "displayLangs": [ "en", "pl" ], "hotkey": "alt-t", "langInMainMenu": true, "sourceLang": "pl", "targetLang": "en", "useGoogleTranslate": true } }, "nbformat": 4, "nbformat_minor": 4 }